-
-
Notifications
You must be signed in to change notification settings - Fork 476
/
WpsDirective.js
98 lines (89 loc) · 2.78 KB
/
WpsDirective.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(function() {
goog.provide('gn_wps_directive');
var module = angular.module('gn_wps_directive', [
]);
module.directive('gnWpsProcessForm', [
'gnWpsService',
function(gnWpsService) {
var inputTypeMapping = {
string: 'text',
float: 'number'
};
var defaultValue = function(literalData) {
var value = undefined;
if (literalData.defaultValue != undefined) {
value = literalData.defaultValue;
}
if (literalData.dataType.value == 'float') {
value = parseFloat(value);
}
if (literalData.dataType.value == 'string') {
value = value || '';
}
return value;
};
return {
restrict: 'AE',
scope: {
uri: '=',
processId: '=',
},
templateUrl: function(elem, attrs) {
return attrs.template ||
'../../catalog/components/viewer/wps/partials/processform.html';
},
link: function(scope, element, attrs) {
scope.status = 'loading';
gnWpsService.describeProcess(scope.uri, scope.processId)
.then(
function(data) {
scope.processDescription = data.processDescription[0];
scope.title = scope.processDescription.title.value
scope.inputs = [];
angular.forEach(scope.processDescription.dataInputs.input,
function(input) {
scope.inputs.push({
name: input.identifier.value,
title: input.title.value,
type: inputTypeMapping[input.literalData.dataType.value],
value: defaultValue(input.literalData),
required: input.minOccurs == 1 ? true : false
})
}
);
scope.status = 'loaded';
},
function(data) {
scope.exception = data;
scope.status = 'error';
}
);
scope.close = function() {
element.remove();
};
scope.submit = function() {
var inputs = scope.inputs.reduce(function(o, v, i) {
o[v.name] = v.value.toString();
return o;
}, {});
gnWpsService.execute(
scope.uri,
scope.processId,
inputs,
scope.processDescription.processOutputs.output[0].identifier.value,
false
).then(
function(data) {
window.open(data);
},
function(data) {
scope.exception = data;
scope.status = 'error';
}
);
};
}
};
}
]);
})();