mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-05 22:27:36 +02:00
Adding Bower Support
This commit is contained in:
4
.bowerrc
Normal file
4
.bowerrc
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"directory": "public/lib",
|
||||
"json": "bower.json"
|
||||
}
|
||||
80
app/controllers/articles.js
Normal file
80
app/controllers/articles.js
Normal file
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
31
app/models/article.js
Normal file
31
app/models/article.js
Normal file
@@ -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)
|
||||
17
bower.json
Normal file
17
bower.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
48
public/js/controllers/articles.js
Normal file
48
public/js/controllers/articles.js
Normal file
@@ -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;
|
||||
});
|
||||
};
|
||||
}
|
||||
4
public/js/services/articles.js
Normal file
4
public/js/services/articles.js
Normal file
@@ -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'}});
|
||||
});
|
||||
21
public/views/articles/create.html
Normal file
21
public/views/articles/create.html
Normal file
@@ -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>
|
||||
25
public/views/articles/edit.html
Normal file
25
public/views/articles/edit.html
Normal file
@@ -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>
|
||||
10
public/views/articles/list.html
Normal file
10
public/views/articles/list.html
Normal file
@@ -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>
|
||||
6
public/views/articles/view.html
Normal file
6
public/views/articles/view.html
Normal file
@@ -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>
|
||||
Reference in New Issue
Block a user