-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtoolAddSpeciesService.js
113 lines (104 loc) · 4.88 KB
/
toolAddSpeciesService.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
(function (angular) {
'use strict';
/**
* @memberof spApp
* @ngdoc service
* @name ToolAddSpeciesService
* @description
* Client side tool to add occurrence layers to the map
*/
angular.module('tool-add-species-service', [])
.factory("ToolAddSpeciesService", ["$http", "$q", "MapService", "BiocacheService",
function ($http, $q, MapService, BiocacheService) {
return {
// Override text with view-config.json
// Im Moment nur deutsche Internationalisierung
spec: {
"input": [
{
"name": "species",
"description": $i18n(416),
"type": "species",
"constraints": {
"min": 1,
"max": 1,
"optional": false,
"spatialValidity": true,
"areaIncludes": false,
"speciesOption": "searchSpecies"
}
},
{
"name": "speciesOptions",
"description": $i18n(417),
"type": "speciesOptions",
"constraints": {
"optional": true,
"spatialValidity": false,
"areaIncludes": true,
"disable": false
}
},
{
"name": "area",
"description": $i18n(418),
"type": "area",
"constraints": {
"min": 1,
"max": 1,
"defaultToWorld": true
}
}],
"description": $i18n(419)
},
refresh: function (inputs, specs) {
if (specs) {
for (k in specs.injectDateRangeInput) {
if (specs.input[k].name === "speciesOptions") {
specs.input[k].constraints.disable = !this.checkAreaCompatible(inputs[0].q);
}
}
}
},
checkAreaCompatible: function (q) {
var enableArea = false;
if (q !== undefined) {
enableArea = (q.length === 0);
for (var i = 0; i < q.length; i++) {
if (q[i].indexOf("lsid:") === 0) {
enableArea = true;
break;
}
}
}
return enableArea
},
execute: function (inputs) {
var newName = inputs[0].name;
//append area to the species layer name
if (inputs[2][0].name !== undefined)
newName += ' (' + inputs[2][0].name + ')';
newName = MapService.nextLayerName(newName);
//Check if areas is compatible
inputs[1].enabled = this.checkAreaCompatible(inputs[0].q);
return BiocacheService.newLayer(inputs[0], inputs[2], newName).then(function (data) {
if (data == null) {
return $q.when(false)
}
if (inputs[1].enabled) {
data.includeAnimalMovement = inputs[1].includeAnimalMovement;
data.includeChecklists = inputs[1].includeChecklists;
data.includeExpertDistributions = inputs[1].includeExpertDistributions;
}
if (inputs[0].species_list) {
data.species_list = inputs[0].species_list;
}
data.log = false
return MapService.add(data).then(function () {
return true;
})
});
}
};
}])
}(angular));