Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 15 additions & 26 deletions api/src/Page/Fault.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

# ------------------------------------------------------------------------
Expand Down Expand Up @@ -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'))
Expand All @@ -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'))
Expand All @@ -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);
}


Expand Down
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
68 changes: 45 additions & 23 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()) url += '/'+f+'/'+this.ui[v].val()
}, 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 All @@ -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
Expand All @@ -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,40 +129,56 @@ 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()
this.ui.system.html('<option value="">-</option>'+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('<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()
this.ui.component.html('<option value="">-</option>'+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('<option value="0">-</option>'+this.subcomponents.opts()).val(val)
this.ui.subcomponent.html('<option value="">-</option>'+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
},

})

})
})
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