From 6cc046197561d9a85400abf39375f6b2e9309065 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 20 Apr 2023 14:36:09 +0200 Subject: [PATCH 1/6] metadata: delete max upload size control --- app.php | 2 -- public/js/metadata.js | 6 ------ 2 files changed, 8 deletions(-) diff --git a/app.php b/app.php index 31be522..79a6fd7 100644 --- a/app.php +++ b/app.php @@ -355,8 +355,6 @@ $f3->route('POST /organize', $f3->route('GET /metadata', function($f3) { - $f3->set('maxSize', min(array(convertPHPSizeToBytes(ini_get('post_max_size')), convertPHPSizeToBytes(ini_get('upload_max_filesize'))))); - echo View::instance()->render('metadata.html.php'); } ); diff --git a/public/js/metadata.js b/public/js/metadata.js index 9cf40b1..b74774d 100644 --- a/public/js/metadata.js +++ b/public/js/metadata.js @@ -177,12 +177,6 @@ var pageUpload = async function() { document.getElementById('input_pdf_upload').focus(); const cache = await caches.open('pdf'); document.getElementById('input_pdf_upload').addEventListener('change', async function(event) { - if(document.getElementById('input_pdf_upload').files[0].size > maxSize) { - - alert("Le PDF ne doit pas dépasser " + Math.round(maxSize/1024/1024) + " Mo"); - document.getElementById('input_pdf_upload').value = ""; - return; - } let filename = document.getElementById('input_pdf_upload').files[0].name; let response = new Response(document.getElementById('input_pdf_upload').files[0], { "status" : 200, "statusText" : "OK" }); let urlPdf = '/pdf/'+filename; From b30be5b344e2ae5c0e242f488638fe415ccac4c4 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 20 Apr 2023 15:37:01 +0200 Subject: [PATCH 2/6] metadata: fields list by default define in configuration --- config/config.ini.example | 3 +++ public/js/metadata.js | 27 +++++++++++++++++++++++---- templates/metadata.html.php | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/config/config.ini.example b/config/config.ini.example index ee6842a..7611cbd 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -9,3 +9,6 @@ PDF_STORAGE_PATH=/path/to/folder ; Manage demo link pdf : true (by default, show), false (hide), or custom link ;PDF_DEMO_LINK=true + +; Metadata default fields +;METADATA_DEFAULT_FIELDS[metadata_key].type = "text" diff --git a/public/js/metadata.js b/public/js/metadata.js index b280fa0..4979ccb 100644 --- a/public/js/metadata.js +++ b/public/js/metadata.js @@ -33,18 +33,23 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) { await loadingTask.promise.then(function(pdf) { pdf.getMetadata().then(function(metadata) { console.log(metadata); + for(fieldKey in defaultFields) { + addMetadata(fieldKey, null, defaultFields[fieldKey]['type']); + } + for(metaKey in metadata.info) { if(metaKey == "Custom" || metaKey == "PDFFormatVersion" || metaKey.match(/^Is/) || metaKey == "Trapped") { continue; } - addMetadata(metaKey, metadata.info[metaKey]); + addMetadata(metaKey, metadata.info[metaKey], "text"); } + for(metaKey in metadata.info.Custom) { if(metaKey == "sha256") { continue; } - addMetadata(metaKey, metadata.info.Custom[metaKey]); + addMetadata(metaKey, metadata.info.Custom[metaKey], "text"); } for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) { @@ -89,12 +94,26 @@ var pageRender = async function(pageIndex) { }); } -var addMetadata = function(key, value) { +var addMetadata = function(key, value, type) { + let input = document.querySelector('.input-metadata input[name="'+key+'"]'); + + if(input && input.value === null) { + input.value = value; + return; + } + + if(input) { + input.focus(); + return; + } + let div = document.createElement('div'); div.classList.add('form-floating', 'mt-3', 'input-metadata'); - let input = document.createElement('input'); + input = document.createElement('input'); input.value = value; + input.type = type; + input.name = key; input.classList.add('form-control'); let label = document.createElement('label'); diff --git a/templates/metadata.html.php b/templates/metadata.html.php index 1ceac5c..a868f2a 100644 --- a/templates/metadata.html.php +++ b/templates/metadata.html.php @@ -100,7 +100,7 @@ From 4965d7878b7b3b67a029299065e4192bb124001b Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 20 Apr 2023 15:43:20 +0200 Subject: [PATCH 3/6] metadata: autofocus on first input --- public/js/metadata.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/public/js/metadata.js b/public/js/metadata.js index 4979ccb..1811100 100644 --- a/public/js/metadata.js +++ b/public/js/metadata.js @@ -34,14 +34,14 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) { pdf.getMetadata().then(function(metadata) { console.log(metadata); for(fieldKey in defaultFields) { - addMetadata(fieldKey, null, defaultFields[fieldKey]['type']); + addMetadata(fieldKey, null, defaultFields[fieldKey]['type'], false); } for(metaKey in metadata.info) { if(metaKey == "Custom" || metaKey == "PDFFormatVersion" || metaKey.match(/^Is/) || metaKey == "Trapped") { continue; } - addMetadata(metaKey, metadata.info[metaKey], "text"); + addMetadata(metaKey, metadata.info[metaKey], "text", false); } for(metaKey in metadata.info.Custom) { @@ -49,7 +49,7 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) { continue; } - addMetadata(metaKey, metadata.info.Custom[metaKey], "text"); + addMetadata(metaKey, metadata.info.Custom[metaKey], "text", false); } for(let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++ ) { @@ -59,6 +59,9 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) { pageRender(pageIndex); }); } + if(document.querySelector('.input-metadata input')) { + document.querySelector('.input-metadata input').focus(); + } }); }, function (reason) { console.error(reason); @@ -94,16 +97,16 @@ var pageRender = async function(pageIndex) { }); } -var addMetadata = function(key, value, type) { +var addMetadata = function(key, value, type, focus) { let input = document.querySelector('.input-metadata input[name="'+key+'"]'); if(input && input.value === null) { input.value = value; - return; } - - if(input) { + if(input && focus) { input.focus(); + } + if(input) { return; } @@ -128,7 +131,9 @@ var addMetadata = function(key, value, type) { div.appendChild(deleteButton); document.getElementById('form-metadata-container').appendChild(div); - input.focus(); + if(focus) { + input.focus(); + } } const deleteMetadata = function(el) { @@ -164,7 +169,7 @@ const save = async function () { var createEventsListener = function() { document.getElementById('form_metadata_add').addEventListener('submit', function(e) { let formData = new FormData(this); - addMetadata(formData.get('metadata_key'), ""); + addMetadata(formData.get('metadata_key'), "", "text", true); this.classList.add('invisible'); setTimeout(function() { document.getElementById('form_metadata_add').classList.remove('invisible'); }, 400); this.reset(); From 4b0ca8265243dbadf2f6661dc53d792e3678cf10 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 20 Apr 2023 15:44:59 +0200 Subject: [PATCH 4/6] metadata: If any field focus on add field --- public/js/metadata.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/js/metadata.js b/public/js/metadata.js index 1811100..a4c457a 100644 --- a/public/js/metadata.js +++ b/public/js/metadata.js @@ -61,6 +61,8 @@ var loadPDF = async function(pdfBlob, filename, pdfIndex) { } if(document.querySelector('.input-metadata input')) { document.querySelector('.input-metadata input').focus(); + } else { + document.getElementById('input_metadata_key').focus(); } }); }, function (reason) { From 9abd4e848bf8e21ec7f3622fbf642e238e1b5de0 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 20 Apr 2023 15:47:12 +0200 Subject: [PATCH 5/6] metadata: new tab on each page --- templates/organization.html.php | 5 ++++- templates/signature.html.php | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/templates/organization.html.php b/templates/organization.html.php index e940a2c..dad323e 100644 --- a/templates/organization.html.php +++ b/templates/organization.html.php @@ -26,6 +26,9 @@ +

Organiser des PDF

@@ -156,4 +159,4 @@ - \ No newline at end of file + diff --git a/templates/signature.html.php b/templates/signature.html.php index d49e967..43f7f98 100644 --- a/templates/signature.html.php +++ b/templates/signature.html.php @@ -25,6 +25,9 @@ +
From 841cc18ed924cc8e03e23c86a4f82170239b58c7 Mon Sep 17 00:00:00 2001 From: Vincent LAURENT Date: Thu, 20 Apr 2023 15:53:50 +0200 Subject: [PATCH 6/6] metadata: textes --- templates/metadata.html.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/metadata.html.php b/templates/metadata.html.php index a868f2a..e65127e 100644 --- a/templates/metadata.html.php +++ b/templates/metadata.html.php @@ -10,7 +10,7 @@ - Métadonnées d'un PDF + Édition des métadonnées d'un PDF