From e8cc9f1465248c34058c57d54cd0635a0fe1922c Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Thu, 5 May 2016 15:53:45 -0500 Subject: [PATCH] Document Upload and Deletion work great --- www/api/controllers/DocController.js | 11 ++++---- www/api/models/Doc.js | 4 +-- www/assets/js/ng/controller_doc.js | 20 +++++++++++++ www/assets/js/ng/factory_docs.js | 25 +++++++++++++++-- www/assets/templates/docs.html | 42 ++++++++++++++++++++++++---- 5 files changed, 87 insertions(+), 15 deletions(-) diff --git a/www/api/controllers/DocController.js b/www/api/controllers/DocController.js index 2fad2da..5db1d8d 100644 --- a/www/api/controllers/DocController.js +++ b/www/api/controllers/DocController.js @@ -17,16 +17,17 @@ module.exports = { Doc.create({ name: files[i].filename, location: files[i].fd.split("assets/")[1], - visible: true + description: req.body.description }).exec(function(err, created){ if (err) console.log(err); console.log("Created :" + created); }); } - return res.json({ - message: files.length + ' file(s) uploaded successfully!', - files: files - }); + return res.redirect("/#/docs"); + // return res.json({ + // message: files.length + ' file(s) uploaded successfully!', + // files: files + // }); }); } }; diff --git a/www/api/models/Doc.js b/www/api/models/Doc.js index f579294..ca8aa4e 100644 --- a/www/api/models/Doc.js +++ b/www/api/models/Doc.js @@ -21,8 +21,8 @@ module.exports = { location: { type: 'string' }, - visible: { - type:'boolean' + description: { + type:'string' } } }; diff --git a/www/assets/js/ng/controller_doc.js b/www/assets/js/ng/controller_doc.js index 9aaa5c8..f86177d 100644 --- a/www/assets/js/ng/controller_doc.js +++ b/www/assets/js/ng/controller_doc.js @@ -11,6 +11,14 @@ poconsole.controller('docsCtrl', function($scope, $route, Page, $log, docs) { var imageExtension = ".png"; $scope.docs = d.docs.map(function(doc){ var spl = doc.location.split("."); + var split_name = doc.name.split("."); + var trunc_filebase = split_name[0]; + + if (trunc_filebase.length > 12){ + trunc_filebase = trunc_filebase.slice(0,5) + "..." + trunc_filebase.slice(-5); + + } + doc.trunc_filename = trunc_filebase + "." + split_name[1]; var ext = spl[spl.length - 1]; if(file_types.indexOf(ext) > -1){ doc.img_url = imageBase + ext + imageExtension; @@ -23,5 +31,17 @@ poconsole.controller('docsCtrl', function($scope, $route, Page, $log, docs) { }; $scope.loadDocs(); + $scope.selectDelete = function(id){ + $scope.del_id = id; + return; + }; + + $scope.deleteDoc = function(id){ + var del = docs.deleteDoc(id); + del.then(function(d){ + $scope.loadDocs(); + }); + }; + }); diff --git a/www/assets/js/ng/factory_docs.js b/www/assets/js/ng/factory_docs.js index a2ea600..c8b680e 100644 --- a/www/assets/js/ng/factory_docs.js +++ b/www/assets/js/ng/factory_docs.js @@ -1,4 +1,14 @@ -poconsole.factory('docs',function($q, $http, $log){ +poconsole.factory('formDataObject', function() { + return function(data) { + var fd = new FormData(); + angular.forEach(data, function(value, key) { + fd.append(key, value); + }); + return fd; + }; +}); + +poconsole.factory('docs',function($q, $http, $log, formDataObject){ var getAllDocs = function(){ var deferred = $q.defer(); @@ -20,10 +30,21 @@ poconsole.factory('docs',function($q, $http, $log){ return deferred.promise; }; + var deleteDoc = function(id){ + var deferred = $q.defer(); + $http.delete('/doc/' + id).success(function(data) { + deferred.resolve({ + deleted:data + }); + }); + return deferred.promise; + }; + return { getAllDocs:getAllDocs, - getDoc: getDoc + getDoc: getDoc, + deleteDoc: deleteDoc }; }); diff --git a/www/assets/templates/docs.html b/www/assets/templates/docs.html index d02589f..f14902e 100644 --- a/www/assets/templates/docs.html +++ b/www/assets/templates/docs.html @@ -1,10 +1,35 @@ + +
-
+
-

{{doc.name}}

+ +

{{doc.description}}

+
Uploaded at: {{ doc.createdAt | date: 'medium'}}
+
@@ -12,11 +37,16 @@
- +

Upload a new document...

-
-
- + +
+
+ +
+
+ +