Project

General

Profile

« Previous | Next » 

Revision 43750

developed first version of REST query

View differences:

modules/dnet-modular-index-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/index_inspector.js
4 4
	'$routeProvider',
5 5
	function($routeProvider) {
6 6
		$routeProvider
7
			.when('/query',		{ templateUrl: '../resources/html/index/indexQuery.html', controller: 'indexQueryController' })
7
			.when('/query',		                                    { templateUrl: '../resources/html/index/indexQuery.html', controller: 'indexQueryController' })
8
			.when('/query/:mdformat/:backend/:index/:start/:query', { templateUrl: '../resources/html/index/indexQuery.html', controller: 'indexQueryController' })
8 9
			.when('/browse',	{ templateUrl: '../resources/html/index/browse.html', controller: 'indexBrowseController' })
9 10
			.when('/manage',	{ templateUrl: '../resources/html/index/indexManage.html', controller: 'indexmanageController' })
10 11
			.when('/deletebyquery',	{ templateUrl: '../resources/html/index/deletebyquery.html', controller: 'indexdbqController' })			
modules/dnet-modular-index-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/index_inspector_controllers.js
2 2

  
3 3
function common_init($scope, $http, $sce, $location) {
4 4
	initSpinner();
5
	$scope.showError        = function(error)   { show_notification("error", error); }
6
	$scope.showNotification = function(message) { show_notification("info", message); }
7
	$scope.showSpinner      = function()        { showSpinner(); }
8
	$scope.hideSpinner      = function()        { hideSpinner(); }
9
	$scope.to_trusted       = function(html)    { return $sce.trustAsHtml(html); }
10
	$scope.go               = function(path)    { $location.path(path); }
11
	$scope.encodeValue      = function(val)     { return val; }
5
	$scope.showError = function (error) {
6
		show_notification("error", error);
7
	}
8
	$scope.showNotification = function (message) {
9
		show_notification("info", message);
10
	}
11
	$scope.showSpinner = function () {
12
		showSpinner();
13
	}
14
	$scope.hideSpinner = function () {
15
		hideSpinner();
16
	}
17
	$scope.to_trusted = function (html) {
18
		return $sce.trustAsHtml(html);
19
	}
20
	$scope.go = function (path) {
21
		$location.path(path);
22
	}
23
	$scope.encodeValue = function (val) {
24
		return val;
25
	}
12 26
}
13 27

  
14
indexInspectorControllers.directive('compileTemplate', function($compile, $parse){
15
    return {
16
            link: function(scope, element, attr){
17
                    var parsed = $parse(attr.ngBindHtml);
18
        
19
                    function getStringValue() { return (parsed(scope) || '').toString(); }
28
indexInspectorControllers.directive('compileTemplate', function ($compile, $parse) {
29
	return {
30
		link: function (scope, element, attr) {
31
			var parsed = $parse(attr.ngBindHtml);
20 32

  
21
                    //Recompile if the template changes
22
                    scope.$watch(getStringValue, function() {
23
            $compile(element, null, -9999)(scope);  //The -9999 makes it skip directives so that we do not recompile ourselves
24
                    });
25
            }         
26
    }
33
			function getStringValue() {
34
				return (parsed(scope) || '').toString();
35
			}
36

  
37
			//Recompile if the template changes
38
			scope.$watch(getStringValue, function () {
39
				$compile(element, null, -9999)(scope);  //The -9999 makes it skip directives so that we do not recompile ourselves
40
			});
41
		}
42
	}
27 43
});
28 44

  
29 45

  
30 46
indexInspectorControllers.controller('indexmanageController', [
31
                 	'$scope', '$http', '$sce', '$location',
32
                     function ($scope, $http, $sce, $location) {
33
                     common_init($scope, $http, $sce, $location);
34
                     
35
                 	
36
                 	
37
                	}]);
47
	'$scope', '$http', '$sce', '$location',
48
	function ($scope, $http, $sce, $location) {
49
		common_init($scope, $http, $sce, $location);
38 50

  
39
indexInspectorControllers.controller('indexdbqController', [ '$scope',
40
		'$http', '$sce', '$location', function($scope, $http, $sce, $location) {
41
			common_init($scope, $http, $sce, $location);
42
			$scope.mdFormats = []
43
       		$scope.backends = []
44
       		$scope.indices = []
45
       		$scope.query = '*=*'
46
       		$scope.from = 0
47
      		$scope.size =10
48
       		$scope.error = null;
49
      		
50
      		$scope.showSpinner();
51
      		
52
      		$scope.to_trusted = function(html_code) {
53
      			return $sce.trustAsHtml(html_code);
54
      		}
55
      		
56
      		
57
      		$http.get('index/indexMetadataFormats.do').success(function(data) {
58
       			$scope.hideSpinner();
59
       			$scope.mdFormats = data;
60
       		}).error(function() {
61
       			$scope.showError('Error listing xmldb collections');
62
       			$scope.hideSpinner();
63
       	    });
64
       		
65
       		$http.get('index/backend.do').success(function(data) {
66
       			$scope.hideSpinner();
67
       			$scope.backends = data;
68
       		}).error(function(error) {
69
       			$scope.showError(error.message);
70
       			$scope.hideSpinner();
71
       	    });
72
       		
73
       		$scope.backendSelected = function(index) {
74
       			
75
       			if ($scope.selectedbackend != null){
76
       				$http.get('index/indexDatastructures.do', {
77
           		        params: {
78
           		        	backend: $scope.selectedbackend           		            
79
           		        }
80
           		     }).success(function(data) {
81
               			$scope.hideSpinner();         			
82
               			$scope.indices = data
83
               			
84
               		}).error(function() {
85
               			$scope.showError('Error listing xmldb collections');
86
               			$scope.hideSpinner();
87
               	    });
88
       			}
89
       			
90
       			
91
       		}
92
      		
93
       		
94
       		$scope.hideSpinner();
95
       		
96
       		$scope.startDelete= function()
97
       		{
98
       			$scope.from =0;
99
       			$scope.size = 10
100
       			$scope.deleteByQuery()
101
       		}
102
       		
103
       		
104
       		$scope.deleteByQuery= function()
105
       		{
106
       			
107
       			if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
108
       				alert("You must select a metadata format and a backend identifier")
109
       				return;
110
       			}
111
       			
112
       			$scope.showSpinner();
113
       			$scope.error =null;
114
       			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
115
       			var selectedId = null;
116
       			if ($scope.selectedIndex != null)
117
       				selectedId =$scope.selectedIndex.id
118
       			$http.post('index/delete.do', $.param({
119
       		        	
120
       				'backend':$scope.selectedbackend,
121
       		        'format': $scope.selectedMdref.format,
122
       		        'layout': $scope.selectedMdref.layout,
123
       		        'interpretation':$scope.selectedMdref.interpretation,
124
       		        'query' :$scope.query,
125
       		        'indexidentifier': selectedId
126
       		        
127
       		        }))
128
       		        .success(function(data) {
129
       		        	$scope.hideSpinner();
130
       		        	$scope.searchResult= data
131
       		        	console.log(data)
132
           		}).error(function(error) {    
133
           			$scope.error = error;           			
134
           			$scope.hideSpinner();
135
           	    });  			
136
       		}
137
       		
138
       		$scope.nextPage= function() {
139
       			if ($scope.searchResult == null)
140
       				return;
141
       			if($scope.from > $scope.searchResult.total)
142
       				return;
143
       			$scope.from +=10;
144
       			$scope.size = $scope.from+10
145
       			$scope.search()
146
       		}
147
       		
148
       		$scope.prevPage= function() {
149
       			if ($scope.from <=0)
150
       			{
151
       				return;
152
       			}
153
       			
154
       			$scope.from -=10;
155
       			$scope.size -= 10
156
       			$scope.search()
157
       		}
158
       		
159
	       	 $scope.range = function(n) {
160
	       		 	return new Array(n);
161
	       	 	};
162
			
163
			
164 51

  
165
		} ]);
52
	}]);
166 53

  
54
indexInspectorControllers.controller('indexdbqController', ['$scope',
55
	'$http', '$sce', '$location', function ($scope, $http, $sce, $location) {
56
		common_init($scope, $http, $sce, $location);
57
		$scope.mdFormats = []
58
		$scope.backends = []
59
		$scope.indices = []
60
		$scope.query = '*=*'
61
		$scope.from = 0
62
		$scope.size = 10
63
		$scope.error = null;
167 64

  
65
		$scope.showSpinner();
168 66

  
67
		$scope.to_trusted = function (html_code) {
68
			return $sce.trustAsHtml(html_code);
69
		}
169 70

  
170 71

  
72
		$http.get('index/indexMetadataFormats.do').success(function (data) {
73
			$scope.hideSpinner();
74
			$scope.mdFormats = data;
75
		}).error(function () {
76
			$scope.showError('Error listing xmldb collections');
77
			$scope.hideSpinner();
78
		});
79

  
80
		$http.get('index/backend.do').success(function (data) {
81
			$scope.hideSpinner();
82
			$scope.backends = data;
83
		}).error(function (error) {
84
			$scope.showError(error.message);
85
			$scope.hideSpinner();
86
		});
87

  
88
		$scope.backendSelected = function (index) {
89

  
90
			if ($scope.selectedbackend != null) {
91
				$http.get('index/indexDatastructures.do', {
92
					params: {
93
						backend: $scope.selectedbackend
94
					}
95
				}).success(function (data) {
96
					$scope.hideSpinner();
97
					$scope.indices = data
98

  
99
				}).error(function () {
100
					$scope.showError('Error listing xmldb collections');
101
					$scope.hideSpinner();
102
				});
103
			}
104

  
105

  
106
		}
107

  
108

  
109
		$scope.hideSpinner();
110

  
111
		$scope.startDelete = function () {
112
			$scope.from = 0;
113
			$scope.size = 10
114
			$scope.deleteByQuery()
115
		}
116

  
117

  
118
		$scope.deleteByQuery = function () {
119

  
120
			if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
121
				alert("You must select a metadata format and a backend identifier")
122
				return;
123
			}
124

  
125
			$scope.showSpinner();
126
			$scope.error = null;
127
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
128
			var selectedId = null;
129
			if ($scope.selectedIndex != null)
130
				selectedId = $scope.selectedIndex.id
131
			$http.post('index/delete.do', $.param({
132

  
133
				'backend': $scope.selectedbackend,
134
				'format': $scope.selectedMdref.format,
135
				'layout': $scope.selectedMdref.layout,
136
				'interpretation': $scope.selectedMdref.interpretation,
137
				'query': $scope.query,
138
				'indexidentifier': selectedId
139

  
140
			}))
141
				.success(function (data) {
142
					$scope.hideSpinner();
143
					$scope.searchResult = data
144
					console.log(data)
145
				}).error(function (error) {
146
				$scope.error = error;
147
				$scope.hideSpinner();
148
			});
149
		}
150

  
151
		$scope.nextPage = function () {
152
			if ($scope.searchResult == null)
153
				return;
154
			if ($scope.from > $scope.searchResult.total)
155
				return;
156
			$scope.from += 10;
157
			$scope.size = $scope.from + 10
158
			$scope.search()
159
		}
160

  
161
		$scope.prevPage = function () {
162
			if ($scope.from <= 0) {
163
				return;
164
			}
165

  
166
			$scope.from -= 10;
167
			$scope.size -= 10
168
			$scope.search()
169
		}
170

  
171
		$scope.range = function (n) {
172
			return new Array(n);
173
		};
174

  
175

  
176
	}]);
177

  
178

  
171 179
indexInspectorControllers.controller('indexBrowseController', [
172
       	'$scope', '$http', '$sce', '$location',
173
       	function ($scope, $http, $sce, $location) {
174
       		common_init($scope, $http, $sce, $location);
175
       		$scope.showSpinner();
176
       		$scope.mdFormats = []
177
       		$scope.backends = []
178
       		$scope.indices = []
179
       		$scope.query = '*=*'
180
       		$scope.error = null;
181
       		
182
       		$scope.browseFields =[];
183
       		$scope.addedBrowseFields =[];
184
       		$scope.selectedMdref = "";   		
185
       		
186
       		$http.get('index/indexMetadataFormats.do').success(function(data) {
187
       			$scope.hideSpinner();
188
       			$scope.mdFormats = data;
189
       		}).error(function() {
190
       			$scope.showError('Error listing xmldb collections');
191
       			$scope.hideSpinner();
192
       	    });
193
       		
194
       		$http.get('index/backend.do').success(function(data) {
195
       			$scope.hideSpinner();
196
       			$scope.backends = data;
197
       		}).error(function(error) {
198
       			$scope.showError(error.message);
199
       			$scope.hideSpinner();
200
       	    });
201
       		
202
       		$scope.backendSelected = function(index) {
203
       			
204
       			if ($scope.selectedbackend != null){
205
       				$http.get('index/indexDatastructures.do', {
206
           		        params: {
207
           		        	backend: $scope.selectedbackend           		            
208
           		        }
209
           		     }).success(function(data) {
210
               			$scope.hideSpinner();         			
211
               			$scope.indices = data
212
               			
213
               		}).error(function() {
214
               			$scope.showError('Error listing xmldb collections');
215
               			$scope.hideSpinner();
216
               	    });
217
       			}
218
       			
219
       			
220
       		}
221
       		
222
       		$scope.metadataFormatSelected = function(index){
223
       			if ($scope.selectedMdref == null)
224
       			{
225
       				$scope.addedBrowseFields =[];
226
       				$scope.browseFields = []
227
       				return;
228
       			}       				
229
       			
230
       			$http.get('index/mdFormatInfo.do', {
231
       		        params: {
232
       		            id: $scope.selectedMdref.id,
233
       		            layout: $scope.selectedMdref.layout
234
       		        }
235
       		     }).success(function(data) {
236
           			$scope.hideSpinner();
237
           			$scope.browseFields = data;
238
           			$scope.browseFields.sort()
239
           			$scope.addedBrowseFields =[];
240
           			$scope.selectedBrowser = '--- Add Field --'
241
           		}).error(function() {
242
           			$scope.showError('Error listing xmldb collections');
243
           			$scope.hideSpinner();
244
           	    });
245
       		};
246
       		
247
       		$scope.startBrowse= function()
248
       		{
249
       			
250
       			if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
251
       				alert("You must select a metadata format and a backend identifier")
252
       				return;
253
       			}
254
       			if($scope.addedBrowseFields.length  == 0) {
255
       				alert("You must select at least one browse field")
256
       				return;
257
       			}
258
       			$scope.showSpinner();
259
       			$scope.error =null;
260
       			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
261
       			$http.post('index/browse.do', $.param({
262
       		        	
263
       				'backend':$scope.selectedbackend,
264
       		        'format': $scope.selectedMdref.format,
265
       		         'layout': $scope.selectedMdref.layout,
266
       		         'interpretation':$scope.selectedMdref.interpretation,
267
       		         'fields':JSON.stringify($scope.addedBrowseFields),
268
       		         'query' :$scope.query
269
       		        }))
270
       		        .success(function(data) {
271
       		        	$scope.hideSpinner();
272
       		        	$scope.browseResult= data
273
           		}).error(function(error) {    
274
           			$scope.error = error;           			
275
           			$scope.hideSpinner();
276
           	    });  			
277
       		}
278
       		
279
       		
280
       		$scope.deleteBrowseField= function(item)
281
       		{
282
       			var i = 0
283
       			
284
       			for (;i<$scope.addedBrowseFields.length; i++) {
285
       					if ($scope.addedBrowseFields[i]==item)
286
       						break;
287
       				}
288
       			$scope.addedBrowseFields.splice(i,1)
289
       			$scope.browseFields  = $scope.browseFields.concat(item)
290
       			$scope.browseFields.sort(); 
291
       			
292
       		}
293
       		
294
       		$scope.browseFieldAdded = function() {
295
       			for (i=0; i<$scope.browseFields.length; i++) {
296
       				if ($scope.browseFields[i] == $scope.selectedBrowser) {
297
       					var data = $scope.browseFields[i];
298
       					$scope.addedBrowseFields  = $scope.addedBrowseFields.concat(data)
299
       					$scope.browseFields.splice(i,1)
300
       					return;
301
       				}       					
302
       			}
303
       		}
304
       		
305
       		
306
       		
307
       		
308
       		
309
       		
310
       		
311
       		
312
       		
313
       	}]);
180
	'$scope', '$http', '$sce', '$location',
181
	function ($scope, $http, $sce, $location) {
182
		common_init($scope, $http, $sce, $location);
183
		$scope.showSpinner();
184
		$scope.mdFormats = []
185
		$scope.backends = []
186
		$scope.indices = []
187
		$scope.query = '*=*'
188
		$scope.error = null;
314 189

  
315
function replaceText(str)
316
{
317
    var str1 = String(str);
318
    
319
    return str1.replace(/\n/g,"<br/>");
190
		$scope.browseFields = [];
191
		$scope.addedBrowseFields = [];
192
		$scope.selectedMdref = "";
193

  
194
		$http.get('index/indexMetadataFormats.do').success(function (data) {
195
			$scope.hideSpinner();
196
			$scope.mdFormats = data;
197
		}).error(function () {
198
			$scope.showError('Error listing xmldb collections');
199
			$scope.hideSpinner();
200
		});
201

  
202
		$http.get('index/backend.do').success(function (data) {
203
			$scope.hideSpinner();
204
			$scope.backends = data;
205
		}).error(function (error) {
206
			$scope.showError(error.message);
207
			$scope.hideSpinner();
208
		});
209

  
210
		$scope.backendSelected = function (index) {
211

  
212
			if ($scope.selectedbackend != null) {
213
				$http.get('index/indexDatastructures.do', {
214
					params: {
215
						backend: $scope.selectedbackend
216
					}
217
				}).success(function (data) {
218
					$scope.hideSpinner();
219
					$scope.indices = data
220

  
221
				}).error(function () {
222
					$scope.showError('Error listing xmldb collections');
223
					$scope.hideSpinner();
224
				});
225
			}
226

  
227

  
228
		}
229

  
230
		$scope.metadataFormatSelected = function (index) {
231
			if ($scope.selectedMdref == null) {
232
				$scope.addedBrowseFields = [];
233
				$scope.browseFields = []
234
				return;
235
			}
236

  
237
			$http.get('index/mdFormatInfo.do', {
238
				params: {
239
					id: $scope.selectedMdref.id,
240
					layout: $scope.selectedMdref.layout
241
				}
242
			}).success(function (data) {
243
				$scope.hideSpinner();
244
				$scope.browseFields = data;
245
				$scope.browseFields.sort()
246
				$scope.addedBrowseFields = [];
247
				$scope.selectedBrowser = '--- Add Field --'
248
			}).error(function () {
249
				$scope.showError('Error listing xmldb collections');
250
				$scope.hideSpinner();
251
			});
252
		};
253

  
254
		$scope.startBrowse = function () {
255

  
256
			if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
257
				alert("You must select a metadata format and a backend identifier")
258
				return;
259
			}
260
			if ($scope.addedBrowseFields.length == 0) {
261
				alert("You must select at least one browse field")
262
				return;
263
			}
264
			$scope.showSpinner();
265
			$scope.error = null;
266
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
267
			$http.post('index/browse.do', $.param({
268

  
269
				'backend': $scope.selectedbackend,
270
				'format': $scope.selectedMdref.format,
271
				'layout': $scope.selectedMdref.layout,
272
				'interpretation': $scope.selectedMdref.interpretation,
273
				'fields': JSON.stringify($scope.addedBrowseFields),
274
				'query': $scope.query
275
			}))
276
				.success(function (data) {
277
					$scope.hideSpinner();
278
					$scope.browseResult = data
279
				}).error(function (error) {
280
				$scope.error = error;
281
				$scope.hideSpinner();
282
			});
283
		}
284

  
285

  
286
		$scope.deleteBrowseField = function (item) {
287
			var i = 0
288

  
289
			for (; i < $scope.addedBrowseFields.length; i++) {
290
				if ($scope.addedBrowseFields[i] == item)
291
					break;
292
			}
293
			$scope.addedBrowseFields.splice(i, 1)
294
			$scope.browseFields = $scope.browseFields.concat(item)
295
			$scope.browseFields.sort();
296

  
297
		}
298

  
299
		$scope.browseFieldAdded = function () {
300
			for (i = 0; i < $scope.browseFields.length; i++) {
301
				if ($scope.browseFields[i] == $scope.selectedBrowser) {
302
					var data = $scope.browseFields[i];
303
					$scope.addedBrowseFields = $scope.addedBrowseFields.concat(data)
304
					$scope.browseFields.splice(i, 1)
305
					return;
306
				}
307
			}
308
		}
309

  
310

  
311
	}]);
312

  
313
function replaceText(str) {
314
	var str1 = String(str);
315

  
316
	return str1.replace(/\n/g, "<br/>");
320 317
}
321 318

  
322 319

  
320
function constructMDREFfromString(input) {
321
	if (input == null || input.length == 0)
322
		return null;
323
	var mdrefArr = input.split('-');
324
	if (3 == mdrefArr.length) {
325
		var x = [];
326
		x['format'] = mdrefArr[0];
327
		x['layout'] = mdrefArr[1];
328
		x['interpretation'] = mdrefArr[2];
329
		return x;
330
	}
331
}
323 332

  
324 333

  
325 334
indexInspectorControllers.controller('indexQueryController', [
326
      	'$scope', '$http', '$sce', '$location',
327
      	function ($scope, $http, $sce, $location) {
328
      		common_init($scope, $http, $sce, $location);
329
      		
330
      		$scope.mdFormats = []
331
       		$scope.backends = []
332
       		$scope.indices = []
333
       		$scope.query = '*=*'
334
       		$scope.from = 0
335
      		$scope.size =10
336
       		$scope.error = null;
337
      		
338
      		$scope.showSpinner();
339
      		
340
      		$scope.to_trusted = function(html_code) {
341
      			return $sce.trustAsHtml(html_code);
342
      		}
343
      		
344
      		
345
      		$http.get('index/indexMetadataFormats.do').success(function(data) {
346
       			$scope.hideSpinner();
347
       			$scope.mdFormats = data;
348
       		}).error(function() {
349
       			$scope.showError('Error listing xmldb collections');
350
       			$scope.hideSpinner();
351
       	    });
352
       		
353
       		$http.get('index/backend.do').success(function(data) {
354
       			$scope.hideSpinner();
355
       			$scope.backends = data;
356
       		}).error(function(error) {
357
       			$scope.showError(error.message);
358
       			$scope.hideSpinner();
359
       	    });
360
       		
361
       		$scope.backendSelected = function(index) {
362
       			
363
       			if ($scope.selectedbackend != null){
364
       				$http.get('index/indexDatastructures.do', {
365
           		        params: {
366
           		        	backend: $scope.selectedbackend           		            
367
           		        }
368
           		     }).success(function(data) {
369
               			$scope.hideSpinner();         			
370
               			$scope.indices = data
371
               			
372
               		}).error(function() {
373
               			$scope.showError('Error listing xmldb collections');
374
               			$scope.hideSpinner();
375
               	    });
376
       			}
377
       			
378
       			
379
       		}
380
      		
381
       		
382
       		$scope.hideSpinner();
383
       		
384
       		$scope.startSearch= function()
385
       		{
386
       			$scope.from =0;
387
       			$scope.size = 10
388
       			$scope.search()
389
       		}
390
       		
391
       		
392
       		$scope.search= function()
393
       		{
394
       			
395
       			if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
396
       				alert("You must select a metadata format and a backend identifier")
397
       				return;
398
       			}
399
       			
400
       			$scope.showSpinner();
401
       			$scope.error =null;
402
       			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
403
       			var selectedId = null;
404
       			if ($scope.selectedIndex != null)
405
       				selectedId =$scope.selectedIndex.id
406
       			$http.post('index/search.do', $.param({
407
       		        	
408
       				'backend':$scope.selectedbackend,
409
       		        'format': $scope.selectedMdref.format,
410
       		        'layout': $scope.selectedMdref.layout,
411
       		        'interpretation':$scope.selectedMdref.interpretation,
412
       		        'query' :$scope.query,
413
       		        'from' :$scope.from,
414
       		        'number' :$scope.size,
415
       		        'indexidentifier': selectedId
416
       		        }))
417
       		        .success(function(data) {
418
       		        	$scope.hideSpinner();
419
       		        	$scope.searchResult= data
420
       		        	console.log(data)
421
           		}).error(function(error) {    
422
           			$scope.error = error;           			
423
           			$scope.hideSpinner();
424
           	    });  			
425
       		}
426
       		
427
       		$scope.nextPage= function() {
428
       			if ($scope.searchResult == null)
429
       				return;
430
       			if($scope.from > $scope.searchResult.total)
431
       				return;
432
       			$scope.from +=10;
433
       			$scope.size = $scope.from+10
434
       			$scope.search()
435
       		}
436
       		
437
       		$scope.prevPage= function() {
438
       			if ($scope.from <=0)
439
       			{
440
       				return;
441
       			}
442
       			
443
       			$scope.from -=10;
444
       			$scope.size -= 10
445
       			$scope.search()
446
       		}
447
       		
448
	       	 $scope.range = function(n) {
449
	       		 	return new Array(n);
450
	       	 	};
451
	      		
452
      		
453
      	}]);
335
	'$scope', '$http', '$sce', '$location', '$routeParams',
336
	function ($scope, $http, $sce, $location, $routeParams) {
337
		common_init($scope, $http, $sce, $location);
454 338

  
339
		$scope.mdFormats = []
340
		$scope.backends = []
341
		$scope.indices = []
342
		$scope.query = '*=*'
343
		$scope.from = 0
344
		$scope.size = 10
345
		$scope.error = null;
346

  
347

  
348
		if ($routeParams['backend'] != null && $routeParams['backend'].length > 0) {
349
			$scope.selectedbackend_param = $routeParams['backend'];
350
			$scope.selectedIndex_param = $routeParams['index'];
351
			$scope.selectedMdref_param = constructMDREFfromString( $routeParams['mdformat']);
352
			$scope.start_param =  $routeParams['start'];
353
			$scope.query_param =  $routeParams['query'];
354

  
355
			$scope.showSpinner();
356
			$scope.error = null;
357
			$scope.size = 10;
358
			$scope.from = $scope.start_param;
359

  
360
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
361
			var selectedId = null;
362
			if ($scope.selectedIndex != null)
363
				selectedId = $scope.selectedIndex.id
364
			$http.post('index/search.do', $.param({
365

  
366
				'backend': $scope.selectedbackend_param,
367
				'format': $scope.selectedMdref_param.format,
368
				'layout': $scope.selectedMdref_param.layout,
369
				'interpretation': $scope.selectedMdref_param.interpretation,
370
				'query': $scope.query_param,
371
				'from': $scope.start_param,
372
				'number': $scope.size,
373
				'indexidentifier': ""
374
			}))
375
				.success(function (data) {
376
					$scope.hideSpinner();
377
					$scope.searchResult = data
378
					console.log(data)
379
				}).error(function (error) {
380
				$scope.error = error;
381
				$scope.hideSpinner();
382
			});
383
		}
384

  
385

  
386
		$scope.showSpinner();
387

  
388
		$scope.to_trusted = function (html_code) {
389
			return $sce.trustAsHtml(html_code);
390
		}
391

  
392

  
393
		$http.get('index/indexMetadataFormats.do').success(function (data) {
394
			$scope.hideSpinner();
395
			$scope.mdFormats = data;
396
		}).error(function () {
397
			$scope.showError('Error listing xmldb collections');
398
			$scope.hideSpinner();
399
		});
400

  
401
		$http.get('index/backend.do').success(function (data) {
402
			$scope.hideSpinner();
403
			$scope.backends = data;
404
		}).error(function (error) {
405
			$scope.showError(error.message);
406
			$scope.hideSpinner();
407
		});
408

  
409
		$scope.backendSelected = function (index) {
410

  
411
			if ($scope.selectedbackend != null) {
412
				$http.get('index/indexDatastructures.do', {
413
					params: {
414
						backend: $scope.selectedbackend
415
					}
416
				}).success(function (data) {
417
					$scope.hideSpinner();
418
					$scope.indices = data
419

  
420
				}).error(function () {
421
					$scope.showError('Error listing xmldb collections');
422
					$scope.hideSpinner();
423
				});
424
			}
425

  
426

  
427
		}
428

  
429

  
430
		$scope.hideSpinner();
431

  
432
		$scope.startSearch = function () {
433
			$scope.from = 0;
434
			$scope.size = 10
435
			$scope.search()
436
		}
437

  
438

  
439
		$scope.search = function () {
440

  
441
			console.log($scope.selectedMdref);
442
			console.log($scope.selectedbackend);
443

  
444
			if (($scope.selectedMdref == null) || ($scope.selectedbackend == null)) {
445
				alert("You must select a metadata format and a backend identifier")
446
				return;
447
			}
448

  
449
			$scope.showSpinner();
450
			$scope.error = null;
451
			$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
452
			var selectedId = null;
453
			if ($scope.selectedIndex != null)
454
				selectedId = $scope.selectedIndex.id
455
			$http.post('index/search.do', $.param({
456

  
457
				'backend': $scope.selectedbackend,
458
				'format': $scope.selectedMdref.format,
459
				'layout': $scope.selectedMdref.layout,
460
				'interpretation': $scope.selectedMdref.interpretation,
461
				'query': $scope.query,
462
				'from': $scope.from,
463
				'number': $scope.size,
464
				'indexidentifier': selectedId
465
			}))
466
				.success(function (data) {
467
					$scope.hideSpinner();
468
					$scope.searchResult = data
469
					console.log(data)
470
				}).error(function (error) {
471
				$scope.error = error;
472
				$scope.hideSpinner();
473
			});
474
		}
475

  
476
		$scope.nextPage = function () {
477
			if ($scope.searchResult == null)
478
				return;
479
			if ($scope.from > $scope.searchResult.total)
480
				return;
481
			$scope.from += 10;
482
			$scope.size = $scope.from + 10
483
			$scope.search()
484
		}
485

  
486
		$scope.prevPage = function () {
487
			if ($scope.from <= 0) {
488
				return;
489
			}
490

  
491
			$scope.from -= 10;
492
			$scope.size -= 10
493
			$scope.search()
494
		}
495

  
496
		$scope.range = function (n) {
497
			return new Array(n);
498
		};
499

  
500

  
501
	}]);
502

  

Also available in: Unified diff