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
;
70 this.date
= function(date
) {
71 return new Date(date
);
76 .state('doc.entity.graph', {
78 templateUrl
: 'views/doc/graph.html',
80 graph
: function(Model
, $q
, $stateParams
, $state
) {
82 Model
.loadEntityGraph($stateParams
.id
, d
.resolve
,
84 $state
.go('404', null, { location
: false })
88 inh
: function(Model
, $q
, $stateParams
, $state
) {
90 Model
.loadEntityInh($stateParams
.id
, d
.resolve
,
92 $state
.go('404', null, { location
: false })
97 controller
: function(inh
, graph
, $sce
) {
98 this.graph
= $sce
.trustAsHtml(graph
);
103 .state('doc.entity.metrics', {
105 templateUrl
: 'views/doc/metrics.html',
107 metrics
: function(Metrics
, $q
, $stateParams
, $state
) {
109 Metrics
.loadStructuralMetrics($stateParams
.id
, d
.resolve
,
111 $state
.go('404', null, { location
: false })
116 controller
: function(mentity
, metrics
) {
117 this.mentity
= mentity
;
118 this.metrics
= metrics
;
122 .state('doc.entity.code', {
124 templateUrl
: 'views/doc/code.html',
126 code
: function(Model
, $q
, $stateParams
, $state
) {
128 Model
.loadEntityCode($stateParams
.id
, d
.resolve
,
130 $state
.go('404', null, { location
: false })
135 controller
: function(mentity
, code
) {
136 this.mentity
= mentity
;
141 .state('doc.entity.defs', {
143 templateUrl
: 'views/doc/defs.html',
145 defs
: function(Model
, $q
, $stateParams
, $state
) {
147 Model
.loadEntityDefs($stateParams
.id
, d
.resolve
,
149 $state
.go('404', null, { location
: false })
154 controller
: function(mentity
, defs
) {
155 this.mentity
= mentity
;
160 .state('doc.entity.lin', {
162 templateUrl
: 'views/doc/lin.html',
164 lin
: function(Model
, $q
, $stateParams
, $state
) {
166 Model
.loadEntityLinearization($stateParams
.id
, d
.resolve
,
168 $state
.go('404', null, { location
: false })
173 controller
: function(mentity
, lin
, $scope
, $location
, $anchorScroll
) {
175 vm
.focus
= $location
.hash() ?
176 $location
.hash() : mentity
.intro
.full_name
;
177 vm
.mentity
= mentity
;
178 vm
.linearization
= lin
;
179 setTimeout(function() {
182 $scope
.$
watch(function () {
183 return $location
.hash();
184 }, function (value
) {
185 vm
.focus
= $location
.hash() ?
186 $location
.hash() : mentity
.intro
.full_name
;
192 .state('doc.entity.all', {
194 templateUrl
: 'views/doc/all.html',
195 controller
: function(mentity
) {
196 this.mentity
= mentity
;
204 .factory('Model', [ '$http', function($http
) {
207 loadEntity
: function(id
, cb
, cbErr
) {
208 $http
.get('/api/entity/' + id
)
213 loadEntityDoc
: function(id
, cb
, cbErr
) {
214 $http
.get('/api/entity/' + id
+ '/doc')
219 loadEntityLinearization
: function(id
, cb
, cbErr
) {
220 $http
.get('/api/linearization/' + id
)
225 loadEntityDefs
: function(id
, cb
, cbErr
) {
226 $http
.get('/api/defs/' + id
)
231 loadEntityCode
: function(id
, cb
, cbErr
) {
232 $http
.get('/api/code/' + id
)
237 loadEntityGraph
: function(id
, cb
, cbErr
) {
238 $http
.get('/api/graph/inheritance/' + id
+ '?cdepth=3')
243 loadEntityInh
: function(id
, cb
, cbErr
) {
244 $http
.get('/api/inheritance/' + id
)
248 search
: function(q
, p
, n
, cb
, cbErr
) {
249 $http
.get('/api/search?q=' + q
+ '&p=' + p
+ '&n=' + n
)
258 .directive('entityLink', function() {
264 templateUrl
: '/directives/entity/link.html'
268 .directive('entityDoc', function() {
274 templateUrl
: '/directives/entity/doc.html'
278 .directive('entitySignature', function() {
284 templateUrl
: '/directives/entity/signature.html'
288 .directive('entityNamespace', function() {
294 templateUrl
: '/directives/entity/namespace.html',
295 link
: function ($scope
, element
, attrs
) {
296 $scope
.isObject
= function(obj
) {
297 return typeof obj
=== 'object';
299 $scope
.isArray
= function(obj
) {
300 return Array
.isArray(obj
);
302 $scope
.isString
= function(obj
) {
303 return typeof obj
=== 'string';
309 .directive('entityTag', function() {
316 templateUrl
: '/directives/entity/tag.html'
320 .directive('entityLocation', function() {
326 templateUrl
: '/directives/entity/location.html'
330 .directive('entityGraph', function() {
338 templateUrl
: '/directives/entity/graph.html'
342 .directive('entityCard', ['Feedback', function(Feedback
) {
349 templateUrl
: '/directives/entity/card.html'
353 .directive('entityList', function() {
360 listObjectFilter
: '=',
362 templateUrl
: '/directives/entity/list.html',
363 link
: function ($scope
, element
, attrs
) {
364 $scope
.showFilters
= false;
365 if(!$scope
.listObjectFilter
) {
366 $scope
.listObjectFilter
= {};
368 if(!$scope
.visibilityFilter
) {
369 $scope
.visibilityFilter
= {
375 $scope
.toggleFilters
= function() {
376 $scope
.showFilters
= !$scope
.showFilters
;
382 .directive('entityLinearization', function() {
390 templateUrl
: '/directives/entity/linearization.html'
394 .directive('entityDef', ['Model', function(Model
, Code
) {
401 templateUrl
: '/directives/entity/defcard.html',
402 link
: function ($scope
, element
, attrs
) {
403 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
405 $scope
.isActive
= function() {
406 return $scope
.focus
== $scope
.definition
.full_name
;
409 $scope
.loadCardCode
= function() {
411 Model
.loadEntityCode($scope
.definition
.full_name
,
414 setTimeout(function() { // smooth collapse
415 $
('#' + $scope
.codeId
).collapse('show')
421 if($
('#' + $scope
.codeId
).hasClass('in')) {
422 $
('#' + $scope
.codeId
).collapse('hide');
424 $
('#' + $scope
.codeId
).collapse('show');
429 $scope
.$
watch('focus', function() {
430 if($scope
.isActive()) $scope
.loadCardCode();
436 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
439 this.postStar
= function(rating
) {
440 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
441 $scope
.dimension
, rating
,
443 $scope
.mean
= data
.mean
;
444 $scope
.list
= data
.ratings
;
445 $scope
.user
= data
.user
;
446 $ctrl
.loadEntityStars($scope
);
452 this.loadEntityStars
= function($scope
) {
453 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
455 $scope
.ratings
= data
;
456 }, function(message
, status
) {
457 $scope
.error
= {message
: message
, status
: status
};
462 .directive('entityRating', ['Feedback', function(Feedback
) {
469 controller
: 'StarsCtrl',
470 controllerAs
: 'ratingsCtrl',
471 templateUrl
: '/directives/entity/rating.html'
475 .directive('entityStars', ['Feedback', function(Feedback
) {
487 controller
: 'StarsCtrl',
488 controllerAs
: 'starsCtrl',
489 templateUrl
: '/directives/entity/stars.html'