-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtoolExportSampleService.js
122 lines (109 loc) · 5.56 KB
/
toolExportSampleService.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(function (angular) {
'use strict';
/**
* @memberof spApp
* @ngdoc service
* @name ToolExportSampleService
* @description
* Client side tool to export points of occurrence layers
*/
angular.module('tool-export-sample-service', [])
.factory("ToolExportSampleService", ["$http", "$q", "MapService", "LayersService", "BiocacheService",
function ($http, $q, MapService, LayersService, BiocacheService) {
var annotateDatasetOnExport = $SH.annotateDatasetOnExport;
var _this = {
species: undefined,
area: undefined,
layers: undefined,
annotation: undefined,
// Override text with view-config.json
spec: {
"input": [
{
"name": "area",
"description": $i18n(420),
"type": "area",
"constraints": {
"min": 1,
"max": 1,
"optional": false,
"defaultAreas": true
}
},
{
"name": "species",
"description": $i18n(416),
"type": "species",
"constraints": {
"min": 1,
"max": 1,
"optional": false,
"spatialValidity": true,
"areaIncludes": false
}
},
{
"name": "layers",
"description": $i18n(414),
"type": "layer",
"constraints": {
"min": 1,
"optional": true
}
}
],
"description": "Punkte exportieren."
},
execute: function (inputs) {
_this.area = inputs[0];
_this.species = inputs[1];
_this.layers = inputs[2];
if (annotateDatasetOnExport) {
_this.annotation = inputs[3];
}
return BiocacheService.newLayer(_this.species, _this.area, '').then(function (query) {
if (query == null) {
return $q.when({output: {}});
}
//include redirect to biocache-service/occurrences/search page
var sampleUrl = _this.species.ws + '/download/options1?searchParams=' +
encodeURIComponent('q=' + query.qid) +
"&targetUri=/occurrences/search%3F&downloadType=records";
if (_this.layers && (_this.layers.length > 0)) {
var layers = '';
var layerNames = '';
$.map(_this.layers,
function (v) {
layers += (layers.length > 0 ? ',' : '') + v;
layerNames += (layerNames.length > 0 ? ',' : '') + LayersService.getLayer(v).name;
});
if (_this.species.species_list) layers += ',' + _this.species.species_list;
sampleUrl += '&layers=' + layers + '&customHeader=' + encodeURIComponent(layerNames) +
"&layersServiceUrl=" + encodeURIComponent($SH.layersServiceUrl);
} else {
sampleUrl += '&layers=' + _this.species.species_list;
}
if (_this.annotation) {
sampleUrl += '&organisation=' + encodeURIComponent(_this.annotation.userOrganisation)
+ '&workflowAnnotation=' + encodeURIComponent(_this.annotation.workflowAnnotation)
+ '&dataSetAnnotation=' + encodeURIComponent(_this.annotation.dataSetAnnotation);
}
return $q.when({output: {0: {openUrl: sampleUrl}}});
});
}
};
// Datasets produced by the CSDM tool are required to be annotated to allow other researchers to
// understand the workflow used to produce the data and decide whether it is relevant to them.
if (annotateDatasetOnExport) {
_this.spec.input.push({
"name":"annotateWorkflow",
"description": "Annotate your workflow",
"type":"annotation",
"constraints":{
"optional":false
}
});
}
return _this;
}])
}(angular));