nitweb: move index state configuration 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', ['model', '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 .controller('IndexCtrl', ['Catalog', '$sce', '$scope', '$location', '$anchorScroll', function(Catalog, $sce, $scope, $location, $anchorScroll) {
32 this.loadHighlighted = function() {
33 Catalog.loadHightlighted(
34 function(data) {
35 $scope.highlighted = data;
36 }, function(err) {
37 $scope.error = err;
38 });
39 };
40
41 this.loadMostRequired = function() {
42 Catalog.loadMostRequired(
43 function(data) {
44 $scope.required = data;
45 }, function(err) {
46 $scope.error = err;
47 });
48 };
49
50 this.loadByTags = function() {
51 Catalog.loadByTags(
52 function(data) {
53 $scope.bytags = data;
54 }, function(err) {
55 $scope.error = err;
56 });
57 };
58
59 this.loadStats = function() {
60 Catalog.loadStats(
61 function(data) {
62 $scope.stats = data;
63 }, function(err) {
64 $scope.error = err;
65 });
66 };
67
68 this.loadContributors = function() {
69 Catalog.loadContributors(
70 function(data) {
71 $scope.contributors = data;
72 }, function(err) {
73 $scope.error = err;
74 });
75 };
76
77
78 this.scrollTo = function(hash) {
79 $anchorScroll(hash);
80 }
81
82 this.loadHighlighted();
83 this.loadStats();
84 this.loadContributors();
85 }])
86
87 .directive('contributorList', ['Model', function(Model) {
88 return {
89 restrict: 'E',
90 scope: {
91 listId: '@',
92 listTitle: '@',
93 listContributors: '='
94 },
95 templateUrl: '/directives/contributor-list.html'
96 };
97 }])
98 })();