Skip to content

Commit d5fb63c

Browse files
author
Adam Collins
committed
#483 use addPoints in selectSpecies
1 parent b785576 commit d5fb63c

File tree

5 files changed

+80
-20
lines changed

5 files changed

+80
-20
lines changed

grails-app/assets/javascripts/spApp/controller/addPointsCtrl.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
$scope.inputData = inputData;
1616

17+
$scope.enablePriorUploads = inputData.enablePriorUploads !== undefined ? inputData.enablePriorUploads : true
18+
1719
$scope.step = 'default';
18-
$scope.method = 'existing';
20+
$scope.method = $scope.enablePriorUploads ? 'existing' : 'upload';
1921

2022
$scope.errorMsg = '';
2123

@@ -195,7 +197,16 @@
195197
if ($scope.errorMsg || $scope.status === 'error') {
196198
$scope.$close();
197199
} else if ($scope.status === 'finished') {
198-
$scope.addToMapAndClose();
200+
if ($scope.inputData.setQ !== undefined) {
201+
$scope.inputData.setQ({
202+
q: ['data_resource_uid:"' + $scope.dataResourceUid + '"'],
203+
name: $scope.datasetName,
204+
bs: $SH.sandboxSpatialServiceUrl,
205+
ws: $SH.sandboxSpatialUiUrl
206+
});
207+
} else {
208+
$scope.addToMapAndClose();
209+
}
199210
} else {
200211
$scope.step = 'uploading';
201212
$scope.uploadingFile = true;

grails-app/assets/javascripts/spApp/directive/sandboxList.js

+52-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* Table of selectable sandbox uploaded layers
99
*/
1010
angular.module('sandbox-list-directive', ['lists-service', 'map-service'])
11-
.directive('sandboxList', ['$http', '$timeout', 'SandboxService', 'MapService',
12-
function ($http, $timeout, SandboxService, MapService) {
11+
.directive('sandboxList', ['$http', '$timeout', 'SandboxService', 'MapService', 'BiocacheService',
12+
function ($http, $timeout, SandboxService, MapService, BiocacheService) {
1313

1414
var sortType = 'updated';
1515
var sortReverse = false;
@@ -61,9 +61,55 @@
6161
MapService.add(scope.selection);
6262
};
6363

64-
SandboxService.list($SH.userId).then(function (data) {
65-
scope.setItems(data);
66-
});
64+
// add spatial-service sandbox uploads
65+
if ($SH.sandboxSpatialServiceUrl && $SH.sandboxSpatialServiceUrl !== '') {
66+
BiocacheService.userUploads($SH.userId, $SH.sandboxSpatialServiceUrl).then(function (data) {
67+
if (data.totalRecords === 0) {
68+
return;
69+
}
70+
71+
// add bs and ws to each item
72+
var items = data.facetResults[0].fieldResult;
73+
items.forEach(function (item) {
74+
item.bs = $SH.sandboxSpatialServiceUrl;
75+
item.ws = $SH.sandboxSpatialUiUrl;
76+
// get dataset_name and last_load_date
77+
BiocacheService.searchForOccurrences({
78+
qid: item.fq, // skip qid registration for this one-off query
79+
bs: item.bs,
80+
ws: item.ws
81+
}, [], 0, 0, 'datasetName,lastProcessedDate').then(function (data) {
82+
if (data.totalRecords > 0) {
83+
// handle facets returning in a different order
84+
var order = data.facetResults[0].fieldName === 'datasetName' ? 0 : 1;
85+
item.label = data.facetResults[order === 0 ? 0 : 1].fieldResult[0].label;
86+
item.date = data.facetResults[order === 0 ? 1 : 0].fieldResult[0].label;
87+
88+
// format the date so that it is sortable. It is currently a string, e.g. "2010-11-01T00:00:00Z"
89+
item.date = new Date(item.date).toISOString().slice(0, 10);
90+
91+
var a = item.fq.substring(item.fq.indexOf(":") + 1);
92+
scope.sandboxItems.push({
93+
ws: item.ws,
94+
bs: item.bs,
95+
uid: item.fq.substring(item.fq.indexOf(":") + 1),
96+
name: item.label,
97+
lastUpdated: item.date,
98+
numberOfRecords: item.count,
99+
selected: false
100+
})
101+
}
102+
});
103+
});
104+
});
105+
}
106+
107+
// add items from the deprecated sandbox
108+
if ($SH.sandboxServiceUrl && $SH.sandboxUrl) {
109+
SandboxService.list($SH.userId).then(function (data) {
110+
scope.setItems(data);
111+
});
112+
}
67113

68114
scope.$watch('sandboxItems', function () {
69115
}, true);
@@ -116,4 +162,4 @@
116162

117163

118164
}])
119-
}(angular));
165+
}(angular));

grails-app/assets/javascripts/spApp/directive/selectSpecies.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,18 @@
120120

121121
scope.openSandbox = function () {
122122
$timeout(function () {
123-
LayoutService.openModal('sandBox', {
124-
setQ: scope.setSandboxQ,
125-
display: {size: 'full'}
126-
}, true, true)
123+
// open new spatial-service sandbox UI when enabled
124+
if ($SH.sandboxSpatialServiceUrl) {
125+
LayoutService.openModal('addPoints', {
126+
setQ: scope.setSandboxQ,
127+
enablePriorUploads: false // disabled because it is available without opening addPoints UI
128+
}, true, true)
129+
} else {
130+
LayoutService.openModal('sandBox', {
131+
setQ: scope.setSandboxQ,
132+
display: {size: 'full'}
133+
}, true, true)
134+
}
127135
}, 0)
128136
};
129137

grails-app/assets/javascripts/spApp/service/sandboxService.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function (angular) {
22
'use strict';
33
/**
4+
* @deprecated
45
* @memberof spApp
56
* @ngdoc service
67
* @name SandboxService
@@ -26,12 +27,6 @@
2627
* @memberof SandboxService
2728
* @param {string} userId
2829
* @returns {List} list of sandbox uploads
29-
*
30-
* TODO: collections is unaware of sandbox instances so some validation should occur
31-
*
32-
* @example:
33-
* Output:
34-
* [TODO: example]
3530
*/
3631
list: function (userId) {
3732
var urlProxy = $SH.baseUrl + "/collection/list?alaId=" + userId
@@ -41,4 +36,4 @@
4136
}
4237
};
4338
}])
44-
}(angular));
39+
}(angular));

grails-app/assets/javascripts/spApp/templates/addPointsContent.tpl.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h3 i18n="558" class="panel-title">Select method</h3>
1818
<div class="checkbox"><label><input type="radio" ng-model="method"
1919
value="upload" name="addPoints_method"
2020
ng-change="method='upload'">Upload CSV</label></div>
21-
<div class="checkbox"><label><input type="radio" ng-model="method"
21+
<div class="checkbox" ng-show="enablePriorUploads"><label><input type="radio" ng-model="method"
2222
value="existing" name="addPoints_method"
2323
ng-change="method='existing'; file=null">Previous upload</label></div>
2424
</div>

0 commit comments

Comments
 (0)