-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQCPlotHoverPanel.js
More file actions
327 lines (290 loc) · 14.8 KB
/
QCPlotHoverPanel.js
File metadata and controls
327 lines (290 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
* Copyright (c) 2017-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
Ext4.define('LABKEY.targetedms.QCPlotHoverPanel', {
extend: 'Ext.panel.Panel',
border: false,
pointData: null,
valueName: null,
metricProps: null,
originalStatus: 0,
existingExclusions: null,
canEdit: false,
trailingRuns: null,
trailingStartDate: null,
trailingEndDate: null,
STATE: {
INCLUDE: 0,
EXCLUDE_METRIC: 1,
EXCLUDE_ALL: 2
},
initComponent : function() {
if (this.pointData == null) {
this.pointData = {};
}
if (this.metricProps == null) {
this.metricProps = {};
}
this.items = [];
this.callParent();
if(!this.metricProps.precursorScoped)
this.getRunId();
else
this.getExistingReplicateExclusions();
},
getExistingReplicateExclusions : function() {
if (Ext4.isNumber(this.pointData['ReplicateId'])) {
LABKEY.Query.selectRows({
schemaName: 'targetedms',
queryName: 'QCMetricExclusion',
filterArray: [LABKEY.Filter.create('ReplicateId', this.pointData['ReplicateId'])],
scope: this,
success: function(data) {
this.existingExclusions = data.rows;
// set the initial status for this point based on the existing exclusions
var metricIds = Ext4.Array.pluck(this.existingExclusions, 'MetricId');
if (metricIds.indexOf(null) > -1) {
this.originalStatus = this.STATE.EXCLUDE_ALL;
}
else if (metricIds.indexOf(this.metricProps.id) > -1) {
this.originalStatus = this.STATE.EXCLUDE_METRIC;
}
this.initializePanel();
}
});
}
},
initializePanel : function() {
let hideExclusionAndPointClickLinks = false;
if (this.valueName === "TrailingMean") {
hideExclusionAndPointClickLinks = true
}
if (this.valueName === "TrailingCV") {
hideExclusionAndPointClickLinks = true
}
if (this.metricProps.name !== undefined) {
this.add(this.getPlotPointDetailField('Metric', this.metricProps.name));
}
this.add(this.getPlotPointDetailField(this.pointData['dataType'], this.pointData['fragment'], 'qc-hover-value-break'));
if (this.valueName.indexOf('CUSUM') > -1) {
this.add(this.getPlotPointDetailField('Group', 'CUSUMmN' === this.valueName || 'CUSUMvN' === this.valueName ? 'CUSUM-' : 'CUSUM+'));
}
if (this.pointData.conversion && this.pointData.rawValue !== undefined && this.valueName.indexOf("CUSUM") === -1) {
if (this.pointData.conversion === 'percentDeviation') {
this.add(this.getPlotPointDetailField('Value', LABKEY.targetedms.PlotSettingsUtil.formatNumeric(this.pointData.rawValue)));
this.add(this.getPlotPointDetailField('% of Mean', (this.valueName ? this.pointData[this.valueName] : this.pointData['value']) + '%'))
}
else if (this.pointData.conversion === 'standardDeviation') {
this.add(this.getPlotPointDetailField('Value', LABKEY.targetedms.PlotSettingsUtil.formatNumeric(this.pointData.rawValue)));
this.add(this.getPlotPointDetailField('Std Devs', this.valueName ? this.pointData[this.valueName] : this.pointData['value']))
}
else if (this.pointData.conversion === 'deltaFromMean') {
this.add(this.getPlotPointDetailField('Value', LABKEY.targetedms.PlotSettingsUtil.formatNumeric(this.pointData.rawValue)));
this.add(this.getPlotPointDetailField('Delta From Mean', LABKEY.targetedms.PlotSettingsUtil.formatNumeric(this.valueName ? this.pointData[this.valueName] : this.pointData['value'])))
}
else {
this.add(this.getPlotPointDetailField('Value', LABKEY.targetedms.PlotSettingsUtil.formatNumeric(this.valueName ? this.pointData[this.valueName] : this.pointData['value'])));
}
}
else {
this.add(this.getPlotPointDetailField('Value', LABKEY.targetedms.PlotSettingsUtil.formatNumeric(this.valueName ? this.pointData[this.valueName] : this.pointData['value'])));
}
if (hideExclusionAndPointClickLinks) {
let numOfRunsAverage = 0;
// check if guide set is present
if (this.pointData['inGuideSetTrainingRange'] !== undefined) {
numOfRunsAverage = this.trailingRuns > this.pointData['TrainingSeqIdx'] ? this.pointData['TrainingSeqIdx'] : this.trailingRuns
}
else {
numOfRunsAverage = this.trailingRuns > this.pointData['seqValue'] + 1 ? this.pointData['seqValue'] + 1 : this.trailingRuns;
}
this.add(this.getPlotPointDetailField('Replicate', numOfRunsAverage + " runs average"));
this.add(this.getPlotPointDetailField('Acquired', this.trailingStartDate + " - " + this.trailingEndDate));
}
else {
this.add(this.getPlotPointDetailField('Replicate', this.pointData['ReplicateName']));
this.add(this.getPlotPointDetailField('Acquired', this.pointData['fullDate']));
}
if (!hideExclusionAndPointClickLinks) {
this.add(this.getPlotPointDetailField('File Path', this.pointData['FilePath'].replace(/\\/g, '\\<wbr>').replace(/\//g, '\/<wbr>').replace(/_/g, '_<wbr>')));
if (this.canEdit) {
this.add(this.getPlotPointExclusionPanel());
}
else {
this.add(this.getPlotPointDetailField('Status', this.pointData['IgnoreInQC'] ? 'Not included in QC' : 'Included in QC'));
}
this.add(Ext4.create('Ext.Component', {html: this.getPlotPointClickLinks()}));
}
},
getPlotPointDetailField : function(label, value, includeCls) {
return Ext4.create('Ext.form.field.Display', {
cls: 'qc-hover-field' + (Ext4.isString(includeCls) ? ' ' + includeCls : ''),
fieldLabel: label,
labelWidth: 75,
width: 450,
value: value
});
},
getPlotPointExclusionPanel : function() {
if (!this.exclusionPanel) {
this.exclusionPanel = Ext4.create('Ext.form.Panel', {
border: false,
margin: '10px 0',
style: 'border-top: solid #eeeeee 1px; border-bottom: solid #eeeeee 1px;',
items: [this.getPlotPointExclusionRadioGroup()],
dockedItems: [{
xtype: 'toolbar',
dock: 'right',
ui: 'footer',
padding: '0 0 10px 0',
items: ['->', this.getPlotPointExclusionSaveBtn()]
}]
});
}
return this.exclusionPanel;
},
getPlotPointExclusionSaveBtn : function() {
if (!this.exclusionsSaveBtn) {
this.exclusionsSaveBtn = Ext4.create('Ext.button.Button', {
text: 'Save',
disabled: true,
scope: this,
handler: function() {
var newStatus = this.getPlotPointExclusionRadioGroup().getValue().status;
if (newStatus !== this.originalStatus) {
this.getEl().mask();
// Scenarios:
// 1 - from include to exclude metric - insert new row with MetricId
// 2 - from include to exclude all - delete all for replicate and then insert new row without MetricId
// 3 - from exclude metric to include - delete row for MetricId
// 4 - from exclude metric to exclude all - delete all for replicate and then insert new row without MetricId
// 5 - from exclude all to include - delete all for replicate
// 6 - from exclude all to exclude metric - delete all for replicate and then insert new row with MetricId
var s1 = this.originalStatus === this.STATE.INCLUDE && newStatus === this.STATE.EXCLUDE_METRIC;
var s2 = this.originalStatus === this.STATE.INCLUDE && newStatus === this.STATE.EXCLUDE_ALL;
var s3 = this.originalStatus === this.STATE.EXCLUDE_METRIC && newStatus === this.STATE.INCLUDE;
var s4 = this.originalStatus === this.STATE.EXCLUDE_METRIC && newStatus === this.STATE.EXCLUDE_ALL;
var s5 = this.originalStatus === this.STATE.EXCLUDE_ALL && newStatus === this.STATE.INCLUDE;
var s6 = this.originalStatus === this.STATE.EXCLUDE_ALL && newStatus === this.STATE.EXCLUDE_METRIC;
var commands = [];
if (this.existingExclusions.length > 0) {
// for scenarios s2, s4, s5, and s6 - delete all existing exclusions for this replicate
if (s2 || s4 || s5 || s6) {
commands.push({
schemaName: 'targetedms',
queryName: 'QCMetricExclusion',
command: 'delete',
rows: this.existingExclusions
});
}
// for scenario s3 - delete the existing exclusion for this replicate/metric
if (s3) {
commands.push({
schemaName: 'targetedms',
queryName: 'QCMetricExclusion',
command: 'delete',
rows: [this.existingExclusions[Ext4.Array.pluck(this.existingExclusions, 'MetricId').indexOf(this.metricProps.id)]]
});
}
}
// for scenarios s1 and s6 - insert a new exclusion for this replicate/metric
if (s1 || s6) {
commands.push({
schemaName: 'targetedms',
queryName: 'QCMetricExclusion',
command: 'insert',
rows: [{ ReplicateId: this.pointData['ReplicateId'], MetricId: this.metricProps.id }]
});
}
// for scenarios s2 and s4 - insert a new exclusion for this replicate without a metric value
if (s2 || s4) {
commands.push({
schemaName: 'targetedms',
queryName: 'QCMetricExclusion',
command: 'insert',
rows: [{ ReplicateId: this.pointData['ReplicateId'] }]
});
}
LABKEY.Query.saveRows({
commands: commands,
scope: this,
success: function(data) {
// Issue 30343: need to reload the full page because the QC Summary webpart might be
// present and need to be updated according to the updated exclusion state.
window.location.reload();
}
});
}
else {
this.fireEvent('close');
}
}
});
}
return this.exclusionsSaveBtn;
},
getPlotPointExclusionRadioGroup : function() {
if (!this.exclusionRadioGroup) {
this.exclusionRadioGroup = Ext4.create('Ext.form.RadioGroup', {
cls: 'qc-hover-field',
fieldLabel: 'Status',
labelWidth: 75,
padding: '10px 0 0 0',
width: 450,
columns: 1,
items: [{
boxLabel: 'Include', name: 'status',
inputValue: this.STATE.INCLUDE,
checked: this.originalStatus === this.STATE.INCLUDE
},{
boxLabel: 'Exclude replicate for this metric', name: 'status',
inputValue: this.STATE.EXCLUDE_METRIC,
checked: this.originalStatus === this.STATE.EXCLUDE_METRIC
},{
boxLabel: 'Exclude replicate for all metrics', name: 'status',
inputValue: this.STATE.EXCLUDE_ALL,
checked: this.originalStatus === this.STATE.EXCLUDE_ALL
}],
listeners: {
scope: this,
change: function(cmp, newVal, oldVal) {
this.getPlotPointExclusionSaveBtn().setDisabled(newVal.status === this.originalStatus);
}
}
});
}
return this.exclusionRadioGroup;
},
getPlotPointClickLinks : function() {
//Choose action target based on precursor type
var action = this.pointData['dataType'] === 'Peptide' ? "precursorAllChromatogramsChart" : "moleculePrecursorAllChromatogramsChart",
url = LABKEY.ActionURL.buildURL('targetedms', action, LABKEY.ActionURL.getContainer(), {
id: this.pointData['PrecursorId'],
chromInfoId: this.pointData['PrecursorChromInfoId']
});
return LABKEY.Utils.textLink({
text: this.metricProps.precursorScoped ? 'View Chromatogram': 'View Document',
href: this.metricProps.precursorScoped ? url + '#ChromInfo' + this.pointData['PrecursorChromInfoId'] : this.viewDocumentURL
}) + ' ' +
LABKEY.Utils.textLink({
text: 'View Replicate',
href: LABKEY.ActionURL.buildURL('targetedms', 'showSampleFile', LABKEY.ActionURL.getContainer(), {id: this.pointData['SampleFileId']})
});
},
getRunId: function () {
LABKEY.Query.executeSql({
schemaName: 'targetedms',
sql: 'SELECT SampleFileId.ReplicateId.RunId.Id as runId from PrecursorChromInfo',
scope: this,
success: function (results) {
var runId;
if(results && results.rows)
runId = results.rows[0]["runId"];
this.viewDocumentURL = LABKEY.ActionURL.buildURL('targetedms', 'showPrecursorList', null, {id: runId});
this.getExistingReplicateExclusions();
}
});
}
});