diff --git a/app/components/button/download_document_version.hbs b/app/components/button/download_document_version.hbs index 0931d85e881c4459ea4823e07d600fbd940d7ebf..f67d364278e3877851c9577845aa3326472297fc 100644 --- a/app/components/button/download_document_version.hbs +++ b/app/components/button/download_document_version.hbs @@ -6,7 +6,7 @@ <i class="fa fa-download"></i> Download </button> - <ul class="dropdown-menu"> + <ul class="dropdown-menu download-document-version"> {{#each @document_versions as |document_version|}} <li> <a class="dropdown-item" href="#" diff --git a/app/components/button/download_document_version.js b/app/components/button/download_document_version.js index c974ce5fdd435dd395b3b0bc597595cde0b04ec5..a2aea6ff09b33e4b5299b446d10a318fb86e9866 100644 --- a/app/components/button/download_document_version.js +++ b/app/components/button/download_document_version.js @@ -22,6 +22,7 @@ export default class ButtonDownloadComponent extends Component { attributes which correspond to server side (or client side) DocumentVersion model */ + this.requests.downloadDocumentVersion( document_version ); diff --git a/app/components/commander/index.hbs b/app/components/commander/index.hbs index 4cd64dacc840b92e8c021ac4d6943e4b306db2b7..0b62aaa7ac140516c992fcc8ad29bbd3dac1992f 100644 --- a/app/components/commander/index.hbs +++ b/app/components/commander/index.hbs @@ -3,7 +3,7 @@ onDrop=this.onDrop onDragOver=this.onDragOver onDragEnter=this.onDragEnter - onDragLeave=this.onDragLeave }} + onDragLeave=this.onDragLeave}} {{uiSelect view_mode=this.view_mode enabled_on='grid'}} {{contextMenu}}> diff --git a/app/components/viewer/index.js b/app/components/viewer/index.js index ec2e4a26c4d574f1821b168f5b3e46388b25605f..e9f6b4618997e45ebb429df1529afb357e64cc84 100644 --- a/app/components/viewer/index.js +++ b/app/components/viewer/index.js @@ -267,6 +267,7 @@ export default class ViewerComponent extends Component { 'New page order successfully applied' ); this.page_order_changed = false; + this.router.refresh(); }, () => { // on failure this.apply_page_order_changes_in_progress = false; diff --git a/app/modifiers/droppable.js b/app/modifiers/droppable.js index 1822f8b6019aa21ad8619c2ed3cc6b38ec0015fb..f2463f19414807563ef6eace60f6f7b1168ebb5e 100644 --- a/app/modifiers/droppable.js +++ b/app/modifiers/droppable.js @@ -31,21 +31,18 @@ export default class DrappableModifier extends Modifier { @action onDrop(event) { let _onDrop = this.args.named['onDrop'], element; - element = this.element; _onDrop({event, element}); } @action onDragOver(event) { - //const isNode = event.dataTransfer.types.includes("application/x.node"); - - //event.preventDefault(); - //if (isNode) { - //console.log(`dragging over a node`); - //} let _onDragOver = this.args.named['onDragOver'], element; + // Important! + // When removed caused file drop feature to break! + event.preventDefault(); + element = this.element; if (_onDragOver) { _onDragOver({event, element}); diff --git a/app/services/notify.js b/app/services/notify.js index 0c8df9b6e2cfe6205bb025809ec8f501e64c8ff0..c2f54be07cef83326d97cf889faef6c2ad702211 100644 --- a/app/services/notify.js +++ b/app/services/notify.js @@ -1,29 +1,87 @@ import Service from '@ember/service'; import { tracked } from 'tracked-built-ins'; import { TrackedArray } from 'tracked-built-ins'; +import randrange from 'papermerge/utils/random'; export default class Notify extends Service { /* - Push notifications to your visitors with a toast, a lightweight and easily customizable alert message. + Lightweight notifications service. + + Usage: + + @service notify; + + some_function() { + ... + this.info('New page order successfully applied'); + ... + } + + The snipped above will display in upper right corner notification message. + Notification messages can be manually closed. Alternatively notification + messages will 'disappear' themselves after ``this.NOTIFICATION_TIMEOUT`` + milliseconds. */ + + NOTIFICATION_TIMEOUT = 9000 // milliseconds @tracked notifications = new TrackedArray([]); + info(message) { - let type = 'info'; + let type = 'info', id = this._random_id; - this.notifications.push({message, type}); + this.add({id, message, type}); } warning(message) { - let type = 'warning'; + let type = 'warning', id = this._random_id; - this.notifications.push({message, type}); + this.add({id, message, type}); } error(message) { - let type = 'error'; + let type = 'error', id = this._random_id; + + this.add({id, message, type}); + } + + add({id, message, type}) { + /* + Adds notification message to the list. + + Notification message will be removed automatically + from the list after ``this.NOTIFICATION_TIMEOUT`` milliseconds + */ + this.notifications.push({id, message, type}); + this.delayed_remove_by({id: id, delay: this.NOTIFICATION_TIMEOUT}); + } + + remove_by(id) { + /* + Removes notification with given ID from ``this.notifications`` array + */ + let index; + + index = this.notifications.findIndex(item => item.id === id); + if (index >= 0) { + this.notifications.splice(index, 1); + } + } + + delayed_remove_by({id, delay}) { + /* + Remove notification (with ID) from list after ``delay`` milliseconds + */ + setTimeout(() => { + this.remove_by(id); + }, delay); + } - this.notifications.push({message, type}); + get _random_id() { + /* + Returns random integer number/ID between 1 and 99999 + */ + return randrange(1, 99999); } } diff --git a/app/services/requests.js b/app/services/requests.js index 57d2d71dc55c97a3e848372b68c65cd19d235dda..4a046eee66a0fc90ada623f1066a2fb99d838050 100644 --- a/app/services/requests.js +++ b/app/services/requests.js @@ -76,25 +76,27 @@ export default class Requests extends Service { }); } - /** - * `document_version` contains following attributes: - * id - * number - * file_name - * lang - * pages - * size - * page_count - * short_description - * - * attributes which correspond to server side (or client side) DocumentVersion model - */ + async downloadDocumentVersion(document_version) { + /** + * `document_version` contains following attributes: + * id + * number + * file_name + * lang + * pages + * size + * page_count + * short_description + * + * attributes which correspond to server side (or client side) DocumentVersion model + */ let response, blob; response = await this._get(`/document-versions/${document_version.id}/download/`); blob = await response.blob(); + insert_blob( document_version.file_name, blob diff --git a/app/styles/document_version.scss b/app/styles/document_version.scss index ee5f580c56971c9ba4442ff8433a540f61de4d87..db5507a8a0a52321874aa42b2372067ba8ba96aa 100644 --- a/app/styles/document_version.scss +++ b/app/styles/document_version.scss @@ -100,3 +100,8 @@ svg.failed { transform: rotate(360deg); } } + +ul.download-document-version { + max-height: 80vh; + overflow-y: scroll; +} diff --git a/app/utils/index.js b/app/utils/index.js index 81adccf8cf7c0cb5ad9498123e94ca7b7e5dd610..8140c2748fe046f35d8134d6e488ec11b137a88d 100644 --- a/app/utils/index.js +++ b/app/utils/index.js @@ -85,21 +85,23 @@ function extract_file_name(response, fallback) { return file_name; } -/** - * Insert a blob data into DOM and prompt use to download it - */ + function insert_blob(file_name, blob) { + /** + * Insert a blob data into DOM and prompt use to download it + */ let url, a; url = window.URL.createObjectURL(blob); a = document.createElement('a'); a.href = url; + a.download = file_name; + a.target = '_blank'; // we need to append the element to the dom -> otherwise it will not // work in firefox document.body.appendChild(a); a.click(); - //afterwards we remove the element again a.remove(); } diff --git a/app/utils/random.js b/app/utils/random.js new file mode 100644 index 0000000000000000000000000000000000000000..1690a7b2d98cc2ff303052a9bc6d2975a1d163ae --- /dev/null +++ b/app/utils/random.js @@ -0,0 +1,9 @@ + +export default function randrange(min, max) { + /* + Gerates a random integer number between min and max; + */ + return Math.floor( + Math.random() * (max - min + 1) + min + ); +}