diff --git a/client/components/documentList/documentList.controller.js b/client/components/documentList/documentList.controller.js index c429359..caf60c6 100644 --- a/client/components/documentList/documentList.controller.js +++ b/client/components/documentList/documentList.controller.js @@ -1,9 +1,16 @@ 'use strict'; angular.module('manticoreApp') .controller('DocumentListCtrl', function ($scope, $http) { $scope.displayedDocuments = []; - $http.get('/api/documents').success(function (documents) { - $scope.documents = documents; - }); + + function update() { + console.log('here'); + $http.get('/api/documents').success(function (documents) { + $scope.documents = documents; + }); + } + + $scope.$on('documentsUploaded', update); + update(); }); diff --git a/client/components/documentList/documentList.jade b/client/components/documentList/documentList.jade index 342b4bf..5064bf1 100644 --- a/client/components/documentList/documentList.jade +++ b/client/components/documentList/documentList.jade @@ -1,16 +1,16 @@ -.container - .no-docs(ng-if='!documents.length') +.container(ng-switch='documents.length === 0') + .no-docs(ng-switch-when='true') p.advice No documents yet. Why not add some? - .document-list(ng-if='documents.length') + .document-list(ng-switch-when='false') table.table.table-striped(st-table='displayedDocuments' st-safe-src='documents') thead tr th Title th Creator th(st-sort='date' st-sort-default='reverse') Updated tbody tr(ng-repeat='document in displayedDocuments') td.title a(ui-sref='editor({id: document._id})' target='_blank') {{document.title}} td {{document.creator.name}} td {{document.date | amCalendar}} diff --git a/client/components/import/import.controller.js b/client/components/import/import.controller.js index 5995a96..d4a91b3 100644 --- a/client/components/import/import.controller.js +++ b/client/components/import/import.controller.js @@ -1,28 +1,35 @@ 'use strict'; angular.module('manticoreApp') - .controller('ImportCtrl', function ($scope, FileUploader, Auth) { + .controller('ImportCtrl', function ($scope, $rootScope, FileUploader, Auth) { var uploader = new FileUploader({ url: '/api/documents/upload', - removeAfterUpload: true, - autoUpload: true, headers: { 'Authorization': 'Bearer ' + Auth.getToken() + }, + removeAfterUpload: true, + autoUpload: true, + onCompleteAll: function () { + // Wait a little before firing this event, as the upload may not + // be accessible from MongoDB immediately + window.setTimeout(function () { + $rootScope.$broadcast('documentsUploaded'); + }, 1000); } }); uploader.filters.push({ name: 'sizeFilter', fn: function (item) { return item.size <= 10485760; // 10 Megabytes } }); uploader.filters.push({ name: 'typeFilter', fn: function (item) { return item.type === 'application/vnd.oasis.opendocument.text'; } }); $scope.uploader = uploader; });