diff --git a/viDoc/config/assets/default.js b/viDoc/config/assets/default.js index 875cdf4..372d0bc 100644 --- a/viDoc/config/assets/default.js +++ b/viDoc/config/assets/default.js @@ -27,7 +27,7 @@ module.exports = { 'public/lib/AdminLTE/plugins/slimScroll/jquery.slimscroll.min.js', 'public/lib/AdminLTE/plugins/iCheck/icheck.min.js', 'public/lib/AdminLTE/dist/js/app.min.js', - 'public/lib/angular/angular.js', + 'public/lib/angular/angular.js', 'public/lib/ckeditor/ckeditor.js', 'public/lib/angular-animate/angular-animate.js', 'public/lib/AdminLTE/bootstrap/js/bootstrap.min.js', diff --git a/viDoc/modules/articles/client/config/articles.client.routes.js b/viDoc/modules/articles/client/config/articles.client.routes.js index 0a7e272..5e67965 100644 --- a/viDoc/modules/articles/client/config/articles.client.routes.js +++ b/viDoc/modules/articles/client/config/articles.client.routes.js @@ -12,18 +12,41 @@ $stateProvider .state('articles', { abstract: true, - url: '/projects/:projectId/folders/:folderName/articles', + url: '/projects/:projectId/folders/:folderId/articles', template: '' }) - .state('articles.list', { - url: '', - templateUrl: '/modules/articles/client/views/list-articles.client.view.html', - controller: 'ArticlesListController', + .state('articles.create', { + url: '/create', + templateUrl: '/modules/articles/client/views/admin/create-articles.client.view.html', + controller: 'CreateArticlesAdminController', + controllerAs: 'vm', + data: { + roles: ['user', 'admin'], + pageTitle: 'New Articles' + }, + resolve: { + articleResolve: newArticleFolder + } + }) + .state('articles.edit', { + url: '/:articleId', + templateUrl: '/modules/articles/client/views/admin/edit-articles.client.view.html', + controller: 'EditArticlesAdminController', controllerAs: 'vm', data: { - pageTitle: 'Articles List' + roles: ['user', 'admin'], + pageTitle: '{{articleResolve.title}}' + }, + resolve: { + articleResolve: getArticleFolder } - }).state('articles.create', { + }) + .state('article', { + abstract: true, + url: '/projects/:projectId/articles', + template: '' + }) + .state('article.create', { url: '/create', templateUrl: '/modules/articles/client/views/admin/create-articles.client.view.html', controller: 'CreateArticlesAdminController', @@ -33,10 +56,10 @@ pageTitle: 'New Articles' }, resolve: { - articleResolve: newArticle + articleResolve: newArticleProject } }) - .state('articles.edit', { + .state('article.edit', { url: '/:articleId', templateUrl: '/modules/articles/client/views/admin/edit-articles.client.view.html', controller: 'EditArticlesAdminController', @@ -46,23 +69,39 @@ pageTitle: '{{articleResolve.title}}' }, resolve: { - articleResolve: getArticle + articleResolve: getArticleProject } }); } - getArticle.$inject = ['$stateParams', 'ArticlesService']; + getArticleFolder.$inject = ['$stateParams', 'ArticlesService']; - function getArticle($stateParams, ArticlesService) { + function getArticleFolder($stateParams, ArticlesService) { return ArticlesService.get({ - folderId: $stateParams.folderName, + projectId: $stateParams.projectId, + folderId: $stateParams.folderId, articleId: $stateParams.articleId }).$promise; } - newArticle.$inject = ['ArticlesService']; + newArticleFolder.$inject = ['ArticlesService']; - function newArticle(ArticlesService) { + function newArticleFolder(ArticlesService) { return new ArticlesService(); } + + getArticleProject.$inject = ['$stateParams', 'ArticlesServiceProject']; + + function getArticleProject($stateParams, ArticlesServiceProject) { + return ArticlesServiceProject.get({ + projectId: $stateParams.projectId, + articleId: $stateParams.articleId + }).$promise; + } + + newArticleProject.$inject = ['ArticlesServiceProject']; + + function newArticleProject(ArticlesServiceProject) { + return new ArticlesServiceProject(); + } }()); diff --git a/viDoc/modules/articles/client/controllers/admin/create-articles.client.controller.js b/viDoc/modules/articles/client/controllers/admin/create-articles.client.controller.js index eafc473..931aa14 100644 --- a/viDoc/modules/articles/client/controllers/admin/create-articles.client.controller.js +++ b/viDoc/modules/articles/client/controllers/admin/create-articles.client.controller.js @@ -39,10 +39,16 @@ // Remove existing Article function close() { vm.content.destroy(); - $state.go('folders.view', { - projectId: $state.params.projectId, - folderName: $state.params.folderName - }); + if ($state.params.folderId) { + $state.go('folders.view', { + projectId: $state.params.projectId, + folderId: $state.params.folderId + }); + } else { + $state.go('projects.view', { + projectId: $state.params.projectId + }); + } } // Save Article @@ -53,15 +59,23 @@ } vm.article.content = vm.content.getData(); - vm.article.folder = $state.params.folderName; + vm.article.project = $state.params.projectId; + vm.article.folder = $state.params.folderId; vm.article.createOrUpdate() .then(successCallback) .catch(errorCallback); function successCallback(res) { - $state.go('projects.view', { - projectId: $state.params.projectId - }); + if ($state.params.folderId) { + $state.go('folders.view', { + projectId: $state.params.projectId, + folderId: $state.params.folderId + }); + } else { + $state.go('projects.view', { + projectId: $state.params.projectId, + }); + } // should we send the User to the list or the updated Article's view? Notification.success({ message: ' Article saved successfully!' }); } diff --git a/viDoc/modules/articles/client/controllers/admin/edit-articles.client.controller.js b/viDoc/modules/articles/client/controllers/admin/edit-articles.client.controller.js index 8ac2fd6..a525ad3 100644 --- a/viDoc/modules/articles/client/controllers/admin/edit-articles.client.controller.js +++ b/viDoc/modules/articles/client/controllers/admin/edit-articles.client.controller.js @@ -16,8 +16,7 @@ vm.article = article; vm.authentication = Authentication; vm.projectId = $state.params.projectId; - vm.folderNameUrl = $state.params.folderName; - vm.folderNameNav = $state.params.folderName.replace(/-/gi, ' '); + vm.folderId = $state.params.folderId; vm.form = {}; vm.remove = remove; vm.save = save; @@ -68,10 +67,16 @@ function remove() { if ($window.confirm('Are you sure you want to delete?')) { vm.article.$remove(function() { - $state.go('folders.view', { - projectId: vm.projectId, - folderName: vm.folderNameUrl - }); + if (vm.folderId) { + $state.go('folders.view', { + projectId: vm.projectId, + folderId: vm.folderId + }); + } else { + $state.go('projects.view', { + projectId: vm.projectId + }); + } Notification.success({ message: ' Article deleted successfully!' }); }); } @@ -88,10 +93,16 @@ function successCallback(res) { vm.x.destroy(); - $state.go('folders.view', { - projectId: vm.projectId, - folderName: vm.folderNameUrl - }); + if (vm.folderId) { + $state.go('folders.view', { + projectId: vm.projectId, + folderId: vm.folderId + }); + } else { + $state.go('projects.view', { + projectId: vm.projectId + }); + } // should we send the User to the list or the updated Article's view? Notification.success({ message: ' Article saved successfully!' }); } diff --git a/viDoc/modules/articles/client/services/articles-project.client.service.js b/viDoc/modules/articles/client/services/articles-project.client.service.js new file mode 100644 index 0000000..eccaf0e --- /dev/null +++ b/viDoc/modules/articles/client/services/articles-project.client.service.js @@ -0,0 +1,54 @@ +(function () { + 'use strict'; + + angular + .module('articles.services') + .factory('ArticlesServiceProject', ArticlesServiceProject); + + ArticlesServiceProject.$inject = ['$resource', '$log']; + + function ArticlesServiceProject($resource, $log) { + var Article = $resource('/api/projects/:projectId/articles/:articleId', { + projectId: '@project', + articleId: '@_id' + }, { + update: { + method: 'PUT' + } + }); + + angular.extend(Article.prototype, { + createOrUpdate: function () { + var article = this; + return createOrUpdate(article); + } + }); + + return Article; + + function createOrUpdate(article) { + if (article._id) { + return article.$update(onSuccess, onError); + } else { + return article.$save(onSuccess, onError); + } + + // Handle successful response + function onSuccess(article) { + // Any required internal processing from inside the service, goes here. + } + + // Handle error response + function onError(errorResponse) { + var error = errorResponse.data; + // Handle error internally + handleError(error); + } + } + + function handleError(error) { + // Log error + $log.error(error); + } + } +}()); diff --git a/viDoc/modules/articles/client/services/articles.client.service.js b/viDoc/modules/articles/client/services/articles.client.service.js index 45aeff3..bf49d2e 100644 --- a/viDoc/modules/articles/client/services/articles.client.service.js +++ b/viDoc/modules/articles/client/services/articles.client.service.js @@ -8,7 +8,8 @@ ArticlesService.$inject = ['$resource', '$log']; function ArticlesService($resource, $log) { - var Article = $resource('/api/folders/:folderId/articles/:articleId', { + var Article = $resource('/api/projects/:projectId/folders/:folderId/articles/:articleId', { + projectId: '@project', folderId: '@folder', articleId: '@_id' }, { diff --git a/viDoc/modules/articles/client/views/admin/edit-articles.client.view.html b/viDoc/modules/articles/client/views/admin/edit-articles.client.view.html index a7ef344..50da514 100644 --- a/viDoc/modules/articles/client/views/admin/edit-articles.client.view.html +++ b/viDoc/modules/articles/client/views/admin/edit-articles.client.view.html @@ -3,9 +3,10 @@