mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 22:07:56 +01:00
Attach orphan files to a new document
This commit is contained in:
parent
0d4643cc93
commit
5e3093d0d3
@ -79,4 +79,18 @@ angular.module('docs').controller('DocumentDefault', function($scope, $state, Re
|
|||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns checked files.
|
||||||
|
*/
|
||||||
|
$scope.checkedFiles = function() {
|
||||||
|
return _.where($scope.files, { checked: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a document with checked files.
|
||||||
|
*/
|
||||||
|
$scope.addDocument = function() {
|
||||||
|
$state.transitionTo('document.add', { files: _.pluck($scope.checkedFiles(), 'id') });
|
||||||
|
};
|
||||||
});
|
});
|
@ -7,6 +7,9 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
|
|||||||
// Alerts
|
// Alerts
|
||||||
$scope.alerts = [];
|
$scope.alerts = [];
|
||||||
|
|
||||||
|
// Orphan files to add
|
||||||
|
$scope.orphanFiles = $stateParams.files ? $stateParams.files.split(',') : [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close an alert.
|
* Close an alert.
|
||||||
*/
|
*/
|
||||||
@ -51,6 +54,8 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit a document.
|
* Edit a document.
|
||||||
|
* Workflow:
|
||||||
|
* Edit/add the file -> upload local files -> attach orphan files -> redirect to edited document or stay if adding
|
||||||
*/
|
*/
|
||||||
$scope.edit = function() {
|
$scope.edit = function() {
|
||||||
var promise = null;
|
var promise = null;
|
||||||
@ -65,35 +70,44 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
|
|||||||
document.tags = _.pluck(document.tags, 'id');
|
document.tags = _.pluck(document.tags, 'id');
|
||||||
|
|
||||||
if ($scope.isEdit()) {
|
if ($scope.isEdit()) {
|
||||||
promise = Restangular
|
promise = Restangular.one('document', $stateParams.id).post('', document);
|
||||||
.one('document', $stateParams.id)
|
|
||||||
.post('', document);
|
|
||||||
} else {
|
} else {
|
||||||
promise = Restangular
|
promise = Restangular.one('document').put(document);
|
||||||
.one('document')
|
|
||||||
.put(document);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attach orphan files after edition
|
||||||
|
var attachOrphanFiles = function(data) {
|
||||||
|
var promises = [];
|
||||||
|
_.each($scope.orphanFiles, function(fileId) {
|
||||||
|
promises.push(Restangular.one('file/' + fileId).post('', { id: data.id }));
|
||||||
|
});
|
||||||
|
$scope.orphanFiles = [];
|
||||||
|
return $q.all(promises);
|
||||||
|
};
|
||||||
|
|
||||||
// Upload files after edition
|
// Upload files after edition
|
||||||
promise.then(function(data) {
|
promise.then(function(data) {
|
||||||
$scope.fileProgress = 0;
|
$scope.fileProgress = 0;
|
||||||
|
|
||||||
// When all files upload are over, move on
|
// When all files upload are over, attach orphan files and move on
|
||||||
var navigateNext = function() {
|
var navigateNext = function() {
|
||||||
if ($scope.isEdit()) {
|
attachOrphanFiles(data).then(function(resolve) {
|
||||||
// Go back to the edited document
|
if ($scope.isEdit()) {
|
||||||
$scope.pageDocuments();
|
// Go back to the edited document
|
||||||
$state.transitionTo('document.view', { id: $stateParams.id });
|
$scope.pageDocuments();
|
||||||
} else {
|
$state.transitionTo('document.view', { id: $stateParams.id });
|
||||||
// Reset the scope and stay here
|
} else {
|
||||||
var fileUploadCount = _.size($scope.newFiles);
|
// Reset the scope and stay here
|
||||||
$scope.alerts.unshift({
|
var fileUploadCount = _.size($scope.newFiles) + resolve.length;
|
||||||
type: 'success',
|
$scope.alerts.unshift({
|
||||||
msg: 'Document successfully added (with ' + fileUploadCount + ' file' + (fileUploadCount > 1 ? 's' : '') + ')'
|
type: 'success',
|
||||||
});
|
msg: 'Document successfully added (with ' + fileUploadCount + ' file' + (fileUploadCount > 1 ? 's' : '') + ')'
|
||||||
$scope.resetForm();
|
});
|
||||||
$scope.loadDocuments();
|
|
||||||
}
|
$scope.resetForm();
|
||||||
|
$scope.loadDocuments();
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_.size($scope.newFiles) == 0) {
|
if (_.size($scope.newFiles) == 0) {
|
||||||
|
@ -39,6 +39,10 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="btn-group" ng-show="checkedFiles().length > 0">
|
||||||
|
<button class="btn btn-primary" ng-click="addDocument()"><span class="glyphicon glyphicon-plus"></span> Add to new document</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div ui-view="file"></div>
|
<div ui-view="file"></div>
|
||||||
|
|
||||||
<div class="text-muted text-right">
|
<div class="text-muted text-right">
|
||||||
|
@ -37,10 +37,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-2 control-label" for="inputFiles">New files</label>
|
<label class="col-sm-2 control-label" for="inputFiles">New files</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-6">
|
||||||
<file class="form-control" id="inputFiles" multiple="multiple" ng-model="newFiles"
|
<file class="form-control" id="inputFiles" multiple="multiple" ng-model="newFiles"
|
||||||
accept="image/png,image/jpg,image/jpeg,image/gif,application/pdf" ng-disabled="fileIsUploading"></file>
|
accept="image/png,image/jpg,image/jpeg,image/gif,application/pdf" ng-disabled="fileIsUploading"></file>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-sm-4" ng-if="orphanFiles.length > 0">
|
||||||
|
+ {{ orphanFiles.length }} file{{ orphanFiles.length > 1 ? 's' : '' }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-2 control-label" for="inputTags">Tags</label>
|
<label class="col-sm-2 control-label" for="inputTags">Tags</label>
|
||||||
|
Loading…
Reference in New Issue
Block a user