#256: upload a new version UI

This commit is contained in:
Benjamin Gamard 2019-01-30 18:15:00 +01:00
parent b2dc460b4b
commit 4469bb7bee
3 changed files with 30 additions and 6 deletions

View File

@ -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) {

View File

@ -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",

View File

@ -56,7 +56,7 @@
<div class="file-info">
<div></div><!-- Actually useful -->
<div class="v-align file-name" ng-if="file.name">{{ file.name }}</div>
<div class="v-align file-name" ng-if="file.name" title="{{ file.name }} (v{{ file.version + 1 }}.0)">{{ file.name }}</div>
<div class="v-align" ng-show="document.writable">
<div uib-dropdown>
<button class="btn btn-default" uib-dropdown-toggle>
@ -72,6 +72,12 @@
<span class="fas fa-eye"></span>
{{ 'document.view.content.reprocess_file' | translate }}
</a>
<a href ngf-select
ngf-change="uploadNewVersion($files, file)"
ngf-multiple="false">
<span class="fas fa-plus"></span>
{{ 'document.view.content.upload_new_version' | translate }}
</a>
<a href ng-click="deleteFile(file)">
<span class="fas fa-trash"></span>
{{ 'delete' | translate }}