(function() {
angular
- .module('entities', ['ngSanitize', 'ui', 'model'])
+ .module('entities', ['ngSanitize', 'ui'])
- .controller('EntityCtrl', ['Model', 'Metrics', '$routeParams', '$scope', '$sce', function(Model, Metrics, $routeParams, $scope, $sce) {
- $scope.entityId = $routeParams.id;
+ .factory('Model', [ '$http', function($http) {
+ return {
+
+ loadEntity: function(id, cb, cbErr) {
+ $http.get('/api/entity/' + id)
+ .success(cb)
+ .error(cbErr);
+ },
+
+ loadEntityLinearization: function(id, cb, cbErr) {
+ $http.get('/api/linearization/' + id)
+ .success(cb)
+ .error(cbErr);
+ },
+
+ loadEntityDefs: function(id, cb, cbErr) {
+ $http.get('/api/defs/' + id)
+ .success(cb)
+ .error(cbErr);
+ },
+
+ loadEntityCode: function(id, cb, cbErr) {
+ $http.get('/api/code/' + id)
+ .success(cb)
+ .error(cbErr);
+ },
+
+ loadEntityGraph: function(id, cb, cbErr) {
+ $http.get('/api/graph/inheritance/' + id + '?cdepth=3')
+ .success(cb)
+ .error(cbErr);
+ },
+
+ search: function(q, n, cb, cbErr) {
+ $http.get('/api/search?q=' + q + '&n=' + n)
+ .success(cb)
+ .error(cbErr);
+ }
+ };
+ }])
+
+ .controller('EntityCtrl', ['Model', 'Metrics', 'Feedback', '$stateParams', '$scope', '$sce', function(Model, Metrics, Feedback, $stateParams, $scope, $sce) {
+ $scope.entityId = $stateParams.id;
this.loadEntityLinearization = function() {
- Model.loadEntityLinearization($routeParams.id,
+ Model.loadEntityLinearization($stateParams.id,
function(data) {
$scope.linearization = data;
}, function(err) {
};
this.loadEntityDefs = function() {
- Model.loadEntityDefs($routeParams.id,
+ Model.loadEntityDefs($stateParams.id,
function(data) {
$scope.defs = data;
}, function(err) {
};
this.loadEntityCode = function() {
- Model.loadEntityCode($routeParams.id,
+ Model.loadEntityCode($stateParams.id,
function(data) {
$scope.code = data;
}, function(err) {
};
this.loadEntityGraph = function(e) {
- Model.loadEntityGraph($routeParams.id,
+ Model.loadEntityGraph($stateParams.id,
function(data) {
$scope.graph = $sce.trustAsHtml(data);
}, function(err) {
};
this.loadStructuralMetrics = function() {
- Metrics.loadStructuralMetrics($routeParams.id,
+ Metrics.loadStructuralMetrics($stateParams.id,
function(data) {
$scope.metrics = data;
}, function(message, status) {
});
};
- Model.loadEntity($routeParams.id,
+ Model.loadEntity($stateParams.id,
function(data) {
$scope.mentity = data;
}, function(message, status) {
scope: {
mentity: '='
},
- templateUrl: '/directives/entity/doc.html',
- link: function ($scope, element, attrs) {
- $scope.currentTab = 'doc';
- }
+ templateUrl: '/directives/entity/doc.html'
};
})
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';
+ };
+ }
};
})
};
})
- .directive('entityCard', function() {
+ .directive('entityCard', ['Feedback', function(Feedback) {
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';
+
+ $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 {
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,
}
}
};
+
+ 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'
};
}])
})();