Skip to content

Commit 6c2f9e8

Browse files
authored
Update MCC shipping window to allow multiple IDs at once (#162)
* Update MCC shipping window to allow multiple IDs at once
1 parent c823024 commit 6c2f9e8

2 files changed

Lines changed: 186 additions & 133 deletions

File tree

mcc/resources/web/mcc/window/MarkShippedWindow.js

Lines changed: 182 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ Ext4.define('MCC.window.MarkShippedWindow', {
1010
return;
1111
}
1212

13-
if (checked.length !== 1) {
14-
Ext4.Msg.alert('Error', 'Currently only one ID is supported as a time');
15-
return;
16-
}
17-
1813
Ext4.create('MCC.window.MarkShippedWindow', {
1914
dataRegionName: dataRegionName,
2015
rowIds: checked
@@ -37,23 +32,6 @@ Ext4.define('MCC.window.MarkShippedWindow', {
3732
html: 'This will: <br>1) Mark the selected animals as shipped from this center<br>2) Enter a new demographics record in the selected study<br>3) Preserve the MCC ID for each animal.',
3833
border: false,
3934
style: 'padding-bottom: 10px;'
40-
},{
41-
xtype: 'checkbox',
42-
fieldLabel: 'Animal Will Use Previous Id',
43-
itemId: 'usePreviousId',
44-
listeners: {
45-
scope: this,
46-
change: function (field, val) {
47-
var target = field.up('panel').down('#newId');
48-
target.allowBlank = !!val;
49-
target.setVisible(!val);
50-
}
51-
},
52-
},{
53-
xtype: 'textfield',
54-
fieldLabel: 'New ID (blank if unchanged)',
55-
itemId: 'newId',
56-
allowBlank: false
5735
},{
5836
xtype: 'datefield',
5937
fieldLabel: 'Effective Date',
@@ -105,7 +83,7 @@ Ext4.define('MCC.window.MarkShippedWindow', {
10583
}
10684
}
10785
}
108-
}],
86+
}, this.getAnimalIdFields()],
10987
buttons: [{
11088
text: 'Submit',
11189
handler: this.onSubmit,
@@ -121,11 +99,72 @@ Ext4.define('MCC.window.MarkShippedWindow', {
12199
this.callParent(arguments);
122100
},
123101

102+
getAnimalIdFields: function(){
103+
var fields = [{
104+
xtype: 'displayfield',
105+
value: 'Animal ID',
106+
width: 150
107+
},{
108+
xtype: 'displayfield',
109+
value: 'Keep Existing ID?',
110+
width: 150
111+
},{
112+
xtype: 'displayfield',
113+
value: 'New ID (blank if unchanged)',
114+
}];
115+
116+
Ext4.Array.forEach(this.rowIds, function(rowId){
117+
const animalId = this.lsidToAnimalId(rowId);
118+
fields = fields.concat([{
119+
xtype: 'displayfield',
120+
value: animalId,
121+
},{
122+
xtype: 'checkbox',
123+
itemId: 'usePreviousId-' + animalId,
124+
checked: false,
125+
listeners: {
126+
scope: this,
127+
change: function (field, val) {
128+
var target = field.up('panel').down('#newId-' + animalId);
129+
target.allowBlank = !!val;
130+
target.setDisabled(val);
131+
}
132+
}
133+
},{
134+
xtype: 'textfield',
135+
itemId: 'newId-' + animalId,
136+
disabled: false,
137+
allowBlank: true
138+
}]);
139+
}, this);
140+
141+
return {
142+
layout: {
143+
type: 'table',
144+
columns: 3
145+
},
146+
border: false,
147+
defaults: {
148+
style: 'padding:5px;',
149+
border: false
150+
},
151+
items: fields
152+
};
153+
},
154+
155+
lsidToAnimalId: function(lsid){
156+
lsid = lsid.split(':')[4];
157+
lsid = lsid.split('.');
158+
lsid.shift();
159+
160+
return lsid.join('.');
161+
},
162+
124163
onSubmit: function(btn){
125164
Ext4.Msg.wait('Loading...');
126165

127166
var win = btn.up('window');
128-
var lsid = win.rowIds[0];
167+
var lsids = win.rowIds;
129168
var effectiveDate = win.down('#effectiveDate').getValue();
130169
var centerName = win.down('#centerName').getValue();
131170
var targetFolder = win.down('#targetFolder').getValue();
@@ -134,9 +173,19 @@ Ext4.define('MCC.window.MarkShippedWindow', {
134173
return;
135174
}
136175

137-
if (!win.down('#usePreviousId').getValue() && !win.down('#newId').getValue()) {
138-
Ext4.Msg.hide();
139-
Ext4.Msg.alert('Error', 'Must enter the new ID');
176+
var hasError = false;
177+
Ext4.Array.forEach(this.rowIds, function(rowId) {
178+
var animalId = this.lsidToAnimalId(rowId);
179+
var useExisting = win.down('#usePreviousId-' + animalId).getValue();
180+
if (!useExisting && !win.down('#newId-' + animalId).getValue()) {
181+
Ext4.Msg.hide();
182+
Ext4.Msg.alert('Error', 'Must enter the new ID for: ' + animalId);
183+
hasError = true;
184+
return false;
185+
}
186+
}, this);
187+
188+
if (hasError) {
140189
return;
141190
}
142191

@@ -145,122 +194,125 @@ Ext4.define('MCC.window.MarkShippedWindow', {
145194
LABKEY.Query.selectRows({
146195
schemaName: 'study',
147196
queryName: 'Demographics',
148-
filterArray: [LABKEY.Filter.create('lsid', lsid)],
197+
filterArray: [LABKEY.Filter.create('lsid', lsids.join(';'), LABKEY.Filter.Types.IN)],
149198
columns: 'Id,gender,colony,species,birth,death,center,Id/MostRecentDeparture/MostRecentDeparture,Id/mccAlias/externalAlias,calculated_status,dam,sire,damMccAlias/externalAlias,sireMccAlias/externalAlias',
150199
scope: this,
151200
failure: LDK.Utils.getErrorCallback(),
152201
success: function(results) {
153202
if (!results || !results.rows || !results.rows.length) {
154203
Ext4.Msg.hide();
155-
Ext4.Msg.alert('Error', 'No row round for LSID: ' + lsid + '. This is not expected');
156-
return;
204+
Ext4.Msg.alert('Error', 'No rows found for, this is not expected');
205+
return false;
157206
}
158207

159-
var row = results.rows[0];
160-
var newId = win.down('#newId').getValue() || row.Id;
161208
var commands = [];
209+
Ext4.Array.forEach(results.rows, function(row){
210+
var effectiveId = win.down('#usePreviousId-' + row.Id).getValue() ? row.Id : win.down('#newId-' + row.Id).getValue();
211+
// This should be checked above, although perhaps case sensitivity could get involved:
212+
LDK.Assert.assertNotEmpty('Missing effective ID after query', effectiveId);
162213

163-
var shouldAddDeparture = !row['Id/MostRecentDeparture/MostRecentDeparture'] || row['Id/MostRecentDeparture/MostRecentDeparture'] !== Ext4.Date.format(row.effectiveDate, 'Y-m-d') || row.Id !== newId;
164-
if (shouldAddDeparture) {
165-
commands.push({
166-
command: 'insert',
167-
schemaName: 'study',
168-
queryName: 'Departure',
169-
rows: [{
170-
Id: row.Id,
171-
date: effectiveDate,
172-
destination: centerName,
173-
description: row.colony ? 'Original center: ' + row.colony : null,
174-
qcstate: null,
175-
objectId: null,
176-
QCStateLabel: 'Completed'
177-
}]
178-
});
179-
}
214+
var shouldAddDeparture = !row['Id/MostRecentDeparture/MostRecentDeparture'] || row['Id/MostRecentDeparture/MostRecentDeparture'] !== Ext4.Date.format(row.effectiveDate, 'Y-m-d') || row.Id !== effectiveId;
215+
if (shouldAddDeparture) {
216+
commands.push({
217+
command: 'insert',
218+
schemaName: 'study',
219+
queryName: 'Departure',
220+
rows: [{
221+
Id: row.Id,
222+
date: effectiveDate,
223+
destination: centerName,
224+
description: row.colony ? 'Original center: ' + row.colony : null,
225+
qcstate: null,
226+
objectId: null,
227+
QCStateLabel: 'Completed'
228+
}]
229+
});
230+
}
180231

181-
// If going to a new LK folder, we're creating a whole new record:
182-
if (targetFolderId.toUpperCase() !== LABKEY.Security.currentContainer.id.toUpperCase() || newId !== row.Id) {
183-
commands.push({
184-
command: 'insert',
185-
containerPath: targetFolder,
186-
schemaName: 'study',
187-
queryName: 'Demographics',
188-
rows: [{
189-
Id: newId,
190-
date: effectiveDate,
191-
alternateIds: row.Id !== newId ? row.Id : null,
192-
gender: row.gender,
193-
species: row.species,
194-
birth: row.birth,
195-
death: row.death,
196-
dam: row.dam,
197-
sire: row.sire,
198-
damMccAlias: row['damMccAlias/externalAlias'],
199-
sireMccAlias: row['sireMccAlias/externalAlias'],
200-
colony: centerName,
201-
source: row.colony,
202-
calculated_status: 'Alive',
203-
mccAlias: row['Id/mccAlias/externalAlias'],
204-
QCState: null,
205-
QCStateLabel: 'Completed',
206-
objectId: null
207-
}]
208-
});
232+
// If going to a new LK folder, we're creating a whole new record:
233+
if (targetFolderId.toUpperCase() !== LABKEY.Security.currentContainer.id.toUpperCase() || effectiveId !== row.Id) {
234+
commands.push({
235+
command: 'insert',
236+
containerPath: targetFolder,
237+
schemaName: 'study',
238+
queryName: 'Demographics',
239+
rows: [{
240+
Id: effectiveId,
241+
date: effectiveDate,
242+
alternateIds: row.Id !== effectiveId ? row.Id : null,
243+
gender: row.gender,
244+
species: row.species,
245+
birth: row.birth,
246+
death: row.death,
247+
dam: row.dam,
248+
sire: row.sire,
249+
damMccAlias: row['damMccAlias/externalAlias'],
250+
sireMccAlias: row['sireMccAlias/externalAlias'],
251+
colony: centerName,
252+
source: row.colony,
253+
calculated_status: 'Alive',
254+
mccAlias: row['Id/mccAlias/externalAlias'],
255+
QCState: null,
256+
QCStateLabel: 'Completed',
257+
objectId: null
258+
}]
259+
});
209260

210-
commands.push({
211-
command: 'update',
212-
containerPath: null, //Use current folder
213-
schemaName: 'study',
214-
queryName: 'Demographics',
215-
rows: [{
216-
Id: row.Id, // NOTE: always change the original record
217-
excludeFromCensus: true
218-
}]
219-
});
220-
}
221-
else {
222-
// Otherwise update the existing:
223-
commands.push({
224-
command: 'update',
225-
containerPath: targetFolder,
226-
schemaName: 'study',
227-
queryName: 'Demographics',
228-
rows: [{
229-
Id: row.Id,
230-
date: effectiveDate,
231-
alternateIds: null,
232-
gender: row.gender,
233-
species: row.species,
234-
birth: row.birth,
235-
death: row.death,
236-
dam: row.dam,
237-
sire: row.sire,
238-
colony: centerName,
239-
source: row.colony,
240-
calculated_status: 'Alive',
241-
QCState: null,
242-
QCStateLabel: 'Completed',
243-
objectId: null
244-
}]
245-
});
261+
commands.push({
262+
command: 'update',
263+
containerPath: null, //Use current folder
264+
schemaName: 'study',
265+
queryName: 'Demographics',
266+
rows: [{
267+
Id: row.Id, // NOTE: always change the original record
268+
excludeFromCensus: true
269+
}]
270+
});
271+
}
272+
else {
273+
// Otherwise update the existing:
274+
commands.push({
275+
command: 'update',
276+
containerPath: targetFolder,
277+
schemaName: 'study',
278+
queryName: 'Demographics',
279+
rows: [{
280+
Id: row.Id,
281+
date: effectiveDate,
282+
alternateIds: null,
283+
gender: row.gender,
284+
species: row.species,
285+
birth: row.birth,
286+
death: row.death,
287+
dam: row.dam,
288+
sire: row.sire,
289+
colony: centerName,
290+
source: row.colony,
291+
calculated_status: 'Alive',
292+
QCState: null,
293+
QCStateLabel: 'Completed',
294+
objectId: null
295+
}]
296+
});
246297

247-
// And also add an arrival record. NOTE: set the date after the departure to get status to update properly
248-
var arrivalDate = new Date(effectiveDate).setMinutes(effectiveDate.getMinutes() + 1);
249-
commands.push({
250-
command: 'insert',
251-
containerPath: targetFolder,
252-
schemaName: 'study',
253-
queryName: 'Arrival',
254-
rows: [{
255-
Id: newId,
256-
date: arrivalDate,
257-
source: centerName,
258-
QCState: null,
259-
QCStateLabel: 'Completed',
260-
objectId: null
261-
}]
262-
});
263-
}
298+
// And also add an arrival record. NOTE: set the date after the departure to get status to update properly
299+
var arrivalDate = new Date(effectiveDate).setMinutes(effectiveDate.getMinutes() + 1);
300+
commands.push({
301+
command: 'insert',
302+
containerPath: targetFolder,
303+
schemaName: 'study',
304+
queryName: 'Arrival',
305+
rows: [{
306+
Id: effectiveId,
307+
date: arrivalDate,
308+
source: centerName,
309+
QCState: null,
310+
QCStateLabel: 'Completed',
311+
objectId: null
312+
}]
313+
});
314+
}
315+
}, this);
264316

265317
LABKEY.Query.saveRows({
266318
commands: commands,

0 commit comments

Comments
 (0)