Skip to content

Commit

Permalink
#2 create folder in the folder and file in the project
Browse files Browse the repository at this point in the history
  • Loading branch information
quoctran18 committed Aug 28, 2017
1 parent 0482f88 commit 857e127
Show file tree
Hide file tree
Showing 29 changed files with 580 additions and 128 deletions.
2 changes: 1 addition & 1 deletion viDoc/config/assets/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
69 changes: 54 additions & 15 deletions viDoc/modules/articles/client/config/articles.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,41 @@
$stateProvider
.state('articles', {
abstract: true,
url: '/projects/:projectId/folders/:folderName/articles',
url: '/projects/:projectId/folders/:folderId/articles',
template: '<ui-view/>'
})
.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: '<ui-view/>'
})
.state('article.create', {
url: '/create',
templateUrl: '/modules/articles/client/views/admin/create-articles.client.view.html',
controller: 'CreateArticlesAdminController',
Expand All @@ -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',
Expand All @@ -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();
}
}());
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: '<i class="glyphicon glyphicon-ok"></i> Article deleted successfully!' });
});
}
Expand All @@ -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: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}());
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<nav class="navbar navbar-default">
<div class="container-fluid">
<ul class="nav navbar-nav">
<li ng-if="!vm.inline"><a ui-sref="folders.view({ projectId: vm.projectId, folderName: vm.folderNameUrl })">
<span class="glyphicon glyphicon-folder-close"
style="font-size: 12px;padding-right: 8px"></span>{{vm.folderNameNav}}</a></li>
<li ng-if="!vm.inline && vm.folderId"><a ui-sref="folders.view({ projectId: vm.projectId, folderId: vm.folderId })">
<span class="glyphicon glyphicon-arrow-left" style="font-size: 12px;padding-right: 8px"></span> Back</a></li>
<li ng-if="!vm.inline && !vm.folderId"><a ui-sref="projects.view({ projectId: vm.projectId })">
<span class="glyphicon glyphicon-arrow-left" style="font-size: 12px;padding-right: 8px"></span> Back</a></li>
<li ng-if="vm.inline"><a href="#" ng-click="vm.close()"><span class="glyphicon glyphicon-arrow-left" style="font-size: 12px"></span> Back</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
Expand Down
Loading

0 comments on commit 857e127

Please sign in to comment.