Skip to content

Commit 608b29b

Browse files
andrewkfiedlerrzwiefel
authored andcommitted
DDF-2644 Add validation to location model
- Validation is now applied to point radius, line, and bbox drawing. Point radius lat / lon are validated, as well as the radius value itself. Line width is now validated. BBox lat / lon values are validated. - Added try catch to usng code to prevent errors for special cases (outside -80 and 84 degrees). These are still valid outside usng, so we shouldn't be preventing them. They're also valid in usng technically, we just don't offer support yet.
1 parent d283cbe commit 608b29b

File tree

6 files changed

+107
-25
lines changed

6 files changed

+107
-25
lines changed

catalog/ui/catalog-ui-search/src/main/webapp/component/location-old/location-old.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<i class="fa fa-circle-o"></i>
2525
Polygon
2626
</label>
27-
<label id="locationPoint" class="btn location {{#if radius}}active{{/if}}" data-target="#pointradius{{cid}}" data-toggle="tab">
27+
<label id="locationPoint" class="btn location {{#if lat}}active{{/if}}" data-target="#pointradius{{cid}}" data-toggle="tab">
2828
<input type="radio" name="pointRadiusButton">
2929
<i class="fa fa-circle"></i>
3030
<i class="fa fa-circle-o"></i>
@@ -83,7 +83,7 @@
8383
</div>
8484
</div>
8585

86-
<div id="pointradius{{cid}}" class="tab-pane {{#if radius}}active{{/if}}">
86+
<div id="pointradius{{cid}}" class="tab-pane {{#if lat}}active{{/if}}">
8787
<input type="hidden" name="radius" value="{{radius}}">
8888

8989
<div class="col-lg-10">

catalog/ui/catalog-ui-search/src/main/webapp/component/location-old/location-old.js

+78-9
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,58 @@ define([
1515
'backbone',
1616
'wellknown',
1717
'usngs',
18-
'js/store'
19-
], function (_, Backbone, wellknown, usngs, store) {
18+
'js/store',
19+
'js/Common'
20+
], function (_, Backbone, wellknown, usngs, store, Common) {
2021

2122
var converter = new usngs.Converter();
23+
var minimumDifference = 0.0001;
24+
var minimumBuffer = 0.000001;
25+
26+
function convertToValid(key, model){
27+
if (key.mapSouth !== undefined && (key.mapSouth >= key.mapNorth || key.mapSouth >= model.get('mapNorth'))){
28+
key.mapSouth = parseFloat((key.mapNorth || model.get('mapNorth'))) - minimumDifference;
29+
}
30+
if (key.mapEast !== undefined && (key.mapEast <= key.mapWest || key.mapEast <= model.get('mapWest'))){
31+
key.mapEast = parseFloat((key.mapWest || model.get('mapWest'))) + minimumDifference;
32+
}
33+
if (key.mapWest !== undefined && (key.mapWest >= key.mapEast || key.mapWest >= model.get('mapEast'))){
34+
key.mapWest = parseFloat((key.mapEast || model.get('mapEast'))) - minimumDifference;
35+
}
36+
if (key.mapNorth !== undefined && (key.mapNorth <= key.mapSouth || key.mapNorth <= model.get('mapSouth'))){
37+
key.mapNorth = parseFloat((key.mapSouth || model.get('mapSouth'))) + minimumDifference;
38+
}
39+
if (key.mapNorth !== undefined){
40+
key.mapNorth = Math.max(-90 + minimumDifference, key.mapNorth);
41+
key.mapNorth = Math.min(90, key.mapNorth);
42+
}
43+
if (key.mapSouth !== undefined){
44+
key.mapSouth = Math.max(-90, key.mapSouth);
45+
key.mapSouth = Math.min(90 - minimumDifference, key.mapSouth);
46+
}
47+
if (key.mapWest !== undefined){
48+
key.mapWest = Math.max(-180, key.mapWest);
49+
key.mapWest = Math.min(180 - minimumDifference, key.mapWest);
50+
}
51+
if (key.mapEast !== undefined){
52+
key.mapEast = Math.max(-180 + minimumDifference, key.mapEast);
53+
key.mapEast = Math.min(180, key.mapEast);
54+
}
55+
if (key.lat !== undefined){
56+
key.lat = Math.max(-90, key.lat);
57+
key.lat = Math.min(90, key.lat);
58+
}
59+
if (key.lon !== undefined){
60+
key.lon = Math.max(-180, key.lon);
61+
key.lon = Math.min(180, key.lon);
62+
}
63+
if (key.radius !== undefined){
64+
key.radius = Math.max(minimumBuffer, key.radius);
65+
}
66+
if (key.lineWidth !== undefined){
67+
key.lineWidth = Math.max(minimumBuffer, key.lineWidth);
68+
}
69+
}
2270

2371
return Backbone.AssociatedModel.extend({
2472
defaults: {
@@ -32,7 +80,7 @@ define([
3280
mapWest: undefined,
3381
mapSouth: undefined,
3482
radiusUnits: 'meters',
35-
radius: 0,
83+
radius: 1,
3684
locationType: 'latlon',
3785
lat: undefined,
3886
lon: undefined,
@@ -44,6 +92,19 @@ define([
4492
lineWidth: 1,
4593
lineUnits: 'meters'
4694
},
95+
set: function(key, value, options){
96+
if (!_.isObject(key)){
97+
var keyObject = {};
98+
keyObject[key] = value;
99+
key = keyObject;
100+
value = options;
101+
}
102+
convertToValid(key, this);
103+
Backbone.AssociatedModel.prototype.set.call(this, key, value, options);
104+
Common.queueExecution(function(){
105+
this.trigger('change', Object.keys(key));
106+
}.bind(this));
107+
},
47108
initialize: function(){
48109
this.listenTo(this, 'change:north change:south change:east change:west', this.setBBox);
49110
this.listenTo(this, 'change:locationType', this.handleLocationType);
@@ -110,11 +171,15 @@ define([
110171
west = this.get('west'),
111172
east = this.get('east');
112173
if (north && south && east && west) {
113-
var usngsStr = converter.LLBboxtoUSNG(north, south, east, west);
174+
try {
175+
var usngsStr = converter.LLBboxtoUSNG(north, south, east, west);
176+
177+
this.set('usngbb', usngsStr, {silent: this.get('locationType') !== 'usng'});
178+
if (this.get('locationType') === 'usng' && this.drawing) {
179+
this.repositionLatLon();
180+
}
181+
} catch(err){
114182

115-
this.set('usngbb', usngsStr, {silent: this.get('locationType') !== 'usng'});
116-
if (this.get('locationType') === 'usng' && this.drawing) {
117-
this.repositionLatLon();
118183
}
119184
}
120185
},
@@ -123,8 +188,12 @@ define([
123188
var lat = this.get('lat'),
124189
lon = this.get('lon');
125190
if (lat && lon) {
126-
var usngsStr = converter.LLtoUSNG(lat, lon, 5);
127-
this.set('usng', usngsStr, {silent: true});
191+
try {
192+
var usngsStr = converter.LLtoUSNG(lat, lon, 5);
193+
this.set('usng', usngsStr, {silent: true});
194+
} catch(err){
195+
196+
}
128197
}
129198
},
130199

catalog/ui/catalog-ui-search/src/main/webapp/component/location-old/location-old.view.js

+24-11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ define([
2828
], function ($, Backbone, Marionette, _, properties, MetaCard, wreqr, template, maptype,
2929
store, CustomElements, LocationOldModel, CQLUtils) {
3030

31+
var minimumDifference = 0.0001;
32+
var minimumBuffer = 0.000001;
33+
var deltaThreshold = 0.0000001;
34+
3135
return Marionette.ItemView.extend({
3236
template: template,
3337
tagName: CustomElements.register('location-old'),
@@ -40,8 +44,8 @@ define([
4044
'click #usng': 'swapLocationTypeUsng',
4145
'change #radiusUnits': 'onRadiusUnitsChanged',
4246
'change #lineUnits': 'onLineUnitsChanged',
43-
'keydown input[id=radiusValue]': 'filterNonPositiveNumericValues',
44-
'keydown input[id=lineWidthValue]': 'filterNonPositiveNumericValues'
47+
// 'keydown input[id=radiusValue]': 'filterNonPositiveNumericValues',
48+
//'keydown input[id=lineWidthValue]': 'filterNonPositiveNumericValues'
4549
},
4650
initialize: function (options) {
4751
this.propertyModel = this.model;
@@ -53,6 +57,17 @@ define([
5357
},
5458
setupListeners: function () {
5559
this.listenTo(this.propertyModel.get('property'), 'change:isEditing', this.handleEdit);
60+
this.listenTo(this.model, 'change:mapNorth change:mapSouth change:mapEast change:mapWest', this.updateMaxAndMin);
61+
this.listenTo(this.model, 'change', function(attrs){
62+
this.modelBinder.copyModelAttributesToView(attrs);
63+
}.bind(this));
64+
},
65+
updateMaxAndMin: function(){
66+
this.$el.find('#mapWest').attr('max', parseFloat(this.model.get('mapEast')) - minimumDifference);
67+
this.$el.find('#mapEast').attr('min', parseFloat(this.model.get('mapWest')) + minimumDifference);
68+
this.$el.find('#mapNorth').attr('min', parseFloat(this.model.get('mapSouth')) + minimumDifference);
69+
this.$el.find('#mapSouth').attr('max', parseFloat(this.model.get('mapNorth')) - minimumDifference);
70+
this.model.setLatLon();
5671
},
5772
handleEdit: function () {
5873
if (this.propertyModel.get('property').get('isEditing')) {
@@ -144,7 +159,7 @@ define([
144159
south: undefined,
145160
lat: undefined,
146161
lon: undefined,
147-
radius: 0,
162+
radius: 1,
148163
bbox: undefined,
149164
polygon: undefined,
150165
usng: undefined,
@@ -210,10 +225,9 @@ define([
210225
case 'ModelToView':
211226
var distanceFromMeters = view.getDistanceFromMeters(view.model.get('radius'), radiusUnitVal);
212227
var currentValue = this.boundEls[0].value;
213-
var deltaThreshold = 0.0000001;
214228
// same used in cesium.bbox.js
215-
// only update the view's value if it's significantly different from the model's value
216-
return Math.abs(currentValue - distanceFromMeters) > deltaThreshold ? distanceFromMeters : currentValue;
229+
// only update the view's value if it's significantly different from the model's value or is <= minimumBuffer (min for cql)
230+
return (Math.abs((currentValue - distanceFromMeters)) > deltaThreshold) || currentValue <= minimumBuffer ? distanceFromMeters : currentValue;
217231
}
218232
}, lineWidthConverter = function (direction, value) {
219233
var lineUnitVal = view.model.get('lineUnits');
@@ -227,10 +241,9 @@ define([
227241
case 'ModelToView':
228242
var distanceFromMeters = view.getDistanceFromMeters(view.model.get('lineWidth'), lineUnitVal);
229243
var currentValue = this.boundEls[0].value;
230-
var deltaThreshold = 0.0000001;
231244
// same used in cesium.bbox.js
232-
// only update the view's value if it's significantly different from the model's value
233-
return Math.abs(currentValue - distanceFromMeters) > deltaThreshold ? distanceFromMeters : currentValue;
245+
// only update the view's value if it's significantly different from the model's value or is <= minimumBuffer (min for cql)
246+
return (Math.abs((currentValue - distanceFromMeters)) > deltaThreshold) || currentValue <= minimumBuffer ? distanceFromMeters : currentValue;
234247
}
235248
}, polygonConverter = function (direction, value) {
236249
if (value && direction === 'ViewToModel') {
@@ -362,8 +375,8 @@ define([
362375

363376
return _.extend(modelJSON, {
364377
type: type,
365-
lineWidth: Math.max(modelJSON.lineWidth, 0.000001),
366-
radius: Math.max(modelJSON.radius, 0.000001)
378+
lineWidth: Math.max(modelJSON.lineWidth, minimumBuffer),
379+
radius: Math.max(modelJSON.radius, minimumBuffer)
367380
});
368381
},
369382
onDestroy: function () {

catalog/ui/catalog-ui-search/src/main/webapp/component/login-form/login-form.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
--}}
1414
<div class="login-container">
1515
{{#if user.isGuest}}
16-
<form class="login-form">
16+
<form class="login-form" novalidate>
1717
<div align="center" id="loginError" class="alert alert-error" style="display: none;">Credentials are invalid.</div>
1818

1919
<input placeholder="Username" type="text" id="username" name="username" />

catalog/ui/catalog-ui-search/src/main/webapp/component/query-advanced/query-advanced.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
**/
1313
--}}
14-
<form target="autocomplete" action="about:blank">
14+
<form target="autocomplete" action="about:blank" novalidate>
1515
<div class="editor-properties">
1616
<div class="query-advanced-label">
1717
CQL

catalog/ui/catalog-ui-search/src/main/webapp/component/query-basic/query-basic.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
**/
1313
--}}
14-
<form target="autocomplete" action="about:blank">
14+
<form target="autocomplete" action="about:blank" novalidate>
1515
<div class="editor-properties">
1616
<div class="basic-text" data-help="Search by free text using the
1717
grammar of the underlying source.

0 commit comments

Comments
 (0)