Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions client/src/js/modules/fault/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ var bc = { title: 'Fault Database', url: '/fault' }
const routes = [
{
// sys, com and sub should all be ids of sub systems and components for the beamline
path: '/faults(/bl/)?:bl([a-zA-Z0-9_-]+)?(/sys/)?:sys([0-9]+)?(/com/)?:com([0-9]+)?(/sub/)?:sub([0-9]+)?(/page/)?:page([0-9]+)?',
path: '/faults(/bl/)?:bl([a-zA-Z0-9_-]+)?(/sys/)?:sys([0-9]+)?(/com/)?:com([0-9]+)?(/sub/)?:sub([0-9]+)?(/s/)?:s([a-zA-Z0-9_%-]+)?(/page/)?:page([0-9]+)?',
name: 'faults-view',
component: MarionetteView,
props: route => ({
mview: FaultListView,
options: {
collection: new Faults(null, { state: { currentPage: route.params.page ? parseInt(route.params.page) : 1} })
},
params: {
beamline: route.params.bl || '',
system: route.params.sys || '',
component: route.params.com || '',
subcomponent: route.params.sub || ''
collection: new Faults(null, { state: { currentPage: route.params.page ? parseInt(route.params.page) : 1} }),
params: {
beamline: route.params.bl || '',
system: route.params.sys || '',
component: route.params.com || '',
subcomponent: route.params.sub || '',
s: route.params.s,
},
},
breadcrumbs: [bc],
})
Expand Down
56 changes: 39 additions & 17 deletions client/src/js/modules/fault/views/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,28 @@ define(['marionette',
},

updateUrlFragment: function() {
var frags = {
const frags = {
bl: 'bl',
sys: 'system',
com: 'component',
sub: 'subcomponent',
}

var url = window.location.pathname
let url = window.location.pathname

let searchFrag = ''
const searchMatch = url.match(/\/s\/.*$/)
if (searchMatch) {
searchFrag = searchMatch[0]
url = url.replace(searchFrag, '')
}

_.each(frags, function(v, f) {
url = url.replace(new RegExp('\\/'+f+'\\/\\w+'), '')
if (this.ui[v].val() != 0) url += '/'+f+'/'+this.ui[v].val()
if (this.ui[v].val() && this.ui[v].val() != 0) url += '/'+f+'/'+this.ui[v].val()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.ui[v].val() && this.ui[v].val() != 0) url += '/'+f+'/'+this.ui[v].val()
if (!!this.ui[v].val()) url += '/'+f+'/'+this.ui[v].val()
Suggested change
if (this.ui[v].val() && this.ui[v].val() != 0) url += '/'+f+'/'+this.ui[v].val()
if (this.ui[v].val()) url += '/'+f+'/'+this.ui[v].val()

Is there any reason why we need the "!= 0"? As 0 is already falsy in JS

As an added measure of precaution, we can even cast the val to a bool with !! before evaluating (that means null, undefined, 0, false will all evaluate to false)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out it was "0" not 0, so it was truthy. So I've removed the value="0" from the dropdowns, and changed the PHP to handle that. Also removed some weirdness with a misnamed beamline "i04 1" and an arg called "array" which I can't find anywhere.

}, this)

url += searchFrag
window.history.pushState({}, '', url)
},

Expand All @@ -50,6 +59,7 @@ define(['marionette',
this.ui.system.val('')
this.ui.component.val('')
this.ui.subcomponent.val('')
this.updateUrlFragment()

this.collection.fetch()
this.updateSystems()
Expand Down Expand Up @@ -85,12 +95,8 @@ define(['marionette',
var self = this

this.beamlines = new Beamlines()
this.beamlines.fetch().done(function() {
self.ui.bl.html('<option value="">-</option><option value="P01">Phase I</option>'+self.beamlines.opts())
if (self.getOption('params')) self.ui.bl.val(self.getOption('params').beamline)
self.updateSystems()
})

this.updateBeamlines()

this.systems = new Systems(null, {
queryParams: {
bl: function() {
Expand Down Expand Up @@ -123,29 +129,45 @@ define(['marionette',
})
},

updateBeamlines: function(e) {
this.beamlines.fetch().done(this.doUpdateBeamlines.bind(this,e))
},
doUpdateBeamlines: function(e) {
this.ui.bl.html('<option value="">-</option><option value="P01">Phase I</option>'+this.beamlines.opts())
if (this.getOption('params') && this.getOption('params').beamline) {
this.ui.bl.val(this.getOption('params').beamline)
this.updateSystems()
}
},

updateSystems: function(e) {
this.systems.fetch().done(this.doUpdateSystems.bind(this,e))
},
doUpdateSystems: function(e) {
var val = this.ui.system.val()
this.ui.system.html('<option value="0">-</option>'+this.systems.opts()).val(val)
if (this.getOption('params') && this.firstLoad) this.ui.system.val(this.getOption('params').system)
if (e) this.collection.fetch()
this.updateComponents()
if (this.getOption('params') && this.getOption('params').system && this.firstLoad) {
this.ui.system.val(this.getOption('params').system)
this.updateComponents()
} else {
this.collection.fetch()
}
},


updateComponents: function(e) {
this.components.fetch().done(this.doUpdateComponents.bind(this,e))
},
doUpdateComponents: function(e) {
var val = this.ui.component.val()
this.ui.component.html('<option value="0">-</option>'+this.components.opts()).val(val)
if (this.getOption('params') && this.firstLoad) this.ui.component.val(this.getOption('params').component)
this.updateSubComponents()
if (e) this.collection.fetch()
if (this.getOption('params') && this.getOption('params').component && this.firstLoad) {
this.ui.component.val(this.getOption('params').component)
this.updateSubComponents()
} else {
this.collection.fetch()
}
},

updateSubComponents: function(e) {
this.subcomponents.fetch().done(this.doUpdateSubComponents.bind(this,e))
},
Expand All @@ -159,4 +181,4 @@ define(['marionette',

})

})
})
4 changes: 2 additions & 2 deletions client/src/js/modules/fault/views/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define(['marionette', 'modules/fault/views/filters', 'views/table', 'utils/table
})
}

this.table = new TableView({ collection: options.collection, columns: columns, tableClass: 'proposals', filter: this.getOption('search') ? 's' : false, loading: true, backgrid: { row: ClickableRow, emptyText: 'No faults found' } })
this.table = new TableView({ collection: options.collection, columns: columns, tableClass: 'proposals', filter: 's', search: options.params.s, loading: true, backgrid: { row: ClickableRow, emptyText: 'No faults found' } })

if (this.getOption('filters')) this.filters = new FilterView({ collection: options.collection, params: this.getOption('params') })
},
Expand All @@ -48,4 +48,4 @@ define(['marionette', 'modules/fault/views/filters', 'views/table', 'utils/table
},
})

})
})
Loading