Sort templates by usage in the PCS
This commit is contained in:
parent
52d6c9d468
commit
ec0fc85b9f
@ -1780,11 +1780,15 @@ define([
|
|||||||
var sframeChan = common.getSframeChannel();
|
var sframeChan = common.getSframeChannel();
|
||||||
var focus;
|
var focus;
|
||||||
|
|
||||||
var pickerCfg = {
|
var pickerCfgInit = {
|
||||||
types: [type],
|
types: [type],
|
||||||
where: ['template'],
|
where: ['template'],
|
||||||
hidden: true
|
hidden: true
|
||||||
};
|
};
|
||||||
|
var pickerCfg = {
|
||||||
|
types: [type],
|
||||||
|
where: ['template'],
|
||||||
|
};
|
||||||
var onConfirm = function (yes) {
|
var onConfirm = function (yes) {
|
||||||
if (!yes) {
|
if (!yes) {
|
||||||
if (focus) { focus.focus(); }
|
if (focus) { focus.focus(); }
|
||||||
@ -1812,7 +1816,7 @@ define([
|
|||||||
|
|
||||||
sframeChan.query("Q_TEMPLATE_EXIST", type, function (err, data) {
|
sframeChan.query("Q_TEMPLATE_EXIST", type, function (err, data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
common.openFilePicker(pickerCfg);
|
common.openFilePicker(pickerCfgInit);
|
||||||
focus = document.activeElement;
|
focus = document.activeElement;
|
||||||
if (force) { return void onConfirm(true); }
|
if (force) { return void onConfirm(true); }
|
||||||
UI.confirm(Messages.useTemplate, onConfirm, {
|
UI.confirm(Messages.useTemplate, onConfirm, {
|
||||||
@ -1968,10 +1972,13 @@ define([
|
|||||||
if (!res.data || !Array.isArray(res.data)) {
|
if (!res.data || !Array.isArray(res.data)) {
|
||||||
return void console.error("Error: get the templates list");
|
return void console.error("Error: get the templates list");
|
||||||
}
|
}
|
||||||
// TODO Sort the templates by number of use?
|
|
||||||
var data = res.data.slice().sort(function (a, b) {
|
var data = res.data.slice().sort(function (a, b) {
|
||||||
if (a.name === b.name) { return 0; }
|
if (a.used === b.used) {
|
||||||
return a.name < b.name ? -1 : 1;
|
// Sort by name
|
||||||
|
if (a.name === b.name) { return 0; }
|
||||||
|
return a.name < b.name ? -1 : 1;
|
||||||
|
}
|
||||||
|
return b.used - a.used;
|
||||||
}).slice(0, 2);
|
}).slice(0, 2);
|
||||||
data.unshift({
|
data.unshift({
|
||||||
name: Messages.creation_newTemplate,
|
name: Messages.creation_newTemplate,
|
||||||
|
|||||||
@ -424,6 +424,7 @@ define([
|
|||||||
// it allows us to add owners and expiration time if it is a new file
|
// it allows us to add owners and expiration time if it is a new file
|
||||||
var parsed = Hash.parsePadUrl(href);
|
var parsed = Hash.parsePadUrl(href);
|
||||||
if(!parsed) { throw new Error("Cannot get template hash"); }
|
if(!parsed) { throw new Error("Cannot get template hash"); }
|
||||||
|
postMessage("INCREMENT_TEMPLATE_USE", href);
|
||||||
Crypt.get(parsed.hash, function (err, val) {
|
Crypt.get(parsed.hash, function (err, val) {
|
||||||
if (err) { throw new Error(err); }
|
if (err) { throw new Error(err); }
|
||||||
var p = Hash.parsePadUrl(window.location.href);
|
var p = Hash.parsePadUrl(window.location.href);
|
||||||
|
|||||||
@ -660,6 +660,15 @@ define([
|
|||||||
});
|
});
|
||||||
cb(res);
|
cb(res);
|
||||||
};
|
};
|
||||||
|
Store.incrementTemplateUse = function (href) {
|
||||||
|
store.userObject.getPadAttribute(href, 'used', function (err, data) {
|
||||||
|
// This is a not critical function, abort in case of error to make sure we won't
|
||||||
|
// create any issue with the user object or the async store
|
||||||
|
if (err) { return; }
|
||||||
|
var used = typeof data === "number" ? ++data : 1;
|
||||||
|
store.userObject.setPadAttribute(href, 'used', used);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Pads
|
// Pads
|
||||||
Store.moveToTrash = function (data, cb) {
|
Store.moveToTrash = function (data, cb) {
|
||||||
|
|||||||
@ -126,6 +126,9 @@ define([
|
|||||||
case 'GET_STRONGER_HASH': {
|
case 'GET_STRONGER_HASH': {
|
||||||
Store.getStrongerHash(data, cb); break;
|
Store.getStrongerHash(data, cb); break;
|
||||||
}
|
}
|
||||||
|
case 'INCREMENT_TEMPLATE_USE': {
|
||||||
|
Store.incrementTemplateUse(data); break;
|
||||||
|
}
|
||||||
// Messaging
|
// Messaging
|
||||||
case 'INVITE_FROM_USERLIST': {
|
case 'INVITE_FROM_USERLIST': {
|
||||||
Store.inviteFromUserlist(data, cb); break;
|
Store.inviteFromUserlist(data, cb); break;
|
||||||
|
|||||||
@ -431,6 +431,8 @@ define([
|
|||||||
// File picker
|
// File picker
|
||||||
var FP = {};
|
var FP = {};
|
||||||
var initFilePicker = function (cfg) {
|
var initFilePicker = function (cfg) {
|
||||||
|
// cfg.hidden means pre-loading the filepicker while keeping it hidden.
|
||||||
|
// if cfg.hidden is true and the iframe already exists, do nothing
|
||||||
if (!FP.$iframe) {
|
if (!FP.$iframe) {
|
||||||
var config = {};
|
var config = {};
|
||||||
config.onFilePicked = function (data) {
|
config.onFilePicked = function (data) {
|
||||||
@ -449,7 +451,7 @@ define([
|
|||||||
};
|
};
|
||||||
FP.$iframe = $('<iframe>', {id: 'sbox-filePicker-iframe'}).appendTo($('body'));
|
FP.$iframe = $('<iframe>', {id: 'sbox-filePicker-iframe'}).appendTo($('body'));
|
||||||
FP.picker = FilePicker.create(config);
|
FP.picker = FilePicker.create(config);
|
||||||
} else {
|
} else if (!cfg.hidden) {
|
||||||
FP.$iframe.show();
|
FP.$iframe.show();
|
||||||
FP.picker.refresh(cfg);
|
FP.picker.refresh(cfg);
|
||||||
}
|
}
|
||||||
@ -491,7 +493,8 @@ define([
|
|||||||
res.push({
|
res.push({
|
||||||
id: el,
|
id: el,
|
||||||
name: data[el].filename || data[el].title || '?',
|
name: data[el].filename || data[el].title || '?',
|
||||||
thumbnail: thumb
|
thumbnail: thumb,
|
||||||
|
used: data[el].used || 0
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user