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.
Added an Admin feature to Articles. This change removes the ability of
non-Admin user's to create & edit Articles. The Article list views have been split into two views; one for Admin & non-Admin users (including non-Authenticated users). Added tests for admin feature for Articles. Removed unnecessary tests for non Admin users when interacting with Articles.
- Loading branch information
Showing
17 changed files
with
656 additions
and
323 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
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
'use strict'; | ||
|
||
// Configuring the Articles module | ||
angular.module('articles.admin').run(['Menus', | ||
function (Menus) { | ||
Menus.addSubMenuItem('topbar', 'admin', { | ||
title: 'Manage Articles', | ||
state: 'admin.articles.list' | ||
}); | ||
} | ||
]); |
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
'use strict'; | ||
|
||
// Setting up route | ||
angular.module('articles.admin.routes').config(['$stateProvider', | ||
function ($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: 'ArticlesAdminController', | ||
data: { | ||
roles: ['admin'] | ||
} | ||
}) | ||
.state('admin.articles.create', { | ||
url: '/create', | ||
templateUrl: 'modules/articles/client/views/admin/create-article.client.view.html', | ||
controller: 'ArticlesAdminController', | ||
data: { | ||
roles: ['admin'] | ||
} | ||
}) | ||
.state('admin.articles.edit', { | ||
url: '/:articleId/edit', | ||
templateUrl: 'modules/articles/client/views/admin/edit-article.client.view.html', | ||
controller: 'ArticlesAdminController', | ||
data: { | ||
roles: ['admin'] | ||
} | ||
}); | ||
} | ||
]); |
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
70 changes: 70 additions & 0 deletions
70
modules/articles/client/controllers/admin.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,70 @@ | ||
'use strict'; | ||
|
||
// Articles controller | ||
angular.module('articles.admin').controller('ArticlesAdminController', ['$scope', '$stateParams', '$state', 'Authentication', 'Articles', | ||
function ($scope, $stateParams, $state, Authentication, Articles) { | ||
$scope.authentication = Authentication; | ||
|
||
// Create new Article | ||
$scope.create = function () { | ||
// Create new Article object | ||
var article = new Articles({ | ||
title: this.title, | ||
content: this.content | ||
}); | ||
|
||
// Redirect after save | ||
article.$save(function (response) { | ||
$state.go('admin.articles.list'); | ||
|
||
// Clear form fields | ||
$scope.title = ''; | ||
$scope.content = ''; | ||
}, function (errorResponse) { | ||
$scope.error = errorResponse.data.message; | ||
}); | ||
}; | ||
|
||
// Remove existing Article | ||
$scope.remove = function (article) { | ||
if (confirm('Are you sure you want to delete this article?')) { | ||
if (article) { | ||
article.$remove(); | ||
|
||
for (var i in $scope.articles) { | ||
if ($scope.articles[i] === article) { | ||
$scope.articles.splice(i, 1); | ||
} | ||
} | ||
} else { | ||
$scope.article.$remove(function () { | ||
$state.go('admin.articles.list'); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
// Update existing Article | ||
$scope.update = function () { | ||
var article = $scope.article; | ||
|
||
article.$update(function () { | ||
$state.go('admin.articles.list'); | ||
}, function (errorResponse) { | ||
$scope.error = errorResponse.data.message; | ||
}); | ||
}; | ||
|
||
// Find a list of Articles | ||
$scope.find = function () { | ||
$scope.articles = Articles.query(); | ||
}; | ||
|
||
// Find existing Article | ||
$scope.findOne = function () { | ||
$scope.article = Articles.get({ | ||
articleId: $stateParams.articleId | ||
}); | ||
}; | ||
} | ||
]); |
52 changes: 2 additions & 50 deletions
52
modules/articles/client/controllers/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
29 changes: 29 additions & 0 deletions
29
modules/articles/client/views/admin/create-article.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,29 @@ | ||
<section data-ng-controller="ArticlesAdminController"> | ||
<div class="page-header"> | ||
<h1>New Article</h1> | ||
</div> | ||
<div class="col-md-12"> | ||
<form name="articleForm" class="form-horizontal" data-ng-submit="create()" novalidate> | ||
<fieldset> | ||
<div class="form-group"> | ||
<label class="control-label" for="title">Title</label> | ||
<div class="controls"> | ||
<input name="title" type="text" data-ng-model="title" id="title" class="form-control" placeholder="Title"> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label" for="content">Content</label> | ||
<div class="controls"> | ||
<textarea name="content" data-ng-model="content" id="content" class="form-control" cols="30" rows="10" placeholder="Content"></textarea> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<input type="submit" class="btn btn-default"> | ||
</div> | ||
<div data-ng-show="error" class="text-danger"> | ||
<strong data-ng-bind="error"></strong> | ||
</div> | ||
</fieldset> | ||
</form> | ||
</div> | ||
</section> |
34 changes: 34 additions & 0 deletions
34
modules/articles/client/views/admin/edit-article.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,34 @@ | ||
<section data-ng-controller="ArticlesAdminController" data-ng-init="findOne()"> | ||
<div class="page-header"> | ||
<h1> | ||
Edit Article | ||
<a class="btn btn-primary pull-right" data-ng-click="remove();"> | ||
<i class="glyphicon glyphicon-trash"></i> | ||
</a> | ||
</h1> | ||
</div> | ||
<div class="col-md-12"> | ||
<form name="articleForm" class="form-horizontal" data-ng-submit="update()" novalidate> | ||
<fieldset> | ||
<div class="form-group"> | ||
<label class="control-label" for="title">Title</label> | ||
<div class="controls"> | ||
<input name="title" type="text" data-ng-model="article.title" id="title" class="form-control" placeholder="Title" required> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label" for="content">Content</label> | ||
<div class="controls"> | ||
<textarea name="content" data-ng-model="article.content" id="content" class="form-control" cols="30" rows="10" placeholder="Content"></textarea> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<input type="submit" value="Update" class="btn btn-default"> | ||
</div> | ||
<div data-ng-show="error" class="text-danger"> | ||
<strong data-ng-bind="error"></strong> | ||
</div> | ||
</fieldset> | ||
</form> | ||
</div> | ||
</section> |
25 changes: 25 additions & 0 deletions
25
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,25 @@ | ||
<section data-ng-controller="ArticlesAdminController" data-ng-init="find()"> | ||
<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 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 data-ng-bind="article.user.displayName"></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.