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',
56 controller
: function(mentity
) {
57 this.mentity
= mentity
;
61 .state('doc.entity.graph', {
63 templateUrl
: 'views/doc/graph.html',
65 graph
: function(Model
, $q
, $stateParams
, $state
) {
67 Model
.loadEntityGraph($stateParams
.id
, d
.resolve
,
69 $state
.go('404', null, { location
: false })
74 controller
: function(graph
, $sce
) {
75 this.graph
= $sce
.trustAsHtml(graph
);
79 .state('doc.entity.metrics', {
81 templateUrl
: 'views/doc/metrics.html',
83 metrics
: function(Metrics
, $q
, $stateParams
, $state
) {
85 Metrics
.loadStructuralMetrics($stateParams
.id
, d
.resolve
,
87 $state
.go('404', null, { location
: false })
92 controller
: function(mentity
, metrics
) {
93 this.mentity
= mentity
;
94 this.metrics
= metrics
;
98 .state('doc.entity.code', {
100 templateUrl
: 'views/doc/code.html',
102 code
: function(Model
, $q
, $stateParams
, $state
) {
104 Model
.loadEntityCode($stateParams
.id
, d
.resolve
,
106 $state
.go('404', null, { location
: false })
111 controller
: function(mentity
, code
) {
112 this.mentity
= mentity
;
117 .state('doc.entity.defs', {
119 templateUrl
: 'views/doc/defs.html',
121 defs
: function(Model
, $q
, $stateParams
, $state
) {
123 Model
.loadEntityDefs($stateParams
.id
, d
.resolve
,
125 $state
.go('404', null, { location
: false })
130 controller
: function(mentity
, defs
) {
131 this.mentity
= mentity
;
136 .state('doc.entity.lin', {
138 templateUrl
: 'views/doc/lin.html',
140 lin
: function(Model
, $q
, $stateParams
, $state
) {
142 Model
.loadEntityLinearization($stateParams
.id
, d
.resolve
,
144 $state
.go('404', null, { location
: false })
149 controller
: function(mentity
, lin
, $scope
, $location
, $anchorScroll
) {
151 vm
.focus
= $location
.hash() ?
152 $location
.hash() : mentity
.intro
.full_name
;
153 vm
.mentity
= mentity
;
154 vm
.linearization
= lin
;
155 setTimeout(function() {
158 $scope
.$
watch(function () {
159 return $location
.hash();
160 }, function (value
) {
161 vm
.focus
= $location
.hash() ?
162 $location
.hash() : mentity
.intro
.full_name
;
168 .state('doc.entity.all', {
170 templateUrl
: 'views/doc/all.html',
171 controller
: function(mentity
) {
172 this.mentity
= mentity
;
180 .factory('Model', [ '$http', function($http
) {
183 loadEntity
: function(id
, cb
, cbErr
) {
184 $http
.get('/api/entity/' + id
)
189 loadEntityLinearization
: function(id
, cb
, cbErr
) {
190 $http
.get('/api/linearization/' + id
)
195 loadEntityDefs
: function(id
, cb
, cbErr
) {
196 $http
.get('/api/defs/' + id
)
201 loadEntityCode
: function(id
, cb
, cbErr
) {
202 $http
.get('/api/code/' + id
)
207 loadEntityGraph
: function(id
, cb
, cbErr
) {
208 $http
.get('/api/graph/inheritance/' + id
+ '?cdepth=3')
213 search
: function(q
, n
, cb
, cbErr
) {
214 $http
.get('/api/search?q=' + q
+ '&n=' + n
)
223 .directive('entityLink', function() {
229 templateUrl
: '/directives/entity/link.html'
233 .directive('entityDoc', function() {
239 templateUrl
: '/directives/entity/doc.html'
243 .directive('entitySignature', function() {
249 templateUrl
: '/directives/entity/signature.html'
253 .directive('entityNamespace', function() {
259 templateUrl
: '/directives/entity/namespace.html',
260 link
: function ($scope
, element
, attrs
) {
261 $scope
.isObject
= function(obj
) {
262 return typeof obj
=== 'object';
264 $scope
.isArray
= function(obj
) {
265 return Array
.isArray(obj
);
267 $scope
.isString
= function(obj
) {
268 return typeof obj
=== 'string';
274 .directive('entityTag', function() {
281 templateUrl
: '/directives/entity/tag.html'
285 .directive('entityLocation', function() {
291 templateUrl
: '/directives/entity/location.html'
295 .directive('entityGraph', function() {
303 templateUrl
: '/directives/entity/graph.html'
307 .directive('entityCard', ['Feedback', function(Feedback
) {
316 templateUrl
: '/directives/entity/card.html',
317 link
: function ($scope
, element
, attrs
) {
318 $scope
.currentTab
= $scope
.defaultTab ? $scope
.defaultTab
: 'signature';
320 $scope
.loadEntityStars
= function() {
321 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
323 $scope
.ratings
= data
;
324 }, function(message
, status
) {
325 $scope
.error
= {message
: message
, status
: status
};
332 .directive('entityList', function() {
339 listObjectFilter
: '=',
341 templateUrl
: '/directives/entity/list.html',
342 link
: function ($scope
, element
, attrs
) {
343 $scope
.showFilters
= false;
344 if(!$scope
.listObjectFilter
) {
345 $scope
.listObjectFilter
= {};
347 if(!$scope
.visibilityFilter
) {
348 $scope
.visibilityFilter
= {
354 $scope
.toggleFilters
= function() {
355 $scope
.showFilters
= !$scope
.showFilters
;
361 .directive('entityLinearization', function() {
369 templateUrl
: '/directives/entity/linearization.html'
373 .directive('entityDef', ['Model', function(Model
, Code
) {
380 templateUrl
: '/directives/entity/defcard.html',
381 link
: function ($scope
, element
, attrs
) {
382 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
384 $scope
.isActive
= function() {
385 return $scope
.focus
== $scope
.definition
.full_name
;
388 $scope
.loadCardCode
= function() {
390 Model
.loadEntityCode($scope
.definition
.full_name
,
393 setTimeout(function() { // smooth collapse
394 $
('#' + $scope
.codeId
).collapse('show')
400 if($
('#' + $scope
.codeId
).hasClass('in')) {
401 $
('#' + $scope
.codeId
).collapse('hide');
403 $
('#' + $scope
.codeId
).collapse('show');
408 $scope
.$
watch('focus', function() {
409 if($scope
.isActive()) $scope
.loadCardCode();
415 .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback
, $scope
) {
418 this.postStar
= function(rating
) {
419 Feedback
.postEntityStarDimension($scope
.mentity
.full_name
,
420 $scope
.dimension
, rating
,
422 $scope
.mean
= data
.mean
;
423 $scope
.list
= data
.ratings
;
424 $scope
.user
= data
.user
;
425 $ctrl
.loadEntityStars($scope
);
431 this.loadEntityStars
= function($scope
) {
432 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
434 $scope
.ratings
= data
;
435 }, function(message
, status
) {
436 $scope
.error
= {message
: message
, status
: status
};
441 .directive('entityRating', ['Feedback', function(Feedback
) {
448 controller
: 'StarsCtrl',
449 controllerAs
: 'ratingsCtrl',
450 templateUrl
: '/directives/entity/rating.html'
454 .directive('entityStars', ['Feedback', function(Feedback
) {
466 controller
: 'StarsCtrl',
467 controllerAs
: 'starsCtrl',
468 templateUrl
: '/directives/entity/stars.html'