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.
- Loading branch information
Showing
10 changed files
with
246 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"directory": "public/lib", | ||
"json": "bower.json" | ||
} |
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,80 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var mongoose = require('mongoose') | ||
, async = require('async') | ||
, Article = mongoose.model('Article') | ||
, _ = require('underscore') | ||
|
||
|
||
/** | ||
* Find article by id | ||
*/ | ||
|
||
exports.article = function(req, res, next, id){ | ||
var User = mongoose.model('User') | ||
|
||
Article.load(id, function (err, article) { | ||
if (err) return next(err) | ||
if (!article) return next(new Error('Failed to load article ' + id)) | ||
req.article = article | ||
next() | ||
}) | ||
} | ||
|
||
/** | ||
* Create a article | ||
*/ | ||
exports.create = function (req, res) { | ||
var article = new Article(req.body) | ||
article.user = req.user | ||
article.save() | ||
res.jsonp(article) | ||
} | ||
|
||
/** | ||
* Update a article | ||
*/ | ||
exports.update = function(req, res){ | ||
var article = req.article | ||
article = _.extend(article, req.body) | ||
|
||
article.save(function(err) { | ||
res.jsonp(article) | ||
}) | ||
} | ||
|
||
/** | ||
* Delete an article | ||
*/ | ||
exports.destroy = function(req, res){ | ||
var article = req.article | ||
article.remove(function(err){ | ||
if (err) { | ||
res.render('error', {status: 500}); | ||
} else { | ||
res.jsonp(article); | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Show an article | ||
*/ | ||
exports.show = function(req, res){ | ||
res.jsonp(req.article); | ||
} | ||
|
||
/** | ||
* List of Articles | ||
*/ | ||
exports.all = function(req, res){ | ||
Article.find().sort('-created').populate('user').exec(function(err, articles) { | ||
if (err) { | ||
res.render('error', {status: 500}); | ||
} else { | ||
res.jsonp(articles); | ||
} | ||
}); | ||
} |
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,31 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var mongoose = require('mongoose') | ||
, env = process.env.NODE_ENV || 'development' | ||
, config = require('../../config/config')[env] | ||
, Schema = mongoose.Schema | ||
|
||
/** | ||
* Article Schema | ||
*/ | ||
|
||
var ArticleSchema = new Schema({ | ||
created: {type : Date, default : Date.now}, | ||
title: {type: String, default: '', trim : true}, | ||
content: {type: String, default: '', trim : true}, | ||
user: {type : Schema.ObjectId, ref : 'User'} | ||
}); | ||
|
||
|
||
/** | ||
* Statics | ||
*/ | ||
|
||
ArticleSchema.statics = { | ||
load: function (id, cb) { | ||
this.findOne({ _id : id }).populate('user').exec(cb); | ||
} | ||
} | ||
|
||
mongoose.model('Article', ArticleSchema) |
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 @@ | ||
{ | ||
"name": "angularJS-IL", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"bootstrap": "2.3.2", | ||
"angular": "~1.0.6", | ||
"angular-resource": "~1.0.6", | ||
"angular-cookies": "~1.0.6", | ||
"angular-bootstrap": "~0.4.0", | ||
"json3": "~3.2.4", | ||
"jquery": "~1.9.1" | ||
}, | ||
"devDependencies": { | ||
"angular-mocks": "~1.0.5", | ||
"angular-scenario": "~1.0.5" | ||
} | ||
} |
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 ArticlesController($scope, $routeParams, $location, Articles) { | ||
$scope.articles = []; | ||
$scope.article = {}; | ||
|
||
$scope.create = function () { | ||
var article = new Articles({ title: this.title, content: this.content }); | ||
article.$save(function (response) { | ||
$location.path("articles/" + response._id); | ||
}); | ||
|
||
this.title = ""; | ||
this.content = ""; | ||
}; | ||
|
||
$scope.remove = function (article) { | ||
article.$remove(); | ||
|
||
for (var i in $scope.articles) { | ||
if ($scope.articles[i] == article) { | ||
$scope.articles.splice(i, 1) | ||
} | ||
} | ||
}; | ||
|
||
$scope.update = function () { | ||
var article = $scope.article; | ||
if (!article.updated) { | ||
article.updated = []; | ||
} | ||
article.updated.push(new Date().getTime()); | ||
|
||
article.$update(function () { | ||
$location.path('articles/' + article._id); | ||
}); | ||
}; | ||
|
||
$scope.find = function (query) { | ||
Articles.query(query, function (articles) { | ||
$scope.articles = articles; | ||
}); | ||
}; | ||
|
||
$scope.findOne = function () { | ||
Articles.get({ articleId: $routeParams.articleId }, function (article) { | ||
$scope.article = article; | ||
}); | ||
}; | ||
} |
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,4 @@ | ||
//Articles service used for articles REST endpoint | ||
window.app.factory("Articles", function($resource){ | ||
return $resource('articles/:articleId', {articleId:'@_id'}, {update: {method: 'PUT'}}); | ||
}); |
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,21 @@ | ||
<section data-ng-controller="ArticlesController"> | ||
<form class="form-horizontal" data-ng-submit="create()"> | ||
<div class="control-group"> | ||
<label class="control-label" for="title">כותרת</label> | ||
<div class="controls"> | ||
<input type="text" data-ng-model="title" id="title" placeholder="כותרת"> | ||
</div> | ||
</div> | ||
<div class="control-group"> | ||
<label class="control-label" for="content">תוכן</label> | ||
<div class="controls"> | ||
<textarea data-ng-model="content" id="content" cols="30" rows="10" placeholder="תוכן"></textarea> | ||
</div> | ||
</div> | ||
<div class="control-group"> | ||
<div class="controls"> | ||
<input type="submit" class="btn"> | ||
</div> | ||
</div> | ||
</form> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<section data-ng-controller="ArticlesController" data-ng-init="findOne()"> | ||
<form class="form-horizontal" data-ng-submit="update()"> | ||
<div class="control-group"> | ||
<label class="control-label" for="title">Title</label> | ||
|
||
<div class="controls"> | ||
<input type="text" data-ng-model="article.title" id="title" placeholder="Title"> | ||
</input> | ||
</div> | ||
</div> | ||
<div class="control-group"> | ||
<label class="control-label" for="content">Content</label> | ||
|
||
<div class="controls"> | ||
<textarea data-ng-model="article.content" id="content" cols="30" rows="10" placeholder="Content"> | ||
</textarea> | ||
</div> | ||
</div> | ||
<div class="control-group"> | ||
<div class="controls"> | ||
<input type="submit" class="btn"> | ||
</div> | ||
</div> | ||
</form> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<section data-ng-controller="ArticlesController" data-ng-init="find()"> | ||
<ul> | ||
<li data-ng-repeat="article in articles"> | ||
<span>{{article.created | date:'medium'}}</span> / | ||
<span>{{article.user.name}}</span> | ||
<h2><a data-ng-href="#!/articles/{{article._id}}">{{article.title}}</a></h2> | ||
<div>{{article.content}}</div> | ||
</li> | ||
</ul> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<section data-ng-controller="ArticlesController" data-ng-init="findOne()"> | ||
<span>{{article.created | date:'medium'}}</span> / | ||
<span>{{article.user.name}}</span> | ||
<h2>{{article.title}}</h2> | ||
<div>{{article.content}}</div> | ||
</section> |