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'])
23 .config(function($stateProvider
, $locationProvider
) {
27 templateUrl
: 'views/doc/index.html',
29 mentity
: function(Model
, $q
, $stateParams
, $state
) {
31 Model
.loadEntity($stateParams
.id
, d
.resolve
,
33 $state
.go('404', null, { location
: false })
38 controller
: function(mentity
) {
39 this.mentity
= mentity
;
44 .state('doc.entity', {
46 templateUrl
: 'views/doc/entity.html',
47 controller
: function(mentity
) {
48 this.mentity
= mentity
;
53 .state('doc.entity.doc', {
55 templateUrl
: 'views/doc/doc.html',
57 doc
: function(Model
, $q
, $stateParams
, $state
) {
59 Model
.loadEntityDoc($stateParams
.id
, d
.resolve
,
61 $state
.go('404', null, { location
: false })
66 controller
: function(mentity
, doc
) {
67 this.mentity
= mentity
;
72 .state('doc.entity.graph', {
74 templateUrl
: 'views/doc/graph.html',
76 graph
: function(Model
, $q
, $stateParams
, $state
) {
78 Model
.loadEntityGraph($stateParams
.id
, d
.resolve
,
80 $state
.go('404', null, { location
: false })
84 inh
: function(Model
, $q
, $stateParams
, $state
) {
86 Model
.loadEntityInh($stateParams
.id
, d
.resolve
,
88 $state
.go('404', null, { location
: false })
93 controller
: function(inh
, graph
, $sce
) {
94 this.graph
= $sce
.trustAsHtml(graph
);
99 .state('doc.entity.metrics', {
101 templateUrl
: 'views/doc/metrics.html',
103 metrics
: function(Metrics
, $q
, $stateParams
, $state
) {
105 Metrics
.loadStructuralMetrics($stateParams
.id
, d
.resolve
,
107 $state
.go('404', null, { location
: false })
112 controller
: function(mentity
, metrics
) {
113 this.mentity
= mentity
;
114 this.metrics
= metrics
;
118 .state('doc.entity.code', {
120 templateUrl
: 'views/doc/code.html',
122 code
: function(Model
, $q
, $stateParams
, $state
) {
124 Model
.loadEntityCode($stateParams
.id
, d
.resolve
,
126 $state
.go('404', null, { location
: false })
131 controller
: function(mentity
, code
) {
132 this.mentity
= mentity
;
137 .state('doc.entity.defs', {
139 templateUrl
: 'views/doc/defs.html',
141 defs
: function(Model
, $q
, $stateParams
, $state
) {
143 Model
.loadEntityDefs($stateParams
.id
, d
.resolve
,
145 $state
.go('404', null, { location
: false })
150 controller
: function(mentity
, defs
) {
151 this.mentity
= mentity
;
156 .state('doc.entity.lin', {
158 templateUrl
: 'views/doc/lin.html',
160 lin
: function(Model
, $q
, $stateParams
, $state
) {
162 Model
.loadEntityLinearization($stateParams
.id
, d
.resolve
,
164 $state
.go('404', null, { location
: false })
169 controller
: function(mentity
, lin
, $scope
, $location
, $anchorScroll
) {
171 vm
.focus
= $location
.hash() ?
172 $location
.hash() : mentity
.intro
.full_name
;
173 vm
.mentity
= mentity
;
174 vm
.linearization
= lin
;
175 setTimeout(function() {
178 $scope
.$
watch(function () {
179 return $location
.hash();
180 }, function (value
) {
181 vm
.focus
= $location
.hash() ?
182 $location
.hash() : mentity
.intro
.full_name
;
188 .state('doc.entity.all', {
190 templateUrl
: 'views/doc/all.html',
191 controller
: function(mentity
) {
192 this.mentity
= mentity
;
200 .factory('Model', [ '$http', function($http
) {
203 loadEntity
: function(id
, cb
, cbErr
) {
204 $http
.get('/api/entity/' + id
)
209 loadEntityDoc
: function(id
, cb
, cbErr
) {
210 $http
.get('/api/entity/' + id
+ '/doc')
215 loadEntityLinearization
: function(id
, cb
, cbErr
) {
216 $http
.get('/api/linearization/' + id
)
221 loadEntityDefs
: function(id
, cb
, cbErr
) {
222 $http
.get('/api/defs/' + id
)
227 loadEntityCode
: function(id
, cb
, cbErr
) {
228 $http
.get('/api/code/' + id
)
233 loadEntityGraph
: function(id
, cb
, cbErr
) {
234 $http
.get('/api/graph/inheritance/' + id
+ '?cdepth=3')
239 loadEntityInh
: function(id
, cb
, cbErr
) {
240 $http
.get('/api/inheritance/' + id
)
245 search
: function(q
, n
, cb
, cbErr
) {
246 $http
.get('/api/search?q=' + q
+ '&n=' + n
)
255 .directive('entityLink', function() {
261 templateUrl
: '/directives/entity/link.html'
265 .directive('entityDoc', function() {
271 templateUrl
: '/directives/entity/doc.html'
275 .directive('entitySignature', function() {
281 templateUrl
: '/directives/entity/signature.html'
285 .directive('entityNamespace', function() {
291 templateUrl
: '/directives/entity/namespace.html',
292 link
: function ($scope
, element
, attrs
) {
293 $scope
.isObject
= function(obj
) {
294 return typeof obj
=== 'object';
296 $scope
.isArray
= function(obj
) {
297 return Array
.isArray(obj
);
299 $scope
.isString
= function(obj
) {
300 return typeof obj
=== 'string';
306 .directive('entityTag', function() {
313 templateUrl
: '/directives/entity/tag.html'
317 .directive('entityLocation', function() {
323 templateUrl
: '/directives/entity/location.html'
327 .directive('entityGraph', function() {
335 templateUrl
: '/directives/entity/graph.html'
339 .directive('entityCard', ['Feedback', function(Feedback
) {
348 templateUrl
: '/directives/entity/card.html',
349 link
: function ($scope
, element
, attrs
) {
350 $scope
.currentTab
= $scope
.defaultTab ? $scope
.defaultTab
: 'signature';
352 $scope
.loadEntityStars
= function() {
353 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
355 $scope
.ratings
= data
;
356 }, function(message
, status
) {
357 $scope
.error
= {message
: message
, status
: status
};
364 .directive('entityList', function() {
371 listObjectFilter
: '=',
373 templateUrl
: '/directives/entity/list.html',
374 link
: function ($scope
, element
, attrs
) {
375 $scope
.showFilters
= false;
376 if(!$scope
.listObjectFilter
) {
377 $scope
.listObjectFilter
= {};
379 if(!$scope
.visibilityFilter
) {
380 $scope
.visibilityFilter
= {
386 $scope
.toggleFilters
= function() {
387 $scope
.showFilters
= !$scope
.showFilters
;
393 .directive('entityLinearization', function() {
401 templateUrl
: '/directives/entity/linearization.html'
405 .directive('entityDef', ['Model', function(Model
, Code
) {
412 templateUrl
: '/directives/entity/defcard.html',
413 link
: function ($scope
, element
, attrs
) {
414 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
416 $scope
.isActive
= function() {
417 return $scope
.focus
== $scope
.definition
.full_name
;
420 $scope
.loadCardCode
= function() {
422 Model
.loadEntityCode($scope
.definition
.full_name
,
425 setTimeout(function() { // smooth collapse
426 $
('#' + $scope
.codeId
).collapse('show')
432 if($
('#' + $scope
.codeId
).hasClass('in')) {
433 $
('#' + $scope
.codeId
).collapse('hide');
435 $
('#' + $scope
.codeId
).collapse('show');
440 $scope
.$
watch('focus', function() {
441 if($scope
.isActive()) $scope
.loadCardCode();
447 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
450 this.postStar
= function(rating
) {
451 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
452 $scope
.dimension
, rating
,
454 $scope
.mean
= data
.mean
;
455 $scope
.list
= data
.ratings
;
456 $scope
.user
= data
.user
;
457 $ctrl
.loadEntityStars($scope
);
463 this.loadEntityStars
= function($scope
) {
464 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
466 $scope
.ratings
= data
;
467 }, function(message
, status
) {
468 $scope
.error
= {message
: message
, status
: status
};
473 .directive('entityRating', ['Feedback', function(Feedback
) {
480 controller
: 'StarsCtrl',
481 controllerAs
: 'ratingsCtrl',
482 templateUrl
: '/directives/entity/rating.html'
486 .directive('entityStars', ['Feedback', function(Feedback
) {
498 controller
: 'StarsCtrl',
499 controllerAs
: 'starsCtrl',
500 templateUrl
: '/directives/entity/stars.html'