From: pablozg Date: Tue, 24 Apr 2018 19:20:01 +0000 (+0200) Subject: webui: Added custom date format field in config tab X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ec30caa97c6bf554edca17fb319e1f51b730810;p=thirdparty%2Ftvheadend.git webui: Added custom date format field in config tab --- diff --git a/src/config.c b/src/config.c index ce899a744..a6c024249 100644 --- a/src/config.c +++ b/src/config.c @@ -1704,6 +1704,7 @@ config_boot config.theme_ui = strdup("blue"); config.chname_num = 1; config.iptv_tpool_count = 2; + config.date_mask = strdup(""); idclass_register(&config_class); @@ -1839,6 +1840,7 @@ void config_done ( void ) free(config.chicon_path); free(config.picon_path); free(config.cors_origin); + free(config.date_mask); file_unlock(config_lock, config_lock_fd); } @@ -2226,6 +2228,15 @@ const idclass_t config_class = { .off = offsetof(config_t, chname_src), .group = 2 }, + { + .type = PT_STR, + .id = "date_mask", + .name = N_("Custom date Format"), + .desc = N_("Custom date mask like (%yyyy-%M-%dd %h:%m:%s)"), + .opts = PO_ADVANCED, + .off = offsetof(config_t, date_mask), + .group = 2, + }, { .type = PT_STR, .islist = 1, diff --git a/src/config.h b/src/config.h index 39680475d..91c167b8b 100644 --- a/src/config.h +++ b/src/config.h @@ -67,6 +67,7 @@ typedef struct config { uint32_t epg_cut_window; uint32_t epg_update_window; int iptv_tpool_count; + char *date_mask; } config_t; extern const idclass_t config_class; diff --git a/src/webui/comet.c b/src/webui/comet.c index 4a41292bc..ed917fc46 100644 --- a/src/webui/comet.c +++ b/src/webui/comet.c @@ -191,6 +191,7 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb) htsmsg_add_u32(m, "quicktips", config.ui_quicktips); htsmsg_add_u32(m, "chname_num", config.chname_num); htsmsg_add_u32(m, "chname_src", config.chname_src); + htsmsg_add_str(m, "date_mask", config.date_mask); if (!access_noacl) htsmsg_add_str(m, "username", username); if (hc->hc_peer_ipstr) diff --git a/src/webui/static/app/epg.js b/src/webui/static/app/epg.js index 597bda416..6ab139eea 100644 --- a/src/webui/static/app/epg.js +++ b/src/webui/static/app/epg.js @@ -506,7 +506,11 @@ tvheadend.epg = function() { if (value) { var dt = new Date(value); - return dt.format('D, M d, H:i'); + if (tvheadend.date_mask.length > 1){ + return tvheadend.toCustomDate(dt,tvheadend.date_mask); + }else{ + return tvheadend.toCustomDate(dt,'%ddd, %MMMM %dd, %hh:%mm'); + } } return ""; } diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 18d8e8a55..fe1048a40 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -370,7 +370,7 @@ tvheadend.IdNodeField = function(conf) return function(v) { if (v > 0) { var dt = new Date(v * 1000); - return dt.toLocaleDateString(); + return dt.toLocaleDateString(tvheadend.toLocaleFormat()); } return ''; } @@ -378,8 +378,11 @@ tvheadend.IdNodeField = function(conf) return function(v) { if (v > 0) { var dt = new Date(v * 1000); - var wd = dt.toLocaleString(tvheadend.language, {weekday: 'short'}); - return wd + ' ' + dt.toLocaleString(); + if (tvheadend.date_mask.length > 1){ + return tvheadend.toCustomDate(dt,tvheadend.date_mask); + }else{ + return tvheadend.toCustomDate(dt,'%ddd %dd/%MM/%YYYY, %hh:%mm:%ss'); + } } return ''; } @@ -754,8 +757,8 @@ tvheadend.idnode_editor_field = function(f, conf) if (!f.duration) { if (d) { var dt = new Date(value * 1000); - value = f.date ? dt.toLocaleDateString() : - dt.toLocaleString(); + value = f.date ? dt.toLocaleDateString(tvheadend.toLocaleFormat()) : + dt.toLocaleString(tvheadend.toLocaleFormat()); r = new Ext.form.TextField({ fieldLabel: f.caption, name: f.id, @@ -3016,4 +3019,4 @@ tvheadend.idnode_simple = function(panel, conf) }); tvheadend.idnode_panel(conf, panel, dpanel, builder, destroyer); -}; +}; \ No newline at end of file diff --git a/src/webui/static/app/tvheadend.js b/src/webui/static/app/tvheadend.js index c776f610c..40e5b0ef3 100644 --- a/src/webui/static/app/tvheadend.js +++ b/src/webui/static/app/tvheadend.js @@ -12,6 +12,7 @@ tvheadend.wizard = null; tvheadend.docs_toc = null; tvheadend.doc_history = []; tvheadend.doc_win = null; +tvheadend.date_mask = ''; tvheadend.language = window.navigator.userLanguage || window.navigator.language; // Use en-US if browser language detection fails. @@ -744,8 +745,8 @@ Ext.Ajax.request({ */ tvheadend.niceDate = function(dt) { var d = new Date(dt); - return '
' + d.toLocaleString(tvheadend.language, {weekday: 'long'}) + '
' + - '
' + d.toLocaleDateString() + '
' + + return '
' + d.toLocaleString(tvheadend.toLocaleFormat(), {weekday: 'long'}) + '
' + + '
' + d.toLocaleDateString(tvheadend.toLocaleFormat()) + '
' + '
' + d.toLocaleTimeString() + '
'; } @@ -787,8 +788,8 @@ tvheadend.niceDateYearMonth = function(dt, refdate) { } } } - return '
' + d.toLocaleString(tvheadend.language, {weekday: 'long'}) + '
' + - '
' + d.toLocaleDateString() + '
'; + return '
' + d.toLocaleString(tvheadend.toLocaleFormat(), {weekday: 'long'}) + '
' + + '
' + d.toLocaleDateString(tvheadend.toLocaleFormat()) + '
'; } /* @@ -998,6 +999,7 @@ function accessUpdate(o) { tvheadend.quicktips = o.quicktips ? true : false; tvheadend.chname_num = o.chname_num ? 1 : 0; tvheadend.chname_src = o.chname_src ? 1 : 0; + tvheadend.date_mask = o.date_mask; if (o.uilevel_nochange) tvheadend.uilevel_nochange = true; @@ -1336,7 +1338,7 @@ tvheadend.RootTabPanel = Ext.extend(Ext.TabPanel, { var d = stime ? new Date(stime) : new Date(); var el = Ext.get(panel.extra.time.tabEl).child('span.x-tab-strip-extra-comp', true); el.innerHTML = '' + d.toLocaleTimeString() + ''; - el.qtip = d.toLocaleString(); + el.qtip = d.toLocaleString(tvheadend.toLocaleFormat()); }, onLoginCmdClicked: function(e) { @@ -1352,6 +1354,42 @@ tvheadend.RootTabPanel = Ext.extend(Ext.TabPanel, { }); +/* + * Return tvh_locale_lang in date().toLocaleDateString() compatible format + */ +tvheadend.toLocaleFormat = function() +{ + return tvh_locale_lang.replace('_','-'); +}; + +tvheadend.toCustomDate = function(date, format) //author: meizz, improvements by pablozg +{ + var o = { + "\%M+" : date.getMonth()+1, //month + "\%d+" : date.getDate(), //day + "\%h+" : date.getHours(), //hour + "\%m+" : date.getMinutes(), //minute + "\%s+" : date.getSeconds(), //second + "\%q+" : Math.floor((date.getMonth()+3)/3), //quarter + "\%S" : date.getMilliseconds() //millisecond + } + + if(/(\%[yY]+)/.test(format)) format=format.replace(RegExp.$1, (date.getFullYear()+"").substr(5 - RegExp.$1.length)); + + if(/(\%MMMM)/.test(format)) format=format.replace(RegExp.$1, (date.toLocaleDateString('es', {month: 'long'}))); + + if(/(\%MMM)/.test(format)) format=format.replace(RegExp.$1, (date.toLocaleDateString('es', {month: 'short'}))); + + if(/(\%dddd)/.test(format)) format=format.replace(RegExp.$1, (date.toLocaleDateString('es', {weekday: 'long'}))); + + if(/(\%ddd)/.test(format)) format=format.replace(RegExp.$1, (date.toLocaleDateString('es', {weekday: 'short'}))); + + for(var k in o) if(new RegExp("("+ k +")").test(format)) + format = format.replace(RegExp.$1, RegExp.$1.length==2 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); + + return format; +} + /** * */