This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(articles): Article Admin feature (#807)
This feature introduces a breaking change, that restricts the User's that can create/edit/delete Articles to only those that have the `admin` Role. Fixed ESLint issues. Resolved merge conflicts, and moved new client Article Service `createOrUpdate` functionality to new Admin feature controller. Removed edit functionality from client-side Article controller.
- Loading branch information
Showing
20 changed files
with
913 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
modules/articles/client/config/articles-admin.client.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
// Configuring the Articles Admin module | ||
angular | ||
.module('articles.admin') | ||
.run(menuConfig); | ||
|
||
menuConfig.$inject = ['menuService']; | ||
|
||
function menuConfig(Menus) { | ||
Menus.addSubMenuItem('topbar', 'admin', { | ||
title: 'Manage Articles', | ||
state: 'admin.articles.list' | ||
}); | ||
} | ||
}()); |
65 changes: 65 additions & 0 deletions
65
modules/articles/client/config/articles-admin.client.routes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('articles.admin.routes') | ||
.config(routeConfig); | ||
|
||
routeConfig.$inject = ['$stateProvider']; | ||
|
||
function routeConfig($stateProvider) { | ||
$stateProvider | ||
.state('admin.articles', { | ||
abstract: true, | ||
url: '/articles', | ||
template: '<ui-view/>' | ||
}) | ||
.state('admin.articles.list', { | ||
url: '', | ||
templateUrl: 'modules/articles/client/views/admin/list-articles.client.view.html', | ||
controller: 'ArticlesListController', | ||
controllerAs: 'vm', | ||
data: { | ||
roles: ['admin'] | ||
} | ||
}) | ||
.state('admin.articles.create', { | ||
url: '/create', | ||
templateUrl: 'modules/articles/client/views/admin/form-article.client.view.html', | ||
controller: 'ArticlesController', | ||
controllerAs: 'vm', | ||
data: { | ||
roles: ['admin'] | ||
}, | ||
resolve: { | ||
articleResolve: newArticle | ||
} | ||
}) | ||
.state('admin.articles.edit', { | ||
url: '/:articleId/edit', | ||
templateUrl: 'modules/articles/client/views/admin/form-article.client.view.html', | ||
controller: 'ArticlesController', | ||
controllerAs: 'vm', | ||
data: { | ||
roles: ['admin'] | ||
}, | ||
resolve: { | ||
articleResolve: getArticle | ||
} | ||
}); | ||
} | ||
|
||
getArticle.$inject = ['$stateParams', 'ArticlesService']; | ||
|
||
function getArticle($stateParams, ArticlesService) { | ||
return ArticlesService.get({ | ||
articleId: $stateParams.articleId | ||
}).$promise; | ||
} | ||
|
||
newArticle.$inject = ['ArticlesService']; | ||
|
||
function newArticle(ArticlesService) { | ||
return new ArticlesService(); | ||
} | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
modules/articles/client/controllers/admin/article.client.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('articles.admin') | ||
.controller('ArticlesController', ArticlesController); | ||
|
||
ArticlesController.$inject = ['$scope', '$state', '$window', 'articleResolve', 'Authentication']; | ||
|
||
function ArticlesController($scope, $state, $window, article, Authentication) { | ||
var vm = this; | ||
|
||
vm.article = article; | ||
vm.authentication = Authentication; | ||
vm.error = null; | ||
vm.form = {}; | ||
vm.remove = remove; | ||
vm.save = save; | ||
|
||
// Remove existing Article | ||
function remove() { | ||
if ($window.confirm('Are you sure you want to delete?')) { | ||
vm.article.$remove($state.go('admin.articles.list')); | ||
} | ||
} | ||
|
||
// Save Article | ||
function save(isValid) { | ||
if (!isValid) { | ||
$scope.$broadcast('show-errors-check-validity', 'vm.form.articleForm'); | ||
return false; | ||
} | ||
|
||
// Create a new article, or update the current instance | ||
vm.article.createOrUpdate() | ||
.then(successCallback) | ||
.catch(errorCallback); | ||
|
||
function successCallback(res) { | ||
$state.go('admin.articles.list'); // should we send the User to the list or the updated Article's view? | ||
} | ||
|
||
function errorCallback(res) { | ||
vm.error = res.data.message; | ||
} | ||
} | ||
} | ||
}()); |
15 changes: 15 additions & 0 deletions
15
modules/articles/client/controllers/admin/list-articles.client.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular | ||
.module('articles') | ||
.controller('ArticlesListController', ArticlesListController); | ||
|
||
ArticlesListController.$inject = ['ArticlesService']; | ||
|
||
function ArticlesListController(ArticlesService) { | ||
var vm = this; | ||
|
||
vm.articles = ArticlesService.query(); | ||
} | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
modules/articles/client/views/admin/list-articles.client.view.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<section> | ||
<div class="page-header"> | ||
<h1> | ||
Articles | ||
<a class="btn btn-primary pull-right" data-ui-sref="admin.articles.create"> | ||
<i class="glyphicon glyphicon-plus"></i> | ||
</a> | ||
</h1> | ||
</div> | ||
<div class="list-group"> | ||
<a data-ng-repeat="article in vm.articles" data-ui-sref="admin.articles.edit({articleId: article._id})" class="list-group-item"> | ||
<small class="list-group-item-text"> | ||
Posted on | ||
<span data-ng-bind="article.created | date:'mediumDate'"></span> | ||
by | ||
<span ng-if="article.user" ng-bind="article.user.displayName"></span> | ||
<span ng-if="!article.user">Deleted User</span> | ||
</small> | ||
<h4 class="list-group-item-heading" data-ng-bind="article.title"></h4> | ||
<p class="list-group-item-text" data-ng-bind="article.content"></p> | ||
</a> | ||
</div> | ||
<div class="alert alert-warning text-center" data-ng-if="articles.$resolved && !articles.length"> | ||
No articles yet, why don't you <a data-ui-sref="admin.articles.create">create one</a>? | ||
</div> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@mleanos If all that average users can do now is list articles anyway, why is this still a dropdown? I suggest: