-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtoolExportChecklistService.js
128 lines (113 loc) · 5.65 KB
/
toolExportChecklistService.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
123
124
125
126
127
128
(function (angular) {
'use strict';
/**
* @memberof spApp
* @ngdoc service
* @name ToolExportChecklistService
* @description
* Client side tool to export list of species in an occurrence layer
*/
angular.module('tool-export-checklist-service', [])
.factory("ToolExportChecklistService", ["$http", "$q", "MapService", "BiocacheService", "LayoutService",
function ($http, $q, MapService, BiocacheService, LayoutService) {
var _this = {
// Override text with view-config.json
spec: {
"input": [
{
"description": $i18n(418),
"type": "area",
"constraints": {
"min": 1,
"max": 1,
"defaultToWorld": true
}
},
{
"description": $i18n(411),
"type": "speciesOptions",
"constraints": {
"areaIncludes": false,
"kosherIncudes": true,
"endemicIncludes": true,
"absentOption": true
}
}],
"description": $i18n(426)
},
downloading: false,
downloadSize: 0,
init: function () {
_this.downloading = false;
_this.downloadSize = 0;
},
execute: function (inputs) {
var area = inputs[0];
var speciesOptions = inputs[1];
var q = [];
var wkt = undefined;
if (area[0].q && (area[0].q.length > 0)) {
q = area[0].q
} else if (area[0].wkt.length > 0) {
q = ['*:*'];
wkt = area[0].wkt;
}
if (speciesOptions.spatiallyUnknown) {
if (speciesOptions.spatiallyValid && speciesOptions.spatiallySuspect) { /* do nothing */
} else if (speciesOptions.spatiallyValid) q.push('-geospatial_kosher:false');
else if (speciesOptions.spatiallySuspect) q.push('-geospatial_kosher:true');
} else {
if (speciesOptions.spatiallyValid && speciesOptions.spatiallySuspect) q.push('geospatial_kosher:*');
else if (speciesOptions.spatiallyValid) q.push('geospatial_kosher:true');
else if (speciesOptions.spatiallySuspect) q.push('geospatial_kosher:false');
}
if (!speciesOptions.includeAbsences) {
q.push($SH.fqExcludeAbsent)
}
var query = BiocacheService.newQuery(q, '', wkt);
var future;
var showPreview = false;
if (showPreview) {
_this.downloading = true;
_this.cancelDownload = $q.defer();
var config = {
eventHandlers: {
progress: function (c) {
_this.downloadSize = c.loaded
}
},
timeout: _this.cancelDownload.promise
};
future = speciesOptions.includeEndemic ? BiocacheService.speciesListEndemic(query, undefined, config) :
BiocacheService.speciesList(query, undefined, config);
future.then(function (data) {
_this.openCsv(data, speciesOptions.includeEndemic);
_this.cancelDownload.resolve();
})
} else {
if (_this.cancelDownload) _this.cancelDownload.resolve();
future = _this.endemic ? BiocacheService.speciesListEndemicUrl(query) :
BiocacheService.speciesListUrl(query);
future.then(function (url) {
Util.download(url, 'speciesList.csv');
})
}
},
openCsv: function (csv, endemic) {
LayoutService.openModal('csv', {
title: (endemic ? $i18n(427, "Endemic") + ' ' : '') + $i18n(428, "Species List"),
csv: csv,
columnOrder: ['Species Name',
'Vernacular Name',
'Number of records',
'Conservation',
'Invasive'],
info: '',
filename: (endemic ? 'endemicS' : 's') + 'peciesList.csv',
display: {size: 'full'}
}, false)
}
};
return _this
}])
}(angular));