8000 new example · markandrewj/angular-examples@e38adee · GitHub
[go: up one dir, main page]

Skip to content

Commit e38adee

Browse files
committed
new example
1 parent 6dad3a1 commit e38adee

File tree

13 files changed

+221
-0
lines changed

13 files changed

+221
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author Peter Širka
3+
* @version 1.0.1
4+
*/
5+
6+
exports.install = function(framework) {
7+
framework.install('/', view_homepage);
8+
};
9+
10+
/**
11+
* Homepage (GET)
12+
* @return {View}
13+
*/
14+
function view_homepage() {
15+
var self = this;
16+
17+
/** @todo: NOT IMPLEMENTED **/
18+
self.view501();
19+
20+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* @author Peter Širka
3+
* @version 1.0.1
4+
*/
5+
6+
exports.install = function(framework) {
7+
framework.install('/users/', view_list);
8+
framework.install('/users/{id}/', view_detail);
9+
};
10+
11+
/**
12+
* Users (GET)
13+
* @return {View}
14+
*/
15+
function view_list() {
16+
17+
var self = this;
18+
var users = MODULE('users');
19+
20+
users.find({}, function(err, rows) {
21+
22+
if (err) {
23+
self.view500(err);
24+
return;
25+
}
26+
27+
/** @todo NOT IMPLEMENTED **/
28+
self.view501();
29+
30+
});
31+
32+
}
33+
34+
/**
35+
* User detail (GET)
36+
* @param {String} id User identificator.
37+
* @return {View}
38+
*/
39+
function view_detail(id) {
40+
41+
var self = this;
42+
var users = MODULE('users');
43+
44+
users.detail(id, function(err, row) {
45+
46+
if (err) {
47+
self.view500(err);
48+
return;
49+
}
50+
51+
if (row === null) {
52+
self.view404('User not found.');
53+
return;
54+
}
55+
56+
/** @todo NOT IMPLEMENTED **/
57+
self.view501();
58+
59+
});
60+
61+
}

project-structure/debug.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
/**
3+
* Configure all modules and dependencies
4+
*/
5+
6+
// @todo: CONFIGURATION IS NOT IMPLEMENTED

project-structure/modules/database.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @module database
3+
* @author Peter Širka
4+
* @version 1.0.1
5+
*/
6+
7+
/**
8+
* Find in database
9+
* @param {Database name} name Name of database.
10+
* @param {Object} options Filter for query.
11+
* @param {Function} callback Callback.
12+
*/
13+
exports.find = function(name, options, callback) {
14+
15+
16+
/**
17+
* @todo: NOT IMPLEMENTED
18+
*/
19+
throw new Error('NOT IMPLEMENTED');
20+
21+
}

project-structure/modules/users.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @module users
3+
* @author Peter Širka
4+
* @version 1.0.1
5+
*/
6+
7+
/**
8+
* Find users
9+
* @public
10+
* @param {Object} options Custom filter.
11+
* @param {Function} callback Callback.
12+
*/
13+
exports.find = function(options, callback) {
14+
15+
var db = MODULE('database');
16+
17+
if (!options.limit)
18+
options.limit = 50;
19+
20+
db.find('users', options, callback);
21+
22+
}
23+
24+
/**
25+
* User detail
26+
* @public
27+
* @param {String} id User identificator.
28+
* @param {Function} callback Callback.
29+
*/
30+
exports.detail = function(id, callback) {
31+
32+
var db = MODULE('database');
33+
var options = { id: id, limit: 1 };
34+
35+
db.find('users', options, function(err, rows) {
36+
37+
if (err) {
38+
callback(err);
39+
return;
40+
}
41+
42+
callback(err, rows[0] || null);
43+
});
44+
}

project-structure/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Project structure
2+
3+
This example describes good and simple structure for web application. Example is a good point where to start.

project-structure/release.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var framework = require('total.js');
2+
var http = require('http');
3+
4+
framework.run(http, false, parseInt(process.argv[2]));

project-structure/source/business.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Some business logic
3+
* @author Peter Širka
4+
* @version 1.0.1
5+
*/

project-structure/test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var framework = require('total.js');
2+
var http = require('http');
3+
4+
framework.run(http, true, parseInt(process.argv[2]));
5+
6+
setTimeout(function() {
7+
framework.stop();
8+
}, 3000);
9+
10+
framework.test(true, function() {
11+
console.log('');
12+
console.log('====================================================');
13+
console.log('C 462E ongratulations, the test was successful!');
14+
console.log('====================================================');
15+
console.log('');
16+
});

0 commit comments

Comments
 (0)
0