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
;
283 .state('doc.entity.license', {
285 templateUrl
: 'views/doc/license.html',
287 content
: function(Model
, $q
, $stateParams
, $state
) {
289 Model
.loadEntityLicenseContent($stateParams
.id
, d
.resolve
,
291 $state
.go('404', null, { location
: false })
296 controller
: function(mentity
, content
) {
297 this.mentity
= mentity
;
298 this.content
= content
;
302 .state('doc.entity.contrib', {
304 templateUrl
: 'views/doc/contrib.html',
306 content
: function(Model
, $q
, $stateParams
, $state
) {
308 Model
.loadEntityContribContent($stateParams
.id
, d
.resolve
,
310 $state
.go('404', null, { location
: false })
315 controller
: function(mentity
, content
) {
316 this.mentity
= mentity
;
317 this.content
= content
;
325 .factory('Model', [ '$http', function($http
) {
328 loadEntity
: function(id
, cb
, cbErr
) {
329 $http
.get('/api/entity/' + id
)
334 loadEntityDoc
: function(id
, cb
, cbErr
) {
335 $http
.get('/api/doc/' + id
+ '?format=html')
340 loadEntityLin
: function(id
, cb
, cbErr
) {
341 $http
.get('/api/lin/' + id
)
346 loadEntityDefs
: function(id
, cb
, cbErr
) {
347 $http
.get('/api/defs/' + id
)
352 loadEntityIntros
: function(id
, cb
, cbErr
) {
353 $http
.get('/api/intros/' + id
)
358 loadEntityRedefs
: function(id
, cb
, cbErr
) {
359 $http
.get('/api/redefs/' + id
)
364 loadEntityAll
: function(id
, cb
, cbErr
) {
365 $http
.get('/api/all/' + id
)
370 loadEntityCode
: function(id
, cb
, cbErr
) {
371 $http
.get('/api/code/' + id
+ '?format=html')
376 loadEntityAncestors
: function(id
, cb
, cbErr
) {
377 $http
.get('/api/ancestors/' + id
)
382 loadEntityParents
: function(id
, cb
, cbErr
) {
383 $http
.get('/api/parents/' + id
)
388 loadEntityChildren
: function(id
, cb
, cbErr
) {
389 $http
.get('/api/children/' + id
)
394 loadEntityDescendants
: function(id
, cb
, cbErr
) {
395 $http
.get('/api/descendants/' + id
)
400 loadEntityMeta
: function(id
, cb
, cbErr
) {
401 $http
.get('/api/meta/' + id
)
406 loadEntityGraph
: function(id
, cb
, cbErr
) {
407 $http
.get('/api/graph/inheritance/' + id
+ '?format=svg&cdepth=3')
412 loadEntityLicenseContent
: function(id
, cb
, cbErr
) {
413 $http
.get('/api/ini/license-content/' + id
)
418 loadEntityContribContent
: function(id
, cb
, cbErr
) {
419 $http
.get('/api/ini/contrib-content/' + id
)
424 loadEntityGraph
: function(id
, cb
, cbErr
) {
425 $http
.get('/api/graph/inheritance/' + id
+ '?format=svg&cdepth=3')
430 search
: function(q
, p
, n
, cb
, cbErr
) {
431 $http
.get('/api/search?q=' + q
+ '&p=' + p
+ '&l=' + n
)
440 .directive('entityLink', function() {
447 templateUrl
: '/directives/entity/link.html'
451 .directive('entityDoc', function() {
457 templateUrl
: '/directives/entity/doc.html'
461 .directive('entitySignature', function() {
467 templateUrl
: '/directives/entity/signature.html'
471 .directive('entityNamespace', function() {
477 templateUrl
: '/directives/entity/namespace.html',
478 link
: function ($scope
, element
, attrs
) {
479 $scope
.isObject
= function(obj
) {
480 return typeof obj
=== 'object';
482 $scope
.isArray
= function(obj
) {
483 return Array
.isArray(obj
);
485 $scope
.isString
= function(obj
) {
486 return typeof obj
=== 'string';
492 .directive('entityTag', function() {
499 templateUrl
: '/directives/entity/tag.html'
503 .directive('entityLocation', function() {
511 controller
: function() {},
513 templateUrl
: '/directives/entity/location.html'
517 .directive('entityGraph', function() {
525 templateUrl
: '/directives/entity/graph.html'
529 .directive('entityCard', ['Feedback', function(Feedback
) {
536 templateUrl
: '/directives/entity/card.html'
540 .directive('entityList', function() {
547 listObjectFilter
: '=',
549 templateUrl
: '/directives/entity/list.html',
550 link
: function ($scope
, element
, attrs
) {
551 $scope
.showFilters
= false;
552 if(!$scope
.listObjectFilter
) {
553 $scope
.listObjectFilter
= {};
555 if(!$scope
.visibilityFilter
) {
556 $scope
.visibilityFilter
= {
562 $scope
.toggleFilters
= function() {
563 $scope
.showFilters
= !$scope
.showFilters
;
569 .directive('entityLinearization', function() {
577 templateUrl
: '/directives/entity/linearization.html'
581 .directive('entityDef', ['Model', function(Model
, Code
) {
588 templateUrl
: '/directives/entity/defcard.html',
589 link
: function ($scope
, element
, attrs
) {
590 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
592 $scope
.isActive
= function() {
593 return $scope
.focus
== $scope
.definition
.full_name
;
596 $scope
.loadCardCode
= function() {
598 Model
.loadEntityCode($scope
.definition
.full_name
,
601 setTimeout(function() { // smooth collapse
602 $
('#' + $scope
.codeId
).collapse('show')
608 if($
('#' + $scope
.codeId
).hasClass('in')) {
609 $
('#' + $scope
.codeId
).collapse('hide');
611 $
('#' + $scope
.codeId
).collapse('show');
616 $scope
.$
watch('focus', function() {
617 if($scope
.isActive()) $scope
.loadCardCode();
623 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
626 this.postStar
= function(rating
) {
627 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
628 $scope
.dimension
, rating
,
630 $scope
.mean
= data
.mean
;
631 $scope
.list
= data
.ratings
;
632 $scope
.user
= data
.user
;
633 $ctrl
.loadEntityStars($scope
);
639 this.loadEntityStars
= function($scope
) {
640 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
642 $scope
.ratings
= data
;
643 }, function(message
, status
) {
644 $scope
.error
= {message
: message
, status
: status
};
649 .directive('entityRating', ['Feedback', function(Feedback
) {
656 controller
: 'StarsCtrl',
657 controllerAs
: 'ratingsCtrl',
658 templateUrl
: '/directives/entity/rating.html'
662 .directive('entityStars', ['Feedback', function(Feedback
) {
674 controller
: 'StarsCtrl',
675 controllerAs
: 'starsCtrl',
676 templateUrl
: '/directives/entity/stars.html'