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'])
21 .factory('Model', [ '$http', function($http
) {
24 loadEntity
: function(id
, cb
, cbErr
) {
25 $http
.get('/api/entity/' + id
)
30 loadEntityLinearization
: function(id
, cb
, cbErr
) {
31 $http
.get('/api/linearization/' + id
)
36 loadEntityDefs
: function(id
, cb
, cbErr
) {
37 $http
.get('/api/defs/' + id
)
42 loadEntityCode
: function(id
, cb
, cbErr
) {
43 $http
.get('/api/code/' + id
)
48 loadEntityGraph
: function(id
, cb
, cbErr
) {
49 $http
.get('/api/graph/inheritance/' + id
+ '?cdepth=3')
54 search
: function(q
, n
, cb
, cbErr
) {
55 $http
.get('/api/search?q=' + q
+ '&n=' + n
)
62 .controller('EntityCtrl', ['Model', 'Metrics', 'Feedback', '$stateParams', '$scope', '$sce', function(Model
, Metrics
, Feedback
, $stateParams
, $scope
, $sce
) {
63 $scope
.entityId
= $stateParams
.id
;
65 this.loadEntityLinearization
= function() {
66 Model
.loadEntityLinearization($stateParams
.id
,
68 $scope
.linearization
= data
;
74 this.loadEntityDefs
= function() {
75 Model
.loadEntityDefs($stateParams
.id
,
83 this.loadEntityCode
= function() {
84 Model
.loadEntityCode($stateParams
.id
,
92 this.loadEntityGraph
= function(e
) {
93 Model
.loadEntityGraph($stateParams
.id
,
95 $scope
.graph
= $sce
.trustAsHtml(data
);
101 this.loadStructuralMetrics
= function() {
102 Metrics
.loadStructuralMetrics($stateParams
.id
,
104 $scope
.metrics
= data
;
105 }, function(message
, status
) {
106 $scope
.error
= {message
: message
, status
: status
};
110 Model
.loadEntity($stateParams
.id
,
112 $scope
.mentity
= data
;
113 }, function(message
, status
) {
114 $scope
.error
= {message
: message
, status
: status
};
118 .directive('entityLink', function() {
124 templateUrl
: '/directives/entity/link.html'
128 .directive('entityDoc', function() {
134 templateUrl
: '/directives/entity/doc.html'
138 .directive('entitySignature', function() {
144 templateUrl
: '/directives/entity/signature.html'
148 .directive('entityNamespace', function() {
154 templateUrl
: '/directives/entity/namespace.html',
155 link
: function ($scope
, element
, attrs
) {
156 $scope
.isObject
= function(obj
) {
157 return typeof obj
=== 'object';
159 $scope
.isArray
= function(obj
) {
160 return Array
.isArray(obj
);
162 $scope
.isString
= function(obj
) {
163 return typeof obj
=== 'string';
169 .directive('entityTag', function() {
176 templateUrl
: '/directives/entity/tag.html'
180 .directive('entityLocation', function() {
186 templateUrl
: '/directives/entity/location.html'
190 .directive('entityGraph', function() {
198 templateUrl
: '/directives/entity/graph.html'
202 .directive('entityCard', ['Feedback', function(Feedback
) {
211 templateUrl
: '/directives/entity/card.html',
212 link
: function ($scope
, element
, attrs
) {
213 $scope
.currentTab
= $scope
.defaultTab ? $scope
.defaultTab
: 'signature';
215 $scope
.loadEntityStars
= function() {
216 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
218 $scope
.ratings
= data
;
219 }, function(message
, status
) {
220 $scope
.error
= {message
: message
, status
: status
};
227 .directive('entityList', function() {
234 listObjectFilter
: '=',
236 templateUrl
: '/directives/entity/list.html',
237 link
: function ($scope
, element
, attrs
) {
238 $scope
.showFilters
= false;
239 if(!$scope
.listObjectFilter
) {
240 $scope
.listObjectFilter
= {};
242 if(!$scope
.visibilityFilter
) {
243 $scope
.visibilityFilter
= {
249 $scope
.toggleFilters
= function() {
250 $scope
.showFilters
= !$scope
.showFilters
;
256 .directive('entityLinearization', function() {
264 templateUrl
: '/directives/entity/linearization.html'
268 .directive('entityDef', ['Model', function(Model
, Code
) {
275 templateUrl
: '/directives/entity/defcard.html',
276 link
: function ($scope
, element
, attrs
) {
277 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
279 $scope
.isActive
= function() {
280 return $scope
.focus
.full_name
== $scope
.definition
.full_name
;
283 $scope
.loadCardCode
= function() {
285 Model
.loadEntityCode($scope
.definition
.full_name
,
288 setTimeout(function() { // smooth collapse
289 $
('#' + $scope
.codeId
).collapse('show')
295 if($
('#' + $scope
.codeId
).hasClass('in')) {
296 $
('#' + $scope
.codeId
).collapse('hide');
298 $
('#' + $scope
.codeId
).collapse('show');
303 if($scope
.isActive()) $scope
.loadCardCode();
308 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
311 this.postStar
= function(rating
) {
312 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
313 $scope
.dimension
, rating
,
315 $scope
.mean
= data
.mean
;
316 $scope
.list
= data
.ratings
;
317 $scope
.user
= data
.user
;
318 $ctrl
.loadEntityStars($scope
);
324 this.loadEntityStars
= function($scope
) {
325 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
327 $scope
.ratings
= data
;
328 }, function(message
, status
) {
329 $scope
.error
= {message
: message
, status
: status
};
334 .directive('entityRating', ['Feedback', function(Feedback
) {
341 controller
: 'StarsCtrl',
342 controllerAs
: 'ratingsCtrl',
343 templateUrl
: '/directives/entity/rating.html'
347 .directive('entityStars', ['Feedback', function(Feedback
) {
359 controller
: 'StarsCtrl',
360 controllerAs
: 'starsCtrl',
361 templateUrl
: '/directives/entity/stars.html'