Skip to content

Commit 6745ff1

Browse files
ndg63276Mark Williams
andauthored
LIMS-1664: Improvements to registered dewar and container pages (#927)
* LIMS-1664: Improvements to registered dewar and container pages * LIMS-1664: Fix counts now where clause has changed * LIMS-1664: Fix bug on first page of dewars/containers --------- Co-authored-by: Mark Williams <mark.williams@diamond.ac.uk>
1 parent 68b17df commit 6745ff1

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

api/src/Page/Shipment.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,15 @@ function _dewar_registry()
649649

650650
if ($this->has_arg('s')) {
651651
$st = sizeof($args) + 1;
652-
$where .= " AND (lower(r.facilitycode) LIKE lower(CONCAT(CONCAT('%', :" . ($st) . "), '%')) OR lower(CONCAT(p.proposalcode,p.proposalnumber)) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 1) . "), '%')))";
652+
$where .= " AND (r.dewarregistryid IN (
653+
SELECT DISTINCT r2.dewarregistryid
654+
FROM dewarregistry r2
655+
LEFT JOIN dewarregistry_has_proposal rhp2 ON rhp2.dewarregistryid = r2.dewarregistryid
656+
LEFT JOIN Proposal p2 ON p2.proposalid = rhp2.proposalid
657+
WHERE r2.facilitycode LIKE CONCAT('%',:" . $st . ",'%')
658+
OR CONCAT(p2.proposalcode, p2.proposalnumber) LIKE CONCAT('%',:" . ($st + 1) . ",'%')
659+
)
660+
)";
653661
array_push($args, $this->arg('s'), $this->arg('s'));
654662
}
655663

@@ -2731,10 +2739,17 @@ function _container_registry()
27312739

27322740
if ($this->has_arg('s')) {
27332741
$st = sizeof($args) + 1;
2734-
$where .= " AND (lower(r.barcode) LIKE lower(CONCAT(CONCAT('%',:" . $st . "), '%')) OR lower(r.comments) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 1) . "), '%')) OR lower(CONCAT(p.proposalcode,p.proposalnumber)) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 2) . "), '%')))";
2735-
array_push($args, $this->arg('s'));
2736-
array_push($args, $this->arg('s'));
2737-
array_push($args, $this->arg('s'));
2742+
$where .= " AND (r.containerregistryid IN (
2743+
SELECT DISTINCT r2.containerregistryid
2744+
FROM containerregistry r2
2745+
LEFT JOIN containerregistry_has_proposal rhp2 ON rhp2.containerregistryid = r2.containerregistryid
2746+
LEFT JOIN proposal p2 ON p2.proposalid = rhp2.proposalid
2747+
WHERE r2.barcode LIKE CONCAT('%',:" . $st . ",'%')
2748+
OR r2.comments LIKE CONCAT('%',:" . ($st + 1) . ",'%')
2749+
OR CONCAT(p2.proposalcode, p2.proposalnumber) LIKE CONCAT('%',:" . ($st + 2) . ",'%')
2750+
)
2751+
)";
2752+
array_push($args, $this->arg('s'), $this->arg('s'), $this->arg('s'));
27382753
}
27392754

27402755
if ($this->has_arg('t')) {
@@ -2743,7 +2758,7 @@ function _container_registry()
27432758
}
27442759

27452760

2746-
$tot = $this->db->pq("SELECT count(r.containerregistryid) as tot
2761+
$tot = $this->db->pq("SELECT count(DISTINCT r.containerregistryid) as tot
27472762
FROM containerregistry r
27482763
LEFT OUTER JOIN containerregistry_has_proposal rhp on rhp.containerregistryid = r.containerregistryid
27492764
LEFT OUTER JOIN proposal p ON p.proposalid = rhp.proposalid

client/src/js/modules/shipment/views/containerregistry.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ define(['marionette',
111111

112112
if (app.staff) {
113113
this.listenTo(this.collection, 'backgrid:selected', this.selectModel, this)
114+
this.collection.each(this.bindModelEvents, this)
114115

115116
this.proposals = new Proposals()
116117
this.listenTo(this.proposals, 'backgrid:selected', this.selectModel, this)
@@ -138,7 +139,11 @@ define(['marionette',
138139
})
139140
}
140141
},
141-
142+
143+
bindModelEvents: function(model) {
144+
this.listenTo(model, 'backgrid:selected', this.selectModel)
145+
},
146+
142147
addToCollection: function(m) {
143148
this.collection.add(m)
144149
this.addProposalsToModel(m)
@@ -156,7 +161,16 @@ define(['marionette',
156161
props.push(p.get('PROPOSAL'))
157162
m.set('PROPOSALS', props.join(','))
158163
// This will be called multiple times for many proposals. Might be a cleaner method..?
159-
app.alert({message: 'Added registered container ' + m.get('BARCODE') + ' to proposal(s) ' + props, notify: true})
164+
app.message({message: 'Added registered container ' + m.get('BARCODE') + ' to proposal ' + p.get('PROPOSAL'), notify: true})
165+
},
166+
error: function(model, response, options) {
167+
var errorMsg
168+
try {
169+
errorMsg = response.responseJSON.message
170+
} catch (e) {
171+
errorMsg = 'An unknown error occurred.'
172+
}
173+
app.alert({message: 'Failed to add ' + m.get('BARCODE') + ' to proposal ' + p.get('PROPOSAL') + ': ' + errorMsg, notify: true})
160174
}
161175
})
162176
}, this)

client/src/js/modules/shipment/views/dewarregistry.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ define(['marionette', 'backgrid',
161161

162162
if (app.staff) {
163163
this.listenTo(this.collection, 'backgrid:selected', this.selectModel, this)
164+
this.collection.each(this.bindModelEvents, this)
164165

165166
this.proposals = new Proposals()
166167
this.listenTo(this.proposals, 'backgrid:selected', this.selectModel, this)
@@ -189,7 +190,11 @@ define(['marionette', 'backgrid',
189190
})
190191
}
191192
},
192-
193+
194+
bindModelEvents: function(model) {
195+
this.listenTo(model, 'backgrid:selected', this.selectModel)
196+
},
197+
193198
addToCollection: function(m) {
194199
this.collection.add(m)
195200
this.addProposalsToModel(m)
@@ -207,7 +212,16 @@ define(['marionette', 'backgrid',
207212
m.set('PROPOSALS', props.join(','))
208213
if (!m.get('PROP')) m.set('PROP', p.get('PROPOSAL'))
209214
// This will be called multiple times for many proposals. Might be a cleaner method..?
210-
app.message({message: 'Added registered dewar ' + m.get('FACILITYCODE') + ' to proposal(s) ' + props, notify: true})
215+
app.message({message: 'Added registered dewar ' + m.get('FACILITYCODE') + ' to proposal ' + p.get('PROPOSAL'), notify: true})
216+
},
217+
error: function(model, response, options) {
218+
var errorMsg
219+
try {
220+
errorMsg = response.responseJSON.message
221+
} catch (e) {
222+
errorMsg = 'An unknown error occurred.'
223+
}
224+
app.alert({message: 'Failed to add ' + m.get('FACILITYCODE') + ' to proposal ' + p.get('PROPOSAL') + ': ' + errorMsg, notify: true})
211225
}
212226
})
213227
}, this)

0 commit comments

Comments
 (0)