(function() {
angular
- .module('entities', ['ngSanitize', 'ui', 'model'])
+ .module('entities', ['ngSanitize', 'ui'])
- .controller('EntityCtrl', ['Model', '$routeParams', '$scope', '$sce', function(Model, $routeParams, $scope, $sce) {
- this.loadEntityLinearization = function() {
- Model.loadEntityLinearization($routeParams.id,
- function(data) {
- $scope.linearization = data;
- }, function(err) {
- $scope.error = err;
- });
- };
+ /* Router */
- this.loadEntityDefs = function() {
- Model.loadEntityDefs($routeParams.id,
- function(data) {
- $scope.defs = data;
- }, function(err) {
- $scope.error = err;
- });
- };
+ .config(function($stateProvider, $locationProvider) {
+ $stateProvider
+ .state('doc', {
+ url: '/doc/:id',
+ templateUrl: 'views/doc/index.html',
+ resolve: {
+ mentity: function(Model, $q, $stateParams, $state) {
+ var d = $q.defer();
+ Model.loadEntity($stateParams.id, d.resolve,
+ function() {
+ $state.go('404', null, { location: false })
+ });
+ return d.promise;
+ }
+ },
+ controller: function(mentity) {
+ this.mentity = mentity;
+ },
+ controllerAs: 'vm',
+ abstract: true
+ })
+ .state('doc.entity', {
+ url: '',
+ templateUrl: 'views/doc/entity.html',
+ controller: function(mentity) {
+ this.mentity = mentity;
+ },
+ controllerAs: 'vm',
+ abstract: true
+ })
+ .state('doc.entity.doc', {
+ url: '',
+ templateUrl: 'views/doc/doc.html',
+ resolve: {
+ doc: function(Model, $q, $stateParams, $state) {
+ var d = $q.defer();
+ Model.loadEntityDoc($stateParams.id, d.resolve,
+ function() {
+ $state.go('404', null, { location: false })
+ });
+ return d.promise;
+ }
+ },
+ controller: function(mentity, doc) {
+ this.mentity = mentity;
+ this.doc = doc;
- this.loadEntityCode = function() {
- Model.loadEntityCode($routeParams.id,
- function(data) {
- $scope.code = data;
- }, function(err) {
- $scope.code = err;
- });
- };
+ this.date = function(date) {
+ return new Date(date);
+ }
+ },
+ controllerAs: 'vm',
+ })
+ .state('doc.entity.graph', {
+ url: '/graph',
+ templateUrl: 'views/doc/graph.html',
+ resolve: {
+ graph: function(Model, $q, $stateParams, $state) {
+ var d = $q.defer();
+ Model.loadEntityGraph($stateParams.id, d.resolve,
+ function() {
+ $state.go('404', null, { location: false })
+ });
+ return d.promise;
+ },
+ inh: function(Model, $q, $stateParams, $state) {
+ var d = $q.defer();
+ Model.loadEntityInh($stateParams.id, d.resolve,
+ function() {
+ $state.go('404', null, { location: false })
+ });
+ return d.promise;
+ }
+ },
+ controller: function(inh, graph, $sce) {
+ this.graph = $sce.trustAsHtml(graph);
+ this.inh = inh;
+ },
+ controllerAs: 'vm',
+ })
+ .state('doc.entity.metrics', {
+ url: '/metrics',
+ templateUrl: 'views/doc/metrics.html',
+ resolve: {
+ metrics: function(Metrics, $q, $stateParams, $state) {
+ var d = $q.defer();
+ Metrics.loadStructuralMetrics($stateParams.id, d.resolve,
+ function() {
+ $state.go('404', null, { location: false })
+ });
+ return d.promise;
+ }
+ },
+ controller: function(mentity, metrics) {
+ this.mentity = mentity;
+ this.metrics = metrics;
+ },
+ controllerAs: 'vm',
+ })
+ .state('doc.entity.code', {
+ url: '/code',
+ templateUrl: 'views/doc/code.html',
+ resolve: {
+ code: function(Model, $q, $stateParams, $state) {
+ var d = $q.defer();
+ Model.loadEntityCode($stateParams.id, d.resolve,
+ function() {
+ $state.go('404', null, { location: false })
+ });
+ return d.promise;
+ }
+ },
+ controller: function(mentity, code) {
+ this.mentity = mentity;
+ this.code = code;
+ },
+ controllerAs: 'vm',
+ })
+ .state('doc.entity.defs', {
+ url: '/defs',
+ templateUrl: 'views/doc/defs.html',
+ resolve: {
+ defs: function(Model, $q, $stateParams, $state) {
+ var d = $q.defer();
+ Model.loadEntityDefs($stateParams.id, d.resolve,
+ function() {
+ $state.go('404', null, { location: false })
+ });
+ return d.promise;
+ }
+ },
+ controller: function(mentity, defs) {
+ this.mentity = mentity;
+ this.defs = defs;
+ },
+ controllerAs: 'vm',
+ })
+ .state('doc.entity.lin', {
+ url: '/lin',
+ templateUrl: 'views/doc/lin.html',
+ resolve: {
+ lin: function(Model, $q, $stateParams, $state) {
+ var d = $q.defer();
+ Model.loadEntityLinearization($stateParams.id, d.resolve,
+ function() {
+ $state.go('404', null, { location: false })
+ });
+ return d.promise;
+ }
+ },
+ controller: function(mentity, lin, $scope, $location, $anchorScroll) {
+ var vm = this;
+ vm.focus = $location.hash() ?
+ $location.hash() : mentity.intro.full_name;
+ vm.mentity = mentity;
+ vm.linearization = lin;
+ setTimeout(function() {
+ $anchorScroll();
+ }, 400);
+ $scope.$watch(function () {
+ return $location.hash();
+ }, function (value) {
+ vm.focus = $location.hash() ?
+ $location.hash() : mentity.intro.full_name;
+ $anchorScroll();
+ });
+ },
+ controllerAs: 'vm'
+ })
+ .state('doc.entity.all', {
+ url: '/all',
+ templateUrl: 'views/doc/all.html',
+ controller: function(mentity) {
+ this.mentity = mentity;
+ },
+ controllerAs: 'vm',
+ })
+ })
- this.loadEntityGraph = function(e) {
- Model.loadEntityGraph($routeParams.id,
- function(data) {
- $scope.graph = $sce.trustAsHtml(data);
- }, function(err) {
- $scope.error = err;
- });
- };
+ /* Model */
- Model.loadEntity($routeParams.id,
- function(data) {
- $scope.mentity = data;
- }, function(err) {
- $scope.error = err;
- });
+ .factory('Model', [ '$http', function($http) {
+ return {
+
+ loadEntity: function(id, cb, cbErr) {
+ $http.get('/api/entity/' + id)
+ .success(cb)
+ .error(cbErr);
+ },
+
+ loadEntityDoc: function(id, cb, cbErr) {
+ $http.get('/api/entity/' + id + '/doc')
+ .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);
+ },
+
+ loadEntityInh: function(id, cb, cbErr) {
+ $http.get('/api/inheritance/' + id)
+ .success(cb)
+ .error(cbErr);
+ },
+ search: function(q, p, n, cb, cbErr) {
+ $http.get('/api/search?q=' + q + '&p=' + p + '&n=' + n)
+ .success(cb)
+ .error(cbErr);
+ }
+ };
}])
+ /* Directives */
+
.directive('entityLink', function() {
return {
restrict: 'E',
};
})
+ .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('entityCard', function() {
+ .directive('entityGraph', function() {
+ return {
+ restrict: 'E',
+ scope: {
+ mentity: '=',
+ graph: '='
+ },
+ replace: true,
+ templateUrl: '/directives/entity/graph.html'
+ };
+ })
+
+ .directive('entityCard', ['Feedback', function(Feedback) {
return {
restrict: 'E',
scope: {
replace: true,
templateUrl: '/directives/entity/card.html'
};
- })
+ }])
.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 == $scope.definition.full_name;
+ }
+
$scope.loadCardCode = function() {
if(!$scope.code) {
Model.loadEntityCode($scope.definition.full_name,
}
}
};
+
+ $scope.$watch('focus', function() {
+ 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: '='
+ },
+ controller: 'StarsCtrl',
+ controllerAs: 'starsCtrl',
+ templateUrl: '/directives/entity/stars.html'
+ };
+ }])
})();