nitweb: index use ui-router and views for tabs
[nit.git] / share / nitweb / javascripts / index.js
1 /*
2 * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 (function() {
18 angular
19 .module('index', [])
20
21 .config(function($stateProvider, $locationProvider) {
22 $stateProvider
23 .state('catalog', {
24 url: '/',
25 templateUrl: 'views/catalog/index.html',
26 controller: 'CatalogCtrl',
27 controllerAs: 'vm',
28 abstract: true
29 })
30 .state('catalog.highlighted', {
31 url: '',
32 templateUrl: 'views/catalog/highlighted.html',
33 controller: 'CatalogHighlightedCtrl',
34 controllerAs: 'vm'
35 })
36 .state('catalog.required', {
37 url: 'required',
38 templateUrl: 'views/catalog/most_required.html',
39 controller: 'CatalogRequiredCtrl',
40 controllerAs: 'vm'
41 })
42 .state('catalog.tags', {
43 url: 'tags',
44 templateUrl: 'views/catalog/by_tags.html',
45 controller: 'CatalogTagsCtrl',
46 controllerAs: 'vm'
47 })
48 })
49
50 .factory('Catalog', [ '$http', function($http) {
51 return {
52 loadHightlighted: function(cb, cbErr) {
53 $http.get('/api/catalog/highlighted')
54 .success(cb)
55 .error(cbErr);
56 },
57
58 loadMostRequired: function(cb, cbErr) {
59 $http.get('/api/catalog/required')
60 .success(cb)
61 .error(cbErr);
62 },
63
64 loadByTags: function(cb, cbErr) {
65 $http.get('/api/catalog/bytags')
66 .success(cb)
67 .error(cbErr);
68 },
69
70 loadStats: function(cb, cbErr) {
71 $http.get('/api/catalog/stats')
72 .success(cb)
73 .error(cbErr);
74 },
75
76 loadContributors: function(cb, cbErr) {
77 $http.get('/api/catalog/contributors')
78 .success(cb)
79 .error(cbErr);
80 },
81 }
82 }])
83
84 .controller('CatalogCtrl', function(Catalog) {
85 var vm = this;
86
87 Catalog.loadContributors(
88 function(data) {
89 vm.contributors = data;
90 }, function(err) {
91 vm.error = err;
92 });
93
94 Catalog.loadStats(
95 function(data) {
96 vm.stats = data;
97 }, function(err) {
98 vm.error = err;
99 });
100 })
101
102 .controller('CatalogHighlightedCtrl', function(Catalog) {
103 var vm = this;
104
105 Catalog.loadHightlighted(
106 function(data) {
107 vm.highlighted = data;
108 }, function(err) {
109 vm.error = err;
110 });
111 })
112
113 .controller('CatalogRequiredCtrl', function(Catalog) {
114 var vm = this;
115
116 Catalog.loadMostRequired(
117 function(data) {
118 vm.required = data;
119 }, function(err) {
120 vm.error = err;
121 });
122 })
123
124 .controller('CatalogTagsCtrl', function(Catalog, $anchorScroll, $location) {
125 var vm = this;
126
127 Catalog.loadByTags(
128 function(data) {
129 vm.bytags = data;
130 }, function(err) {
131 vm.error = err;
132 });
133
134
135 vm.scrollTo = function(hash) {
136 $location.hash(hash);
137 $anchorScroll();
138 }
139 })
140
141 .directive('contributorList', function(Model) {
142 return {
143 restrict: 'E',
144 scope: {
145 listId: '@',
146 listTitle: '@',
147 listContributors: '='
148 },
149 templateUrl: '/directives/contributor-list.html'
150 };
151 })
152 })();