Merge: Added contributing guidelines and link from readme
[nit.git] / share / nitweb / javascripts / entities.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('entities', ['ui', 'model'])
20
21 .controller('EntityCtrl', ['Model', '$routeParams', '$scope', function(Model, $routeParams, $scope) {
22 this.loadEntityLinearization = function() {
23 Model.loadEntityLinearization($routeParams.id,
24 function(data) {
25 $scope.linearization = data;
26 }, function(err) {
27 $scope.error = err;
28 });
29 };
30
31 this.loadEntityDefs = function() {
32 Model.loadEntityDefs($routeParams.id,
33 function(data) {
34 $scope.defs = data;
35 }, function(err) {
36 $scope.error = err;
37 });
38 };
39
40 this.loadEntityCode = function() {
41 Model.loadEntityCode($routeParams.id,
42 function(data) {
43 $scope.code = data;
44 }, function(err) {
45 $scope.code = err;
46 });
47 };
48
49 Model.loadEntity($routeParams.id,
50 function(data) {
51 $scope.mentity = data;
52 }, function(err) {
53 $scope.error = err;
54 });
55 }])
56
57 .directive('entityLink', function() {
58 return {
59 restrict: 'E',
60 scope: {
61 mentity: '='
62 },
63 templateUrl: '/directives/entity/link.html'
64 };
65 })
66
67 .directive('entityDoc', function() {
68 return {
69 restrict: 'E',
70 scope: {
71 mentity: '='
72 },
73 templateUrl: '/directives/entity/doc.html'
74 };
75 })
76
77 .directive('entitySignature', function() {
78 return {
79 restrict: 'E',
80 scope: {
81 mentity: '='
82 },
83 templateUrl: '/directives/entity/signature.html'
84 };
85 })
86
87 .directive('entityTag', function() {
88 return {
89 restrict: 'E',
90 scope: {
91 mentity: '='
92 },
93 replace: true,
94 templateUrl: '/directives/entity/tag.html'
95 };
96 })
97
98 .directive('entityLocation', function() {
99 return {
100 restrict: 'E',
101 scope: {
102 mentity: '='
103 },
104 templateUrl: '/directives/entity/location.html'
105 };
106 })
107
108 .directive('entityCard', function() {
109 return {
110 restrict: 'E',
111 scope: {
112 mentity: '='
113 },
114 replace: true,
115 templateUrl: '/directives/entity/card.html'
116 };
117 })
118
119 .directive('entityList', function() {
120 return {
121 restrict: 'E',
122 scope: {
123 listEntities: '=',
124 listId: '@',
125 listTitle: '@',
126 listObjectFilter: '=',
127 },
128 templateUrl: '/directives/entity/list.html',
129 link: function ($scope, element, attrs) {
130 $scope.showFilters = false;
131 if(!$scope.listObjectFilter) {
132 $scope.listObjectFilter = {};
133 }
134 if(!$scope.visibilityFilter) {
135 $scope.visibilityFilter = {
136 public: true,
137 protected: true,
138 private: false
139 };
140 }
141 $scope.toggleFilters = function() {
142 $scope.showFilters = !$scope.showFilters;
143 };
144 }
145 };
146 })
147
148 .directive('entityLinearization', function() {
149 return {
150 restrict: 'E',
151 scope: {
152 listEntities: '=',
153 listTitle: '@',
154 listFocus: '='
155 },
156 templateUrl: '/directives/entity/linearization.html'
157 };
158 })
159
160 .directive('entityDef', ['Model', function(Model, Code) {
161 return {
162 restrict: 'E',
163 scope: {
164 definition: '=',
165 focus: '='
166 },
167 templateUrl: '/directives/entity/defcard.html',
168 link: function ($scope, element, attrs) {
169 $scope.codeId = 'code_' + $scope.definition.full_name.replace(/[^a-zA-Z0-9]/g, '_');
170 $scope.loadCardCode = function() {
171 if(!$scope.code) {
172 Model.loadEntityCode($scope.definition.full_name,
173 function(data) {
174 $scope.code = data;
175 setTimeout(function() { // smooth collapse
176 $('#' + $scope.codeId).collapse('show')
177 }, 1);
178 }, function(err) {
179 $scope.code = err;
180 });
181 } else {
182 if($('#' + $scope.codeId).hasClass('in')) {
183 $('#' + $scope.codeId).collapse('hide');
184 } else {
185 $('#' + $scope.codeId).collapse('show');
186 }
187 }
188 };
189 }
190 };
191 }])
192 })();