forked from meanjs/mean
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(articles): Modify articles module to implement style guidelines.
Update the articles module to implement the style guidelines. Much of this work is from @trainerbill Closes meanjs#874 Closes meanjs#339
- Loading branch information
1 parent
169d4cd
commit b3ad56e
Showing
14 changed files
with
508 additions
and
257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
'use strict'; | ||
(function (app) { | ||
'use strict'; | ||
|
||
// Use Applicaion configuration module to register a new module | ||
ApplicationConfiguration.registerModule('articles'); | ||
app.registerModule('articles'); | ||
app.registerModule('articles.services'); | ||
app.registerModule('articles.routes', ['ui.router', 'articles.services']); | ||
})(ApplicationConfiguration); |
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
106 changes: 37 additions & 69 deletions
106
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,52 @@ | ||
'use strict'; | ||
(function () { | ||
'use strict'; | ||
|
||
// Articles controller | ||
angular.module('articles').controller('ArticlesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Articles', | ||
function ($scope, $stateParams, $location, Authentication, Articles) { | ||
$scope.authentication = Authentication; | ||
angular | ||
.module('articles') | ||
.controller('ArticlesController', ArticlesController); | ||
|
||
// Create new Article | ||
$scope.create = function (isValid) { | ||
$scope.error = null; | ||
ArticlesController.$inject = ['$scope', '$state', 'articleResolve', 'Authentication']; | ||
|
||
if (!isValid) { | ||
$scope.$broadcast('show-errors-check-validity', 'articleForm'); | ||
|
||
return false; | ||
} | ||
|
||
// Create new Article object | ||
var article = new Articles({ | ||
title: this.title, | ||
content: this.content | ||
}); | ||
function ArticlesController($scope, $state, article, Authentication) { | ||
var vm = this; | ||
|
||
// Redirect after save | ||
article.$save(function (response) { | ||
$location.path('articles/' + response._id); | ||
|
||
// Clear form fields | ||
$scope.title = ''; | ||
$scope.content = ''; | ||
}, function (errorResponse) { | ||
$scope.error = errorResponse.data.message; | ||
}); | ||
}; | ||
vm.article = article; | ||
vm.authentication = Authentication; | ||
vm.error = null; | ||
vm.form = {}; | ||
vm.remove = remove; | ||
vm.save = save; | ||
|
||
// Remove existing Article | ||
$scope.remove = function (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 () { | ||
$location.path('articles'); | ||
}); | ||
function remove() { | ||
if (confirm('Are you sure you want to delete?')) { | ||
vm.article.$remove($state.go('articles.list')); | ||
} | ||
}; | ||
|
||
// Update existing Article | ||
$scope.update = function (isValid) { | ||
$scope.error = null; | ||
} | ||
|
||
// Save Article | ||
function save(isValid) { | ||
if (!isValid) { | ||
$scope.$broadcast('show-errors-check-validity', 'articleForm'); | ||
|
||
$scope.$broadcast('show-errors-check-validity', 'vm.form.articleForm'); | ||
return false; | ||
} | ||
|
||
var article = $scope.article; | ||
|
||
article.$update(function () { | ||
$location.path('articles/' + article._id); | ||
}, function (errorResponse) { | ||
$scope.error = errorResponse.data.message; | ||
}); | ||
}; | ||
// TODO: move create/update logic to service | ||
if (vm.article._id) { | ||
vm.article.$update(successCallback, errorCallback); | ||
} else { | ||
vm.article.$save(successCallback, errorCallback); | ||
} | ||
|
||
// Find a list of Articles | ||
$scope.find = function () { | ||
$scope.articles = Articles.query(); | ||
}; | ||
function successCallback(res) { | ||
$state.go('articles.view', { | ||
articleId: res._id | ||
}); | ||
} | ||
|
||
// Find existing Article | ||
$scope.findOne = function () { | ||
$scope.article = Articles.get({ | ||
articleId: $stateParams.articleId | ||
}); | ||
}; | ||
function errorCallback(res) { | ||
vm.error = res.data.message; | ||
} | ||
} | ||
} | ||
]); | ||
})(); |
15 changes: 15 additions & 0 deletions
15
modules/articles/client/controllers/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
28 changes: 0 additions & 28 deletions
28
modules/articles/client/views/create-article.client.view.html
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
modules/articles/client/views/edit-article.client.view.html
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
modules/articles/client/views/form-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,28 @@ | ||
<section> | ||
<div class="page-header"> | ||
<h1>{{vm.article._id ? 'Edit Article' : 'New Article'}}</h1> | ||
</div> | ||
<div class="col-md-12"> | ||
<form name="vm.form.articleForm" class="form-horizontal" ng-submit="vm.save(vm.form.articleForm.$valid)" novalidate> | ||
<fieldset> | ||
<div class="form-group" show-errors> | ||
<label class="control-label" for="title">Title</label> | ||
<input name="title" type="text" ng-model="vm.article.title" id="title" class="form-control" placeholder="Title" required> | ||
<div ng-messages="vm.form.articleForm.title.$error" role="alert"> | ||
<p class="help-block error-text" ng-message="required">Article title is required.</p> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label" for="content">Content</label> | ||
<textarea name="content" data-ng-model="vm.article.content" id="content" class="form-control" cols="30" rows="10" placeholder="Content"></textarea> | ||
</div> | ||
<div class="form-group"> | ||
<button type="submit" class="btn btn-default">{{vm.article._id ? 'Update' : 'Create'}}</button> | ||
</div> | ||
<div ng-show="vm.error" class="text-danger"> | ||
<strong ng-bind="vm.error"></strong> | ||
</div> | ||
</fieldset> | ||
</form> | ||
</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
Oops, something went wrong.