c1eb43d3b6972ef0478f4e8ac6748cf4836ee63f
2 * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 .module('entities', ['ngSanitize', 'ui', 'model'])
21 .controller('EntityCtrl', ['Model', 'Metrics', '$routeParams', '$scope', '$sce', function(Model
, Metrics
, $routeParams
, $scope
, $sce
) {
22 $scope
.entityId
= $routeParams
.id
;
24 this.loadEntityLinearization
= function() {
25 Model
.loadEntityLinearization($routeParams
.id
,
27 $scope
.linearization
= data
;
33 this.loadEntityDefs
= function() {
34 Model
.loadEntityDefs($routeParams
.id
,
42 this.loadEntityCode
= function() {
43 Model
.loadEntityCode($routeParams
.id
,
51 this.loadEntityGraph
= function(e
) {
52 Model
.loadEntityGraph($routeParams
.id
,
54 $scope
.graph
= $sce
.trustAsHtml(data
);
60 this.loadStructuralMetrics
= function() {
61 Metrics
.loadStructuralMetrics($routeParams
.id
,
63 $scope
.metrics
= data
;
64 }, function(message
, status
) {
65 $scope
.error
= {message
: message
, status
: status
};
69 Model
.loadEntity($routeParams
.id
,
71 $scope
.mentity
= data
;
72 }, function(message
, status
) {
73 $scope
.error
= {message
: message
, status
: status
};
77 .directive('entityLink', function() {
83 templateUrl
: '/directives/entity/link.html'
87 .directive('entityDoc', function() {
93 templateUrl
: '/directives/entity/doc.html'
97 .directive('entitySignature', function() {
103 templateUrl
: '/directives/entity/signature.html'
107 .directive('entityNamespace', function() {
113 templateUrl
: '/directives/entity/namespace.html',
114 link
: function ($scope
, element
, attrs
) {
115 $scope
.isObject
= function(obj
) {
116 return typeof obj
=== 'object';
118 $scope
.isArray
= function(obj
) {
119 return Array
.isArray(obj
);
121 $scope
.isString
= function(obj
) {
122 return typeof obj
=== 'string';
128 .directive('entityTag', function() {
135 templateUrl
: '/directives/entity/tag.html'
139 .directive('entityLocation', function() {
145 templateUrl
: '/directives/entity/location.html'
149 .directive('entityGraph', function() {
157 templateUrl
: '/directives/entity/graph.html'
161 .directive('entityCard', function() {
169 templateUrl
: '/directives/entity/card.html',
170 link
: function ($scope
, element
, attrs
) {
171 $scope
.currentTab
= $scope
.defaultTab ? $scope
.defaultTab
: 'signature';
176 .directive('entityList', function() {
183 listObjectFilter
: '=',
185 templateUrl
: '/directives/entity/list.html',
186 link
: function ($scope
, element
, attrs
) {
187 $scope
.showFilters
= false;
188 if(!$scope
.listObjectFilter
) {
189 $scope
.listObjectFilter
= {};
191 if(!$scope
.visibilityFilter
) {
192 $scope
.visibilityFilter
= {
198 $scope
.toggleFilters
= function() {
199 $scope
.showFilters
= !$scope
.showFilters
;
205 .directive('entityLinearization', function() {
213 templateUrl
: '/directives/entity/linearization.html'
217 .directive('entityDef', ['Model', function(Model
, Code
) {
224 templateUrl
: '/directives/entity/defcard.html',
225 link
: function ($scope
, element
, attrs
) {
226 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
228 $scope
.isActive
= function() {
229 return $scope
.focus
.full_name
== $scope
.definition
.full_name
;
232 $scope
.loadCardCode
= function() {
234 Model
.loadEntityCode($scope
.definition
.full_name
,
237 setTimeout(function() { // smooth collapse
238 $
('#' + $scope
.codeId
).collapse('show')
244 if($
('#' + $scope
.codeId
).hasClass('in')) {
245 $
('#' + $scope
.codeId
).collapse('hide');
247 $
('#' + $scope
.codeId
).collapse('show');
252 if($scope
.isActive()) $scope
.loadCardCode();
257 .directive('entityRating', ['Feedback', function(Feedback
, Code
) {
263 templateUrl
: '/directives/entity/stars.html',
264 link
: function ($scope
, element
, attrs
) {
265 $scope
.postStar
= function(rating
) {
266 Feedback
.postEntityStar($scope
.mentity
.full_name
, rating
,
268 $scope
.ratings
= data
;
274 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
276 $scope
.ratings
= data
;