mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-09-01 05:07:46 +02:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}());
|
||||
Reference in New Issue
Block a user