diff --git a/app.py b/app.py index 400a138..abc4c8e 100644 --- a/app.py +++ b/app.py @@ -28,12 +28,17 @@ app.config['UPLOAD_FOLDER'] = 'uploads' @app.route('/') def index(): + return redirect("/split", code=302) + + +@app.route('/project') +def project(): return render_template('base.html', page='project', settings='set', error=False) -@app.route('/splitt') +@app.route('/split') def splitt(): - return render_template('base.html', page='splitt', settings='set', error=False) + return render_template('base.html', page='split', settings='set', error=False) @app.route('/merge') @@ -46,11 +51,6 @@ def ocr(): return render_template('base.html', page='ocr', settings='set', error=False) -@app.route('/app/') -def pdf_app(): - return render_template('app.html') - - @app.route('/split/') def send_report(path): return send_from_directory('split', path) diff --git a/static/css/base_styles.css b/static/css/base_styles.css deleted file mode 100644 index cfc3539..0000000 --- a/static/css/base_styles.css +++ /dev/null @@ -1,36 +0,0 @@ -div { - /* border: 2px solid yellowgreen; */ -} - - -.div_float_clear { - clear: both; -} - - -/* The snackbar - position it at the bottom and in the middle of the screen */ -#snackbar { - visibility: hidden; /* Hidden by default. Visible on click */ - min-width: 800px; /* Set a default minimum width */ - margin-left: -400px; /* Divide value of min-width by 2 */ - background-color: #333; /* Black background color */ - color: #fff; /* White text color */ - text-align: center; /* Centered text */ - border-radius: 2px; /* Rounded borders */ - padding: 16px; /* Padding */ - position: fixed; /* Sit on top of the screen */ - z-index: 1; /* Add a z-index if needed */ - left: 50%; /* Center the snackbar */ - bottom: 30px; /* 30px from the bottom */ -} - -/* Show the snackbar when clicking on a button (class added with JavaScript) */ -#snackbar.show { - visibility: visible; /* Show the snackbar */ - /* Add animation: Take 0.5 seconds to fade in and out the snackbar. - However, delay the fade out process for 2.5 seconds */ - /* - -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s; - animation: fadein 0.5s, fadeout 0.5s 2.5s; - */ -} \ No newline at end of file diff --git a/static/css/main.css b/static/css/main.css index e69de29..ec7f68d 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -0,0 +1,36 @@ +.div_float_clear { + clear: both; +} + +/* The snackbar - position it at the bottom and in the middle of the screen */ +#snackbar { + visibility: hidden; /* Hidden by default. Visible on click */ + min-width: 800px; /* Set a default minimum width */ + margin-left: -400px; /* Divide value of min-width by 2 */ + background-color: #333; /* Black background color */ + color: #fff; /* White text color */ + text-align: center; /* Centered text */ + border-radius: 2px; /* Rounded borders */ + padding: 16px; /* Padding */ + position: fixed; /* Sit on top of the screen */ + z-index: 1; /* Add a z-index if needed */ + left: 50%; /* Center the snackbar */ + bottom: 30px; /* 30px from the bottom */ +} + +/* Show the snackbar when clicking on a button (class added with JavaScript) */ +#snackbar.show { + visibility: visible; /* Show the snackbar */ + /* Add animation: Take 0.5 seconds to fade in and out the snackbar. + However, delay the fade out process for 2.5 seconds */ + /* + -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s; + animation: fadein 0.5s, fadeout 0.5s 2.5s; + */ +} + +@media (min-width: 992px) { + .nav-item.active { + border-bottom: 1px solid var(--bs-nav-link-color); + } +} \ No newline at end of file diff --git a/static/css/merge.css b/static/css/merge.css new file mode 100644 index 0000000..756a81d --- /dev/null +++ b/static/css/merge.css @@ -0,0 +1,9 @@ + +#btn-group-download { + width: 100%; + margin-top: 1em; + display: none; +} +#btn_download_complete { + width: 100%; +} diff --git a/static/css/project.css b/static/css/project.css index 11ad3e6..81678a6 100644 --- a/static/css/project.css +++ b/static/css/project.css @@ -17,9 +17,6 @@ width: 500px; text-align: center; } -.pdf-interact-buttons { - padding-left: 1em; -} #btn-group-download { width: 100%; diff --git a/static/css/split.css b/static/css/split.css new file mode 100644 index 0000000..89f83a3 --- /dev/null +++ b/static/css/split.css @@ -0,0 +1,9 @@ + +#btn-group-download { + width: 100%; + margin-top: 1em; + display: none; +} +#btn_download_singel_pages { + width: 100%; +} diff --git a/static/js/merge.js b/static/js/merge.js new file mode 100644 index 0000000..676f371 --- /dev/null +++ b/static/js/merge.js @@ -0,0 +1,84 @@ +/* eslint-disable new-cap */ +/* eslint-disable camelcase */ +/* eslint-disable no-console */ + +let uuid; +let pdf_uploaded = false; +import('./pdf_api_wrapper.js'); + +// eslint-disable-next-line no-undef, no-unused-vars +const vueInstance = new Vue({ + el: '#app', + data() { + return { + pdf_file: null, + project_uuid: null, + }; + }, + mounted() { + window.addEventListener('load', () => this.side_loaded()); + }, + methods: { + move_page(from_page, to_page) { + console.debug('trying to move page: ', from_page, to_page); + fetch(`/move_page/${this.project_uuid}/${from_page}/${to_page}`, { + method: 'GET', + }) + .then((response) => response.json()) + .then((data) => { + console.debug('data from Backend: ', data); + if (data.status === 200) { + this.display_pages(); + console.info('Page was moved'); + } else { + console.error('Page could not be moved'); + } + }) + .catch((error) => console.error(error)); + }, + side_loaded() { + document.getElementById('btn_download_complete').addEventListener('click', () => new pdf_api_wrapper(`${uuid}`).download_pdf()); + + fetch('/init_project/', { + method: 'GET', + }) + .then((response) => response.json()) + .then((data) => { + console.debug('data from Backend: ', data); + if (data.status === 200) { + this.project_uuid = data.project_uuid; + uuid = data.project_uuid; + } else { + this.project_uuid = null; + console.error('Project could not be created'); + } + }) + .catch((error) => console.error(error)); + + // Dropzone has been added as a global variable. + // eslint-disable-next-line no-undef + const dropzone = new Dropzone('div#pdf-dropzone', { + url: '/add_pdf_to_project/', + paramName: 'pdf', + }); + + dropzone.on('addedfile', (file) => { + console.log('A file has been added'); + // eslint-disable-next-line no-param-reassign + file.previewElement.innerHTML = ''; + console.debug('Suppress file.previewElement'); + console.debug('PDF Project UUID: ', this.project_uuid); + }); + + dropzone.on('sending', (file, xhr, formData) => { + formData.append('uuid', uuid); + }); + + // eslint-disable-next-line no-unused-vars + dropzone.on('complete', (file, xhr, formData) => { + pdf_uploaded = true; + document.getElementById('btn-group-download').style.display = 'flex'; + }); + }, + }, +}); diff --git a/static/js/project.js b/static/js/project.js index 6825d0a..39e4551 100644 --- a/static/js/project.js +++ b/static/js/project.js @@ -4,7 +4,7 @@ let uuid; let pdf_uploaded = false; -import('./pdf_api_wrapper'); +import('./pdf_api_wrapper.js'); // eslint-disable-next-line no-undef, no-unused-vars const vueInstance = new Vue({ diff --git a/static/js/split.js b/static/js/split.js new file mode 100644 index 0000000..4e7ae89 --- /dev/null +++ b/static/js/split.js @@ -0,0 +1,84 @@ +/* eslint-disable new-cap */ +/* eslint-disable camelcase */ +/* eslint-disable no-console */ + +let uuid; +let pdf_uploaded = false; +import('./pdf_api_wrapper.js'); + +// eslint-disable-next-line no-undef, no-unused-vars +const vueInstance = new Vue({ + el: '#app', + data() { + return { + pdf_file: null, + project_uuid: null, + }; + }, + mounted() { + window.addEventListener('load', () => this.side_loaded()); + }, + methods: { + move_page(from_page, to_page) { + console.debug('trying to move page: ', from_page, to_page); + fetch(`/move_page/${this.project_uuid}/${from_page}/${to_page}`, { + method: 'GET', + }) + .then((response) => response.json()) + .then((data) => { + console.debug('data from Backend: ', data); + if (data.status === 200) { + this.display_pages(); + console.info('Page was moved'); + } else { + console.error('Page could not be moved'); + } + }) + .catch((error) => console.error(error)); + }, + side_loaded() { + document.getElementById('btn_download_singel_pages').addEventListener('click', () => new pdf_api_wrapper(`${uuid}`).download_split_pdf()); + + fetch('/init_project/', { + method: 'GET', + }) + .then((response) => response.json()) + .then((data) => { + console.debug('data from Backend: ', data); + if (data.status === 200) { + this.project_uuid = data.project_uuid; + uuid = data.project_uuid; + } else { + this.project_uuid = null; + console.error('Project could not be created'); + } + }) + .catch((error) => console.error(error)); + + // Dropzone has been added as a global variable. + // eslint-disable-next-line no-undef + const dropzone = new Dropzone('div#pdf-dropzone', { + url: '/add_pdf_to_project/', + paramName: 'pdf', + }); + + dropzone.on('addedfile', (file) => { + console.log('A file has been added'); + // eslint-disable-next-line no-param-reassign + file.previewElement.innerHTML = ''; + console.debug('Suppress file.previewElement'); + console.debug('PDF Project UUID: ', this.project_uuid); + }); + + dropzone.on('sending', (file, xhr, formData) => { + formData.append('uuid', uuid); + }); + + // eslint-disable-next-line no-unused-vars + dropzone.on('complete', (file, xhr, formData) => { + pdf_uploaded = true; + document.getElementById('btn-group-download').style.display = 'flex'; + }); + }, + }, +}); diff --git a/templates/app.html b/templates/app.html deleted file mode 100644 index adf74e3..0000000 --- a/templates/app.html +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - - - - - - - - - - - - PDF Web Toolkit - - - -
-
-
-

PDF Web Toolkit

-
-
-
-
-
-
-
-
-
Drop pdf here or click to upload...
-
-
-
-
- -
-
- - -
-
-
- - - - - - \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 073135c..1cebff9 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,18 +8,15 @@ - - PDF-Web-Toolkit{% if page == 'project' %} | Project{% endif %}{% if page == 'splitt' %} | Splitt{% endif %}{% if page == 'merge' %} | Merge{% endif %}{% if page == 'ocr' %} | OCR{% endif %} + PDF-Web-Toolkit{% if page == 'project' %} | Project{% endif %}{% if page == 'split' %} | Split{% endif %}{% if page == 'merge' %} | Merge{% endif %}{% if page == 'ocr' %} | OCR{% endif %} - -