Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIMS-103: Fix various bugs in Screens UI #863

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions api/src/Database/Type/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class MySQL extends DatabaseParent {

// VMXi
'ContainerInspection',
'ContainerType',
'Imager',
'Screen',
'ScreenComponentGroup',
Expand Down
13 changes: 8 additions & 5 deletions api/src/Page/Imaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Imaging extends Page
'PROPOSALID' => '\d+',
'COMPONENTID' => '\d+',
'GLOBAL' => '\d',
'CONTAINERTYPEID' => '\d*',
'SCREENCOMPONENTGROUPID' => '\d+',
'SCREENCOMPONENTID' => '\d+',
'CONCENTRATION' => '\d+(.\d+)?',
Expand Down Expand Up @@ -865,10 +866,11 @@ function _get_screens()
array_push($args, $this->arg('scid'));
}

$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
$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
FROM screen s
LEFT OUTER JOIN screencomponentgroup sg ON sg.screenid = s.screenid
LEFT OUTER JOIN screencomponent sc ON sc.screencomponentgroupid = sg.screencomponentgroupid
LEFT OUTER JOIN containertype ct ON ct.containertypeid = s.containertypeid
INNER JOIN proposal p ON p.proposalid = s.proposalid
WHERE $where
GROUP BY CONCAT(p.proposalcode, p.proposalnumber), s.global, s.name, s.screenid, s.proposalid", $args);
Expand All @@ -888,8 +890,8 @@ function _add_screen()
if (!$this->has_arg('NAME'))
$this->_error('No screen name provided');

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

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

foreach (array('NAME', 'GLOBAL') as $f) {
foreach (array('NAME', 'GLOBAL', 'CONTAINERTYPEID') as $f) {
if ($this->has_arg($f)) {
$this->db->pq('UPDATE screen SET ' . $f . '=:1 WHERE screenid=:2', array($this->arg($f), $this->arg('scid')));
$argf = $this->arg($f) == '' ? null : $this->arg($f);
$this->db->pq('UPDATE screen SET ' . $f . '=:1 WHERE screenid=:2', array($argf, $this->arg('scid')));
$this->_output(array($f => $this->arg($f)));
}
}
Expand Down
11 changes: 10 additions & 1 deletion api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class Shipment extends Page
'TOKEN' => '\w+',
'tracking_number' => '\w+',
'AWBURL' => '[\w\:\/\.\-]+',
'PROPOSALTYPE' => '\w+',

'manifest' => '\d',
'currentuser' => '\d',
Expand Down Expand Up @@ -2499,14 +2500,22 @@ function _add_container_history()
function _get_container_types()
{
$where = '';
$args = array();
// By default only return active container types.
// If all param set return everything
if ($this->has_arg('all')) {
$where .= '1=1';
} else {
$where .= 'ct.active = 1';
}
$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");
if ($this->has_arg('ty') && $this->arg('ty') == 'plate') {
$where .= " AND ct.wellperrow is not null";
}
if ($this->has_arg('PROPOSALTYPE')) {
$where .= ' AND ct.proposaltype = :1';
array_push($args, $this->arg('PROPOSALTYPE'));
}
$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);
$this->_output(array('total' => count($rows), 'data' => $rows));
}

Expand Down
35 changes: 23 additions & 12 deletions client/src/js/collections/containertypes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
define(['backbone', 'utils/kvcollection'], function(Backbone, KVCollection) {

return Backbone.Collection.extend({

initialize: function(options) {
this.add({ name: 'Puck' })
this.add({ name: 'CrystalQuickX', plate: 1 })
define(['backbone.paginator', 'models/containertypes', 'utils/kvcollection'], function(PageableCollection, ContainerTypes, KVCollection) {

return PageableCollection.extend(_.extend({}, KVCollection, {
model: ContainerTypes,
mode: 'client',
url: '/shipment/containers/types',

state: {
pageSize: 9999,
},

keyAttribute: 'name',
valueAttribute: 'name',
})
})

parseState: function(r, q, state, options) {
return { totalRecords: r.total }
},

parseRecords: function(r, options) {
return r.data
},

keyAttribute: 'NAME',
valueAttribute: 'CONTAINERTYPEID',

}))
})
8 changes: 8 additions & 0 deletions client/src/js/models/containertypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define(['backbone'], function(Backbone) {

return Backbone.Model.extend({
idAttribute: 'CONTAINERTYPEID',
})

})

4 changes: 2 additions & 2 deletions client/src/js/modules/imaging/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ define(['marionette',
screens.fetch({
success: function(r) {
app.content.show(new ScreenAdmin({ collection: screens }))
app.bc.reset([{ title: 'Crysallisation Screens', url: '/imaging/screen' }])
app.bc.reset([{ title: 'Crystallisation Screens', url: '/imaging/screen' }])
},

error: function() {
Expand Down Expand Up @@ -155,4 +155,4 @@ define(['marionette',
})

return controller
})
})
6 changes: 3 additions & 3 deletions client/src/js/modules/imaging/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const routes = [
options: {
collection: new Screens()
},
breadcrumbs: [{ title: 'Crysallisation Screens', url: '/imaging/screen' }],
breadcrumbs: [{ title: 'Crystallisation Screens', url: '/imaging/screen' }],
},
},
{
Expand All @@ -176,12 +176,12 @@ const routes = [
options: {
model: new Screen({SCREENID: route.params.sid})
},
breadcrumbs: [{ title: 'Crysallisation Screens', url: '/imaging/screen' }],
breadcrumbs: [{ title: 'Crystallisation Screens', url: '/imaging/screen' }],
breadcrumb_tags: ['NAME']
}),
},
]
}
]

export default routes
export default routes
4 changes: 2 additions & 2 deletions client/src/js/modules/imaging/views/screenadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ define(['marionette', 'backbone',
addScreen: function(e) {
e.preventDefault()
if (this.$el.find('.new').length) return
this.collection.add(new Screen({ new: true }))
this.collection.unshift(new Screen({ new: true }))
},


Expand All @@ -92,4 +92,4 @@ define(['marionette', 'backbone',
},
})

})
})
30 changes: 26 additions & 4 deletions client/src/js/modules/imaging/views/screencompadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
'modules/imaging/collections/screencomponents',
'modules/imaging/views/screencomponentgroup',

'modules/shipment/collections/platetypes',
'collections/containertypes',
'modules/shipment/views/plate',

'templates/imaging/screencomps.html',

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


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

ui: {
containertype: '.containertype',
},

regions: {
group: '.group',
plate: '.plate',
Expand All @@ -40,6 +44,7 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',

modelEvents: {
'change:CAPACITY': 'updatePositions',
'change:CONTAINERTYPEID': 'updateCapacity',
},

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

updateCapacity: function() {
var newct = this.ctypes.findWhere({ CONTAINERTYPEID: this.model.get('CONTAINERTYPEID') })
var newcapacity = newct ? newct.get('CAPACITY') : 96
this.model.set('CAPACITY', newcapacity)
this.$el.find('.CAPACITY').html(newcapacity)
this.onRender()
},

updatePositions: function(e) {
var pos = []
_.each(_.range(this.model.get('CAPACITY')), function(i) {
Expand All @@ -69,6 +82,7 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
},

setGroup: function(pos) {
if (!pos) return
var s = this.collection.findWhere({ POSITION: pos.toString() })
if (s) this.groupview.setModel(s)
else {
Expand All @@ -87,17 +101,25 @@ define(['marionette', 'backbone', 'backgrid', 'views/table', 'views/filter',
edit.create('NAME', 'text')
if (app.prop == this.model.get('PROP')) {
edit.create('GLOBAL', 'select', { data: { 1: 'Yes', 0: 'No' } })
var self = this
this.ctypes = new PlateTypes()
this.ctypes.queryParams = { 'PROPOSALTYPE': 'mx', 'ty': 'plate' }
this.ctypes.fetch().done(function() {
edit.create('CONTAINERTYPEID', 'select', { data: self.ctypes.kv({ empty: true }) })
})
} else {
this.ui.containertype.hide()
}

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

this.filterview = new FilterView({ filters: this.positions, url: false, className: 'plate-12-wide' })
this.filterview = new FilterView({ filters: this.positions, url: false, className: 'plate-12-wide', value: 1 })
this.listenTo(this.filterview, 'selected:change', this.setGroup, this)
this.plate.show(this.filterview)
this.setGroup(1)
},


saveGroups: function(e) {
e.preventDefault()
console.log('save groups')
Expand Down
5 changes: 5 additions & 0 deletions client/src/js/templates/imaging/screencomps.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ <h1>Crystallisation Screen</h1>
<span class="GLOBAL"><%-GLOBAL == 1 ? 'Yes' : 'No' %></span><span><%-GLOBAL == 1 ? ' (Proposal '+PROP+')' : '' %></span>
</li>

<li class="containertype">
<span class="label">Container Type</span>
<span class="CONTAINERTYPEID"><%-CONTAINERTYPEID%></span>
</li>

<li>
<span class="label">Capacity</span>
<span class="CAPACITY"><%-CAPACITY%></span>
Expand Down
Loading