From 63c7e9710b8942a774119f9e3070537f39c0c15c Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Fri, 9 Mar 2018 11:18:19 +0100 Subject: [PATCH] Closes #194: PDF viewer --- .../docs/controller/document/FileModalView.js | 68 +++++++++++++------ .../webapp/src/partial/docs/file.view.html | 27 ++++++-- docs-web/src/main/webapp/src/style/main.less | 20 ++++++ 3 files changed, 90 insertions(+), 25 deletions(-) diff --git a/docs-web/src/main/webapp/src/app/docs/controller/document/FileModalView.js b/docs-web/src/main/webapp/src/app/docs/controller/document/FileModalView.js index ae4baf6a..b62627f3 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/document/FileModalView.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/document/FileModalView.js @@ -3,58 +3,77 @@ /** * File modal view controller. */ -angular.module('docs').controller('FileModalView', function($uibModalInstance, $scope, $state, $stateParams, Restangular, $transitions) { +angular.module('docs').controller('FileModalView', function ($uibModalInstance, $scope, $state, $stateParams, $sce, Restangular, $transitions) { // Load files - Restangular.one('file/list').get({ id: $stateParams.id }).then(function(data) { + Restangular.one('file/list').get({ id: $stateParams.id }).then(function (data) { $scope.files = data.files; // Search current file - _.each($scope.files, function(value) { + _.each($scope.files, function (value) { if (value.id === $stateParams.fileId) { $scope.file = value; + $scope.trustedFileUrl = $sce.trustAsResourceUrl('../api/file/' + $stateParams.fileId + '/data'); } }); }); /** - * Navigate to the next file. + * Return the next file. */ - $scope.nextFile = function() { - _.each($scope.files, function(value, key) { + $scope.nextFile = function () { + var next = undefined; + _.each($scope.files, function (value, key) { if (value.id === $stateParams.fileId) { - var next = $scope.files[key + 1]; - if (next) { - $state.go('^.file', { id: $stateParams.id, fileId: next.id }); - } + next = $scope.files[key + 1]; } }); + return next; + }; + + /** + * Return the previous file. + */ + $scope.previousFile = function () { + var previous = undefined; + _.each($scope.files, function (value, key) { + if (value.id === $stateParams.fileId) { + previous = $scope.files[key - 1]; + } + }); + return previous; + }; + + /** + * Navigate to the next file. + */ + $scope.goNextFile = function () { + var next = $scope.nextFile(); + if (next) { + $state.go('^.file', { id: $stateParams.id, fileId: next.id }); + } }; /** * Navigate to the previous file. */ - $scope.previousFile = function() { - _.each($scope.files, function(value, key) { - if (value.id === $stateParams.fileId) { - var previous = $scope.files[key - 1]; - if (previous) { - $state.go('^.file', { id: $stateParams.id, fileId: previous.id }); - } - } - }); + $scope.goPreviousFile = function () { + var previous = $scope.previousFile(); + if (previous) { + $state.go('^.file', { id: $stateParams.id, fileId: previous.id }); + } }; /** * Open the file in a new window. */ - $scope.openFile = function() { + $scope.openFile = function () { window.open('../api/file/' + $stateParams.fileId + '/data'); }; /** * Print the file. */ - $scope.printFile = function() { + $scope.printFile = function () { var popup = window.open('../api/file/' + $stateParams.fileId + '/data', '_blank'); popup.onload = function () { popup.print(); @@ -80,4 +99,11 @@ angular.module('docs').controller('FileModalView', function($uibModalInstance, $ } off(); }); + + /** + * Return true if we can display the preview image. + */ + $scope.canDisplayPreview = function () { + return $scope.file && $scope.file.mimetype !== 'application/pdf'; + }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/file.view.html b/docs-web/src/main/webapp/src/partial/docs/file.view.html index e4f51a3c..656d1dc5 100644 --- a/docs-web/src/main/webapp/src/partial/docs/file.view.html +++ b/docs-web/src/main/webapp/src/partial/docs/file.view.html @@ -6,8 +6,19 @@
- - + + +
@@ -21,16 +32,24 @@
+ - + + + + + + + +

{{ 'file.view.not_found' | translate }} diff --git a/docs-web/src/main/webapp/src/style/main.less b/docs-web/src/main/webapp/src/style/main.less index 7a27646f..5aac89ee 100644 --- a/docs-web/src/main/webapp/src/style/main.less +++ b/docs-web/src/main/webapp/src/style/main.less @@ -422,6 +422,18 @@ input[readonly].share-link { } } +// PDF viewer +.pdf-viewer { + display: block; + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + width: 100%; + height: 80vh; +} + // Vertical alignment .vertical-center { min-height: 100vh; @@ -618,4 +630,12 @@ input[readonly].share-link { .widgets .col-md-12 { padding-left: 0; padding-right: 0; +} + +// Button placeholder +.btn-placeholder { + visibility: hidden; + width: 0; + padding-left: 0; + padding-right: 0; } \ No newline at end of file