Project

General

Profile

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

    
3

    
4
module.directive('compileTemplate', function($compile, $parse){
5
	return {
6
		link: function(scope, element, attr){
7
			var parsed = $parse(attr.ngBindHtml);
8
            
9
			function getStringValue() { return (parsed(scope) || '').toString(); }
10

    
11
			//Recompile if the template changes
12
			scope.$watch(getStringValue, function() {
13
                $compile(element, null, -9999)(scope);  //The -9999 makes it skip directives so that we do not recompile ourselves
14
			});
15
		}         
16
	}
17
});
18

    
19
function oaiExplorerCtrl($scope, $http, $sce) {
20
	$scope.tmpBaseUrl = getInitialBaseUrl();
21
	$scope.baseUrl = "";
22
	$scope.currentAction = "";
23
	$scope.oaiUrl = "";
24
	$scope.testAllVerbsData = [];
25
	$scope.testHarvestingData = [];
26
	$scope.continueIteration = false;
27
	
28
	$scope.identifyData = "";
29
	
30
	$scope.isValidUrl = function(url) {
31
		return (/^http/).test(url);
32
	}
33
		
34
	$scope.verifyBaseUrl = function(url) {
35
		$scope.baseUrl = "";
36
		$scope.currentAction = "";
37
		if ($scope.isValidUrl(url)) {
38
			$scope.baseUrl = url;
39
			$scope.identify();
40
		}
41
	}
42
	
43
	initSpinner();
44
	$scope.showError        = function(error)   { show_notification("error", error); }
45
	$scope.showNotification = function(message) { show_notification("info", message); }
46
	$scope.showSpinner      = function()        { showSpinner(); }
47
	$scope.hideSpinner      = function()        { hideSpinner(); }
48

    
49
	
50
	$scope.identify = function() {
51
		$scope.oaiUrl = $scope.baseUrl + "?verb=Identify";
52
		
53
		$scope.callRemoteMethod('Identify', {
54
			'baseUrl' : $scope.baseUrl,
55
			'verb'    : 'Identify' 
56
        });
57
	}
58
	
59
	$scope.listMetadataFormats = function() {
60
		$scope.oaiUrl = $scope.baseUrl + "?verb=ListMetadataFormats";
61
		
62
		$scope.callRemoteMethod('ListMetadataFormats', {
63
			'baseUrl' : $scope.baseUrl,
64
			'verb'    : 'ListMetadataFormats' 
65
        });
66
	}
67
	
68
	$scope.listSets = function() {
69
		$scope.oaiUrl = $scope.baseUrl + "?verb=ListSets";
70
		
71
		$scope.callRemoteMethod('ListSets', {
72
			'baseUrl' : $scope.baseUrl,
73
			'verb'    : 'ListSets'
74
        });
75
	}
76

    
77
	$scope.listRecords = function(mdf, set) {
78
		$scope.oaiUrl = $scope.baseUrl + "?verb=ListRecords&metadataPrefix=" + mdf;
79
		if (set) {
80
			$scope.oaiUrl += "&set=" + set; 
81
		}
82
		
83
		$scope.callRemoteMethod('ListRecords', {
84
			'baseUrl' : $scope.baseUrl,
85
			'verb'    : 'ListRecords',
86
			'mdf'     : mdf,
87
			'set'     : set
88
        });
89
	}
90

    
91
	$scope.listIdentifiers = function(mdf, set) {
92
		$scope.oaiUrl = $scope.baseUrl + "?verb=ListIdentifier&metadataPrefix=" + mdf;
93
		if (set) {
94
			$scope.oaiUrl += "&set=" + set; 
95
		}
96
		
97
		$scope.callRemoteMethod('ListIdentifiers', {
98
			'baseUrl' : $scope.baseUrl,
99
			'verb'    : 'ListIdentifiers',
100
			'mdf'     : mdf,
101
			'set'     : set
102
        });
103
	}
104

    
105
	$scope.getRecord = function(id, mdf) {
106
		$scope.currentAction = "GetRecord";
107
		$scope.oaiUrl = $scope.baseUrl + "?verb=GetRecord&metadataPrefix=" + mdf + "&identifier=" + id;
108
		$scope.callRemoteMethod('GetRecord', {
109
			'baseUrl' : $scope.baseUrl,
110
			'verb'    : 'GetRecord',
111
			'mdf'     : mdf,
112
			'id'      : id
113
        });
114
	}
115
	
116
	$scope.nextPage = function(token) {
117
		$scope.oaiUrl = $scope.baseUrl + "?verb=" + $scope.currentAction + "&resumptionToken=" + token;
118
		$scope.callRemoteMethod($scope.currentAction, {
119
			'baseUrl': $scope.baseUrl,
120
			'verb': $scope.currentAction,
121
			'token' : token
122
        });
123
	}
124

    
125
	
126
	$scope.testAllVerbs = function() {
127
		$scope.currentAction = "testAllVerbs";
128
		$scope.oaiDataHTML = "";
129
		$scope.oaiUrl = $scope.baseUrl + "?verb=Identify";
130
		$scope.testAllVerbsData = [];
131
		$scope.testHarvestingData = [];
132
		$scope.continueIteration = true;		
133
		
134
		$scope.time_min = 9999999;
135
		$scope.time_max = 0;
136
		$scope.time_total = 0;
137
		$scope.time_sqrTotal = 0;
138
		$scope.time_avg = 0;
139
		$scope.time_stddev = 0;
140
		
141
		$scope.testVerb($scope.testAllVerbsData, "test_oai_verb", {
142
			'baseUrl' : $scope.baseUrl,
143
			'verb'    : 'Identify',
144
        });
145
	}
146
	
147
	$scope.testHarvesting = function() {
148
		$scope.currentAction = "testHarvesting";
149
		$scope.oaiUrl = $scope.baseUrl + "?verb=ListRecords&metadataPrefix=oai_dc";
150
		$scope.oaiDataHTML = "";
151
		$scope.testAllVerbsData = [];
152
		$scope.testHarvestingData = [];
153
		$scope.continueIteration = false;
154
		
155
		$scope.time_min = 9999999;
156
		$scope.time_max = 0;
157
		$scope.time_total = 0;
158
		$scope.time_sqrTotal = 0;
159
		$scope.time_avg = 0;
160
		$scope.time_stddev = 0;
161
	}
162

    
163
	$scope.startTestHarvesting = function() {
164
		$scope.continueIteration = true;
165
		$scope.time_min = 9999999;
166
		$scope.time_max = 0;
167
		$scope.time_total = 0;
168
		$scope.time_sqrTotal = 0;
169
		$scope.time_avg = 0;
170
		$scope.time_stddev = 0;
171
		
172
		$scope.testHarvestingData = [];
173
		$scope.testVerb($scope.testHarvestingData, "test_harvesting", {
174
			'baseUrl' : $scope.baseUrl,
175
			'verb'    : 'ListRecords',
176
			'mdf'     : 'oai_dc'
177
        });
178
	}
179
	
180
	$scope.stopTestHarvesting = function() {
181
		$scope.continueIteration = false;
182
	}
183
	
184
	$scope.testVerb = function(list, method, params) {
185
		//$scope.showSpinner();
186
		$http.post(method, params).success(function(data) {
187
        	list.push(data);
188
        	
189
        	if (data.time) {
190
        		var curr = data.time / 1000;
191

    
192
        		$scope.time_min = Math.min($scope.time_min, curr);
193
        		$scope.time_max = Math.max($scope.time_max, curr);
194
        		$scope.time_total += curr;
195
        		$scope.time_sqrTotal += curr*curr;
196
        		$scope.time_avg = ($scope.time_total/list.length);
197
        		$scope.time_stddev = Math.sqrt((list.length * $scope.time_sqrTotal) - ($scope.time_total * $scope.time_total)) / list.length;
198
        	}
199
        	
200
        	location.href="#endPage";
201
        	//$scope.hideSpinner();
202
        	if ($scope.continueIteration && data.nextCall && data.nextCall.verb) {
203
        		$scope.testVerb(list, method, data.nextCall);
204
        	} else {
205
        		$scope.continueIteration = false;
206
        	}
207
        }).error(
208
            function(err) {
209
            	$scope.showError(err.message);
210
            	//$scope.hideSpinner();
211
            }
212
        );
213
	}
214
		
215
	$scope.callRemoteMethod = function(name, params) {
216
		$scope.currentAction = name;
217
		$scope.oaiDataHTML = "";
218
		$scope.testAllVerbsData = [];
219
		$scope.testHarvestingData = [];
220
		
221
		$scope.showSpinner();
222

    
223
		$http.post('oai_verb', params).success(function(data) {
224
        	$scope.oaiDataHTML = $sce.trustAsHtml(data);
225
        	$scope.hideSpinner();
226
        }).error(
227
            function(err) {
228
            	$scope.showError(err.message);
229
            	$scope.hideSpinner();
230
            }
231
        );
232
	}
233
	
234
	$scope.updateGraph = function(list, field) {
235
		var i = 1;
236
		var d = [];
237
		angular.forEach(list, function(obj) {
238
			if (obj[field]) {
239
				d[i] = [i, obj[field]];
240
			}
241
			i++;
242
		});
243
		jQuery.plot("#harvestingGraph", [ d ]);
244
	}
245
	
246
	
247
	if ($scope.tmpBaseUrl && $scope.isValidUrl($scope.tmpBaseUrl)) {
248
		$scope.verifyBaseUrl($scope.tmpBaseUrl);
249
	}
250

    
251
}
(1-1/2)