2958f584a14b3abeb64216e99bf3244219864051
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 })
85 controller
: function(graph
, $sce
) {
86 this.graph
= $sce
.trustAsHtml(graph
);
90 .state('doc.entity.metrics', {
92 templateUrl
: 'views/doc/metrics.html',
94 metrics
: function(Metrics
, $q
, $stateParams
, $state
) {
96 Metrics
.loadStructuralMetrics($stateParams
.id
, d
.resolve
,
98 $state
.go('404', null, { location
: false })
103 controller
: function(mentity
, metrics
) {
104 this.mentity
= mentity
;
105 this.metrics
= metrics
;
109 .state('doc.entity.code', {
111 templateUrl
: 'views/doc/code.html',
113 code
: function(Model
, $q
, $stateParams
, $state
) {
115 Model
.loadEntityCode($stateParams
.id
, d
.resolve
,
117 $state
.go('404', null, { location
: false })
122 controller
: function(mentity
, code
) {
123 this.mentity
= mentity
;
128 .state('doc.entity.defs', {
130 templateUrl
: 'views/doc/defs.html',
132 defs
: function(Model
, $q
, $stateParams
, $state
) {
134 Model
.loadEntityDefs($stateParams
.id
, d
.resolve
,
136 $state
.go('404', null, { location
: false })
141 controller
: function(mentity
, defs
) {
142 this.mentity
= mentity
;
147 .state('doc.entity.lin', {
149 templateUrl
: 'views/doc/lin.html',
151 lin
: function(Model
, $q
, $stateParams
, $state
) {
153 Model
.loadEntityLinearization($stateParams
.id
, d
.resolve
,
155 $state
.go('404', null, { location
: false })
160 controller
: function(mentity
, lin
, $scope
, $location
, $anchorScroll
) {
162 vm
.focus
= $location
.hash() ?
163 $location
.hash() : mentity
.intro
.full_name
;
164 vm
.mentity
= mentity
;
165 vm
.linearization
= lin
;
166 setTimeout(function() {
169 $scope
.$
watch(function () {
170 return $location
.hash();
171 }, function (value
) {
172 vm
.focus
= $location
.hash() ?
173 $location
.hash() : mentity
.intro
.full_name
;
179 .state('doc.entity.all', {
181 templateUrl
: 'views/doc/all.html',
182 controller
: function(mentity
) {
183 this.mentity
= mentity
;
191 .factory('Model', [ '$http', function($http
) {
194 loadEntity
: function(id
, cb
, cbErr
) {
195 $http
.get('/api/entity/' + id
)
200 loadEntityDoc
: function(id
, cb
, cbErr
) {
201 $http
.get('/api/entity/' + id
+ '/doc')
206 loadEntityLinearization
: function(id
, cb
, cbErr
) {
207 $http
.get('/api/linearization/' + id
)
212 loadEntityDefs
: function(id
, cb
, cbErr
) {
213 $http
.get('/api/defs/' + id
)
218 loadEntityCode
: function(id
, cb
, cbErr
) {
219 $http
.get('/api/code/' + id
)
224 loadEntityGraph
: function(id
, cb
, cbErr
) {
225 $http
.get('/api/graph/inheritance/' + id
+ '?cdepth=3')
230 search
: function(q
, n
, cb
, cbErr
) {
231 $http
.get('/api/search?q=' + q
+ '&n=' + n
)
240 .directive('entityLink', function() {
246 templateUrl
: '/directives/entity/link.html'
250 .directive('entityDoc', function() {
256 templateUrl
: '/directives/entity/doc.html'
260 .directive('entitySignature', function() {
266 templateUrl
: '/directives/entity/signature.html'
270 .directive('entityNamespace', function() {
276 templateUrl
: '/directives/entity/namespace.html',
277 link
: function ($scope
, element
, attrs
) {
278 $scope
.isObject
= function(obj
) {
279 return typeof obj
=== 'object';
281 $scope
.isArray
= function(obj
) {
282 return Array
.isArray(obj
);
284 $scope
.isString
= function(obj
) {
285 return typeof obj
=== 'string';
291 .directive('entityTag', function() {
298 templateUrl
: '/directives/entity/tag.html'
302 .directive('entityLocation', function() {
308 templateUrl
: '/directives/entity/location.html'
312 .directive('entityGraph', function() {
320 templateUrl
: '/directives/entity/graph.html'
324 .directive('entityCard', ['Feedback', function(Feedback
) {
333 templateUrl
: '/directives/entity/card.html',
334 link
: function ($scope
, element
, attrs
) {
335 $scope
.currentTab
= $scope
.defaultTab ? $scope
.defaultTab
: 'signature';
337 $scope
.loadEntityStars
= function() {
338 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
340 $scope
.ratings
= data
;
341 }, function(message
, status
) {
342 $scope
.error
= {message
: message
, status
: status
};
349 .directive('entityList', function() {
356 listObjectFilter
: '=',
358 templateUrl
: '/directives/entity/list.html',
359 link
: function ($scope
, element
, attrs
) {
360 $scope
.showFilters
= false;
361 if(!$scope
.listObjectFilter
) {
362 $scope
.listObjectFilter
= {};
364 if(!$scope
.visibilityFilter
) {
365 $scope
.visibilityFilter
= {
371 $scope
.toggleFilters
= function() {
372 $scope
.showFilters
= !$scope
.showFilters
;
378 .directive('entityLinearization', function() {
386 templateUrl
: '/directives/entity/linearization.html'
390 .directive('entityDef', ['Model', function(Model
, Code
) {
397 templateUrl
: '/directives/entity/defcard.html',
398 link
: function ($scope
, element
, attrs
) {
399 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
401 $scope
.isActive
= function() {
402 return $scope
.focus
== $scope
.definition
.full_name
;
405 $scope
.loadCardCode
= function() {
407 Model
.loadEntityCode($scope
.definition
.full_name
,
410 setTimeout(function() { // smooth collapse
411 $
('#' + $scope
.codeId
).collapse('show')
417 if($
('#' + $scope
.codeId
).hasClass('in')) {
418 $
('#' + $scope
.codeId
).collapse('hide');
420 $
('#' + $scope
.codeId
).collapse('show');
425 $scope
.$
watch('focus', function() {
426 if($scope
.isActive()) $scope
.loadCardCode();
432 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
435 this.postStar
= function(rating
) {
436 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
437 $scope
.dimension
, rating
,
439 $scope
.mean
= data
.mean
;
440 $scope
.list
= data
.ratings
;
441 $scope
.user
= data
.user
;
442 $ctrl
.loadEntityStars($scope
);
448 this.loadEntityStars
= function($scope
) {
449 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
451 $scope
.ratings
= data
;
452 }, function(message
, status
) {
453 $scope
.error
= {message
: message
, status
: status
};
458 .directive('entityRating', ['Feedback', function(Feedback
) {
465 controller
: 'StarsCtrl',
466 controllerAs
: 'ratingsCtrl',
467 templateUrl
: '/directives/entity/rating.html'
471 .directive('entityStars', ['Feedback', function(Feedback
) {
483 controller
: 'StarsCtrl',
484 controllerAs
: 'starsCtrl',
485 templateUrl
: '/directives/entity/stars.html'