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', 'model'])
21 .controller('EntityCtrl', ['Model', 'Metrics', '$routeParams', '$scope', '$sce', function(Model
, Metrics
, $routeParams
, $scope
, $sce
) {
22 $scope
.entityId
= $routeParams
.id
;
24 this.loadEntityLinearization
= function() {
25 Model
.loadEntityLinearization($routeParams
.id
,
27 $scope
.linearization
= data
;
33 this.loadEntityDefs
= function() {
34 Model
.loadEntityDefs($routeParams
.id
,
42 this.loadEntityCode
= function() {
43 Model
.loadEntityCode($routeParams
.id
,
51 this.loadEntityGraph
= function(e
) {
52 Model
.loadEntityGraph($routeParams
.id
,
54 $scope
.graph
= $sce
.trustAsHtml(data
);
60 this.loadStructuralMetrics
= function() {
61 Metrics
.loadStructuralMetrics($routeParams
.id
,
63 $scope
.metrics
= data
;
64 }, function(message
, status
) {
65 $scope
.error
= {message
: message
, status
: status
};
69 Model
.loadEntity($routeParams
.id
,
71 $scope
.mentity
= data
;
72 }, function(message
, status
) {
73 $scope
.error
= {message
: message
, status
: status
};
77 .directive('entityLink', function() {
83 templateUrl
: '/directives/entity/link.html'
87 .directive('entityDoc', function() {
93 templateUrl
: '/directives/entity/doc.html'
97 .directive('entitySignature', function() {
103 templateUrl
: '/directives/entity/signature.html'
107 .directive('entityNamespace', function() {
113 templateUrl
: '/directives/entity/namespace.html'
117 .directive('entityTag', function() {
124 templateUrl
: '/directives/entity/tag.html'
128 .directive('entityLocation', function() {
134 templateUrl
: '/directives/entity/location.html'
138 .directive('entityCard', function() {
145 templateUrl
: '/directives/entity/card.html'
149 .directive('entityList', function() {
156 listObjectFilter
: '=',
158 templateUrl
: '/directives/entity/list.html',
159 link
: function ($scope
, element
, attrs
) {
160 $scope
.showFilters
= false;
161 if(!$scope
.listObjectFilter
) {
162 $scope
.listObjectFilter
= {};
164 if(!$scope
.visibilityFilter
) {
165 $scope
.visibilityFilter
= {
171 $scope
.toggleFilters
= function() {
172 $scope
.showFilters
= !$scope
.showFilters
;
178 .directive('entityLinearization', function() {
186 templateUrl
: '/directives/entity/linearization.html'
190 .directive('entityDef', ['Model', function(Model
, Code
) {
197 templateUrl
: '/directives/entity/defcard.html',
198 link
: function ($scope
, element
, attrs
) {
199 $scope
.codeId
= 'code_' + $scope
.definition
.full_name
.replace(/[^a
-zA
-Z0
-9]/g
, '_');
200 $scope
.loadCardCode
= function() {
202 Model
.loadEntityCode($scope
.definition
.full_name
,
205 setTimeout(function() { // smooth collapse
206 $
('#' + $scope
.codeId
).collapse('show')
212 if($
('#' + $scope
.codeId
).hasClass('in')) {
213 $
('#' + $scope
.codeId
).collapse('hide');
215 $
('#' + $scope
.codeId
).collapse('show');
223 .directive('entityRating', ['Feedback', function(Feedback
, Code
) {
229 templateUrl
: '/directives/entity/stars.html',
230 link
: function ($scope
, element
, attrs
) {
231 $scope
.postStar
= function(rating
) {
232 Feedback
.postEntityStar($scope
.mentity
.full_name
, rating
,
234 $scope
.ratings
= data
;
240 Feedback
.loadEntityStars($scope
.mentity
.full_name
,
242 $scope
.ratings
= data
;