X-Git-Url: http://nitlanguage.org diff --git a/share/nitweb/javascripts/entities.js b/share/nitweb/javascripts/entities.js index 4428c89..e48b40a 100644 --- a/share/nitweb/javascripts/entities.js +++ b/share/nitweb/javascripts/entities.js @@ -16,9 +16,11 @@ (function() { angular - .module('entities', ['ui', 'model']) + .module('entities', ['ngSanitize', 'ui', 'model']) + + .controller('EntityCtrl', ['Model', 'Metrics', 'Feedback', '$routeParams', '$scope', '$sce', function(Model, Metrics, Feedback, $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) { @@ -28,6 +30,15 @@ }); }; + 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) { @@ -37,11 +48,29 @@ }); }; + 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}; }); }]) @@ -75,6 +104,27 @@ }; }) + .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', @@ -96,17 +146,43 @@ }; }) - .directive('entityCard', function() { + .directive('entityGraph', function() { return { restrict: 'E', scope: { - mentity: '=' + mentity: '=', + graph: '=' }, replace: true, - templateUrl: '/directives/entity/card.html' + templateUrl: '/directives/entity/graph.html' }; }) + .directive('entityCard', ['Feedback', function(Feedback) { + return { + restrict: 'E', + scope: { + mentity: '=', + defaultTab: '@', + noSynopsis: '=' + }, + replace: true, + templateUrl: '/directives/entity/card.html', + link: function ($scope, element, attrs) { + $scope.currentTab = $scope.defaultTab ? $scope.defaultTab : 'signature'; + + $scope.loadEntityStars = function() { + Feedback.loadEntityStars($scope.mentity.full_name, + function(data) { + $scope.ratings = data; + }, function(message, status) { + $scope.error = {message: message, status: status}; + }); + }; + } + }; + }]) + .directive('entityList', function() { return { restrict: 'E', @@ -155,23 +231,93 @@ definition: '=', focus: '=' }, + templateUrl: '/directives/entity/defcard.html', link: function ($scope, element, attrs) { - $scope.$watch("definition", function() { - /*.loadEntityDefs($scope.definition.full_name, - function(data) { - $scope.mentity = data; - }, function(err) { - $scope.error = err; - }); - Model.loadEntityCode($scope.definition.full_name, - function(data) { - $scope.code = data; - }, function(err) { - $scope.error = err; - });*/ + $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(); + } + }; + }]) + + .controller('StarsCtrl', ['Feedback', '$scope', function(Feedback, $scope) { + $ctrl = this; + + this.postStar = function(rating) { + Feedback.postEntityStarDimension($scope.mentity.full_name, + $scope.dimension, rating, + function(data) { + $scope.mean = data.mean; + $scope.list = data.ratings; + $scope.user = data.user; + $ctrl.loadEntityStars($scope); + }, function(err) { + $scope.err = err; + }); + } + + this.loadEntityStars = function($scope) { + Feedback.loadEntityStars($scope.mentity.full_name, + function(data) { + $scope.ratings = data; + }, function(message, status) { + $scope.error = {message: message, status: status}; }); + }; + }]) + + .directive('entityRating', ['Feedback', function(Feedback) { + return { + restrict: 'E', + scope: { + mentity: '=', + ratings: '=' + }, + controller: 'StarsCtrl', + controllerAs: 'ratingsCtrl', + templateUrl: '/directives/entity/rating.html' + }; + }]) + + .directive('entityStars', ['Feedback', function(Feedback) { + return { + restrict: 'E', + scope: { + mentity: '=', + dimension: '@', + mean: '=', + list: '=', + user: '=', + refresh: '=', + ratings: '=' }, - templateUrl: '/directives/entity/defcard.html' + controller: 'StarsCtrl', + controllerAs: 'starsCtrl', + templateUrl: '/directives/entity/stars.html' }; }]) })();