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