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 .config(function($stateProvider
, $locationProvider
) {
25 templateUrl
: 'views/doc.html',
26 controller
: 'EntityCtrl',
27 controllerAs
: 'entityCtrl',
31 .factory('Model', [ '$http', function($http
) {
34 loadEntity
: function(id
, cb
, cbErr
) {
35 $http
.get('/api/entity/' + id
)
40 loadEntityLinearization
: function(id
, cb
, cbErr
) {
41 $http
.get('/api/linearization/' + id
)
46 loadEntityDefs
: function(id
, cb
, cbErr
) {
47 $http
.get('/api/defs/' + id
)
52 loadEntityCode
: function(id
, cb
, cbErr
) {
53 $http
.get('/api/code/' + id
)
58 loadEntityGraph
: function(id
, cb
, cbErr
) {
59 $http
.get('/api/graph/inheritance/' + id
+ '?cdepth=3')
64 search
: function(q
, n
, cb
, cbErr
) {
65 $http
.get('/api/search?q=' + q
+ '&n=' + n
)
72 .controller('EntityCtrl', ['Model', 'Metrics', 'Feedback', '$stateParams', '$scope', '$sce', function(Model
, Metrics
, Feedback
, $stateParams
, $scope
, $sce
) {
73 $scope
.entityId
= $stateParams
.id
;
75 this.loadEntityLinearization
= function() {
76 Model
.loadEntityLinearization($stateParams
.id
,
78 $scope
.linearization
= data
;
84 this.loadEntityDefs
= function() {
85 Model
.loadEntityDefs($stateParams
.id
,
93 this.loadEntityCode
= function() {
94 Model
.loadEntityCode($stateParams
.id
,
102 this.loadEntityGraph
= function(e
) {
103 Model
.loadEntityGraph($stateParams
.id
,
105 $scope
.graph
= $sce
.trustAsHtml(data
);
111 this.loadStructuralMetrics
= function() {
112 Metrics
.loadStructuralMetrics($stateParams
.id
,
114 $scope
.metrics
= data
;
115 }, function(message
, status
) {
116 $scope
.error
= {message
: message
, status
: status
};
120 Model
.loadEntity($stateParams
.id
,
122 $scope
.mentity
= data
;
123 }, function(message
, status
) {
124 $scope
.error
= {message
: message
, status
: status
};
128 .directive('entityLink', function() {
134 templateUrl
: '/directives/entity/link.html'
138 .directive('entityDoc', function() {
144 templateUrl
: '/directives/entity/doc.html'
148 .directive('entitySignature', function() {
154 templateUrl
: '/directives/entity/signature.html'
158 .directive('entityNamespace', function() {
164 templateUrl
: '/directives/entity/namespace.html',
165 link
: function ($scope
, element
, attrs
) {
166 $scope
.isObject
= function(obj
) {
167 return typeof obj
=== 'object';
169 $scope
.isArray
= function(obj
) {
170 return Array
.isArray(obj
);
172 $scope
.isString
= function(obj
) {
173 return typeof obj
=== 'string';
179 .directive('entityTag', function() {
186 templateUrl
: '/directives/entity/tag.html'
190 .directive('entityLocation', function() {
196 templateUrl
: '/directives/entity/location.html'
200 .directive('entityGraph', function() {
208 templateUrl
: '/directives/entity/graph.html'
212 .directive('entityCard', ['Feedback', function(Feedback
) {
221 templateUrl
: '/directives/entity/card.html',
222 link
: function ($scope
, element
, attrs
) {
223 $scope
.currentTab
= $scope
.defaultTab ? $scope
.defaultTab
: 'signature';
225 $scope
.loadEntityStars
= function() {
226 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
228 $scope
.ratings
= data
;
229 }, function(message
, status
) {
230 $scope
.error
= {message
: message
, status
: status
};
237 .directive('entityList', function() {
244 listObjectFilter
: '=',
246 templateUrl
: '/directives/entity/list.html',
247 link
: function ($scope
, element
, attrs
) {
248 $scope
.showFilters
= false;
249 if(!$scope
.listObjectFilter
) {
250 $scope
.listObjectFilter
= {};
252 if(!$scope
.visibilityFilter
) {
253 $scope
.visibilityFilter
= {
259 $scope
.toggleFilters
= function() {
260 $scope
.showFilters
= !$scope
.showFilters
;
266 .directive('entityLinearization', function() {
274 templateUrl
: '/directives/entity/linearization.html'
278 .directive('entityDef', ['Model', function(Model
, Code
) {
285 templateUrl
: '/directives/entity/defcard.html',
286 link
: function ($scope
, element
, attrs
) {
287 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
289 $scope
.isActive
= function() {
290 return $scope
.focus
.full_name
== $scope
.definition
.full_name
;
293 $scope
.loadCardCode
= function() {
295 Model
.loadEntityCode($scope
.definition
.full_name
,
298 setTimeout(function() { // smooth collapse
299 $
('#' + $scope
.codeId
).collapse('show')
305 if($
('#' + $scope
.codeId
).hasClass('in')) {
306 $
('#' + $scope
.codeId
).collapse('hide');
308 $
('#' + $scope
.codeId
).collapse('show');
313 if($scope
.isActive()) $scope
.loadCardCode();
318 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
321 this.postStar
= function(rating
) {
322 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
323 $scope
.dimension
, rating
,
325 $scope
.mean
= data
.mean
;
326 $scope
.list
= data
.ratings
;
327 $scope
.user
= data
.user
;
328 $ctrl
.loadEntityStars($scope
);
334 this.loadEntityStars
= function($scope
) {
335 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
337 $scope
.ratings
= data
;
338 }, function(message
, status
) {
339 $scope
.error
= {message
: message
, status
: status
};
344 .directive('entityRating', ['Feedback', function(Feedback
) {
351 controller
: 'StarsCtrl',
352 controllerAs
: 'ratingsCtrl',
353 templateUrl
: '/directives/entity/rating.html'
357 .directive('entityStars', ['Feedback', function(Feedback
) {
369 controller
: 'StarsCtrl',
370 controllerAs
: 'starsCtrl',
371 templateUrl
: '/directives/entity/stars.html'