nitweb/ng: clean card css
[nit.git] / share / nitweb / javascripts / entities.js
index c54f515..98903e7 100644 (file)
 
 (function() {
        angular
-               .module('entities', ['ui', 'model'])
+               .module('entities', ['ngSanitize', 'ui', 'model'])
+
+               .controller('EntityCtrl', ['Model', 'Metrics', '$routeParams', '$scope', '$sce', function(Model, Metrics, $routeParams, $scope, $sce) {
+                       $scope.entityId = $routeParams.id;
 
-               .controller('EntityCtrl', ['Model', '$routeParams', '$scope', function(Model, $routeParams, $scope) {
                        this.loadEntityLinearization = function() {
                                Model.loadEntityLinearization($routeParams.id,
                                        function(data) {
                                        });
                        };
 
+                       this.loadEntityDefs = function() {
+                               Model.loadEntityDefs($routeParams.id,
+                                       function(data) {
+                                               $scope.defs = data;
+                                       }, function(err) {
+                                               $scope.error = err;
+                                       });
+                       };
+
+                       this.loadEntityCode = function() {
+                               Model.loadEntityCode($routeParams.id,
+                                       function(data) {
+                                               $scope.code = data;
+                                       }, function(err) {
+                                               $scope.code = err;
+                                       });
+                       };
+
+                       this.loadEntityGraph = function(e) {
+                               Model.loadEntityGraph($routeParams.id,
+                                       function(data) {
+                                               $scope.graph = $sce.trustAsHtml(data);
+                                       }, function(err) {
+                                               $scope.error = err;
+                                       });
+                       };
+
+                       this.loadStructuralMetrics = function() {
+                               Metrics.loadStructuralMetrics($routeParams.id,
+                                       function(data) {
+                                               $scope.metrics = data;
+                                       }, function(message, status) {
+                                               $scope.error = {message: message, status: status};
+                                       });
+                       };
+
                        Model.loadEntity($routeParams.id,
                                function(data) {
                                        $scope.mentity = data;
-                               }, function(err) {
-                                       $scope.error = err;
+                               }, function(message, status) {
+                                       $scope.error = {message: message, status: status};
                                });
                }])
 
                        };
                })
 
+               .directive('entityNamespace', function() {
+                       return {
+                               restrict: 'E',
+                               scope: {
+                                       namespace: '='
+                               },
+                               templateUrl: '/directives/entity/namespace.html',
+                               link: function ($scope, element, attrs) {
+                                       $scope.isObject = function(obj) {
+                                               return typeof obj === 'object';
+                                       };
+                                       $scope.isArray = function(obj) {
+                                               return Array.isArray(obj);
+                                       };
+                                       $scope.isString = function(obj) {
+                                               return typeof obj === 'string';
+                                       };
+                               }
+                       };
+               })
+
                .directive('entityTag', function() {
                        return {
                                restrict: 'E',
                        };
                })
 
+               .directive('entityGraph', function() {
+                       return {
+                               restrict: 'E',
+                               scope: {
+                                       mentity: '=',
+                                       graph: '='
+                               },
+                               replace: true,
+                               templateUrl: '/directives/entity/graph.html'
+                       };
+               })
+
                .directive('entityCard', function() {
                        return {
                                restrict: 'E',
                                scope: {
-                                       mentity: '='
+                                       mentity: '=',
+                                       defaultTab: '@',
+                                       noSynopsis: '='
                                },
                                replace: true,
-                               templateUrl: '/directives/entity/card.html'
+                               templateUrl: '/directives/entity/card.html',
+                               link: function ($scope, element, attrs) {
+                                       $scope.currentTab = $scope.defaultTab ? $scope.defaultTab : 'signature';
+                               }
                        };
                })
 
                                }
                        };
                })
+
+               .directive('entityLinearization', function() {
+                       return {
+                               restrict: 'E',
+                               scope: {
+                                       listEntities: '=',
+                                       listTitle: '@',
+                                       listFocus: '='
+                               },
+                               templateUrl: '/directives/entity/linearization.html'
+                       };
+               })
+
+               .directive('entityDef', ['Model', function(Model, Code) {
+                       return {
+                               restrict: 'E',
+                               scope: {
+                                       definition: '=',
+                                       focus: '='
+                               },
+                               templateUrl: '/directives/entity/defcard.html',
+                               link: function ($scope, element, attrs) {
+                                       $scope.codeId = 'code_' + $scope.definition.full_name.replace(/[^a-zA-Z0-9]/g, '_');
+
+                                       $scope.isActive = function() {
+                                               return $scope.focus.full_name == $scope.definition.full_name;
+                                       }
+
+                                       $scope.loadCardCode = function() {
+                                               if(!$scope.code) {
+                                                       Model.loadEntityCode($scope.definition.full_name,
+                                                               function(data) {
+                                                                       $scope.code = data;
+                                                                       setTimeout(function() { // smooth collapse
+                                                                               $('#' + $scope.codeId).collapse('show')
+                                                                       }, 1);
+                                                               }, function(err) {
+                                                                       $scope.code = err;
+                                                               });
+                                               } else {
+                                                       if($('#' + $scope.codeId).hasClass('in')) {
+                                                               $('#' + $scope.codeId).collapse('hide');
+                                                       } else {
+                                                               $('#' + $scope.codeId).collapse('show');
+                                                       }
+                                               }
+                                       };
+
+                                       if($scope.isActive()) $scope.loadCardCode();
+                               }
+                       };
+               }])
+
+               .directive('entityRating', ['Feedback', function(Feedback, Code) {
+                       return {
+                               restrict: 'E',
+                               scope: {
+                                       mentity: '='
+                               },
+                               templateUrl: '/directives/entity/stars.html',
+                               link: function ($scope, element, attrs) {
+                                       $scope.postStar = function(rating) {
+                                               Feedback.postEntityStar($scope.mentity.full_name, rating,
+                                               function(data) {
+                                                       $scope.ratings = data;
+                                               }, function(err) {
+                                                       $scope.err = err;
+                                               });
+                                       }
+
+                                       Feedback.loadEntityStars($scope.mentity.full_name,
+                                               function(data) {
+                                                       $scope.ratings = data;
+                                               }, function(err) {
+                                                       $scope.err = err;
+                                               });
+                               }
+                       };
+               }])
 })();