diff --git a/src/sunstone/public/app/app.js b/src/sunstone/public/app/app.js index 5d14d3416e..fa7375a729 100644 --- a/src/sunstone/public/app/app.js +++ b/src/sunstone/public/app/app.js @@ -294,6 +294,33 @@ define(function(require) { } } + jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "date-euro-pre": function ( a ) { + var x; + + if ( $.trim(a) !== '' ) { + var frDatea = $.trim(a).split(' '); + var frTimea = (undefined != frDatea[1]) ? frDatea[1].split(':') : [00,00,00]; + var frDatea2 = frDatea[0].split('/'); + x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + ((undefined != frTimea[2]) ? frTimea[2] : 0)) * 1; + } + else { + x = Infinity; + } + + return x; + }, + + "date-euro-asc": function ( a, b ) { + return a - b; + }, + + "date-euro-desc": function ( a, b ) { + return b - a; + } + + }); + //source https://cdn.datatables.net/plug-ins/1.10.12/type-detection/ip-address.js (modified) jQuery.fn.dataTableExt.aTypes.unshift( function ( sData ) diff --git a/src/sunstone/public/app/tabs/marketplaceapps-tab/datatable.js b/src/sunstone/public/app/tabs/marketplaceapps-tab/datatable.js index 57087ed5e8..7e145bf86e 100644 --- a/src/sunstone/public/app/tabs/marketplaceapps-tab/datatable.js +++ b/src/sunstone/public/app/tabs/marketplaceapps-tab/datatable.js @@ -75,7 +75,8 @@ define(function(require) { {"sWidth": "35px", "aTargets": [0]}, {"bVisible": true, "aTargets": SunstoneConfig.tabTableColumns(TAB_NAME)}, {"bVisible": false, "aTargets": ['_all']}, - {"sType": "file-size", "aTargets": [ 6 ] } + {"sType": "file-size", "aTargets": [ 6 ]}, + {"sType": "date-euro", "aTargets": [ 9 ]} ] } @@ -150,7 +151,7 @@ define(function(require) { Humanize.sizeFromMB(element.SIZE), state, OpenNebulaMarketPlaceApp.typeStr(element.TYPE), - Humanize.prettyTime(element.REGTIME), + Humanize.prettyTimeDatatable(element.REGTIME), element.MARKETPLACE, zone, (LabelsUtils.labelsStr(element[TEMPLATE_ATTR])||''), diff --git a/src/sunstone/public/app/tabs/templates-tab/datatable-common.js b/src/sunstone/public/app/tabs/templates-tab/datatable-common.js index 15c5d861dd..6d5074d5ac 100644 --- a/src/sunstone/public/app/tabs/templates-tab/datatable-common.js +++ b/src/sunstone/public/app/tabs/templates-tab/datatable-common.js @@ -58,7 +58,8 @@ define(function(require) { {"bSortable": false, "aTargets": ["check"]}, {"sWidth": "35px", "aTargets": [0]}, {"bVisible": true, "aTargets": SunstoneConfig.tabTableColumns(tabId)}, - {"bVisible": false, "aTargets": ['_all']} + {"bVisible": false, "aTargets": ['_all']}, + {"sType": "date-euro", "aTargets": [ 5 ]} ] } @@ -118,7 +119,7 @@ define(function(require) { element.NAME, element.UNAME, element.GNAME, - Humanize.prettyTime(element.REGTIME), + Humanize.prettyTimeDatatable(element.REGTIME), (LabelsUtils.labelsStr(element[TEMPLATE_ATTR])||''), btoa(unescape(encodeURIComponent(JSON.stringify(search)))) ]; diff --git a/src/sunstone/public/app/utils/humanize.js b/src/sunstone/public/app/utils/humanize.js index b62a93ef40..cc3ca2def0 100644 --- a/src/sunstone/public/app/utils/humanize.js +++ b/src/sunstone/public/app/utils/humanize.js @@ -32,7 +32,8 @@ define(function(require) { 'prettyTime': _prettyTime, 'prettyTimeAxis': _prettyTimeAxis, 'prettyPrintJSON': _prettyPrintJSON, - 'prettyTimeAgo': _format_date + 'prettyTimeAgo': _format_date, + 'prettyTimeDatatable': _prettyTimeDatatable } /* @@ -240,6 +241,20 @@ define(function(require) { return str; } + function _prettyTimeDatatable(seconds) { + var d = new Date(); + d.setTime(seconds * 1000); + + var secs = _pad(d.getSeconds(), 2); + var hour = _pad(d.getHours(), 2); + var mins = _pad(d.getMinutes(), 2); + var day = _pad(d.getDate(), 2); + var month = _pad(d.getMonth() + 1, 2); //getMonths returns 0-11 + var year = d.getFullYear(); + + return day + "/" + month + "/" + year + " " + hour + ":" + mins + ":" + secs; + } + function _format_date(unix_timestamp) { var difference_in_seconds = (Math.round((new Date()).getTime() / 1000)) - unix_timestamp, current_date = new Date(unix_timestamp * 1000), minutes, hours;