Recent pads improvements

pull/1/head
yflory 6 years ago
parent c9e53d9ab9
commit 5a19f7cc5d

@ -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); }

@ -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);

@ -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);
};

@ -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;

@ -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 = $('<li>', {

@ -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();
}

Loading…
Cancel
Save