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 })
65 parents
: function(Model
, $q
, $stateParams
, $state
) {
67 Model
.loadEntityParents($stateParams
.id
, d
.resolve
,
69 $state
.go('404', null, { location
: false })
73 children
: function(Model
, $q
, $stateParams
, $state
) {
75 Model
.loadEntityChildren($stateParams
.id
, d
.resolve
,
77 $state
.go('404', null, { location
: false })
81 intros
: function(Model
, $q
, $stateParams
, $state
) {
83 Model
.loadEntityIntros($stateParams
.id
, d
.resolve
,
85 $state
.go('404', null, { location
: false })
89 redefs
: function(Model
, $q
, $stateParams
, $state
) {
91 Model
.loadEntityRedefs($stateParams
.id
, d
.resolve
,
93 $state
.go('404', null, { location
: false })
97 meta
: function(Model
, $q
, $stateParams
, $state
) {
99 Model
.loadEntityMeta($stateParams
.id
, d
.resolve
,
101 $state
.go('404', null, { location
: false })
106 controller
: function(mentity
, doc
, parents
, children
, intros
, redefs
, meta
) {
107 this.mentity
= mentity
;
109 this.parents
= parents
;
110 this.children
= children
;
111 this.intros
= intros
;
112 this.redefs
= redefs
;
115 this.date
= function(date
) {
116 return new Date(date
);
121 .state('doc.entity.graph', {
123 templateUrl
: 'views/doc/graph.html',
125 graph
: function(Model
, $q
, $stateParams
, $state
) {
127 Model
.loadEntityGraph($stateParams
.id
, d
.resolve
,
129 $state
.go('404', null, { location
: false })
133 ancestors
: function(Model
, $q
, $stateParams
, $state
) {
135 Model
.loadEntityAncestors($stateParams
.id
, d
.resolve
,
137 $state
.go('404', null, { location
: false })
141 parents
: function(Model
, $q
, $stateParams
, $state
) {
143 Model
.loadEntityParents($stateParams
.id
, d
.resolve
,
145 $state
.go('404', null, { location
: false })
149 children
: function(Model
, $q
, $stateParams
, $state
) {
151 Model
.loadEntityChildren($stateParams
.id
, d
.resolve
,
153 $state
.go('404', null, { location
: false })
157 descendants
: function(Model
, $q
, $stateParams
, $state
) {
159 Model
.loadEntityDescendants($stateParams
.id
, d
.resolve
,
161 $state
.go('404', null, { location
: false })
166 controller
: function(ancestors
, parents
, children
, descendants
, graph
, $sce
) {
167 this.graph
= $sce
.trustAsHtml(graph
.graph
);
168 this.ancestors
= ancestors
;
169 this.parents
= parents
;
170 this.children
= children
;
171 this.descendants
= descendants
;
175 .state('doc.entity.metrics', {
177 templateUrl
: 'views/doc/metrics.html',
179 metrics
: function(Metrics
, $q
, $stateParams
, $state
) {
181 Metrics
.loadStructuralMetrics($stateParams
.id
, d
.resolve
,
183 $state
.go('404', null, { location
: false })
188 controller
: function(mentity
, metrics
) {
189 this.mentity
= mentity
;
190 this.metrics
= metrics
;
194 .state('doc.entity.code', {
196 templateUrl
: 'views/doc/code.html',
198 code
: function(Model
, $q
, $stateParams
, $state
) {
200 Model
.loadEntityCode($stateParams
.id
, d
.resolve
,
202 $state
.go('404', null, { location
: false })
207 controller
: function(mentity
, code
) {
208 this.mentity
= mentity
;
213 .state('doc.entity.defs', {
215 templateUrl
: 'views/doc/defs.html',
217 defs
: function(Model
, $q
, $stateParams
, $state
) {
219 Model
.loadEntityDefs($stateParams
.id
, d
.resolve
,
221 $state
.go('404', null, { location
: false })
226 controller
: function(mentity
, defs
) {
227 this.mentity
= mentity
;
232 .state('doc.entity.lin', {
234 templateUrl
: 'views/doc/lin.html',
236 lin
: function(Model
, $q
, $stateParams
, $state
) {
238 Model
.loadEntityLin($stateParams
.id
, d
.resolve
,
240 $state
.go('404', null, { location
: false })
245 controller
: function(mentity
, lin
, $scope
, $location
, $anchorScroll
) {
247 vm
.focus
= $location
.hash() ?
248 $location
.hash() : lin
.results
[0].full_name
;
249 vm
.mentity
= mentity
;
250 vm
.linearization
= lin
;
251 setTimeout(function() {
254 $scope
.$
watch(function () {
255 return $location
.hash();
256 }, function (value
) {
257 vm
.focus
= $location
.hash() ?
258 $location
.hash() : lin
.results
[0].full_name
;
264 .state('doc.entity.all', {
266 templateUrl
: 'views/doc/defs.html',
268 defs
: function(Model
, $q
, $stateParams
, $state
) {
270 Model
.loadEntityAll($stateParams
.id
, d
.resolve
,
272 $state
.go('404', null, { location
: false })
277 controller
: function(mentity
, defs
) {
278 this.mentity
= mentity
;
287 .factory('Model', [ '$http', function($http
) {
290 loadEntity
: function(id
, cb
, cbErr
) {
291 $http
.get('/api/entity/' + id
)
296 loadEntityDoc
: function(id
, cb
, cbErr
) {
297 $http
.get('/api/doc/' + id
+ '?format=html')
302 loadEntityLin
: function(id
, cb
, cbErr
) {
303 $http
.get('/api/lin/' + id
)
308 loadEntityDefs
: function(id
, cb
, cbErr
) {
309 $http
.get('/api/defs/' + id
)
314 loadEntityIntros
: function(id
, cb
, cbErr
) {
315 $http
.get('/api/intros/' + id
)
320 loadEntityRedefs
: function(id
, cb
, cbErr
) {
321 $http
.get('/api/redefs/' + id
)
326 loadEntityAll
: function(id
, cb
, cbErr
) {
327 $http
.get('/api/all/' + id
)
332 loadEntityCode
: function(id
, cb
, cbErr
) {
333 $http
.get('/api/code/' + id
+ '?format=html')
338 loadEntityAncestors
: function(id
, cb
, cbErr
) {
339 $http
.get('/api/ancestors/' + id
)
344 loadEntityParents
: function(id
, cb
, cbErr
) {
345 $http
.get('/api/parents/' + id
)
350 loadEntityChildren
: function(id
, cb
, cbErr
) {
351 $http
.get('/api/children/' + id
)
356 loadEntityDescendants
: function(id
, cb
, cbErr
) {
357 $http
.get('/api/descendants/' + id
)
362 loadEntityMeta
: function(id
, cb
, cbErr
) {
363 $http
.get('/api/meta/' + id
)
368 loadEntityGraph
: function(id
, cb
, cbErr
) {
369 $http
.get('/api/graph/inheritance/' + id
+ '?format=svg&cdepth=3')
374 search
: function(q
, p
, n
, cb
, cbErr
) {
375 $http
.get('/api/search?q=' + q
+ '&p=' + p
+ '&l=' + n
)
384 .directive('entityLink', function() {
391 templateUrl
: '/directives/entity/link.html'
395 .directive('entityDoc', function() {
401 templateUrl
: '/directives/entity/doc.html'
405 .directive('entitySignature', function() {
411 templateUrl
: '/directives/entity/signature.html'
415 .directive('entityNamespace', function() {
421 templateUrl
: '/directives/entity/namespace.html',
422 link
: function ($scope
, element
, attrs
) {
423 $scope
.isObject
= function(obj
) {
424 return typeof obj
=== 'object';
426 $scope
.isArray
= function(obj
) {
427 return Array
.isArray(obj
);
429 $scope
.isString
= function(obj
) {
430 return typeof obj
=== 'string';
436 .directive('entityTag', function() {
443 templateUrl
: '/directives/entity/tag.html'
447 .directive('entityLocation', function() {
455 controller
: function() {},
457 templateUrl
: '/directives/entity/location.html'
461 .directive('entityGraph', function() {
469 templateUrl
: '/directives/entity/graph.html'
473 .directive('entityCard', ['Feedback', function(Feedback
) {
480 templateUrl
: '/directives/entity/card.html'
484 .directive('entityList', function() {
491 listObjectFilter
: '=',
493 templateUrl
: '/directives/entity/list.html',
494 link
: function ($scope
, element
, attrs
) {
495 $scope
.showFilters
= false;
496 if(!$scope
.listObjectFilter
) {
497 $scope
.listObjectFilter
= {};
499 if(!$scope
.visibilityFilter
) {
500 $scope
.visibilityFilter
= {
506 $scope
.toggleFilters
= function() {
507 $scope
.showFilters
= !$scope
.showFilters
;
513 .directive('entityLinearization', function() {
521 templateUrl
: '/directives/entity/linearization.html'
525 .directive('entityDef', ['Model', function(Model
, Code
) {
532 templateUrl
: '/directives/entity/defcard.html',
533 link
: function ($scope
, element
, attrs
) {
534 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
536 $scope
.isActive
= function() {
537 return $scope
.focus
== $scope
.definition
.full_name
;
540 $scope
.loadCardCode
= function() {
542 Model
.loadEntityCode($scope
.definition
.full_name
,
545 setTimeout(function() { // smooth collapse
546 $
('#' + $scope
.codeId
).collapse('show')
552 if($
('#' + $scope
.codeId
).hasClass('in')) {
553 $
('#' + $scope
.codeId
).collapse('hide');
555 $
('#' + $scope
.codeId
).collapse('show');
560 $scope
.$
watch('focus', function() {
561 if($scope
.isActive()) $scope
.loadCardCode();
567 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
570 this.postStar
= function(rating
) {
571 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
572 $scope
.dimension
, rating
,
574 $scope
.mean
= data
.mean
;
575 $scope
.list
= data
.ratings
;
576 $scope
.user
= data
.user
;
577 $ctrl
.loadEntityStars($scope
);
583 this.loadEntityStars
= function($scope
) {
584 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
586 $scope
.ratings
= data
;
587 }, function(message
, status
) {
588 $scope
.error
= {message
: message
, status
: status
};
593 .directive('entityRating', ['Feedback', function(Feedback
) {
600 controller
: 'StarsCtrl',
601 controllerAs
: 'ratingsCtrl',
602 templateUrl
: '/directives/entity/rating.html'
606 .directive('entityStars', ['Feedback', function(Feedback
) {
618 controller
: 'StarsCtrl',
619 controllerAs
: 'starsCtrl',
620 templateUrl
: '/directives/entity/stars.html'