Skip to content

Commit bcd9132

Browse files
ndg63276Mark Williamsgfrn
authored
LIMS-103: Fix various bugs in Screens UI (#863)
* LIMS-103: Fix various bugs in Screens UI * Update api/src/Page/Shipment.php Co-authored-by: Guilherme Francisco <guilherme.de-freitas@diamond.ac.uk> --------- Co-authored-by: Mark Williams <mark.williams@diamond.ac.uk> Co-authored-by: Guilherme Francisco <guilherme.de-freitas@diamond.ac.uk>
1 parent 5ba5509 commit bcd9132

File tree

10 files changed

+88
-29
lines changed

10 files changed

+88
-29
lines changed

api/src/Database/Type/MySQL.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class MySQL extends DatabaseParent {
130130

131131
// VMXi
132132
'ContainerInspection',
133+
'ContainerType',
133134
'Imager',
134135
'Screen',
135136
'ScreenComponentGroup',

api/src/Page/Imaging.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Imaging extends Page
4545
'PROPOSALID' => '\d+',
4646
'COMPONENTID' => '\d+',
4747
'GLOBAL' => '\d',
48+
'CONTAINERTYPEID' => '\d*',
4849
'SCREENCOMPONENTGROUPID' => '\d+',
4950
'SCREENCOMPONENTID' => '\d+',
5051
'CONCENTRATION' => '\d+(.\d+)?',
@@ -865,10 +866,11 @@ function _get_screens()
865866
array_push($args, $this->arg('scid'));
866867
}
867868

868-
$screens = $this->db->pq("SELECT 96 as capacity, CONCAT(p.proposalcode, p.proposalnumber) as prop, s.global, s.name, s.screenid, s.proposalid, count(distinct sg.screencomponentgroupid) as groups, count(distinct sc.screencomponentid) as components
869+
$screens = $this->db->pq("SELECT ct.name as containertypeid, IFNULL(ct.capacity, 96) as capacity, CONCAT(p.proposalcode, p.proposalnumber) as prop, s.global, s.name, s.screenid, s.proposalid, count(distinct sg.screencomponentgroupid) as groups, count(distinct sc.screencomponentid) as components
869870
FROM screen s
870871
LEFT OUTER JOIN screencomponentgroup sg ON sg.screenid = s.screenid
871872
LEFT OUTER JOIN screencomponent sc ON sc.screencomponentgroupid = sg.screencomponentgroupid
873+
LEFT OUTER JOIN containertype ct ON ct.containertypeid = s.containertypeid
872874
INNER JOIN proposal p ON p.proposalid = s.proposalid
873875
WHERE $where
874876
GROUP BY CONCAT(p.proposalcode, p.proposalnumber), s.global, s.name, s.screenid, s.proposalid", $args);
@@ -888,8 +890,8 @@ function _add_screen()
888890
if (!$this->has_arg('NAME'))
889891
$this->_error('No screen name provided');
890892

891-
$this->db->pq("INSERT INTO screen (screenid, name, proposalid)
892-
VALUES (s_screen.nextval, :1, :2) RETURNING screenid INTO :id", array($this->arg('NAME'), $this->proposalid));
893+
$this->db->pq("INSERT INTO screen (screenid, name, global, proposalid)
894+
VALUES (s_screen.nextval, :1, :2, :3) RETURNING screenid INTO :id", array($this->arg('NAME'), $this->arg('GLOBAL'), $this->proposalid));
893895

894896
$this->_output(array('SCREENID' => $this->db->id()));
895897
}
@@ -907,9 +909,10 @@ function _update_screen()
907909
if (!sizeof($sc))
908910
$this->_error('No such screen');
909911

910-
foreach (array('NAME', 'GLOBAL') as $f) {
912+
foreach (array('NAME', 'GLOBAL', 'CONTAINERTYPEID') as $f) {
911913
if ($this->has_arg($f)) {
912-
$this->db->pq('UPDATE screen SET ' . $f . '=:1 WHERE screenid=:2', array($this->arg($f), $this->arg('scid')));
914+
$argf = $this->arg($f) == '' ? null : $this->arg($f);
915+
$this->db->pq('UPDATE screen SET ' . $f . '=:1 WHERE screenid=:2', array($argf, $this->arg('scid')));
913916
$this->_output(array($f => $this->arg($f)));
914917
}
915918
}

api/src/Page/Shipment.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class Shipment extends Page
147147
'TOKEN' => '\w+',
148148
'tracking_number' => '\w+',
149149
'AWBURL' => '[\w\:\/\.\-]+',
150+
'PROPOSALTYPE' => '\w+',
150151
'pickup_confirmation_code' => '\w+',
151152

152153
'manifest' => '\d',
@@ -2594,14 +2595,22 @@ function _add_container_history()
25942595
function _get_container_types()
25952596
{
25962597
$where = '';
2598+
$args = array();
25972599
// By default only return active container types.
25982600
// If all param set return everything
25992601
if ($this->has_arg('all')) {
26002602
$where .= '1=1';
26012603
} else {
26022604
$where .= 'ct.active = 1';
26032605
}
2604-
$rows = $this->db->pq("SELECT ct.containerTypeId, name, ct.proposalType, ct.capacity, ct.wellPerRow, ct.dropPerWellX, ct.dropPerWellY, ct.dropHeight, ct.dropWidth, ct.wellDrop FROM ContainerType ct WHERE $where");
2606+
if ($this->has_arg('ty') && $this->arg('ty') == 'plate') {
2607+
$where .= " AND ct.wellperrow is not null";
2608+
}
2609+
if ($this->has_arg('PROPOSALTYPE')) {
2610+
$where .= ' AND ct.proposaltype = :1';
2611+
array_push($args, $this->arg('PROPOSALTYPE'));
2612+
}
2613+
$rows = $this->db->pq("SELECT ct.containerTypeId, name, ct.proposalType, ct.capacity, ct.wellPerRow, ct.dropPerWellX, ct.dropPerWellY, ct.dropHeight, ct.dropWidth, ct.wellDrop FROM ContainerType ct WHERE $where", $args);
26052614
$this->_output(array('total' => count($rows), 'data' => $rows));
26062615
}
26072616

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
define(['backbone', 'utils/kvcollection'], function(Backbone, KVCollection) {
2-
3-
return Backbone.Collection.extend({
4-
5-
initialize: function(options) {
6-
this.add({ name: 'Puck' })
7-
this.add({ name: 'CrystalQuickX', plate: 1 })
1+
define(['backbone.paginator', 'models/containertypes', 'utils/kvcollection'], function(PageableCollection, ContainerTypes, KVCollection) {
2+
3+
return PageableCollection.extend(_.extend({}, KVCollection, {
4+
model: ContainerTypes,
5+
mode: 'client',
6+
url: '/shipment/containers/types',
7+
8+
state: {
9+
pageSize: 9999,
810
},
9-
10-
keyAttribute: 'name',
11-
valueAttribute: 'name',
12-
})
13-
})
11+
12+
parseState: function(r, q, state, options) {
13+
return { totalRecords: r.total }
14+
},
15+
16+
parseRecords: function(r, options) {
17+
return r.data
18+
},
19+
20+
keyAttribute: 'NAME',
21+
valueAttribute: 'CONTAINERTYPEID',
22+
23+
}))
24+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
define(['backbone'], function(Backbone) {
2+
3+
return Backbone.Model.extend({
4+
idAttribute: 'CONTAINERTYPEID',
5+
})
6+
7+
})
8+

client/src/js/modules/imaging/controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ define(['marionette',
8787
screens.fetch({
8888
success: function(r) {
8989
app.content.show(new ScreenAdmin({ collection: screens }))
90-
app.bc.reset([{ title: 'Crysallisation Screens', url: '/imaging/screen' }])
90+
app.bc.reset([{ title: 'Crystallisation Screens', url: '/imaging/screen' }])
9191
},
9292

9393
error: function() {
@@ -155,4 +155,4 @@ define(['marionette',
155155
})
156156

157157
return controller
158-
})
158+
})

client/src/js/modules/imaging/routes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const routes = [
165165
options: {
166166
collection: new Screens()
167167
},
168-
breadcrumbs: [{ title: 'Crysallisation Screens', url: '/imaging/screen' }],
168+
breadcrumbs: [{ title: 'Crystallisation Screens', url: '/imaging/screen' }],
169169
},
170170
},
171171
{
@@ -176,12 +176,12 @@ const routes = [
176176
options: {
177177
model: new Screen({SCREENID: route.params.sid})
178178
},
179-
breadcrumbs: [{ title: 'Crysallisation Screens', url: '/imaging/screen' }],
179+
breadcrumbs: [{ title: 'Crystallisation Screens', url: '/imaging/screen' }],
180180
breadcrumb_tags: ['NAME']
181181
}),
182182
},
183183
]
184184
}
185185
]
186186

187-
export default routes
187+
export default routes

client/src/js/modules/imaging/views/screenadmin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ define(['marionette', 'backbone',
8181
addScreen: function(e) {
8282
e.preventDefault()
8383
if (this.$el.find('.new').length) return
84-
this.collection.add(new Screen({ new: true }))
84+
this.collection.unshift(new Screen({ new: true }))
8585
},
8686

8787

@@ -92,4 +92,4 @@ define(['marionette', 'backbone',
9292
},
9393
})
9494

95-
})
95+
})

client/src/js/modules/imaging/views/screencompadmin.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
88
'modules/imaging/collections/screencomponents',
99
'modules/imaging/views/screencomponentgroup',
1010

11-
'modules/shipment/collections/platetypes',
11+
'collections/containertypes',
1212
'modules/shipment/views/plate',
1313

1414
'templates/imaging/screencomps.html',
1515

1616
'backbone-validation',
1717
], function(Marionette, Backbone, Backgrid, TableView, FilterView, Editable,
18-
ComponentGroup, ComponentGroups, Component, Components, GroupView, PlateType, PlateView,
18+
ComponentGroup, ComponentGroups, Component, Components, GroupView, PlateTypes, PlateView,
1919
template) {
2020

2121

@@ -29,6 +29,10 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
2929
className: 'content',
3030
template: template,
3131

32+
ui: {
33+
containertype: '.containertype',
34+
},
35+
3236
regions: {
3337
group: '.group',
3438
plate: '.plate',
@@ -40,6 +44,7 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
4044

4145
modelEvents: {
4246
'change:CAPACITY': 'updatePositions',
47+
'change:CONTAINERTYPEID': 'updateCapacity',
4348
},
4449

4550
initialize: function(options) {
@@ -58,6 +63,14 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
5863
this.updatePositions()
5964
},
6065

66+
updateCapacity: function() {
67+
var newct = this.ctypes.findWhere({ CONTAINERTYPEID: this.model.get('CONTAINERTYPEID') })
68+
var newcapacity = newct ? newct.get('CAPACITY') : 96
69+
this.model.set('CAPACITY', newcapacity)
70+
this.$el.find('.CAPACITY').html(newcapacity)
71+
this.onRender()
72+
},
73+
6174
updatePositions: function(e) {
6275
var pos = []
6376
_.each(_.range(this.model.get('CAPACITY')), function(i) {
@@ -69,6 +82,7 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
6982
},
7083

7184
setGroup: function(pos) {
85+
if (!pos) return
7286
var s = this.collection.findWhere({ POSITION: pos.toString() })
7387
if (s) this.groupview.setModel(s)
7488
else {
@@ -87,17 +101,25 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
87101
edit.create('NAME', 'text')
88102
if (app.prop == this.model.get('PROP')) {
89103
edit.create('GLOBAL', 'select', { data: { 1: 'Yes', 0: 'No' } })
104+
var self = this
105+
this.ctypes = new PlateTypes()
106+
this.ctypes.queryParams = { 'PROPOSALTYPE': 'mx', 'ty': 'plate' }
107+
this.ctypes.fetch().done(function() {
108+
edit.create('CONTAINERTYPEID', 'select', { data: self.ctypes.kv({ empty: true }) })
109+
})
110+
} else {
111+
this.ui.containertype.hide()
90112
}
91113

92114
this.groupview = new GroupView({ components: this.components, editable: app.prop == this.model.get('PROP') })
93115
this.group.show(this.groupview)
94116

95-
this.filterview = new FilterView({ filters: this.positions, url: false, className: 'plate-12-wide' })
117+
this.filterview = new FilterView({ filters: this.positions, url: false, className: 'plate-12-wide', value: 1 })
96118
this.listenTo(this.filterview, 'selected:change', this.setGroup, this)
97119
this.plate.show(this.filterview)
120+
this.setGroup(1)
98121
},
99122

100-
101123
saveGroups: function(e) {
102124
e.preventDefault()
103125
console.log('save groups')

client/src/js/templates/imaging/screencomps.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ <h1>Crystallisation Screen</h1>
1515
<span class="GLOBAL"><%-GLOBAL == 1 ? 'Yes' : 'No' %></span><span><%-GLOBAL == 1 ? ' (Proposal '+PROP+')' : '' %></span>
1616
</li>
1717

18+
<li class="containertype">
19+
<span class="label">Container Type</span>
20+
<span class="CONTAINERTYPEID"><%-CONTAINERTYPEID%></span>
21+
</li>
22+
1823
<li>
1924
<span class="label">Capacity</span>
2025
<span class="CAPACITY"><%-CAPACITY%></span>

0 commit comments

Comments
 (0)