X-Git-Url: http://nitlanguage.org?ds=sidebyside diff --git a/share/nitweb/javascripts/entities.js b/share/nitweb/javascripts/entities.js index 2438d84..e48b40a 100644 --- a/share/nitweb/javascripts/entities.js +++ b/share/nitweb/javascripts/entities.js @@ -18,7 +18,7 @@ angular .module('entities', ['ngSanitize', 'ui', 'model']) - .controller('EntityCtrl', ['Model', '$routeParams', '$scope', '$sce', function(Model, $routeParams, $scope, $sce) { + .controller('EntityCtrl', ['Model', 'Metrics', 'Feedback', '$routeParams', '$scope', '$sce', function(Model, Metrics, Feedback, $routeParams, $scope, $sce) { $scope.entityId = $routeParams.id; this.loadEntityLinearization = function() { @@ -57,6 +57,15 @@ }); }; + 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; @@ -99,9 +108,20 @@ return { restrict: 'E', scope: { - mentity: '=' + namespace: '=' }, - templateUrl: '/directives/entity/namespace.html' + 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'; + }; + } }; }) @@ -126,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', @@ -188,6 +234,11 @@ 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, @@ -207,34 +258,66 @@ } } }; + + if($scope.isActive()) $scope.loadCardCode(); } }; }]) - .directive('entityRating', ['Feedback', function(Feedback, Code) { + .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: '=' + mentity: '=', + ratings: '=' }, - 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; - }); - } + controller: 'StarsCtrl', + controllerAs: 'ratingsCtrl', + templateUrl: '/directives/entity/rating.html' + }; + }]) - Feedback.loadEntityStars($scope.mentity.full_name, - function(data) { - $scope.ratings = data; - }, function(err) { - $scope.err = err; - }); - } + .directive('entityStars', ['Feedback', function(Feedback) { + return { + restrict: 'E', + scope: { + mentity: '=', + dimension: '@', + mean: '=', + list: '=', + user: '=', + refresh: '=', + ratings: '=' + }, + controller: 'StarsCtrl', + controllerAs: 'starsCtrl', + templateUrl: '/directives/entity/stars.html' }; }]) })();