mirror of
https://github.com/sismics/docs.git
synced 2025-12-21 05:31:42 +00:00
Sequential files upload, basic search system
This commit is contained in:
@@ -22,7 +22,8 @@ App.controller('Document', function($scope, $state, Restangular) {
|
||||
offset: $scope.offset,
|
||||
limit: $scope.limit,
|
||||
sort_column: $scope.sortColumn,
|
||||
asc: $scope.asc
|
||||
asc: $scope.asc,
|
||||
search: $scope.search
|
||||
})
|
||||
.then(function(data) {
|
||||
$scope.documents = data;
|
||||
@@ -47,6 +48,12 @@ App.controller('Document', function($scope, $state, Restangular) {
|
||||
$scope.pageDocuments();
|
||||
});
|
||||
|
||||
$scope.$watch('search', function(prev, next) {
|
||||
if (next) {
|
||||
$scope.loadDocuments();
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Sort documents.
|
||||
*/
|
||||
|
||||
@@ -41,41 +41,58 @@ App.controller('DocumentEdit', function($scope, $q, $http, $state, $stateParams,
|
||||
var promises = [];
|
||||
$scope.fileProgress = 0;
|
||||
|
||||
_.each($scope.newFiles, function(file) {
|
||||
// Build the payload
|
||||
var formData = new FormData();
|
||||
formData.append('id', data.id);
|
||||
formData.append('file', file);
|
||||
|
||||
// Send the file
|
||||
var promiseFile = $http.put('api/file',
|
||||
formData, {
|
||||
headers: { 'Content-Type': false },
|
||||
transformRequest: function(data) { return data; }
|
||||
});
|
||||
|
||||
// TODO Handle progression when $q.notify will be released
|
||||
|
||||
promiseFile.then(function() {
|
||||
$scope.fileProgress += 100 / _.size($scope.newFiles);
|
||||
});
|
||||
|
||||
// Store the promise for later
|
||||
promises.push(promiseFile);
|
||||
});
|
||||
|
||||
// When all files upload are over, move on
|
||||
var promiseAll = $q.all(promises);
|
||||
if ($scope.isEdit()) {
|
||||
promiseAll.then(function(data) {
|
||||
var navigateNext = function() {
|
||||
if ($scope.isEdit()) {
|
||||
$scope.loadDocuments();
|
||||
$state.transitionTo('document.view', { id: $stateParams.id });
|
||||
});
|
||||
} else {
|
||||
promiseAll.then(function(data) {
|
||||
} else {
|
||||
$scope.document = {};
|
||||
$scope.loadDocuments();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (_.size($scope.newFiles) == 0) {
|
||||
navigateNext();
|
||||
} else {
|
||||
$scope.fileIsUploading = true;
|
||||
|
||||
// Send a file from the input file array and return a promise
|
||||
var sendFile = function(key) {
|
||||
// Build the payload
|
||||
var file = $scope.newFiles[key];
|
||||
var formData = new FormData();
|
||||
formData.append('id', data.id);
|
||||
formData.append('file', file);
|
||||
|
||||
// Send the file
|
||||
var promiseFile = $http.put('api/file',
|
||||
formData, {
|
||||
headers: { 'Content-Type': false },
|
||||
transformRequest: function(data) { return data; }
|
||||
});
|
||||
|
||||
// TODO Handle progression when $q.notify will be released
|
||||
|
||||
promiseFile.then(function() {
|
||||
$scope.fileProgress += 100 / _.size($scope.newFiles);
|
||||
});
|
||||
|
||||
return promiseFile;
|
||||
};
|
||||
|
||||
// Upload files sequentially
|
||||
var key = 0;
|
||||
var then = function() {
|
||||
key++;
|
||||
if ($scope.newFiles[key]) {
|
||||
sendFile(key).then(then);
|
||||
} else {
|
||||
$scope.fileIsUploading = false;
|
||||
navigateNext();
|
||||
}
|
||||
};
|
||||
sendFile(key).then(then);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,17 +3,43 @@
|
||||
/**
|
||||
* Document view controller.
|
||||
*/
|
||||
App.controller('DocumentView', function($rootScope, $scope, $state, $stateParams, Restangular) {
|
||||
App.controller('DocumentView', function($rootScope, $scope, $state, $stateParams, $dialog, Restangular) {
|
||||
// Load data from server
|
||||
$scope.document = Restangular.one('document', $stateParams.id).get();
|
||||
Restangular.one('file').getList('list', { id: $stateParams.id }).then(function(data) {
|
||||
$rootScope.files = data.files;
|
||||
});
|
||||
|
||||
/**
|
||||
* Load files from server.
|
||||
*/
|
||||
$scope.loadFiles = function() {
|
||||
Restangular.one('file').getList('list', { id: $stateParams.id }).then(function(data) {
|
||||
$rootScope.files = data.files;
|
||||
});
|
||||
};
|
||||
$scope.loadFiles();
|
||||
|
||||
/**
|
||||
* Navigate to the selected file.
|
||||
*/
|
||||
$scope.openFile = function(file) {
|
||||
$state.transitionTo('document.view.file', { id: $stateParams.id, fileId: file.id })
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a file.
|
||||
*/
|
||||
$scope.deleteFile = function(file) {
|
||||
var title = 'Delete file';
|
||||
var msg = 'Do you really want to delete this file?';
|
||||
var btns = [{result:'cancel', label: 'Cancel'}, {result:'ok', label: 'OK', cssClass: 'btn-primary'}];
|
||||
|
||||
$dialog.messageBox(title, msg, btns)
|
||||
.open()
|
||||
.then(function(result) {
|
||||
if (result == 'ok') {
|
||||
Restangular.one('file', file.id).remove().then(function() {
|
||||
$scope.loadFiles();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -23,6 +23,7 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12"><progress percent="fileProgress" class="progress-info active"></progress></div>
|
||||
<div class="row-fluid" ng-show="fileIsUploading">
|
||||
<h4>Uploading files...</h4>
|
||||
<div class="span6"><progress percent="fileProgress" class="progress-info active"></progress></div>
|
||||
</div>
|
||||
@@ -4,6 +4,10 @@
|
||||
<p class="text-center">
|
||||
<button class="btn btn-primary" type="button" ng-click="addDocument()">Add a document</button>
|
||||
</p>
|
||||
<p class="input-prepend text-center input-block-level">
|
||||
<span class="add-on"><span class="icon-search"></span></span>
|
||||
<input class="span10" type="text" placeholder="Search" ng-model="search" >
|
||||
</p>
|
||||
<table class="table table-striped table-hover table-documents">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</a>
|
||||
<div class="caption">
|
||||
<p class="text-right">
|
||||
<button class="btn btn-danger" ng-click="deleteFile(file.id)"><span class="icon-trash icon-white"></span></button>
|
||||
<button class="btn btn-danger" ng-click="deleteFile(file)"><span class="icon-trash icon-white"></span></button>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user