Skip to content

Commit 75796d2

Browse files
ndg63276Mark Williams
andauthored
LIMS-1876: Fix URL parameters on fault report list (#979)
* LIMS-1876: Fix URL parameters on fault report list * LIMS-1876: Remove funky ids of zero --------- Co-authored-by: Mark Williams <[email protected]>
1 parent de1e91c commit 75796d2

File tree

4 files changed

+71
-59
lines changed

4 files changed

+71
-59
lines changed

api/src/Page/Fault.php

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -308,19 +308,14 @@ function _update_fault()
308308
# Return a list of beamlines with ids
309309
function _get_beamlines()
310310
{
311-
$row_tmp = $this->db->pq("SELECT distinct beamlinename as name FROM blsession WHERE beamlinename NOT LIKE 'i04 1' ORDER BY beamlinename");
311+
$row_tmp = $this->db->pq("SELECT distinct beamlinename as name FROM blsession WHERE beamlinename != '' ORDER BY beamlinename");
312312
$rows = array();
313313
foreach ($row_tmp as $r)
314314
{
315315
array_push($rows, array('NAME' => $r['NAME']));
316316
}
317317

318-
// $rows = array(array('NAME' => 'i02'), array('NAME' => 'i03'), array('NAME' => 'i04'), array('NAME' => 'i04-1'), array('NAME' => 'i24'));
319-
320-
$bls = array();
321-
foreach ($rows as $r)
322-
$bls[$r['NAME']] = $r['NAME'];
323-
$this->_output($this->has_arg('array') ? $bls : $rows);
318+
$this->_output($rows);
324319
}
325320

326321
# ------------------------------------------------------------------------
@@ -348,19 +343,18 @@ function _get_systems()
348343

349344
$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);
350345

351-
$sys = array();
352-
foreach ($rows as $s)
353-
$sys[$s['SYSTEMID']] = $s['NAME'];
354-
355-
$this->_output($this->has_arg('array') ? $sys : $rows);
346+
$this->_output($rows);
356347
}
357348

358349
# ------------------------------------------------------------------------
359350
# Return a list of components for a system on a beamline
360351
function _get_components()
361352
{
362-
if (!$this->has_arg('sid'))
363-
$this->_error('No systemid specified');
353+
if (!$this->has_arg('sid')) {
354+
$this->_output(array());
355+
return;
356+
}
357+
364358
$args = array($this->arg('sid'));
365359

366360
if ($this->has_arg('bl'))
@@ -381,19 +375,18 @@ function _get_components()
381375

382376
$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);
383377

384-
$com = array();
385-
foreach ($rows as $c)
386-
$com[$c['COMPONENTID']] = $c['NAME'];
387-
388-
$this->_output($this->has_arg('array') ? $com : $rows);
378+
$this->_output($rows);
389379
}
390380

391381
# ------------------------------------------------------------------------
392382
# Return a list of subcomponents for a component on a beamline
393383
function _get_subcomponents()
394384
{
395-
if (!$this->has_arg('cid'))
396-
$this->_error('No componentid specified');
385+
if (!$this->has_arg('cid')) {
386+
$this->_output(array());
387+
return;
388+
}
389+
397390
$args = array($this->arg('cid'));
398391

399392
if ($this->has_arg('bl'))
@@ -414,11 +407,7 @@ function _get_subcomponents()
414407

415408
$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);
416409

417-
$scom = array();
418-
foreach ($rows as $s)
419-
$scom[$s['SUBCOMPONENTID']] = $s['NAME'];
420-
421-
$this->_output($this->has_arg('array') ? $scom : $rows);
410+
$this->_output($rows);
422411
}
423412

424413

client/src/js/modules/fault/routes.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ var bc = { title: 'Fault Database', url: '/fault' }
3030
const routes = [
3131
{
3232
// sys, com and sub should all be ids of sub systems and components for the beamline
33-
path: '/faults(/bl/)?:bl([a-zA-Z0-9_-]+)?(/sys/)?:sys([0-9]+)?(/com/)?:com([0-9]+)?(/sub/)?:sub([0-9]+)?(/page/)?:page([0-9]+)?',
33+
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]+)?',
3434
name: 'faults-view',
3535
component: MarionetteView,
3636
props: route => ({
3737
mview: FaultListView,
3838
options: {
39-
collection: new Faults(null, { state: { currentPage: route.params.page ? parseInt(route.params.page) : 1} })
40-
},
41-
params: {
42-
beamline: route.params.bl || '',
43-
system: route.params.sys || '',
44-
component: route.params.com || '',
45-
subcomponent: route.params.sub || ''
39+
collection: new Faults(null, { state: { currentPage: route.params.page ? parseInt(route.params.page) : 1} }),
40+
params: {
41+
beamline: route.params.bl || '',
42+
system: route.params.sys || '',
43+
component: route.params.com || '',
44+
subcomponent: route.params.sub || '',
45+
s: route.params.s,
46+
},
4647
},
4748
breadcrumbs: [bc],
4849
})

client/src/js/modules/fault/views/filters.js

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,28 @@ define(['marionette',
2727
},
2828

2929
updateUrlFragment: function() {
30-
var frags = {
30+
const frags = {
3131
bl: 'bl',
3232
sys: 'system',
3333
com: 'component',
3434
sub: 'subcomponent',
3535
}
3636

37-
var url = window.location.pathname
37+
let url = window.location.pathname
38+
39+
let searchFrag = ''
40+
const searchMatch = url.match(/\/s\/.*$/)
41+
if (searchMatch) {
42+
searchFrag = searchMatch[0]
43+
url = url.replace(searchFrag, '')
44+
}
45+
3846
_.each(frags, function(v, f) {
3947
url = url.replace(new RegExp('\\/'+f+'\\/\\w+'), '')
40-
if (this.ui[v].val() != 0) url += '/'+f+'/'+this.ui[v].val()
48+
if (this.ui[v].val()) url += '/'+f+'/'+this.ui[v].val()
4149
}, this)
4250

51+
url += searchFrag
4352
window.history.pushState({}, '', url)
4453
},
4554

@@ -50,6 +59,7 @@ define(['marionette',
5059
this.ui.system.val('')
5160
this.ui.component.val('')
5261
this.ui.subcomponent.val('')
62+
this.updateUrlFragment()
5363

5464
this.collection.fetch()
5565
this.updateSystems()
@@ -61,13 +71,13 @@ define(['marionette',
6171
return self.ui.bl.val()
6272
}
6373
this.collection.queryParams.sid = function() {
64-
if (self.ui.system.val() > 0) return self.ui.system.val()
74+
return self.ui.system.val()
6575
}
6676
this.collection.queryParams.cid = function() {
67-
if (self.ui.component.val() > 0) return self.ui.component.val()
77+
return self.ui.component.val()
6878
}
6979
this.collection.queryParams.scid = function() {
70-
if (self.ui.subcomponent.val() > 0) return self.ui.subcomponent.val()
80+
return self.ui.subcomponent.val()
7181
}
7282

7383
this.firstLoad = true
@@ -85,12 +95,8 @@ define(['marionette',
8595
var self = this
8696

8797
this.beamlines = new Beamlines()
88-
this.beamlines.fetch().done(function() {
89-
self.ui.bl.html('<option value="">-</option><option value="P01">Phase I</option>'+self.beamlines.opts())
90-
if (self.getOption('params')) self.ui.bl.val(self.getOption('params').beamline)
91-
self.updateSystems()
92-
})
93-
98+
this.updateBeamlines()
99+
94100
this.systems = new Systems(null, {
95101
queryParams: {
96102
bl: function() {
@@ -123,40 +129,56 @@ define(['marionette',
123129
})
124130
},
125131

132+
updateBeamlines: function(e) {
133+
this.beamlines.fetch().done(this.doUpdateBeamlines.bind(this,e))
134+
},
135+
doUpdateBeamlines: function(e) {
136+
this.ui.bl.html('<option value="">-</option><option value="P01">Phase I</option>'+this.beamlines.opts())
137+
if (this.getOption('params') && this.getOption('params').beamline) {
138+
this.ui.bl.val(this.getOption('params').beamline)
139+
this.updateSystems()
140+
}
141+
},
126142

127143
updateSystems: function(e) {
128144
this.systems.fetch().done(this.doUpdateSystems.bind(this,e))
129145
},
130146
doUpdateSystems: function(e) {
131147
var val = this.ui.system.val()
132-
this.ui.system.html('<option value="0">-</option>'+this.systems.opts()).val(val)
133-
if (this.getOption('params') && this.firstLoad) this.ui.system.val(this.getOption('params').system)
134-
if (e) this.collection.fetch()
135-
this.updateComponents()
148+
this.ui.system.html('<option value="">-</option>'+this.systems.opts()).val(val)
149+
if (this.getOption('params') && this.getOption('params').system && this.firstLoad) {
150+
this.ui.system.val(this.getOption('params').system)
151+
this.updateComponents()
152+
} else {
153+
this.collection.fetch()
154+
}
136155
},
137-
138156

139157
updateComponents: function(e) {
140158
this.components.fetch().done(this.doUpdateComponents.bind(this,e))
141159
},
142160
doUpdateComponents: function(e) {
143161
var val = this.ui.component.val()
144-
this.ui.component.html('<option value="0">-</option>'+this.components.opts()).val(val)
145-
if (this.getOption('params') && this.firstLoad) this.ui.component.val(this.getOption('params').component)
146-
this.updateSubComponents()
147-
if (e) this.collection.fetch()
162+
this.ui.component.html('<option value="">-</option>'+this.components.opts()).val(val)
163+
if (this.getOption('params') && this.getOption('params').component && this.firstLoad) {
164+
this.ui.component.val(this.getOption('params').component)
165+
this.updateSubComponents()
166+
} else {
167+
this.collection.fetch()
168+
}
148169
},
170+
149171
updateSubComponents: function(e) {
150172
this.subcomponents.fetch().done(this.doUpdateSubComponents.bind(this,e))
151173
},
152174
doUpdateSubComponents: function(e) {
153175
var val = this.ui.subcomponent.val()
154-
this.ui.subcomponent.html('<option value="0">-</option>'+this.subcomponents.opts()).val(val)
176+
this.ui.subcomponent.html('<option value="">-</option>'+this.subcomponents.opts()).val(val)
155177
if (this.getOption('params') && this.firstLoad) this.ui.subcomponent.val(this.getOption('params').subcomponent)
156178
if (e || this.firstLoad) this.collection.fetch()
157179
if (this.firstLoad) this.firstLoad = false
158180
},
159181

160182
})
161183

162-
})
184+
})

client/src/js/modules/fault/views/list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ define(['marionette', 'modules/fault/views/filters', 'views/table', 'utils/table
3333
})
3434
}
3535

36-
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' } })
36+
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' } })
3737

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

51-
})
51+
})

0 commit comments

Comments
 (0)