diff --git a/api/src/Page/Fault.php b/api/src/Page/Fault.php index 1c7f58004..56d622999 100644 --- a/api/src/Page/Fault.php +++ b/api/src/Page/Fault.php @@ -308,19 +308,14 @@ function _update_fault() # Return a list of beamlines with ids function _get_beamlines() { - $row_tmp = $this->db->pq("SELECT distinct beamlinename as name FROM blsession WHERE beamlinename NOT LIKE 'i04 1' ORDER BY beamlinename"); + $row_tmp = $this->db->pq("SELECT distinct beamlinename as name FROM blsession WHERE beamlinename != '' ORDER BY beamlinename"); $rows = array(); foreach ($row_tmp as $r) { array_push($rows, array('NAME' => $r['NAME'])); } - // $rows = array(array('NAME' => 'i02'), array('NAME' => 'i03'), array('NAME' => 'i04'), array('NAME' => 'i04-1'), array('NAME' => 'i24')); - - $bls = array(); - foreach ($rows as $r) - $bls[$r['NAME']] = $r['NAME']; - $this->_output($this->has_arg('array') ? $bls : $rows); + $this->_output($rows); } # ------------------------------------------------------------------------ @@ -348,19 +343,18 @@ function _get_systems() $rows = $this->db->pq("SELECT s.systemid, s.name, s.description, string_agg(hs.beamlinename) as beamlines FROM bf_system s INNER JOIN bf_system_beamline hs ON s.systemid = hs.systemid " . $where . " GROUP BY s.systemid, s.name, s.description ORDER BY s.name", $args); - $sys = array(); - foreach ($rows as $s) - $sys[$s['SYSTEMID']] = $s['NAME']; - - $this->_output($this->has_arg('array') ? $sys : $rows); + $this->_output($rows); } # ------------------------------------------------------------------------ # Return a list of components for a system on a beamline function _get_components() { - if (!$this->has_arg('sid')) - $this->_error('No systemid specified'); + if (!$this->has_arg('sid')) { + $this->_output(array()); + return; + } + $args = array($this->arg('sid')); if ($this->has_arg('bl')) @@ -381,19 +375,18 @@ function _get_components() $rows = $this->db->pq('SELECT c.componentid, c.name, c.description, string_agg(hc.beamlinename) as beamlines FROM bf_component c INNER JOIN bf_component_beamline hc ON c.componentid = hc.componentid WHERE c.systemid=:1' . $where . ' GROUP BY c.componentid, c.name, c.description ORDER BY beamlines,c.name', $args); - $com = array(); - foreach ($rows as $c) - $com[$c['COMPONENTID']] = $c['NAME']; - - $this->_output($this->has_arg('array') ? $com : $rows); + $this->_output($rows); } # ------------------------------------------------------------------------ # Return a list of subcomponents for a component on a beamline function _get_subcomponents() { - if (!$this->has_arg('cid')) - $this->_error('No componentid specified'); + if (!$this->has_arg('cid')) { + $this->_output(array()); + return; + } + $args = array($this->arg('cid')); if ($this->has_arg('bl')) @@ -414,11 +407,7 @@ function _get_subcomponents() $rows = $this->db->pq('SELECT s.subcomponentid, s.name, s.description, string_agg(hs.beamlinename) as beamlines FROM bf_subcomponent s INNER JOIN bf_subcomponent_beamline hs ON s.subcomponentid = hs.subcomponentid WHERE s.componentid=:1' . $where . ' GROUP BY s.subcomponentid, s.name, s.description ORDER BY s.name', $args); - $scom = array(); - foreach ($rows as $s) - $scom[$s['SUBCOMPONENTID']] = $s['NAME']; - - $this->_output($this->has_arg('array') ? $scom : $rows); + $this->_output($rows); } diff --git a/client/src/js/modules/fault/routes.js b/client/src/js/modules/fault/routes.js index ea591ca08..5b0eb5912 100644 --- a/client/src/js/modules/fault/routes.js +++ b/client/src/js/modules/fault/routes.js @@ -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], }) diff --git a/client/src/js/modules/fault/views/filters.js b/client/src/js/modules/fault/views/filters.js index d58ef4d41..74d683c65 100644 --- a/client/src/js/modules/fault/views/filters.js +++ b/client/src/js/modules/fault/views/filters.js @@ -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()) url += '/'+f+'/'+this.ui[v].val() }, this) + url += searchFrag window.history.pushState({}, '', url) }, @@ -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() @@ -61,13 +71,13 @@ define(['marionette', return self.ui.bl.val() } this.collection.queryParams.sid = function() { - if (self.ui.system.val() > 0) return self.ui.system.val() + return self.ui.system.val() } this.collection.queryParams.cid = function() { - if (self.ui.component.val() > 0) return self.ui.component.val() + return self.ui.component.val() } this.collection.queryParams.scid = function() { - if (self.ui.subcomponent.val() > 0) return self.ui.subcomponent.val() + return self.ui.subcomponent.val() } this.firstLoad = true @@ -85,12 +95,8 @@ define(['marionette', var self = this this.beamlines = new Beamlines() - this.beamlines.fetch().done(function() { - self.ui.bl.html(''+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() { @@ -123,35 +129,51 @@ define(['marionette', }) }, + updateBeamlines: function(e) { + this.beamlines.fetch().done(this.doUpdateBeamlines.bind(this,e)) + }, + doUpdateBeamlines: function(e) { + this.ui.bl.html(''+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(''+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() + this.ui.system.html(''+this.systems.opts()).val(val) + 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(''+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() + this.ui.component.html(''+this.components.opts()).val(val) + 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)) }, doUpdateSubComponents: function(e) { var val = this.ui.subcomponent.val() - this.ui.subcomponent.html(''+this.subcomponents.opts()).val(val) + this.ui.subcomponent.html(''+this.subcomponents.opts()).val(val) if (this.getOption('params') && this.firstLoad) this.ui.subcomponent.val(this.getOption('params').subcomponent) if (e || this.firstLoad) this.collection.fetch() if (this.firstLoad) this.firstLoad = false @@ -159,4 +181,4 @@ define(['marionette', }) -}) \ No newline at end of file +}) diff --git a/client/src/js/modules/fault/views/list.js b/client/src/js/modules/fault/views/list.js index a5125c878..313d5619a 100644 --- a/client/src/js/modules/fault/views/list.js +++ b/client/src/js/modules/fault/views/list.js @@ -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') }) }, @@ -48,4 +48,4 @@ define(['marionette', 'modules/fault/views/filters', 'views/table', 'utils/table }, }) -}) \ No newline at end of file +})