Skip to content

Commit

Permalink
[2.19.x] DDF-UI-294 G-8763 G-8787 fix Unable to remove results filters (
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewzimmer authored Aug 5, 2020
1 parent e0d9d6d commit 9aa891b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ module.exports = Marionette.LayoutView.extend({
this.filterOperator.currentView.turnOffEditing()
this.filterContents.currentView.turnOffEditing()
},
turnOffNesting: function() {
this.$el.addClass('hide-nesting')
},
turnOffFieldAdditions() {
this.$el.addClass('hide-field-button')
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ module.exports = Marionette.LayoutView.extend({
switch (filter.type) {
// these cases are for when the model matches the filter model
case 'DWITHIN':
if (CQLUtils.isPointRadiusFilter(filter)) {
if (CQLUtils.isPointRadiusFilter(filter.value)) {
wreqr.vent.trigger('search:circledisplay', this.model)
} else if (CQLUtils.isPolygonFilter(filter)) {
} else if (CQLUtils.isPolygonFilter(filter.value)) {
wreqr.vent.trigger('search:polydisplay', this.model)
} else {
wreqr.vent.trigger('search:linedisplay', this.model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const template = require('./result-filter.hbs')
const CustomElements = require('../../js/CustomElements.js')
const user = require('../singletons/user-instance.js')
const FilterBuilderView = require('../filter-builder/filter-builder.view.js')
const cql = require('../../js/cql.js')
import {
getFilterErrors,
showErrorMessages,
} from '../../react-component/utils/validation'

module.exports = Marionette.LayoutView.extend({
template,
Expand All @@ -44,14 +47,14 @@ module.exports = Marionette.LayoutView.extend({
onRender() {
const resultFilter = this.getResultFilter()
let filter
if (resultFilter) {
filter = cql.simplify(cql.read(resultFilter))
} else {
if (!resultFilter) {
filter = {
property: 'anyText',
value: '',
type: 'ILIKE',
}
} else {
filter = resultFilter
}
this.editorProperties.show(
new FilterBuilderView({
Expand All @@ -64,7 +67,7 @@ module.exports = Marionette.LayoutView.extend({
this.handleFilter()
},
getFilter() {
return this.editorProperties.currentView.transformToCql()
return this.editorProperties.currentView.getFilters()
},
removeFilter() {
user
Expand All @@ -78,10 +81,16 @@ module.exports = Marionette.LayoutView.extend({
this.$el.trigger('closeDropdown.' + CustomElements.getNamespace())
},
saveFilter() {
const filter = this.getFilter()
const errorMessages = getFilterErrors(filter.filters)
if (errorMessages.length !== 0) {
showErrorMessages(errorMessages)
return
}
user
.get('user')
.get('preferences')
.set('resultFilter', this.getFilter())
.set('resultFilter', filter)
user
.get('user')
.get('preferences')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const PagingView = require('../paging/paging.view.js')
const DropdownView = require('../dropdown/result-display/dropdown.result-display.view.js')
const ResultFilterDropdownView = require('../dropdown/result-filter/dropdown.result-filter.view.js')
const DropdownModel = require('../dropdown/dropdown.js')
const cql = require('../../js/cql.js')
const ResultSortDropdownView = require('../dropdown/result-sort/dropdown.result-sort.view.js')
const user = require('../singletons/user-instance.js')
const ResultStatusView = require('../result-status/result-status.view.js')
Expand Down Expand Up @@ -60,9 +59,6 @@ const ResultSelector = Marionette.LayoutView.extend({
.get('user')
.get('preferences')
.get('resultFilter')
if (resultFilter) {
resultFilter = cql.simplify(cql.read(resultFilter))
}
resultFilter = mixinBlackListCQL(resultFilter)
const filteredResults = this.model
.get('result')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,12 @@ const View = Marionette.LayoutView.extend({
.get('preferences')
.get('resultFilter')
if (resultFilter) {
this.handleFilter(CQLUtils.transformCQLToFilter(resultFilter), '#c89600')
this.handleFilter(
CQLUtils.transformCQLToFilter(
CQLUtils.transformFilterToCQL(resultFilter)
),
'#c89600'
)
}
},
handleFilter(filter, color) {
Expand All @@ -470,14 +475,15 @@ const View = Marionette.LayoutView.extend({
} else {
let pointText
let locationModel
const value = filter.value
switch (filter.type) {
case 'DWITHIN':
if (CQLUtils.isPolygonFilter(filter.value)) {
this.handleFilterAsPolygon(filter.value, color, filter.distance)
if (CQLUtils.isPolygonFilter(value)) {
this.handleFilterAsPolygon(value, color, filter.distance)
break
}
if (CQLUtils.isPointRadiusFilter(filter.value)) {
pointText = filter.value.value.substring(6)
if (CQLUtils.isPointRadiusFilter(value)) {
pointText = value.value.substring(6)
pointText = pointText.substring(0, pointText.length - 1)
const latLon = pointText.split(' ')
locationModel = new LocationModel({
Expand Down
10 changes: 4 additions & 6 deletions ui/packages/catalog-ui-search/src/main/webapp/js/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function intersects(terraformerObject, value) {
}

function matchesPOLYGON(value, filter) {
const polygonToCheck = TerraformerWKTParser.parse(filter.value.value)
const polygonToCheck = TerraformerWKTParser.parse(filter.value)
if (intersects(polygonToCheck, value)) {
return true
}
Expand All @@ -189,7 +189,7 @@ function matchesPOLYGON(value, filter) {

const matchesBufferedPOLYGON = (value, filter) => {
const bufferedPolygon = createBufferedPolygon(
polygonStringToCoordinates(filter.value.value),
polygonStringToCoordinates(filter.value),
filter.distance
)
const teraformedPolygon = new Terraformer.Polygon({
Expand All @@ -203,9 +203,7 @@ function matchesCIRCLE(value, filter) {
if (filter.distance <= 0) {
return false
}
const points = filter.value.value
.substring(6, filter.value.value.length - 1)
.split(' ')
const points = filter.value.substring(6, filter.value.length - 1).split(' ')
const circleToCheck = new Terraformer.Circle(points, filter.distance, 64)
const polygonCircleToCheck = new Terraformer.Polygon(circleToCheck.geometry)
if (intersects(polygonCircleToCheck, value)) {
Expand All @@ -215,7 +213,7 @@ function matchesCIRCLE(value, filter) {
}

function matchesLINESTRING(value, filter) {
let pointText = filter.value.value.substring(11)
let pointText = filter.value.substring(11)
pointText = pointText.substring(0, pointText.length - 1)
const lineWidth = filter.distance || 0
if (lineWidth <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class LocationInput extends React.Component {
switch (filter.type) {
// these cases are for when the model matches the filter model
case 'DWITHIN':
if (CQLUtils.isPointRadiusFilter(filter)) {
if (CQLUtils.isPointRadiusFilter(filter.value)) {
wreqr.vent.trigger('search:circledisplay', this.locationModel)
} else if (CQLUtils.isPolygonFilter(filter)) {
} else if (CQLUtils.isPolygonFilter(filter.value)) {
wreqr.vent.trigger('search:polydisplay', this.locationModel)
} else {
wreqr.vent.trigger('search:linedisplay', this.locationModel)
Expand Down

0 comments on commit 9aa891b

Please sign in to comment.