From 837d6a2b8b5f841309fcb8892545c9a6884d4af2 Mon Sep 17 00:00:00 2001 From: Frank Bergkemper Date: Mon, 30 Jan 2017 18:16:21 +0100 Subject: [PATCH] Fix to bugreport #752 Fixes #752: Retention/Expiration column not sorted by number --- module/Media/view/media/media/index.phtml | 12 ++++++++++- public/js/datatables.functions.js | 25 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/module/Media/view/media/media/index.phtml b/module/Media/view/media/media/index.phtml index 6f88966c..8100dcea 100644 --- a/module/Media/view/media/media/index.phtml +++ b/module/Media/view/media/media/index.phtml @@ -163,7 +163,8 @@ $(document).ready(function() { { "data": null }, { "type": "file-size", "data": "maxvolbytes" }, { "type": "file-size", "data": "volbytes" }, - { "data": "lastwritten" } + { "data": "lastwritten" }, + { "data": null } ], "columnDefs": [ { @@ -181,6 +182,7 @@ $(document).ready(function() { }, { "targets": 6, + "orderData": 10, "render": function(data, type, full, meta) { return formatExpiration(data.volstatus, data.lastwritten, data.volretention); } @@ -201,6 +203,14 @@ $(document).ready(function() { "targets": 9, "visible": false, "searchable": false + }, + { + "targets": 10, + "visible": false, + "searchable": false, + "render": function(data, type, full, meta) { + return formatHiddenRetExp(data.volstatus, data.lastwritten, data.volretention); + } } ], "buttons": [ diff --git a/public/js/datatables.functions.js b/public/js/datatables.functions.js index bd5a9b66..0d48b814 100644 --- a/public/js/datatables.functions.js +++ b/public/js/datatables.functions.js @@ -190,6 +190,31 @@ function formatExpiration(volstatus, lastwritten, volretention) { } } +function formatHiddenRetExp(volstatus, lastwritten, volretention) { + if(volstatus == iJS._("Used") || volstatus == iJS._("Full")) { + if(lastwritten == null || lastwritten == "") { + return 100000000000; + } + else { + var d = Date.now() / 1000; + var a = lastwritten.split(" "); + var b = new Date(a[0]).getTime() / 1000; + var interval = (d - b) / (3600 * 24); + var retention = Math.round(volretention / 60 / 60 / 24); + var expiration = (retention - interval).toFixed(2); + return Math.ceil(expiration); + } + } + else { + // This is kind of ugly but expiration can also be a negativ value, but somehow we need to sort numerical. + // As a workaround we move the area of unused volumes with a retention way down into the negativ by + // prepending a large negativ number out of the scope of the usual rentention times commonly used + // to avoid further problems. + // TODO: Find a better sorting solution for the Retention/Expiration column. + return Math.ceil('-1000000000000'+(volretention / 60 / 60 / 24)); + } +} + function formatLastWritten(data) { if(data == null || data == '' || data == 0) { return iJS._('never');