refs #5517 json value and date format fixes
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Juan Ferrer 2023-04-06 17:02:45 +02:00
parent f7191f0f7f
commit d7d4b9515e
3 changed files with 53 additions and 33 deletions

View File

@ -15,36 +15,53 @@ export default class Controller extends Component {
}
set value(value) {
const wasEmpty = this._value === undefined;
this._value = value;
const span = this.element;
const formattedValue = this.formatValue(value);
span.textContent = formattedValue;
span.title = typeof value == 'string' && value.length > maxStrLen ? value : '';
span.className = `js-${value == null ? 'null' : typeof value}`;
}
formatValue(value) {
if (value == null) return '∅';
switch (typeof value) {
case 'boolean':
return value ? '✓' : '✗';
case 'string':
return value.length <= maxStrLen
? value
: value.substring(0, maxStrLen) + '...';
case 'object':
if (value instanceof Date) {
const hasZeroTime =
value.getHours() === 0 &&
value.getMinutes() === 0 &&
value.getSeconds() === 0;
const format = hasZeroTime ? 'dd/MM/yyyy' : 'dd/MM/yyyy HH:mm:ss';
return this.$filter('date')(value, format);
} else
return value;
default:
return value;
let text;
let cssClass;
const type = typeof value;
if (value == null) {
text = '∅';
cssClass = 'null';
} else {
cssClass = type;
switch (type) {
case 'boolean':
text = value ? '✓' : '✗';
cssClass = value ? 'true' : 'false';
break;
case 'string':
text = value.length <= maxStrLen
? value
: value.substring(0, maxStrLen) + '...';
break;
case 'object':
if (value instanceof Date) {
const hasZeroTime =
value.getHours() === 0 &&
value.getMinutes() === 0 &&
value.getSeconds() === 0;
const format = hasZeroTime ? 'dd/MM/yyyy' : 'dd/MM/yyyy HH:mm:ss';
text = this.$filter('date')(value, format);
} else
text = value;
break;
default:
text = value;
}
}
const el = this.element;
el.textContent = text;
el.title = type == 'string' && value.length > maxStrLen ? value : '';
cssClass = `json-${cssClass}`;
if (wasEmpty)
el.classList.add(cssClass);
else
el.classList.replace(this.className, cssClass);
}
}

View File

@ -1,20 +1,23 @@
vn-json-value {
display: inline;
&.js-string {
&.json-string {
color: #d172cc;
}
&.js-object {
&.json-object {
/*color: #d1a572;*/
color: #d172cc;
}
&.js-number {
&.json-number {
color: #85d0ff;
}
&.js-boolean {
&.json-true {
color: #7dc489;
}
&.js-null {
&.json-false {
color: #c74949;
}
&.json-null {
color: #cd7c7c;
font-style: italic;
}

View File

@ -97,7 +97,7 @@ export default class Controller extends Section {
format = `'${this.$t('today')}'`;
else if (diff == 1)
format = `'${this.$t('yesterday')}'`;
else if (diff < 7)
else if (diff > 1 && diff < 7)
format = `'${date.toLocaleDateString(this.lang, {weekday: 'short'})}'`;
else if (this.today.getFullYear() == date.getFullYear())
format = `d '${date.toLocaleDateString(this.lang, {month: 'short'})}'`;