From 69151630b33f0509637f9da3ded192b54276f477 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Thu, 8 Oct 2015 01:59:19 +0200 Subject: [PATCH] Fix #8 --- Makefile | 4 +- themes/default/lib/Lufi/I18N/en.po | 54 +++++++++++------- themes/default/lib/Lufi/I18N/fr.po | 54 +++++++++++------- themes/default/public/js/lufi-files.js | 79 +++++++++++++++++++++++++- themes/default/templates/files.html.ep | 13 ++++- 5 files changed, 157 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index 1c20f55..bc0b782 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ REAL_LUFI=script/application LUFI=script/lufi locales: - $(XGETTEXT) -f $(EXTRACTFILES) -o $(EN) - $(XGETTEXT) -f $(EXTRACTFILES) -o $(FR) + $(XGETTEXT) -f $(EXTRACTFILES) -o $(EN) 2>/dev/null + $(XGETTEXT) -f $(EXTRACTFILES) -o $(FR) 2>/dev/null test: $(CARTON) $(REAL_LUFI) test diff --git a/themes/default/lib/Lufi/I18N/en.po b/themes/default/lib/Lufi/I18N/en.po index a12a7ca..5ca046a 100644 --- a/themes/default/lib/Lufi/I18N/en.po +++ b/themes/default/lib/Lufi/I18N/en.po @@ -65,23 +65,23 @@ msgstr "" msgid "Copy to clipboard" msgstr "" -#: lib/Lufi/Controller/Files.pm:282 +#: lib/Lufi/Controller/Files.pm:284 msgid "Could not find the file. Are you sure of the URL and the token?" msgstr "" -#: lib/Lufi/Controller/Files.pm:210 +#: lib/Lufi/Controller/Files.pm:212 msgid "Could not find the file. Are you sure of the URL?" msgstr "" -#: themes/default/templates/files.html.ep:17 +#: themes/default/templates/files.html.ep:25 msgid "Counter" msgstr "" -#: themes/default/templates/files.html.ep:18 themes/default/templates/index.html.ep:58 +#: themes/default/templates/files.html.ep:26 themes/default/templates/index.html.ep:58 msgid "Delete at first download?" msgstr "" -#: themes/default/templates/files.html.ep:21 themes/default/templates/index.html.ep:84 +#: themes/default/templates/files.html.ep:29 themes/default/templates/index.html.ep:84 msgid "Deletion link" msgstr "" @@ -93,7 +93,7 @@ msgstr "" msgid "Download" msgstr "" -#: themes/default/templates/files.html.ep:16 themes/default/templates/index.html.ep:85 +#: themes/default/templates/files.html.ep:24 themes/default/templates/index.html.ep:85 msgid "Download link" msgstr "" @@ -117,15 +117,15 @@ msgstr "" msgid "Emails" msgstr "" -#: lib/Lufi/Controller/Files.pm:146 +#: lib/Lufi/Controller/Files.pm:148 msgid "Error: the file existed but has been deleted." msgstr "" -#: lib/Lufi/Controller/Files.pm:187 +#: lib/Lufi/Controller/Files.pm:189 msgid "Error: the file has not been send entirely." msgstr "" -#: lib/Lufi/Controller/Files.pm:192 +#: lib/Lufi/Controller/Files.pm:194 msgid "Error: unable to find the file. Are you sure of your URL?" msgstr "" @@ -133,15 +133,19 @@ msgstr "" msgid "Expiration:" msgstr "" -#: themes/default/templates/files.html.ep:20 +#: themes/default/templates/files.html.ep:28 msgid "Expires at" msgstr "" -#: lib/Lufi/Controller/Files.pm:266 +#: themes/default/templates/files.html.ep:12 +msgid "Export localStorage data" +msgstr "" + +#: lib/Lufi/Controller/Files.pm:268 msgid "File deleted" msgstr "" -#: themes/default/templates/files.html.ep:15 +#: themes/default/templates/files.html.ep:23 msgid "File name" msgstr "" @@ -185,6 +189,10 @@ msgstr "" msgid "If you send the mail from this server, the links will be send to the server, which may lower your privacy protection." msgstr "" +#: themes/default/templates/files.html.ep:14 +msgid "Import localStorage data" +msgstr "" + #: themes/default/templates/index.html.ep:30 msgid "Important: more information on delays" msgstr "" @@ -210,11 +218,11 @@ msgid "My files" msgstr "" #. (format_bytes($json->{size}) -#: lib/Lufi/Controller/Files.pm:45 +#: lib/Lufi/Controller/Files.pm:47 msgid "No enough space available on the server for this file (size: %1)." msgstr "" -#: themes/default/templates/files.html.ep:33 themes/default/templates/index.html.ep:91 +#: themes/default/templates/files.html.ep:41 themes/default/templates/index.html.ep:91 msgid "No expiration delay" msgstr "" @@ -235,7 +243,7 @@ msgstr "" msgid "Privacy" msgstr "" -#: themes/default/templates/files.html.ep:6 +#: themes/default/templates/files.html.ep:11 msgid "Purge expired files from localStorage" msgstr "" @@ -264,7 +272,7 @@ msgstr "" msgid "Sorry, the uploading is currently disabled. Please try again later." msgstr "" -#: lib/Lufi/Controller/Files.pm:33 +#: lib/Lufi/Controller/Files.pm:35 msgid "Sorry, uploading is disabled." msgstr "" @@ -272,6 +280,10 @@ msgstr "" msgid "The administrator can only see the file's name, its size and its mimetype (what kind of file it is: video, text, etc)." msgstr "" +#: themes/default/templates/files.html.ep:42 +msgid "The data has been successfully imported." +msgstr "" + #: lib/Lufi/Controller/Mail.pm:32 msgid "The email body can't be empty." msgstr "" @@ -280,7 +292,7 @@ msgstr "" msgid "The email subject can't be empty." msgstr "" -#: lib/Lufi/Controller/Files.pm:263 +#: lib/Lufi/Controller/Files.pm:265 msgid "The file has already been deleted" msgstr "" @@ -307,12 +319,12 @@ msgid "This server sets limitations according to the file size. The expiration d msgstr "" #. ($short) -#: lib/Lufi/Controller/Files.pm:247 +#: lib/Lufi/Controller/Files.pm:249 msgid "Unable to get counter for %1. The file does not exists. It will be removed from your localStorage." msgstr "" #. ($short) -#: lib/Lufi/Controller/Files.pm:237 +#: lib/Lufi/Controller/Files.pm:239 msgid "Unable to get counter for %1. The token is unvalid." msgstr "" @@ -320,7 +332,7 @@ msgstr "" msgid "Upload files" msgstr "" -#: themes/default/templates/files.html.ep:19 +#: themes/default/templates/files.html.ep:27 msgid "Uploaded at" msgstr "" @@ -361,7 +373,7 @@ msgid "You must give email addresses." msgstr "" #. (format_bytes($json->{size}) -#: lib/Lufi/Controller/Files.pm:39 +#: lib/Lufi/Controller/Files.pm:41 msgid "Your file is too big: %1 (maximum size allowed: %2)" msgstr "" diff --git a/themes/default/lib/Lufi/I18N/fr.po b/themes/default/lib/Lufi/I18N/fr.po index 3d37593..2927037 100644 --- a/themes/default/lib/Lufi/I18N/fr.po +++ b/themes/default/lib/Lufi/I18N/fr.po @@ -71,23 +71,23 @@ msgstr "Copier tous les liens dans le presse-papier" msgid "Copy to clipboard" msgstr "Copier dans le presse-papier" -#: lib/Lufi/Controller/Files.pm:282 +#: lib/Lufi/Controller/Files.pm:284 msgid "Could not find the file. Are you sure of the URL and the token?" msgstr "Impossible de retrouver le fichier. Êtes-vous sûr(e) que l’URL et le jeton sont les bons ?" -#: lib/Lufi/Controller/Files.pm:210 +#: lib/Lufi/Controller/Files.pm:212 msgid "Could not find the file. Are you sure of the URL?" msgstr "Impossible de retrouver le fichier. Êtes-vous sûr(e) que l’URL est la bonne ?" -#: themes/default/templates/files.html.ep:17 +#: themes/default/templates/files.html.ep:25 msgid "Counter" msgstr "Compteur" -#: themes/default/templates/files.html.ep:18 themes/default/templates/index.html.ep:58 +#: themes/default/templates/files.html.ep:26 themes/default/templates/index.html.ep:58 msgid "Delete at first download?" msgstr "Supprimer après le premier téléchargement ?" -#: themes/default/templates/files.html.ep:21 themes/default/templates/index.html.ep:84 +#: themes/default/templates/files.html.ep:29 themes/default/templates/index.html.ep:84 msgid "Deletion link" msgstr "Lien de suppression" @@ -99,7 +99,7 @@ msgstr "Ne vous inquiétez pas : si un utilisateur commence à télécharger le msgid "Download" msgstr "Télécharger" -#: themes/default/templates/files.html.ep:16 themes/default/templates/index.html.ep:85 +#: themes/default/templates/files.html.ep:24 themes/default/templates/index.html.ep:85 msgid "Download link" msgstr "Lien de téléchargement" @@ -123,15 +123,15 @@ msgstr "Sujet du mail" msgid "Emails" msgstr "Mails" -#: lib/Lufi/Controller/Files.pm:146 +#: lib/Lufi/Controller/Files.pm:148 msgid "Error: the file existed but has been deleted." msgstr "Erreur : le fichier existait mais a été supprimé" -#: lib/Lufi/Controller/Files.pm:187 +#: lib/Lufi/Controller/Files.pm:189 msgid "Error: the file has not been send entirely." msgstr "Erreur : le fichier n’a pas été envoyé dans son intégralité" -#: lib/Lufi/Controller/Files.pm:192 +#: lib/Lufi/Controller/Files.pm:194 msgid "Error: unable to find the file. Are you sure of your URL?" msgstr "Erreur : impossible de retrouver le fichier. Êtes-vous sûr(e) de l’URL ?" @@ -139,15 +139,19 @@ msgstr "Erreur : impossible de retrouver le fichier. Êtes-vous sûr(e) de l’ msgid "Expiration:" msgstr "Expiration :" -#: themes/default/templates/files.html.ep:20 +#: themes/default/templates/files.html.ep:28 msgid "Expires at" msgstr "Expire le" -#: lib/Lufi/Controller/Files.pm:266 +#: themes/default/templates/files.html.ep:12 +msgid "Export localStorage data" +msgstr "Exporter les données localStorage" + +#: lib/Lufi/Controller/Files.pm:268 msgid "File deleted" msgstr "Fichier supprimé" -#: themes/default/templates/files.html.ep:15 +#: themes/default/templates/files.html.ep:23 msgid "File name" msgstr "Nom du fichier" @@ -191,6 +195,10 @@ msgstr "Si vous choisissez un délai, le fichier sera supprimé après ce délai msgid "If you send the mail from this server, the links will be send to the server, which may lower your privacy protection." msgstr "Si vous envoyer le mail depuis ce serveur, les liens seront envoyés au serveur, ce qui peut diminuer la protection de la confidentialité." +#: themes/default/templates/files.html.ep:14 +msgid "Import localStorage data" +msgstr "Importer des données localStorage" + #: themes/default/templates/index.html.ep:30 msgid "Important: more information on delays" msgstr "Important : plus d’informations sur les délais" @@ -216,11 +224,11 @@ msgid "My files" msgstr "Mes fichiers" #. (format_bytes($json->{size}) -#: lib/Lufi/Controller/Files.pm:45 +#: lib/Lufi/Controller/Files.pm:47 msgid "No enough space available on the server for this file (size: %1)." msgstr "Espace disque insuffisant sur le serveur pour ce fichier (taille du fichier: %1)." -#: themes/default/templates/files.html.ep:33 themes/default/templates/index.html.ep:91 +#: themes/default/templates/files.html.ep:41 themes/default/templates/index.html.ep:91 msgid "No expiration delay" msgstr "Pas de délai d’expiration" @@ -245,7 +253,7 @@ msgstr "Veuillez patienter pendant la récupération de votre fichier" msgid "Privacy" msgstr "Confidentialité" -#: themes/default/templates/files.html.ep:6 +#: themes/default/templates/files.html.ep:11 msgid "Purge expired files from localStorage" msgstr "Supprimer du localStorage les fichiers expirés" @@ -274,7 +282,7 @@ msgstr "Partagez vos fichiers en toute confidentialité sur %1" msgid "Sorry, the uploading is currently disabled. Please try again later." msgstr "Désolé, l’envoi de fichier est actuellement désactivé. Veuillez réessayer plus tard." -#: lib/Lufi/Controller/Files.pm:33 +#: lib/Lufi/Controller/Files.pm:35 msgid "Sorry, uploading is disabled." msgstr "Désolé, l’envoi de fichier est désactivé." @@ -282,6 +290,10 @@ msgstr "Désolé, l’envoi de fichier est désactivé." msgid "The administrator can only see the file's name, its size and its mimetype (what kind of file it is: video, text, etc)." msgstr "L’administrateur ne peut voir que le nom du fichier, sa taille et son type mime (son type de fichier : vidéo, text, etc)." +#: themes/default/templates/files.html.ep:42 +msgid "The data has been successfully imported." +msgstr "Les données ont été importées avec succès." + #: lib/Lufi/Controller/Mail.pm:32 msgid "The email body can't be empty." msgstr "Le corps du mail ne peut être vide." @@ -290,7 +302,7 @@ msgstr "Le corps du mail ne peut être vide." msgid "The email subject can't be empty." msgstr "Le sujet du mail ne peut être vide." -#: lib/Lufi/Controller/Files.pm:263 +#: lib/Lufi/Controller/Files.pm:265 msgid "The file has already been deleted" msgstr "Le fichier a déjà été supprimé" @@ -321,12 +333,12 @@ msgid "Unable to get counter for %1. The file does not exists." msgstr "Impossible de récupérer le compteur de %1. Le fichier n’existe pas." #. ($short) -#: lib/Lufi/Controller/Files.pm:247 +#: lib/Lufi/Controller/Files.pm:249 msgid "Unable to get counter for %1. The file does not exists. It will be removed from your localStorage." msgstr "Impossible de récupérer le compteur pour %1. Le fichier n’existe pas. Il va être supprimé de votre localStorage." #. ($short) -#: lib/Lufi/Controller/Files.pm:237 +#: lib/Lufi/Controller/Files.pm:239 msgid "Unable to get counter for %1. The token is unvalid." msgstr "Impossible de récupérer le compteur pour %1. Le jeton est invalide." @@ -334,7 +346,7 @@ msgstr "Impossible de récupérer le compteur pour %1. Le jeton est invalide." msgid "Upload files" msgstr "Envoyer des fichiers" -#: themes/default/templates/files.html.ep:19 +#: themes/default/templates/files.html.ep:27 msgid "Uploaded at" msgstr "Envoyé le" @@ -375,7 +387,7 @@ msgid "You must give email addresses." msgstr "Vous devez envoyer des adresses mail." #. (format_bytes($json->{size}) -#: lib/Lufi/Controller/Files.pm:39 +#: lib/Lufi/Controller/Files.pm:41 msgid "Your file is too big: %1 (maximum size allowed: %2)" msgstr "Votre fichier est trop volumineux : %1 (la taille maximum autorisée est %2)" diff --git a/themes/default/public/js/lufi-files.js b/themes/default/public/js/lufi-files.js index e6f9786..36719d1 100644 --- a/themes/default/public/js/lufi-files.js +++ b/themes/default/public/js/lufi-files.js @@ -1,3 +1,15 @@ +// Add item to localStorage +function addItem(item) { + var files = localStorage.getItem('files'); + if (files === null) { + files = new Array(); + } else { + files = JSON.parse(files); + } + files.push(item); + localStorage.setItem('files', JSON.stringify(files)); +} + function delItem(name) { var files = localStorage.getItem('files'); if (files === null) { @@ -14,6 +26,22 @@ function delItem(name) { localStorage.setItem('files', JSON.stringify(files)); } +function itemExists(name) { + var files = localStorage.getItem('files'); + if (files === null) { + return false; + } else { + files = JSON.parse(files); + var i; + for (i = 0; i < files.length; i++) { + if (files[i].short === name) { + return true; + } + } + return false; + } +} + function purgeExpired() { var files = JSON.parse(localStorage.getItem('files')); @@ -36,9 +64,58 @@ function purgeExpired() { }); } +function exportStorage() { + var a = document.createElement("a"); + a.style = "display: none"; + document.body.appendChild(a); + + var storageData = [localStorage.getItem('files')]; + var exportFile = new File(storageData, 'data.json', {type : 'application/json'}); + var url = window.URL.createObjectURL(exportFile); + + a.href = url; + a.setAttribute('download', 'data.json'); + a.click(); + a.remove(); +} + +function importStorage(f) { + var reader = new FileReader(); + reader.addEventListener("loadend", function() { + try { + var newFiles = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(reader.result))); + var i; + var hasImported = 0; + for (i = 0; i < newFiles.length; i++) { + var item = newFiles[i]; + if (!itemExists(item.short)) { + addItem(item); + hasImported++; + } + } + populateFilesTable(); + + alert(i18n.importProcessed); + } catch(err) { + alert(err); + } + }); + reader.readAsArrayBuffer(f[0]); +} + function populateFilesTable() { + document.getElementById('myfiles').innerHTML = ''; + var files = JSON.parse(localStorage.getItem('files')); - files.reverse(); + files.sort(function(a, b) { + if (a.created_at < b.created_at) { + return -1; + } else if (a.created_at > b.created_at) { + return 1; + } else { + return 0 + } + }); files.forEach(function(element, index, array) { var del_view = (element.del_at_first_view) ? '' : ''; var dlink = baseURL+'d/'+element.short+'/'+element.token; diff --git a/themes/default/templates/files.html.ep b/themes/default/templates/files.html.ep index c27200c..77a6e66 100644 --- a/themes/default/templates/files.html.ep +++ b/themes/default/templates/files.html.ep @@ -2,11 +2,19 @@

<%= l('My files') %>


+

- <%= l('Purge expired files from localStorage') %> <%= l('Only the files sent with this browser will be listed here. The informations are stored in localStorage: if you delete your localStorage data, you\'ll loose this informations.') %>
<%= l('Rows in red means that the file has expired and is no longer available.') %>

+

+ <%= l('Purge expired files from localStorage') %> + <%= l('Export localStorage data') %> + +

@@ -30,7 +38,8 @@ var baseURL = '<%== url_for('/')->to_abs() %>'; var counterURL = '<%== url_for('counter') %>'; var i18n = { - noExpiration: '<%= l('No expiration delay') %>', + noExpiration: '<%= l('No expiration delay') %>', + importProcessed: '<%= l('The data has been successfully imported.') %>', }; document.addEventListener('DOMContentLoaded', function() { populateFilesTable();