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', 'Feedback', '$routeParams', '$scope', '$sce', function(Model
, Metrics
, Feedback
, $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', ['Feedback', function(Feedback
) {
170 templateUrl
: '/directives/entity/card.html',
171 link
: function ($scope
, element
, attrs
) {
172 $scope
.currentTab
= $scope
.defaultTab ? $scope
.defaultTab
: 'signature';
174 $scope
.loadEntityStars
= function() {
175 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
177 $scope
.ratings
= data
;
178 }, function(message
, status
) {
179 $scope
.error
= {message
: message
, status
: status
};
186 .directive('entityList', function() {
193 listObjectFilter
: '=',
195 templateUrl
: '/directives/entity/list.html',
196 link
: function ($scope
, element
, attrs
) {
197 $scope
.showFilters
= false;
198 if(!$scope
.listObjectFilter
) {
199 $scope
.listObjectFilter
= {};
201 if(!$scope
.visibilityFilter
) {
202 $scope
.visibilityFilter
= {
208 $scope
.toggleFilters
= function() {
209 $scope
.showFilters
= !$scope
.showFilters
;
215 .directive('entityLinearization', function() {
223 templateUrl
: '/directives/entity/linearization.html'
227 .directive('entityDef', ['Model', function(Model
, Code
) {
234 templateUrl
: '/directives/entity/defcard.html',
235 link
: function ($scope
, element
, attrs
) {
236 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
238 $scope
.isActive
= function() {
239 return $scope
.focus
.full_name
== $scope
.definition
.full_name
;
242 $scope
.loadCardCode
= function() {
244 Model
.loadEntityCode($scope
.definition
.full_name
,
247 setTimeout(function() { // smooth collapse
248 $
('#' + $scope
.codeId
).collapse('show')
254 if($
('#' + $scope
.codeId
).hasClass('in')) {
255 $
('#' + $scope
.codeId
).collapse('hide');
257 $
('#' + $scope
.codeId
).collapse('show');
262 if($scope
.isActive()) $scope
.loadCardCode();
267 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
270 this.postStar
= function(rating
) {
271 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
272 $scope
.dimension
, rating
,
274 $scope
.mean
= data
.mean
;
275 $scope
.list
= data
.ratings
;
276 $scope
.user
= data
.user
;
277 $ctrl
.loadEntityStars($scope
);
283 this.loadEntityStars
= function($scope
) {
284 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
286 $scope
.ratings
= data
;
287 }, function(message
, status
) {
288 $scope
.error
= {message
: message
, status
: status
};
293 .directive('entityRating', ['Feedback', function(Feedback
) {
300 controller
: 'StarsCtrl',
301 controllerAs
: 'ratingsCtrl',
302 templateUrl
: '/directives/entity/rating.html'
306 .directive('entityStars', ['Feedback', function(Feedback
) {
318 controller
: 'StarsCtrl',
319 controllerAs
: 'starsCtrl',
320 templateUrl
: '/directives/entity/stars.html'