10000 added: advanced routing example · markandrewj/angular-examples@b8092bd · GitHub
[go: up one dir, main page]

Skip to content

Commit b8092bd

Browse files
committed
added: advanced routing example
1 parent 3aec22b commit b8092bd

File tree

14 files changed

+264
-0
lines changed

14 files changed

+264
-0
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# Compiled binary addons (http://nodejs.org/api/addons.html)
20+
build/Release
21+
22+
# Dependency directory
23+
# Commenting this out is preferred by some people, see
24+
# https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
25+
node_modules
26+
27+
# Users Environment Variables
28+
.lock-wscript
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
exports.install = function (framework) {
2+
// sets the route
3+
framework.route('/admin/articles', view_articles);
4+
framework.route('/admin/articles', json_articles, ['xhr', 'post']);
5+
};
6+
7+
function view_articles() {
8+
9+
var self = this;
10+
var thisdate = '';
11+
12+
var model = {
13+
title: '',
14+
date: '',
15+
subtitle: '',
16+
article: '',
17+
category: 0,
18+
draft: false,
19+
pagetitle: 'Articles',
20+
pagesubtitle: 'Create edit and delete articles'
21+
};
22+
23+
self.repository.category = [
24+
{
25+
id: 0,
26+
name: 'Select Category'
27+
},
28+
{
29+
id: 1,
30+
name: 'General Info'
31+
},
32+
{
33+
id: 2,
34+
name: 'Safety'
35+
},
36+
{
37+
id: 3,
38+
name: 'Products'
39+
},
40+
{
41+
id: 4,
42+
name: 'Videos'
43+
}
44+
]
45+
self.repository.categories = "categories";
46+
self.repository.date = thisdate;
47+
self.repository.pagetitle = 'articles';
48+
self.layout('_adminlayout');
49+
self.view('articles', model);
50+
}
51+
52+
53+
function json_articles() {
54+
55+
var self = this;
56+
var success = false;
57+
var field = self.validate(self.post, ['title', 'date', 'subtitle', 'article', 'category', 'draft']);
58+
59+
60+
if (self.user !== null) {
61+
field.add('loggedin');
62+
}
63+
64+
if (field.hasError()) {
65+
self.json(field);
66+
return;
67+
} else {
68+
success = true;
69+
}
70+
71+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
exports.install = function (framework) {
2+
framework.route('/admin/categories', view_categories);
3+
framework.route('/admin/categories', json_categories, ['xhr', 'post']);
4+
};
5+
6+
function view_categories() {
7+
8+
var self = this;
9+
10+
var model = {
11+
pagetitle: 'Categories',
12+
pagesubtitle: 'Manage your categories'
13+
}
14+
15+
self.layout('_adminlayout');
16+
17+
//To /views/admin/categories;
18+
self.view('categories', model);
19+
//alternative method ON override
20+
// self.view('admin.categories', model);
21+
// self.view('admin.custom-name', model);
22+
23+
}
24+
25+
26+
function json_categories() {
27+
28+
var self = this;
29+
var host = self.host();
30+
var success = false;
31+
var field = self.validate(self.post, ['categorytitle', 'parentcategory']);
32+
33+
if (!self.cors(''+ host +'/*', ['POST'])) {
34+
self.plain('Not allowed');
35+
return;
36+
}
37+
38+
if (field.hasError()) {
39+
self.json(field);
40+
return;
41+
} else {
42+
success = true;
43+
}
44+
45+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exports.install = function(framework) {
2+
framework.route('/admin', view_dashboard);
3+
};
4+
5+
function view_dashboard() {
6+
7+
var self = this;
8+
var thisdate = self.host();
9+
var model = {
10+
pagetitle: 'Dashboard',
11+
pagesubtitle: 'Control Panel',
12+
}
13+
14+
self.layout('_adminlayout');
15+
self.view('dashboard', model);
16+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var site = require('./site/index');
2+
3+
exports.install = function (framework) {
4+
// sets the route
5+
framework.route('/', site.index);
6+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.index = function view_index() {
2+
3+
var self = this;
4+
5+
var model = {
6+
pagetitle: 'FIREPOWER FIREWORKS',
7+
}
8+
9+
self.layout('_sitelayout');
10+
self.view('index', model);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
framework.on('controller', function(controller, name) {
2+
3+
// Manage controller default directory for views // first method
4+
if (name.indexOf('admin/') !== -1)
5+
controller.currentView('/admin/');
6+
7+
// Manage controller site-folder/file-name.js associated views // with site.route
8+
if (name.indexOf('/site.route') !== -1)
9+
controller.currentView('/site/');
10+
11+
});

routing-advanced/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var framework = require('total.js');
2+
var http = require('http');
3+
4+
var debug = true;
5+
6+
framework.run(http, debug, 8009);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Bootstrap 101 Template</title>
8+
<!-- Bootstrap -->
9+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
10+
<!-- Optional theme -->
11+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
12+
13+
<!-- Custom style -->
14+
<link rel="stylesheet" href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" />
15+
16+
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
17+
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
18+
<!--[if lt IE 9]>
19+
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
20+
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
21+
<![endif]-->
22+
23+
</head>
24+
<body>
25+
26+
@{body}
27+
28+
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
29+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
30+
<!-- Include all compiled plugins (below), or include individual files as needed -->
31+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
32+
</body>
33+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Bootstrap 101 Template</title>
8+
<!-- Bootstrap -->
9+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
10+
<!-- Optional theme -->
11+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" />
12+
13+
<!-- Custom style -->
14+
<link rel="stylesheet" href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" />
15+
16+
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
17+
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
18+
<!--[if lt IE 9]>
19+
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
20+
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
21+
<![endif]-->
22+
23+
</head>
24+
<body>
25+
26+
@{body}
27+
28+
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
29+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
30+
<!-- Include all compiled plugins (below), or include individual files as needed -->
31+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
32+
</body>
33+
</html>

0 commit comments

Comments
 (0)
0