Add SKYType timespan (WIP)

master
Harald Wolff 2019-05-15 13:14:59 +02:00
parent 3137017450
commit a01c7e3f50
2 changed files with 63 additions and 4 deletions

View File

@ -52,7 +52,8 @@
{ name: "Age", type: "int", label: "Alter" },
{ name: "Comment", type: null, label: "Anmerkungen" },
{ name: "IP", type: "ipv4" },
{ name: "Network", type: "network4" }
{ name: "Network", type: "network4" },
{ name: "TimeLeft", type: "timespan", label: "Übrige Zeit" },
]
}
@ -62,21 +63,24 @@
Age: 14,
Comment: "none",
IP: "1.2.3.4",
Network: "1.2.3.0/24"
Network: "1.2.3.0/24",
TimeLeft: 86870
},
{
Name: "Second Demo Item",
Age: 45,
Comment: "none",
IP: "5.6.7.8",
Network: "1.2.3.0/24"
Network: "1.2.3.0/24",
TimeLeft: 6324
},
{
Name: "Third Demo Item",
Age: 87,
Comment: "some",
IP: "3.4.5.6",
Network: "1.2.3.0/24"
Network: "1.2.3.0/24",
TimeLeft: 324
},
];

View File

@ -61,6 +61,24 @@
this._html.attr("type","number");
}
}
class SKYTimeSpanEditor extends SKYEditor {
constructor(){
super("0d 00:00:00","^([0-9]{1,}d){0,1} {1,}[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$");
}
value(value){
if (arguments.length)
{
this._html
.val(SKY.type("timespan").render(value))
.data("value", value);
return this;
}
return this._html.val();
}
}
class SKYType {
constructor(name){
@ -110,9 +128,46 @@
}
class SKYTimeSpanType extends SKYType
{
constructor(){
super("timespan");
}
editor(){
return new SKYTimeSpanEditor();
}
render(value){
var days, hours, minutes, seconds;
value = parseInt(value);
days = parseInt(value / 86400);
value %= 86400;
hours = parseInt(value / 3600);
value %= 3600;
minutes = parseInt(value / 60);
value %= 60;
seconds = parseInt(value);
var r = "";
if (days > 0)
r += `${days}d `;
r += `${SKY.tools.ntos(hours,2)}:${SKY.tools.ntos(minutes,2)}:${SKY.tools.ntos(seconds,2)}`;
return r;
}
parse(t){
}
}
new SKYType(null);
new SKYIntType();
new SKYIPv4Type();
new SKYNetwork4Type();
new SKYTimeSpanType();
}(SKY));