diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 35beb1f02..ad40a7989 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -129,6 +129,7 @@ define(function () { out.saveTemplatePrompt = "Choisir un titre pour ce modèle"; out.templateSaved = "Modèle enregistré !"; out.selectTemplate = "Sélectionner un modèle ou appuyer sur Échap"; + out.useTemplate = "Vous posséder des modèles pour ce type de pad, souhaitez-vous en utiliser un?"; out.previewButtonTitle = "Afficher ou cacher la prévisualisation de Markdown"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index b72d58ce0..5415ae147 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -131,6 +131,7 @@ define(function () { out.saveTemplatePrompt = "Choose a title for the template"; out.templateSaved = "Template saved!"; out.selectTemplate = "Select a template or press escape"; + out.useTemplate = "You have available templates for that type of pad. Do you want to use one?"; out.previewButtonTitle = "Display or hide the Markdown preview mode"; diff --git a/pinneddata.js b/pinneddata.js index 0c45228fd..d7848c7df 100644 --- a/pinneddata.js +++ b/pinneddata.js @@ -81,6 +81,7 @@ nThen((waitFor) => { sema.take((returnAfter) => { Fs.stat(f, waitFor(returnAfter((err, st) => { if (err) { throw err; } + st.filename = f; dsFileStats[f.replace(/^.*\/([^\/\.]*)(\.ndjson)?$/, (all, a) => (a))] = st; }))); }); @@ -118,18 +119,27 @@ nThen((waitFor) => { }).nThen(() => { if (process.argv.indexOf('--unpinned') > -1) { const ot = process.argv.indexOf('--olderthan'); - let before = 0; + let before = Infinity; if (ot > -1) { before = new Date(process.argv[ot+1]); if (isNaN(before)) { throw new Error('--olderthan error [' + process.argv[ot+1] + '] not a valid date'); } } + const bot = process.argv.indexOf('--blobsolderthan'); + let blobsbefore = before; + if (bot > -1) { + blobsbefore = new Date(process.argv[bot+1]); + if (isNaN(blobsbefore)) { + throw new Error('--blobsolderthan error [' + process.argv[bot+1] + '] not a valid date'); + } + } Object.keys(dsFileStats).forEach((f) => { if (!(f in pinned)) { - if ((+dsFileStats[f].mtime) >= before) { return; } - console.log("./datastore/" + f.slice(0,2) + "/" + f + ".ndjson " + - dsFileStats[f].size + " " + (+dsFileStats[f].mtime)); + const isBlob = dsFileStats[f].filename.indexOf('.ndjson') === -1; + if ((+dsFileStats[f].mtime) >= ((isBlob) ? blobsbefore : before)) { return; } + console.log(dsFileStats[f].filename + " " + dsFileStats[f].size + " " + + (+dsFileStats[f].mtime)); } }); } else { diff --git a/www/common/sframe-common-interface.js b/www/common/sframe-common-interface.js index 0b38de654..649e55916 100644 --- a/www/common/sframe-common-interface.js +++ b/www/common/sframe-common-interface.js @@ -442,27 +442,37 @@ define([ UI.openTemplatePicker = function (common) { var metadataMgr = common.getMetadataMgr(); var type = metadataMgr.getMetadataLazy().type; - var first = true; // We can only pick a template once (for a new document) - var fileDialogCfg = { - onSelect: function (data) { - if (data.type === type && first) { - Cryptpad.addLoadingScreen({hideTips: true}); - var sframeChan = common.getSframeChannel(); - sframeChan.query('Q_TEMPLATE_USE', data.href, function () { - first = false; - Cryptpad.removeLoadingScreen(); - common.feedback('TEMPLATE_USED'); - }); - return; + var sframeChan = common.getSframeChannel(); + + var onConfirm = function (yes) { + if (!yes) { return; } + var first = true; // We can only pick a template once (for a new document) + var fileDialogCfg = { + onSelect: function (data) { + if (data.type === type && first) { + Cryptpad.addLoadingScreen({hideTips: true}); + sframeChan.query('Q_TEMPLATE_USE', data.href, function () { + first = false; + Cryptpad.removeLoadingScreen(); + common.feedback('TEMPLATE_USED'); + }); + return; + } } - } - }; - common.initFilePicker(common, fileDialogCfg); - var pickerCfg = { - types: [type], - where: ['template'] + }; + common.initFilePicker(fileDialogCfg); + var pickerCfg = { + types: [type], + where: ['template'] + }; + common.openFilePicker(pickerCfg); }; - common.openFilePicker(common, pickerCfg); + + sframeChan.query("Q_TEMPLATE_EXIST", type, function (err, data) { + if (data) { + Cryptpad.confirm(Messages.useTemplate, onConfirm); + } + }); }; return UI; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index df4259dff..79bc868f7 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -297,6 +297,10 @@ define([ sframeChan.on('Q_TEMPLATE_USE', function (href, cb) { Cryptpad.useTemplate(href, Cryptget, cb); }); + sframeChan.on('Q_TEMPLATE_EXIST', function (type, cb) { + var hasTemplate = Cryptpad.listTemplates(type).length > 0; + cb(hasTemplate); + }); CpNfOuter.start({ sframeChan: sframeChan, diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index 9c79b1495..d27a0a77a 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -104,6 +104,8 @@ define({ // Template picked, replace the content of the pad 'Q_TEMPLATE_USE': true, + // Check if we have template(s) for the selected pad type + 'Q_TEMPLATE_EXIST': true, // File upload queries and events 'Q_UPLOAD_FILE': true,