Skip to content
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
94 changes: 70 additions & 24 deletions resources/web/PanoramaPremium/window/AddNewMetricWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,36 +285,82 @@ Ext4.define('Panorama.Window.AddCustomMetricWindow', {
this.queryError.setVisible(!isValid);
},

saveNewMetric: function () {
var isValid = this.validateValues();
checkMetricNameExists: function (metricName, callback) {
let filterArray = [LABKEY.Filter.create('Name', metricName, LABKEY.Filter.Types.EQUAL)];

if(isValid) {
var records = [];
var newMetric = {};
newMetric.Name = this.metricNameField.getValue();
newMetric.QueryName = this.queriesCombo.getValue();
newMetric.YAxisLabel = this.yAxisLabelField.getValue();
newMetric.PrecursorScoped = this.metricTypeCombo.getValue();
// If updating, exclude the current metric from the check
if (this.operation === this.update && this.metric) {
filterArray.push(LABKEY.Filter.create('id', this.metric.id, LABKEY.Filter.Types.NOT_EQUAL));
}

if(this.operation === this.update) {
newMetric.id = this.metric.id;
LABKEY.Query.selectRows({
containerPath: LABKEY.container.id,
schemaName: this.SCHEMA_NAME,
queryName: 'qcmetricconfiguration',
filterArray: filterArray,
scope: this,
success: function (data) {
callback.call(this, data.rows.length > 0);
},
failure: function () {
callback.call(this, false);
}
});
},

records.push(newMetric);
saveNewMetric: function () {
let isValid = this.validateValues();

LABKEY.Query.saveRows({
containerPath: LABKEY.container.id,
commands: [{
schemaName: 'targetedms',
queryName: 'qcmetricconfiguration',
command: this.operation,
rows: records
}],
scope: this,
method: 'POST',
success: function () {
window.location.reload();
if(isValid) {
let metricName = this.metricNameField.getValue();

// Check if metric name already exists
this.checkMetricNameExists(metricName, function (exists) {
if (exists) {
let errorMessage = 'A metric with the name "' + metricName + '" already exists. Please choose a different name.';
this.queryError.setText(errorMessage);
this.queryError.setVisible(true);
this.metricNameField.setActiveError('Metric name already exists');
return;
}

let records = [];
let newMetric = {};
newMetric.Name = metricName;
newMetric.QueryName = this.queriesCombo.getValue();
newMetric.YAxisLabel = this.yAxisLabelField.getValue();
newMetric.PrecursorScoped = this.metricTypeCombo.getValue();

if (this.operation === this.update) {
newMetric.id = this.metric.id;
}

records.push(newMetric);

LABKEY.Query.saveRows({
containerPath: LABKEY.container.id,
commands: [{
schemaName: 'targetedms',
queryName: 'qcmetricconfiguration',
command: this.operation,
rows: records
}],
scope: this,
method: 'POST',
success: function () {
window.location.reload();
},
failure: function (response) {
let errorMessage = 'Error saving metric';
if (response && response.exception) {
errorMessage = response.exception;
} else if (response && response.message) {
errorMessage = response.message;
}
this.queryError.setText(errorMessage);
this.queryError.setVisible(true);
}
});
});
}

Expand Down
146 changes: 108 additions & 38 deletions resources/web/PanoramaPremium/window/AddNewTraceMetricWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Ext4.define('Panorama.Window.AddTraceMetricWindow', {
this.getMetricNameField(),
this.getTracesCombo(),
this.getYAxisLabelField(),
this.getTraceValueRadioGroup()
this.getTraceValueRadioGroup(),
this.getQueryError()
];
},

Expand Down Expand Up @@ -287,6 +288,19 @@ Ext4.define('Panorama.Window.AddTraceMetricWindow', {
return this.yAxisLabelField;
},

getQueryError: function() {
if (!this.queryError) {
this.queryError = Ext4.create('Ext.form.Label', {
name: 'errorMsg',
hidden: true,
cls: 'labkey-error',
text:''
});
}

return this.queryError;
},

getSaveButton: function() {
if (!this.saveButton) {
this.saveButton = Ext4.create('Ext.button.Button', {
Expand Down Expand Up @@ -367,52 +381,98 @@ Ext4.define('Panorama.Window.AddTraceMetricWindow', {
return isValid;
},

checkMetricNameExists: function (metricName, callback) {
let filterArray = [LABKEY.Filter.create('Name', metricName, LABKEY.Filter.Types.EQUAL)];

// If updating, exclude the current metric from the check
if (this.operation === this.update && this.metric) {
filterArray.push(LABKEY.Filter.create('id', this.metric.id, LABKEY.Filter.Types.NOT_EQUAL));
}

LABKEY.Query.selectRows({
containerPath: LABKEY.container.id,
schemaName: 'targetedms',
queryName: 'qcmetricconfiguration',
filterArray: filterArray,
scope: this,
success: function (data) {
callback.call(this, data.rows.length > 0);
},
failure: function () {
callback.call(this, false);
}
});
},



saveNewMetric: function () {
var isValid = this.validateValues();

if (isValid) {
var records = [];
var newMetric = {};
newMetric.Name = this.metricNameField.getValue();
newMetric.QueryName = 'QCTraceMetric'; // dummy text to insert and not an actual query
newMetric.PrecursorScoped = false;
newMetric.TraceName = this.tracesCombo.getValue();
newMetric.YAxisLabel = this.yAxisLabelField.getValue();

if (this.traceValueNumberField.getValue()) {
newMetric.TraceValue = this.traceValueNumberField.getValue();
}
else {
if (this.timeValueOptionField.getValue()) {
newMetric.TimeValueOption = this.timeValueOptionField.getValue();
}
if (this.minTimeValueNumberField.getValue()) {
newMetric.MinTimeValue = this.minTimeValueNumberField.getValue();
var metricName = this.metricNameField.getValue();

this.checkMetricNameExists(metricName, function (exists) {
if (exists) {
let errorMessage = 'A metric with the name "' + metricName + '" already exists. Please choose a different name.';
this.queryError.setText(errorMessage);
this.queryError.setVisible(true);
this.metricNameField.setActiveError('Metric name already exists');
return;
}
if (this.maxTimeValueNumberField.getValue()) {
newMetric.MaxTimeValue = this.maxTimeValueNumberField.getValue();

var records = [];
var newMetric = {};
newMetric.Name = metricName;
newMetric.QueryName = 'QCTraceMetric'; // dummy text to insert and not an actual query
newMetric.PrecursorScoped = false;
newMetric.TraceName = this.tracesCombo.getValue();
newMetric.YAxisLabel = this.yAxisLabelField.getValue();

if (this.traceValueNumberField.getValue()) {
newMetric.TraceValue = this.traceValueNumberField.getValue();
} else {
if (this.timeValueOptionField.getValue()) {
newMetric.TimeValueOption = this.timeValueOptionField.getValue();
}
if (this.minTimeValueNumberField.getValue()) {
newMetric.MinTimeValue = this.minTimeValueNumberField.getValue();
}
if (this.maxTimeValueNumberField.getValue()) {
newMetric.MaxTimeValue = this.maxTimeValueNumberField.getValue();
}
}
}

if(this.operation === this.update) {
newMetric.id = this.metric.id;
}
if (this.operation === this.update) {
newMetric.id = this.metric.id;
}

records.push(newMetric);
records.push(newMetric);

LABKEY.Query.saveRows({
containerPath: LABKEY.container.id,
commands: [{
schemaName: 'targetedms',
queryName: 'qcmetricconfiguration',
command: this.operation,
rows: records
}],
scope: this,
method: 'POST',
success: function () {
window.location.reload();
}
LABKEY.Query.saveRows({
containerPath: LABKEY.container.id,
commands: [{
schemaName: 'targetedms',
queryName: 'qcmetricconfiguration',
command: this.operation,
rows: records
}],
scope: this,
method: 'POST',
success: function () {
window.location.reload();
},
failure: function (response) {
let errorMessage = 'Error saving metric';
if (response && response.exception) {
errorMessage = response.exception;
} else if (response && response.message) {
errorMessage = response.message;
}
this.queryError.setText(errorMessage);
this.queryError.setVisible(true);
}
});
});
}

Expand Down Expand Up @@ -441,6 +501,16 @@ Ext4.define('Panorama.Window.AddTraceMetricWindow', {
method: 'POST',
success: function () {
window.location.reload();
},
failure: function (response) {
let errorMessage = 'Error saving metric';
if (response && response.exception) {
errorMessage = response.exception;
} else if (response && response.message) {
errorMessage = response.message;
}
this.queryError.setText(errorMessage);
this.queryError.setVisible(true);
}
});
win.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,26 @@ public String clickSaveExpectingError()
return errorMsgId.findElement(getDriver()).getText();
}

public void addNewCustomMetric(Map<CustomMetricProperties, String> metricProperties)
public void addNewCustomMetric(Map<CustomMetricProperties, String> metricProperties, boolean checkForDuplicate)
{
click(Locator.tagWithText("button", ADD_NEW_CUSTOM_METRIC));
waitForElement(Ext4Helper.Locators.window("Add New Metric"));
Window<?> metricWindow = new Window.WindowFinder(getDriver()).withTitle("Add New Metric").waitFor();
editCustomMetricValues(metricWindow, metricProperties);
editCustomMetricValues(metricWindow, metricProperties, checkForDuplicate);
}

public void addNewTraceMetric(Map<TraceMetricProperties, String> traceProperties)
public void addNewTraceMetric(Map<TraceMetricProperties, String> traceProperties, boolean checkForDuplicate)
{
click(Locator.tagWithText("button", "Add New Trace Metric"));
waitForElement(Ext4Helper.Locators.window("Add New Trace Metric"));
Window<?> metricWindow = new Window.WindowFinder(getDriver()).withTitle("Add New Trace Metric").waitFor();
editTraceMetricValues(metricWindow, traceProperties);
editTraceMetricValues(metricWindow, traceProperties, checkForDuplicate);
}

public void editMetric(String metric, Map<CustomMetricProperties, String> metricProperties)
{
Window<?> metricWindow = openForEdit(metric);
editCustomMetricValues(metricWindow, metricProperties);
editCustomMetricValues(metricWindow, metricProperties, false);
}

public void deleteMetric(String metric)
Expand All @@ -155,7 +155,7 @@ private Window<?> openForEdit(String metric)
return new Window.WindowFinder(getDriver()).withTitle("Edit Metric").waitFor();
}

private void editCustomMetricValues(Window<?> metricWindow, Map<CustomMetricProperties, String> metricProperties)
private void editCustomMetricValues(Window<?> metricWindow, Map<CustomMetricProperties, String> metricProperties, boolean checkForDuplicate)
{
metricProperties.forEach((prop, val) -> {
if (!prop.isSelect)
Expand All @@ -176,10 +176,17 @@ private void editCustomMetricValues(Window<?> metricWindow, Map<CustomMetricProp
}
}
});
clickAndWait(Ext4Helper.Locators.ext4Button("Save").findElement(metricWindow));
if (checkForDuplicate)
{
checkForDuplicate(metricProperties.get(CustomMetricProperties.metricName));
}
else
{
clickAndWait(Ext4Helper.Locators.ext4Button("Save").findElement(metricWindow));
}
}

private void editTraceMetricValues(Window<?> metricWindow, Map<TraceMetricProperties, String> metricProperties)
private void editTraceMetricValues(Window<?> metricWindow, Map<TraceMetricProperties, String> metricProperties, boolean checkForDuplicate)
{
metricProperties.forEach((prop, val) -> {
if (!prop.isSelect)
Expand All @@ -195,8 +202,24 @@ else if (prop.formLabel != null)
_ext4Helper.selectComboBoxItem(prop.loc, val);
}
});
clickAndWait(Ext4Helper.Locators.ext4Button("Save").findElement(metricWindow));
waitForElement(Locator.linkWithText(metricProperties.get(ConfigureMetricsUIPage.TraceMetricProperties.metricName)));
if (checkForDuplicate)
{
click(Ext4Helper.Locators.ext4Button("Save"));
assertTextPresent("A metric with the name \"" + metricProperties.get(ConfigureMetricsUIPage.TraceMetricProperties.metricName) + "\" already exists. Please choose a different name.");
click(Ext4Helper.Locators.ext4Button("Cancel"));
}
else
{
clickAndWait(Ext4Helper.Locators.ext4Button("Save").findElement(metricWindow));
waitForElement(Locator.linkWithText(metricProperties.get(ConfigureMetricsUIPage.TraceMetricProperties.metricName)));
}
}

private void checkForDuplicate(String metricName)
{
click(Ext4Helper.Locators.ext4Button("Save"));
assertTextPresent("A metric with the name \"" + metricName + "\" already exists. Please choose a different name.");
click(Ext4Helper.Locators.ext4Button("Cancel"));
}

public void clearMetricCache()
Expand Down
Loading