nitweb: move index model to index module
[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', ['ngSanitize'])
20
21 .config(function($stateProvider, $locationProvider) {
22 $stateProvider
23 .state('index', {
24 url: '/',
25 templateUrl: 'views/index.html',
26 controller: 'IndexCtrl',
27 controllerAs: 'indexCtrl'
28 })
29 })
30
31 .factory('Catalog', [ '$http', function($http) {
32 return {
33 loadHightlighted: function(cb, cbErr) {
34 $http.get('/api/catalog/highlighted')
35 .success(cb)
36 .error(cbErr);
37 },
38
39 loadMostRequired: function(cb, cbErr) {
40 $http.get('/api/catalog/required')
41 .success(cb)
42 .error(cbErr);
43 },
44
45 loadByTags: function(cb, cbErr) {
46 $http.get('/api/catalog/bytags')
47 .success(cb)
48 .error(cbErr);
49 },
50
51 loadStats: function(cb, cbErr) {
52 $http.get('/api/catalog/stats')
53 .success(cb)
54 .error(cbErr);
55 },
56
57 loadContributors: function(cb, cbErr) {
58 $http.get('/api/catalog/contributors')
59 .success(cb)
60 .error(cbErr);
61 },
62 }
63 }])
64
65 .controller('IndexCtrl', function(Catalog, $sce, $scope, $location, $anchorScroll) {
66 this.loadHighlighted = function() {
67 Catalog.loadHightlighted(
68 function(data) {
69 $scope.highlighted = data;
70 }, function(err) {
71 $scope.error = err;
72 });
73 };
74
75 this.loadMostRequired = function() {
76 Catalog.loadMostRequired(
77 function(data) {
78 $scope.required = data;
79 }, function(err) {
80 $scope.error = err;
81 });
82 };
83
84 this.loadByTags = function() {
85 Catalog.loadByTags(
86 function(data) {
87 $scope.bytags = data;
88 }, function(err) {
89 $scope.error = err;
90 });
91 };
92
93 this.loadStats = function() {
94 Catalog.loadStats(
95 function(data) {
96 $scope.stats = data;
97 }, function(err) {
98 $scope.error = err;
99 });
100 };
101
102 this.loadContributors = function() {
103 Catalog.loadContributors(
104 function(data) {
105 $scope.contributors = data;
106 }, function(err) {
107 $scope.error = err;
108 });
109 };
110
111
112 this.scrollTo = function(hash) {
113 $anchorScroll(hash);
114 }
115
116 this.loadHighlighted();
117 this.loadStats();
118 this.loadContributors();
119 })
120
121 .directive('contributorList', function(Model) {
122 return {
123 restrict: 'E',
124 scope: {
125 listId: '@',
126 listTitle: '@',
127 listContributors: '='
128 },
129 templateUrl: '/directives/contributor-list.html'
130 };
131 })
132 })();