From 4469bb7beef47065951d45a114a00d1e1946a51d Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Wed, 30 Jan 2019 18:15:00 +0100 Subject: [PATCH] #256: upload a new version UI --- .../document/DocumentViewContent.js | 25 ++++++++++++++++--- docs-web/src/main/webapp/src/locale/en.json | 3 ++- .../partial/docs/document.view.content.html | 8 +++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentViewContent.js b/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentViewContent.js index b90d1fc6..fa7061cf 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentViewContent.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentViewContent.js @@ -64,10 +64,26 @@ angular.module('docs').controller('DocumentViewContent', function ($scope, $root }); }; + $scope.uploadNewVersion = function (files, file) { + if (!$scope.document.writable || !files || files.length === 0) { + return; + } + + var uploadedfile = files[0]; + var previousFileId = file.id; + file.id = undefined; + file.progress = 0; + file.name = uploadedfile.name; + file.create_date = new Date().getTime(); + file.mimetype = uploadedfile.type; + file.version++; + $scope.uploadFile(uploadedfile, file, previousFileId); + }; + /** * File has been drag & dropped. */ - $scope.fileDropped = function(files) { + $scope.fileDropped = function (files) { if (!$scope.document.writable) { return; } @@ -75,7 +91,7 @@ angular.module('docs').controller('DocumentViewContent', function ($scope, $root if (files && files.length) { // Adding files to the UI var newfiles = []; - _.each(files, function(file) { + _.each(files, function (file) { var newfile = { progress: 0, name: file.name, @@ -101,7 +117,7 @@ angular.module('docs').controller('DocumentViewContent', function ($scope, $root /** * Upload a file. */ - $scope.uploadFile = function(file, newfile) { + $scope.uploadFile = function(file, newfile, previousFileId) { // Upload the file newfile.status = $translate.instant('document.view.content.upload_progress'); return Upload.upload({ @@ -109,7 +125,8 @@ angular.module('docs').controller('DocumentViewContent', function ($scope, $root url: '../api/file', file: file, fields: { - id: $stateParams.id + id: $stateParams.id, + previousFileId: previousFileId } }) .progress(function(e) { diff --git a/docs-web/src/main/webapp/src/locale/en.json b/docs-web/src/main/webapp/src/locale/en.json index 73d300c8..4a979096 100644 --- a/docs-web/src/main/webapp/src/locale/en.json +++ b/docs-web/src/main/webapp/src/locale/en.json @@ -118,7 +118,8 @@ "drop_zone": "Drag & drop files here to upload", "add_files": "Add files", "file_processing_indicator": "This file is being processed. Searching will not be available before it is complete.", - "reprocess_file": "Reprocess this file" + "reprocess_file": "Reprocess this file", + "upload_new_version": "Upload a new version" }, "workflow": { "workflow": "Workflow", diff --git a/docs-web/src/main/webapp/src/partial/docs/document.view.content.html b/docs-web/src/main/webapp/src/partial/docs/document.view.content.html index 69b6b474..e1d9a553 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.view.content.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.view.content.html @@ -56,7 +56,7 @@
-
{{ file.name }}
+
{{ file.name }}