-
Notifications
You must be signed in to change notification settings - Fork 8
/
controllers.js
110 lines (86 loc) · 3.01 KB
/
controllers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// client/code/app/controllers.js
/* AngularJS controllers */
module.exports = function (ngModule) {
'use strict';
/**
* --------------------------------------------------------------------------
* AppCtrl - top-level routing stuff
* --------------------------------------------------------------------------
*/
ngModule.controller('AppCtrl', ['$scope', '$route', '$routeParams', function ($scope, $route, $routeParams) {
var render = function () {
// action is something like 'home.view'
var action = $route.current.action,
// path becomes ['home', 'view']
path = (action && action.split('.')) || [];
// you can use path array to build more complex
// views within views by having a hierarchy defined
$scope.action = action;
$scope.path = path;
$scope.isHome = (path[0] === 'home');
$scope.isFoo = (path[0] === 'foo');
$scope.isBar = (path[0] === 'bar');
};
// updates whenever route changes
$scope.$on('$routeChangeSuccess', function (scopr, next, current) {
render();
});
}]);
/**
* --------------------------------------------------------------------------
* NavCtrl - bootstrap top-level navbar
* --------------------------------------------------------------------------
*/
ngModule.controller('NavCtrl', ['$scope', '$location', function ($scope, $location) {
$scope.isActive = function (clicked) {
if (!clicked) { return ''; }
var path = $location.path(),
location = (path) ? path.substring(1) : '';
return location === clicked ? 'active' : '';
};
}]);
ngModule.controller('HomeCtrl', ['$scope', 'pubsub', function ($scope, pubsub) {
$scope.date = 'never';
$scope.$on('foo:bar', function (evt, msg) {
$scope.date = msg.toString();
});
}]);
/**
* --------------------------------------------------------------------------
* FooCtrl - foo page
* --------------------------------------------------------------------------
*/
ngModule.controller('FooCtrl', ['$scope', 'rpc', 'pubsub', function ($scope, rpc, pubsub) {
$scope.persons = [];
// fetch list of people
var promise = rpc.exec('demoRpc.get', 'hello');
promise.then(
// success
function (msg) {
$scope.persons = msg;
console.log($scope.persons);
},
// error
function (err) {
console.log(err);
}
);
$scope.select = function (index, person) {
if($scope.selectedPerson === person) {
$scope.selectedPerson = undefined;
} else {
$scope.selectedPerson = person;
}
};
$scope.isSelected = function (index, person) {
return ($scope.selectedPerson === person) ? "active" : "";
};
}]);
/**
* --------------------------------------------------------------------------
* BarCtrl - bar page
* --------------------------------------------------------------------------
*/
ngModule.controller('BarCtrl', ['$scope', function ($scope) {
}]);
};