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 = $('
  • ', { diff --git a/www/drive/tests.js b/www/drive/tests.js index 015178208..1633740bc 100644 --- a/www/drive/tests.js +++ b/www/drive/tests.js @@ -268,9 +268,21 @@ define([ assert(function (cb) { console.log('START DRIVE utils'); var files = JSON.parse(JSON.stringify(example)); + + var href6 = "/pad/#67a9385b07352be53e40746d2be6ccd7XAYSuJYYqa9NfmInyGbj7LNy/"; + var id6 = 1000000000006; + var data = { + href: href6, + title: 'Title6', + atime: +new Date(), + ctime: +new Date() + }; + files.filesData[id6] = data; + var fo = FO.init(files, config); fo.fixFiles(); + if (fo.isFile({}) || fo.isFile(href1) || !fo.isFile(href1, true) || !fo.isFile(id1)) { console.log("DRIVE utils: isFile returns an incorrect value"); return cb(); @@ -283,6 +295,10 @@ define([ console.log("DRIVE utils: isReadOnlyFile returns false for a 'view' file"); return cb(); } + if (typeof fo.isReadOnlyFile(id6) !== "undefined") { + console.log("DRIVE utils: isReadOnlyFile should return undefined for a v0 hash"); + return cb(); + } if (!fo.hasSubfolder(files.root.Folder) || fo.hasSubfolder(files.root.Folder2)) { console.log("DRIVE utils: hasSubfolder returns an incorrect value"); return cb(); @@ -303,7 +319,7 @@ define([ console.log("DRIVE utils: 'find' returns an incorrect value"); return cb(); } - if (fo.getFiles().length !== 4 || fo.getFiles(['trash']).length !== 2) { + if (fo.getFiles().length !== 5 || fo.getFiles(['trash']).length !== 2) { console.log("DRIVE utils: getFiles returns an incorrect value"); return cb(); }