@@ -10324,8 +10324,12 @@ const openCopySampleMetadataPopup = async () => {
10324
10324
10325
10325
const specifySubject = (event, subjectNameInput) => {
10326
10326
if (event.which == 13) {
10327
+ const userEnteredSubjectName = subjectNameInput.val().trim();
10328
+ if (userEnteredSubjectName.length === 0) {
10329
+ return;
10330
+ }
10327
10331
try {
10328
- const subjectName = `sub-${subjectNameInput.val().trim() }`;
10332
+ const subjectName = `sub-${userEnteredSubjectName }`;
10329
10333
const subjectNameElement = `
10330
10334
<div class="space-between w-100">
10331
10335
<span class="subject-id">${subjectName}</span>
@@ -10342,28 +10346,26 @@ const specifySubject = (event, subjectNameInput) => {
10342
10346
subjectIdCellToAddNameTo[0].parentElement.nextElementSibling.children[0];
10343
10347
trashCanElement.style.display = "block";
10344
10348
10345
- if (subjectName.length > 0) {
10346
- const subjectNameIsValid = evaluateStringAgainstSdsRequirements(
10347
- subjectName,
10348
- "string-adheres-to-identifier-conventions"
10349
- );
10350
- if (!subjectNameIsValid) {
10351
- generateAlertMessage(subjectNameInput);
10352
- return;
10353
- }
10354
- //remove the add subject help text
10355
- document.getElementById("guided-add-subject-instructions").classList.add("hidden");
10356
- removeAlertMessageIfExists(subjectNameInput);
10357
- if (subjectNameInput.attr("data-prev-name")) {
10358
- const subjectToRename = subjectNameInput.attr("data-prev-name");
10359
- sodaJSONObj.renameSubject(subjectToRename, subjectName);
10360
- } else {
10361
- //case where subject name is valid and not being renamed:
10362
- sodaJSONObj.addSubject(subjectName);
10363
- }
10364
- subjectIdCellToAddNameTo.html(subjectNameElement);
10365
- addSubjectSpecificationTableRow();
10349
+ const subjectNameIsValid = evaluateStringAgainstSdsRequirements(
10350
+ subjectName,
10351
+ "string-adheres-to-identifier-conventions"
10352
+ );
10353
+ if (!subjectNameIsValid) {
10354
+ generateAlertMessage(subjectNameInput);
10355
+ return;
10356
+ }
10357
+ //remove the add subject help text
10358
+ document.getElementById("guided-add-subject-instructions").classList.add("hidden");
10359
+ removeAlertMessageIfExists(subjectNameInput);
10360
+ if (subjectNameInput.attr("data-prev-name")) {
10361
+ const subjectToRename = subjectNameInput.attr("data-prev-name");
10362
+ sodaJSONObj.renameSubject(subjectToRename, subjectName);
10363
+ } else {
10364
+ //case where subject name is valid and not being renamed:
10365
+ sodaJSONObj.addSubject(subjectName);
10366
10366
}
10367
+ subjectIdCellToAddNameTo.html(subjectNameElement);
10368
+ addSubjectSpecificationTableRow();
10367
10369
} catch (error) {
10368
10370
notyf.open({
10369
10371
duration: "3000",
@@ -10380,9 +10382,14 @@ const specifySample = (event, sampleNameInput) => {
10380
10382
.previousElementSibling;
10381
10383
10382
10384
let addSampleButton = buttonContainer.children[0].children[0].children[1];
10385
+
10383
10386
if (event.which == 13) {
10387
+ const userEnteredSample = sampleNameInput.val().trim();
10388
+ if (userEnteredSample.length === 0) {
10389
+ return;
10390
+ }
10384
10391
try {
10385
- const sampleName = `sam-${sampleNameInput.val().trim() }`;
10392
+ const sampleName = `sam-${userEnteredSample }`;
10386
10393
const sampleRenameElement = `
10387
10394
<div class="space-between w-100">
10388
10395
<span class="sample-id">${sampleName}</span>
@@ -10404,40 +10411,34 @@ const specifySample = (event, sampleNameInput) => {
10404
10411
.text();
10405
10412
const subjectToAddSampleTo = subjectSampleAdditionTable.find(".samples-subject-name").text();
10406
10413
10407
- if (sampleName.length > 0) {
10408
- const sampleNameIsValid = evaluateStringAgainstSdsRequirements(
10414
+ const sampleNameIsValid = evaluateStringAgainstSdsRequirements(
10415
+ sampleName,
10416
+ "string-adheres-to-identifier-conventions"
10417
+ );
10418
+ if (!sampleNameIsValid) {
10419
+ //show alert message below pool name input if input is invalid and abort function
10420
+ generateAlertMessage(sampleNameInput);
10421
+ return;
10422
+ }
10423
+ removeAlertMessageIfExists(sampleNameInput);
10424
+
10425
+ if (sampleNameInput.attr("data-prev-name")) {
10426
+ const sampleToRename = sampleNameInput.attr("data-prev-name");
10427
+ sodaJSONObj.renameSample(
10428
+ sampleToRename,
10409
10429
sampleName,
10410
- "string-adheres-to-identifier-conventions"
10430
+ subjectsPoolToAddSampleTo,
10431
+ subjectToAddSampleTo
10411
10432
);
10412
- if (!sampleNameIsValid) {
10413
- //show alert message below pool name input if input is invalid and abort function
10414
- generateAlertMessage(sampleNameInput);
10415
- return;
10416
- }
10417
- removeAlertMessageIfExists(sampleNameInput);
10418
-
10419
- if (sampleNameInput.attr("data-prev-name")) {
10420
- const sampleToRename = sampleNameInput.attr("data-prev-name");
10421
- sodaJSONObj.renameSample(
10422
- sampleToRename,
10423
- sampleName,
10424
- subjectsPoolToAddSampleTo,
10425
- subjectToAddSampleTo
10426
- );
10427
- } else {
10428
- //Add the new sample to sodaJSONObj
10429
- sodaJSONObj.addSampleToSubject(
10430
- sampleName,
10431
- subjectsPoolToAddSampleTo,
10432
- subjectToAddSampleTo
10433
- );
10434
- //then show trash can svg
10435
- sampleTrashCan.style.display = "block";
10436
- }
10437
- sampleIdCellToAddNameTo.html(sampleRenameElement);
10438
- if (!sampleNameInput.attr("data-prev-name")) {
10439
- addSampleSpecificationTableRow(addSampleButton);
10440
- }
10433
+ } else {
10434
+ //Add the new sample to sodaJSONObj
10435
+ sodaJSONObj.addSampleToSubject(sampleName, subjectsPoolToAddSampleTo, subjectToAddSampleTo);
10436
+ //then show trash can svg
10437
+ sampleTrashCan.style.display = "block";
10438
+ }
10439
+ sampleIdCellToAddNameTo.html(sampleRenameElement);
10440
+ if (!sampleNameInput.attr("data-prev-name")) {
10441
+ addSampleSpecificationTableRow(addSampleButton);
10441
10442
}
10442
10443
} catch (error) {
10443
10444
console.log(error);
@@ -10452,8 +10453,12 @@ const specifySample = (event, sampleNameInput) => {
10452
10453
10453
10454
const specifyPool = (event, poolNameInput) => {
10454
10455
if (event.which == 13) {
10456
+ const userEnteredPoolName = poolNameInput.val().trim();
10457
+ if (userEnteredPoolName.length === 0) {
10458
+ return;
10459
+ }
10455
10460
try {
10456
- const poolName = `pool-${poolNameInput.val().trim() }`;
10461
+ const poolName = `pool-${userEnteredPoolName }`;
10457
10462
const poolNameElement = `
10458
10463
<div class="space-between" style="width: 250px;">
10459
10464
<span class="pool-id">${poolName}</span>
@@ -10477,65 +10482,63 @@ const specifyPool = (event, poolNameInput) => {
10477
10482
const poolTrashcan = poolSubjectsDropdownCell[0].nextElementSibling.children[0];
10478
10483
const poolIdCellToAddNameTo = poolNameInput.parent();
10479
10484
let poolsTable = $("#pools-table");
10480
- if (poolName !== "pool-") {
10481
- const poolNameIsValid = evaluateStringAgainstSdsRequirements(
10482
- poolName,
10483
- "string-adheres-to-identifier-conventions"
10484
- );
10485
- if (!poolNameIsValid) {
10486
- notyf.open({
10487
- duration: "3000",
10488
- type: "error",
10489
- message: "Pool IDs may not contain spaces or special characters",
10490
- });
10491
- return;
10492
- }
10493
- removeAlertMessageIfExists(poolsTable);
10494
- if (poolNameInput.attr("data-prev-name")) {
10495
- const poolFolderToRename = poolNameInput.attr("data-prev-name");
10485
+ const poolNameIsValid = evaluateStringAgainstSdsRequirements(
10486
+ poolName,
10487
+ "string-adheres-to-identifier-conventions"
10488
+ );
10489
+ if (!poolNameIsValid) {
10490
+ notyf.open({
10491
+ duration: "3000",
10492
+ type: "error",
10493
+ message: "Pool IDs may not contain spaces or special characters",
10494
+ });
10495
+ return;
10496
+ }
10497
+ removeAlertMessageIfExists(poolsTable);
10498
+ if (poolNameInput.attr("data-prev-name")) {
10499
+ const poolFolderToRename = poolNameInput.attr("data-prev-name");
10496
10500
10497
- sodaJSONObj.renamePool(poolFolderToRename, poolName);
10501
+ sodaJSONObj.renamePool(poolFolderToRename, poolName);
10498
10502
10499
- //refresh the UI to update the dropdowns to avoid having to update select2 dropdowns
10500
- setActiveSubPage("guided-organize-subjects-into-pools-page");
10501
- return;
10502
- } else {
10503
- //Add left border back to subject dropdown cell to separate pool name and subject dropdown
10504
- poolSubjectsDropdownCell.removeClass("remove-left-border");
10503
+ //refresh the UI to update the dropdowns to avoid having to update select2 dropdowns
10504
+ setActiveSubPage("guided-organize-subjects-into-pools-page");
10505
+ return;
10506
+ } else {
10507
+ //Add left border back to subject dropdown cell to separate pool name and subject dropdown
10508
+ poolSubjectsDropdownCell.removeClass("remove-left-border");
10505
10509
10506
- //Add the new pool to sodaJSONObj
10507
- sodaJSONObj.addPool(poolName);
10508
- poolTrashcan.style.display = "block";
10510
+ //Add the new pool to sodaJSONObj
10511
+ sodaJSONObj.addPool(poolName);
10512
+ poolTrashcan.style.display = "block";
10509
10513
10510
- //Add the select2 base element
10511
- poolSubjectsDropdownCell.html(poolSubjectSelectElement);
10514
+ //Add the select2 base element
10515
+ poolSubjectsDropdownCell.html(poolSubjectSelectElement);
10512
10516
10513
- //Get the newly created select2 element
10514
- const newPoolSubjectsSelectElement = document.querySelector(
10515
- `select[name="${poolName}-subjects-selection-dropdown"]`
10516
- );
10517
+ //Get the newly created select2 element
10518
+ const newPoolSubjectsSelectElement = document.querySelector(
10519
+ `select[name="${poolName}-subjects-selection-dropdown"]`
10520
+ );
10517
10521
10518
- //create a select2 dropdown for the pool subjects
10519
- $(newPoolSubjectsSelectElement).select2({
10520
- placeholder: "Select subjects",
10521
- tags: true,
10522
- width: "100%",
10523
- closeOnSelect: false,
10524
- });
10525
- $(newPoolSubjectsSelectElement).on("select2:open", (e) => {
10526
- updatePoolDropdown($(e.currentTarget), poolName);
10527
- });
10528
- $(newPoolSubjectsSelectElement).on("select2:unselect", (e) => {
10529
- const subjectToRemove = e.params.data.id;
10530
- sodaJSONObj.moveSubjectOutOfPool(subjectToRemove, poolName);
10531
- });
10532
- $(newPoolSubjectsSelectElement).on("select2:select", function (e) {
10533
- const selectedSubject = e.params.data.id;
10534
- sodaJSONObj.moveSubjectIntoPool(selectedSubject, poolName);
10535
- });
10536
- }
10537
- poolIdCellToAddNameTo.html(poolNameElement);
10522
+ //create a select2 dropdown for the pool subjects
10523
+ $(newPoolSubjectsSelectElement).select2({
10524
+ placeholder: "Select subjects",
10525
+ tags: true,
10526
+ width: "100%",
10527
+ closeOnSelect: false,
10528
+ });
10529
+ $(newPoolSubjectsSelectElement).on("select2:open", (e) => {
10530
+ updatePoolDropdown($(e.currentTarget), poolName);
10531
+ });
10532
+ $(newPoolSubjectsSelectElement).on("select2:unselect", (e) => {
10533
+ const subjectToRemove = e.params.data.id;
10534
+ sodaJSONObj.moveSubjectOutOfPool(subjectToRemove, poolName);
10535
+ });
10536
+ $(newPoolSubjectsSelectElement).on("select2:select", function (e) {
10537
+ const selectedSubject = e.params.data.id;
10538
+ sodaJSONObj.moveSubjectIntoPool(selectedSubject, poolName);
10539
+ });
10538
10540
}
10541
+ poolIdCellToAddNameTo.html(poolNameElement);
10539
10542
} catch (error) {
10540
10543
notyf.open({
10541
10544
duration: "3000",
0 commit comments