mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-01 04:13:28 +01:00
implement new "units" parameter to limit used units in date-since widget
eg. <date-since units="d" shows age in days
This commit is contained in:
parent
9e655d4de2
commit
26e09680c2
@ -1060,6 +1060,7 @@ var et2_date_ro = /** @class */ (function (_super) {
|
|||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
et2_date_ro.prototype.set_value = function (_value) {
|
et2_date_ro.prototype.set_value = function (_value) {
|
||||||
|
var _this = this;
|
||||||
if (typeof _value == 'undefined')
|
if (typeof _value == 'undefined')
|
||||||
_value = 0;
|
_value = 0;
|
||||||
this.value = _value;
|
this.value = _value;
|
||||||
@ -1156,9 +1157,16 @@ var et2_date_ro = /** @class */ (function (_super) {
|
|||||||
var d = new Date();
|
var d = new Date();
|
||||||
var diff = Math.round(d.valueOf() / 1000) - Math.round(this.date.valueOf() / 1000);
|
var diff = Math.round(d.valueOf() / 1000) - Math.round(this.date.valueOf() / 1000);
|
||||||
display = '';
|
display = '';
|
||||||
|
// limit units used to display
|
||||||
|
var smallest = 's';
|
||||||
|
if (this.options.units) {
|
||||||
|
var valid = Object.entries(unit2s).filter(function (e) { return _this.options.units.includes(e[0]); });
|
||||||
|
unit2s = Object.fromEntries(valid);
|
||||||
|
smallest = (valid.pop() || [])[0];
|
||||||
|
}
|
||||||
for (var unit in unit2s) {
|
for (var unit in unit2s) {
|
||||||
var unit_s = unit2s[unit];
|
var unit_s = unit2s[unit];
|
||||||
if (diff >= unit_s || unit == 's') {
|
if (diff >= unit_s || unit === smallest) {
|
||||||
display = Math.round(diff / unit_s) + ' ' + this.egw().lang(unit2label[unit]);
|
display = Math.round(diff / unit_s) + ' ' + this.egw().lang(unit2label[unit]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1232,6 +1240,10 @@ var et2_date_ro = /** @class */ (function (_super) {
|
|||||||
"ignore": true,
|
"ignore": true,
|
||||||
"description": "Format data is in. This is not used client-side because it's always a timestamp client side."
|
"description": "Format data is in. This is not used client-side because it's always a timestamp client side."
|
||||||
},
|
},
|
||||||
|
units: {
|
||||||
|
"type": "string",
|
||||||
|
"descriptions": "Used units for date-since, default 'YmdHis', e.g. 'd' to display a value in days"
|
||||||
|
},
|
||||||
min: { ignore: true },
|
min: { ignore: true },
|
||||||
max: { ignore: true },
|
max: { ignore: true },
|
||||||
year_range: { ignore: true }
|
year_range: { ignore: true }
|
||||||
|
@ -1227,6 +1227,10 @@ export class et2_date_ro extends et2_valueWidget implements et2_IDetachedDOM
|
|||||||
"ignore": true,
|
"ignore": true,
|
||||||
"description": "Format data is in. This is not used client-side because it's always a timestamp client side."
|
"description": "Format data is in. This is not used client-side because it's always a timestamp client side."
|
||||||
},
|
},
|
||||||
|
units: {
|
||||||
|
"type": "string",
|
||||||
|
"descriptions": "Used units for date-since, default 'YmdHis', e.g. 'd' to display a value in days"
|
||||||
|
},
|
||||||
min: {ignore: true},
|
min: {ignore: true},
|
||||||
max: {ignore: true},
|
max: {ignore: true},
|
||||||
year_range: {ignore: true}
|
year_range: {ignore: true}
|
||||||
@ -1360,7 +1364,7 @@ export class et2_date_ro extends et2_valueWidget implements et2_IDetachedDOM
|
|||||||
'i': 'minutes',
|
'i': 'minutes',
|
||||||
's': 'seconds'
|
's': 'seconds'
|
||||||
};
|
};
|
||||||
var unit2s = {
|
var unit2s : Object = {
|
||||||
'Y': 31536000,
|
'Y': 31536000,
|
||||||
'm': 2628000,
|
'm': 2628000,
|
||||||
'd': 86400,
|
'd': 86400,
|
||||||
@ -1372,10 +1376,19 @@ export class et2_date_ro extends et2_valueWidget implements et2_IDetachedDOM
|
|||||||
var diff = Math.round(d.valueOf() / 1000) - Math.round(this.date.valueOf()/1000);
|
var diff = Math.round(d.valueOf() / 1000) - Math.round(this.date.valueOf()/1000);
|
||||||
display = '';
|
display = '';
|
||||||
|
|
||||||
|
// limit units used to display
|
||||||
|
let smallest = 's';
|
||||||
|
if (this.options.units)
|
||||||
|
{
|
||||||
|
const valid = Object.entries(unit2s).filter((e) => (<string>this.options.units).includes(e[0]));
|
||||||
|
unit2s = Object.fromEntries(valid);
|
||||||
|
smallest = (valid.pop() || [])[0];
|
||||||
|
}
|
||||||
|
|
||||||
for(var unit in unit2s)
|
for(var unit in unit2s)
|
||||||
{
|
{
|
||||||
var unit_s = unit2s[unit];
|
var unit_s = unit2s[unit];
|
||||||
if (diff >= unit_s || unit == 's')
|
if (diff >= unit_s || unit === smallest)
|
||||||
{
|
{
|
||||||
display = Math.round(diff/unit_s)+' '+this.egw().lang(unit2label[unit]);
|
display = Math.round(diff/unit_s)+' '+this.egw().lang(unit2label[unit]);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user