Project

General

Profile

1
var repoControllers = angular.module('repoControllers', []);
2

    
3
repoControllers.controller('repoBrowseCtrl', [
4
	'$scope', '$http', '$timeout', '$sce', '$location',
5
	function ($scope, $http, $timeout, $sce, $location) {
6
		common_init($scope, $http, $sce, $location);
7
		$scope.repoBrowseFields = getBrowseFields();
8
		$scope.filterBrowseData = {filterText: ''};
9
		$scope.repoBrowseData = {'data': []};
10

    
11
		$scope.gridBrowseData = {
12
			data: 'repoBrowseData.data',
13
			enableRowSelection: false,
14
			enableCellEditOnFocus: false,
15
			enableHighlighting: true,
16
			filterOptions: $scope.filterBrowseData,
17
			sortInfo: {fields: ['value'], directions: ['desc']},
18
			columnDefs: [
19
				{
20
					field: 'name',
21
					displayName: 'Name',
22
					cellTemplate: '<div class="ngCellText"><a href="javascript:void(0)" ng-click="browseApis(repoBrowseData.id, row.getProperty(\'id\'))">{{row.getProperty(col.field)}}</a></div>'
23
				},
24
				{field: 'value', displayName: '# datasources', width: '20%', headerClass: 'text-right', cellClass: 'text-right'}
25
			]
26
		};
27

    
28
		$scope.searchApis = function (text) {
29
			$scope.go('/list/__SEARCH__/' + text);
30
		}
31

    
32
		$scope.browseApis = function (field, value) {
33
			$('#showRepoBrowseData').modal('hide');
34
			$scope.showSpinner();
35
			$timeout(function () {
36
				$scope.go('/list/' + field + '/' + value);
37
			}, 1500);
38
		}
39

    
40
		$scope.browseRepoField = function (field) {
41
			$scope.repoBrowseData = {
42
				'label': field.label,
43
				'id': field.id,
44
				'data': []
45
			};
46
			$scope.showSpinner();
47
			$http.get('browseRepoField.do?field=' + field.id).success(
48
				function (data) {
49
					$scope.hideSpinner();
50
					$scope.repoBrowseData.data = data;
51
					$('#showRepoBrowseData').modal('show');
52
				}
53
			).error(
54
				function () {
55
					$scope.showError('Something really bad must have happened to our fellow hamster..');
56
					$scope.hideSpinner();
57
				}
58
			);
59
		};
60
	}
61
]);
62

    
63
repoControllers.controller('repoListCtrl', [
64
	'$scope', '$http', '$timeout', '$sce', '$routeParams', '$location',
65
	function ($scope, $http, $timeout, $sce, $routeParams, $location) {
66
		common_init($scope, $http, $sce, $location);
67

    
68
		$scope.apis = [];
69
		$scope.filterApis = {filterText: ''};
70
		$scope.gridApis = {
71
			data: 'apis',
72
			enableRowSelection: false,
73
			enableCellEditOnFocus: false,
74
			enableHighlighting: true,
75
			filterOptions: $scope.filterApis,
76
			columnDefs: [
77
				{field: 'repoCountry', displayName: 'Country', width: '80px', headerClass: 'text-center', cellTemplate: '<ng-repo-country-cell />'},
78
				{field: 'repoName', displayName: 'Datasource Api', cellTemplate: '<ng-reponame-cell />'},
79
				{field: 'repoPrefix', displayName: 'Namespace Prefix', width: '150px', headerClass: 'text-center', cellClass: 'text-center'},
80
				{field: 'protocol', displayName: 'Protocol', width: '160px', headerClass: 'text-center', cellClass: 'text-center'},
81
				{field: 'aggrDate', displayName: 'Last Aggregation Date', width: '200px', headerClass: 'text-center', cellTemplate: '<ng-aggr-date-cell />'},
82
				{field: 'aggrTotal', displayName: 'Total', width: '80px', headerClass: 'text-center', cellTemplate: '<ng-aggr-total-cell />'}
83
			]
84
		};
85

    
86
		$scope.currentApiSelectionParam = $routeParams.param;
87
		$scope.currentApiSelectionValue = $routeParams.value;
88

    
89
		$scope.updateApis = function (refresh) {
90
			$scope.showSpinner();
91

    
92
			var params = {
93
				'param': $scope.currentApiSelectionParam,
94
				'value': $scope.currentApiSelectionValue,
95
			};
96
			if (refresh) {
97
				params.refresh = 1;
98
			}
99

    
100
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
101
			$http.post('listApis.do', $.param(params)).success(
102
				function (data) {
103
					$scope.hideSpinner();
104
					$scope.apis = data;
105
					$scope.resizeMainElement(document.getElementById('apisTable'));
106
				}
107
			).error(
108
				function () {
109
					$scope.showError('Something really bad must have happened to our fellow hamster..');
110
					$scope.hideSpinner();
111
				}
112
			);
113
		};
114

    
115
		$scope.showApi = function (repoId, ifaceId) {
116
			location.href = 'workflows.do#/api/' + repoId + '/' + ifaceId;
117
		}
118

    
119
		window.onresize = function () {
120
			var elem = document.getElementById('apisTable');
121
			if (elem) {
122
				angular.element(elem).scope().resizeMainElement(elem);
123
			}
124
		};
125

    
126
		$scope.updateApis(false);
127
	}
128
]);
129

    
130

    
131

    
(11-11/15)