diff --git a/www/common/outer/userObject.js b/www/common/outer/userObject.js index 46ae72b3b..10e30ba95 100644 --- a/www/common/outer/userObject.js +++ b/www/common/outer/userObject.js @@ -636,7 +636,7 @@ define([ } // If we have an edit link, check the view link - if (el.href && parsed.hashData.type === "pad") { + if (el.href && parsed.hashData.type === "pad" && parsed.hashData.version) { if (parsed.hashData.mode === "view") { el.roHref = el.href; delete el.href; @@ -651,6 +651,10 @@ define([ } } } + // v0 hashes don't support read-only + if (parsed.hashData.version === 0) { + delete el.roHref; + } // Fix href if (el.href && /^https*:\/\//.test(el.href)) { el.href = Hash.getRelativeHref(el.href); } diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index d23ab3ebc..a933da776 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -961,7 +961,20 @@ define([ }; var getRecentPads = function (Env) { - return Env.user.userObject.getRecentPads(); + var files = []; + var userObjects = _getUserObjects(Env); + userObjects.forEach(function (uo) { + var data = uo.getFiles([UserObject.FILES_DATA]).map(function (id) { + return [Number(id), uo.getFileData(id)]; + }); + Array.prototype.push.apply(files, data); + }); + var sorted = files.filter(function (a) { return a[1].atime; }) + .sort(function (a,b) { + return b[1].atime - a[1].atime; + }); + return sorted; + //return Env.user.userObject.getRecentPads(); }; var getOwnedPads = function (Env) { return Env.user.userObject.getOwnedPads(Env.edPublic); diff --git a/www/common/userObject.js b/www/common/userObject.js index ce6a3168d..1a2229d40 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -95,6 +95,8 @@ define([ exp.isReadOnlyFile = function (element) { if (!isFile(element)) { return false; } var data = exp.getFileData(element); + // undefined means this pad doesn't support read-only + if (!data.roHref) { return; } return Boolean(data.roHref && !data.href); }; diff --git a/www/drive/app-drive.less b/www/drive/app-drive.less index 5bf6a7ea8..7a993a5e5 100644 --- a/www/drive/app-drive.less +++ b/www/drive/app-drive.less @@ -509,6 +509,10 @@ } } } + &.cp-app-drive-element-separator { + text-align: left; + font-weight: bold; + } } } .cp-app-drive-element { @@ -521,6 +525,12 @@ &.cp-app-drive-element { position: relative; } + &.cp-app-drive-element-separator { + display: block; + height: auto; + width: auto; + border: none !important; + } input { width: 100%; margin: 0; @@ -600,6 +610,14 @@ height: @variables_bar-height; line-height: @variables_bar-height; } + &.cp-app-drive-element-separator { + position: relative; + height: 1.5 * @variables_bar-height; + line-height: 1.5 * @variables_bar-height; + span { + position: absolute; + } + } &.cp-app-drive-element-header { cursor: default; color: @drive_table-header-fg; diff --git a/www/drive/inner.js b/www/drive/inner.js index 850db5450..a58cee94f 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2454,24 +2454,51 @@ define([ var displayRecent = function ($list) { var filesList = manager.getRecentPads(); var limit = 20; + + var now = new Date(); + var last1 = new Date(now); + last1.setDate(last1.getDate()-1); + var last7 = new Date(now); + last7.setDate(last7.getDate()-7); + var last28 = new Date(now); + last28.setDate(last28.getDate()-28); + + var header7, header28, headerOld; var i = 0; - filesList.forEach(function (id) { - if (i >= limit) { return; } - // Check path (pad exists and not in trash) + $list.append(h('li.cp-app-drive-element-separator', h('span', Messages.drive_active1Day))); + filesList.some(function (arr) { + if (i >= limit) { return true; } + var id = arr[0]; + var file = arr[1]; + if (!file || !file.atime) { return; } + + if (file.atime <= last28 && i >= limit) { + return true; + } + var paths = manager.findFile(id); if (!paths.length) { return; } var path = paths[0]; if (manager.isPathIn(path, [TRASH])) { return; } - // Display the pad - var file = manager.getFileData(id); - if (!file) { - //debug("Unsorted or template returns an element not present in filesData: ", href); - file = { title: Messages.fm_noname }; - //return; + + + if (!header7 && file.atime < last1) { + $list.append(h('li.cp-app-drive-element-separator', h('span', Messages.drive_active7Days))); + header7 = true; + } + if (!header28 && file.atime < last7) { + $list.append(h('li.cp-app-drive-element-separator', h('span', Messages.drive_active28Days))); + header28 = true; } + if (!headerOld && file.atime < last28) { + $list.append(h('li.cp-app-drive-element-separator', h('span', Messages.drive_activeOld))); + headerOld = true; + } + + // Display the pad var $icon = getFileIcon(id); var ro = manager.isReadOnlyFile(id); - // ro undefined mens it's an old hash which doesn't support read-only + // ro undefined means it's an old hash which doesn't support read-only var roClass = typeof(ro) === 'undefined' ? ' cp-app-drive-element-noreadonly' : ro ? ' cp-app-drive-element-readonly' : ''; var $element = $('