Skip to content

Commit

Permalink
wip: navigation code reorganized - nav entry point moved
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Feb 10, 2025
1 parent bdbdf7c commit 7a43e2d
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 215 deletions.
3 changes: 2 additions & 1 deletion src/renderer/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import "./assets/nav";
import "./scripts/client";
import "./scripts/globals";
import "./scripts/guided-mode/buttons/radioButtons";
import "./scripts/guided-mode/pageNavigation/pageLoading";
import "./scripts/guided-mode/pages/pageLoading";
import "./scripts/guided-mode/pages/curationPreparation/openPage";
import "./scripts/guided-mode/pages/openPage";
import "./scripts/guided-mode/guided-curate-dataset";
import "./scripts/guided-mode/pages/navigate";
import "./scripts/others/renderer";
import "./scripts/metadata-files/submission";
import "./scripts/manage-dataset/manage-dataset";
Expand Down
190 changes: 2 additions & 188 deletions src/renderer/src/scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// // sourcery skip: merge-nested-ifs

import { existingDataset, modifyDataset } from "../../assets/lotties/lotties";
import { guidedSetNavLoadingState } from "./pageNavigation/pageLoading";
import { guidedSetNavLoadingState } from "./pages/pageLoading";
import { guidedSaveProgress, savePageChanges } from "./pages/savePageChanges";
import { openPage } from "./pages/openPage";
import {
getNonSkippedGuidedModePages,
guidedResetSkippedPages,
guidedSkipPage,
guidedUnSkipPage,
} from "./pageNavigation/pageSkipping";
} from "./pages/pageSkipping";
import { resetLazyLoading, guidedUnLockSideBar } from "../../assets/nav";
import determineDatasetLocation from "../analytics/analytics-utils";
import { clientError, userErrorMessage } from "../others/http-error-handler/error-handler";
Expand Down Expand Up @@ -532,65 +532,6 @@ for (const infoDropdown of Array.from(infoDropdowns)) {
});
}

const guidedSaveAndExit = async () => {
if (!window.sodaJSONObj["digital-metadata"]["name"]) {
// If a progress file has not been created, then we don't need to save anything
guidedTransitionToHome();
return;
}
const { value: returnToGuidedHomeScreen } = await Swal.fire({
title: "Are you sure?",
text: `Exiting Guided Mode will discard any changes you have made on the
current page. You will be taken back to the homescreen, where you will be able
to continue the current dataset you are curating which will be located under datasets
in progress.`,
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Exit guided mode",
heightAuto: false,
backdrop: "rgba(0,0,0,0.4)",
});
if (returnToGuidedHomeScreen) {
const currentPageID = window.CURRENT_PAGE.id;

try {
await savePageChanges(currentPageID);
} catch (error) {
const pageWithErrorName = window.CURRENT_PAGE.dataset.pageName;

const { value: continueWithoutSavingCurrPageChanges } = await Swal.fire({
title: "The current page was not able to be saved before exiting",
html: `The following error${
error.length > 1 ? "s" : ""
} occurred when attempting to save the ${pageWithErrorName} page:
<br />
<br />
<ul>
${error.map((error) => `<li class="text-left">${error.message}</li>`).join("")}
</ul>
<br />
Would you like to exit without saving the changes to the current page?`,
icon: "info",
showCancelButton: true,
confirmButtonText: "Yes, exit without saving",
cancelButtonText: "No, address errors before saving",
focusCancel: true,
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
width: 700,
});
if (continueWithoutSavingCurrPageChanges) {
guidedTransitionToHome();
} else {
return;
}
}
guidedTransitionToHome();
}
};

//Initialize description tagify variables as null
//to make them accessible to functions outside of $(document).ready
let guidedDatasetKeywordsTagify = null;
Expand Down Expand Up @@ -657,21 +598,6 @@ const guidedTransitionFromHome = async () => {
guidedResetSkippedPages();
};

const guidedTransitionToHome = () => {
guidedUnLockSideBar();
window.guidedPrepareHomeScreen();

document.getElementById("guided-home").classList.remove("hidden");
// Hide all of the parent tabs
const guidedParentTabs = Array.from(document.querySelectorAll(".guided--parent-tab"));
for (const guidedParentTab of guidedParentTabs) {
guidedParentTab.classList.add("hidden");
}
window.CURRENT_PAGE = undefined;

document.getElementById("guided-footer-div").classList.add("hidden");
};

const readDirAsync = async (path) => {
let result = await window.fs.readdir(path);
return result;
Expand Down Expand Up @@ -10023,118 +9949,6 @@ $("#guided-save-banner-image").click(async () => {
}
});

const getNextPageNotSkipped = (currentPageID) => {
const parentContainer = document.getElementById(currentPageID).closest(".guided--parent-tab");
const siblingPages = getNonSkippedGuidedModePages(parentContainer).map((page) => page.id);

const currentPageIndex = siblingPages.indexOf(currentPageID);
if (currentPageIndex != siblingPages.length - 1) {
return document.getElementById(siblingPages[currentPageIndex + 1]);
} else {
const nextParentContainer = parentContainer.nextElementSibling;
return getNonSkippedGuidedModePages(nextParentContainer)[0];
}
};

//next button click handler
$("#guided-next-button").on("click", async function () {
console.log("Next button clicked");
//Get the ID of the current page to handle actions on page leave (next button pressed)
window.pageBeingLeftID = window.CURRENT_PAGE.id;

if (window.pageBeingLeftID === "guided-dataset-generation-tab") {
guidedUnSkipPage("guided-dataset-dissemination-tab");
await openPage("guided-dataset-dissemination-tab");
return;
}

try {
console.log("About to save");
await savePageChanges(window.pageBeingLeftID);
console.log("Past save changes");

//Mark page as completed in JSONObj so we know what pages to load when loading local saves
//(if it hasn't already been marked complete)
if (!window.sodaJSONObj["completed-tabs"].includes(window.pageBeingLeftID)) {
window.sodaJSONObj["completed-tabs"].push(window.pageBeingLeftID);
}

//NAVIGATE TO NEXT PAGE + CHANGE ACTIVE TAB/SET ACTIVE PROGRESSION TAB
//if more tabs in parent tab, go to next tab and update capsule
let targetPage = getNextPageNotSkipped(window.CURRENT_PAGE.id);
let targetPageID = targetPage.id;

console.log("Navigating to next page", targetPageID);

await openPage(targetPageID);
} catch (error) {
window.log.error(error);
if (Array.isArray(error)) {
error.map((error) => {
// get the total number of words in error.message
if (error.type === "notyf") {
window.notyf.open({
duration: "7000",
type: "error",
message: error.message,
});
}

if (error.type === "swal") {
Swal.fire({
icon: "error",
title: error.title,
html: error.message,
width: 600,
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
confirmButtonText: `OK`,
focusConfirm: true,
allowOutsideClick: false,
});
}
});
}
}
});

// Save and exit button click handlers
document.getElementById("guided-button-save-and-exit").addEventListener("click", async () => {
await guidedSaveAndExit();
});

const getPrevPageNotSkipped = (currentPageID) => {
const parentContainer = document.getElementById(currentPageID).closest(".guided--parent-tab");
const siblingPages = getNonSkippedGuidedModePages(parentContainer).map((page) => page.id);
const currentPageIndex = siblingPages.indexOf(currentPageID);
if (currentPageIndex != 0) {
return document.getElementById(siblingPages[currentPageIndex - 1]);
} else {
const prevParentContainer = parentContainer.previousElementSibling;
const prevParentContainerPages = getNonSkippedGuidedModePages(prevParentContainer);
return prevParentContainerPages[prevParentContainerPages.length - 1];
}
};

//back button click handler
$("#guided-back-button").on("click", async () => {
window.pageBeingLeftID = window.CURRENT_PAGE.id;
const targetPage = getPrevPageNotSkipped(window.pageBeingLeftID);

// If the target page when clicking the back button does not exist, then we are on the first not skipped page.
// In this case, we want to save and exit guided mode.
if (!targetPage) {
await guidedSaveAndExit();
return;
}

// Get the id of the target page
const targetPageID = targetPage.id;

// open the target page
await openPage(targetPageID);
});

//tagify initializations
const guidedOtherFundingSourcesInput = document.getElementById("guided-ds-other-funding");
guidedOtherFundingsourcesTagify = new Tagify(guidedOtherFundingSourcesInput, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import api from "../../../others/api/api";
import { clientError } from "../../../others/http-error-handler/error-handler";
import { guidedShowOptionalRetrySwal } from "../../swals/helperSwals";
import { userErrorMessage } from "../../../others/http-error-handler/error-handler";
import { setPageLoadingState } from "../../pageNavigation/pageLoading";
import { setPageLoadingState } from "../pageLoading.js";
import { setSelectedEntities } from "../../../../stores/slices/datasetContentSelectorSlice.js";
import client from "../../../client";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { guidedSkipPage, guidedUnSkipPage } from "../../pageNavigation/pageSkipping";
import { guidedSkipPage, guidedUnSkipPage } from "../pageSkipping";
import useGlobalStore from "../../../../stores/globalStore";

let homeDir = await window.electron.ipcRenderer.invoke("get-app-path", "home");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { guidedSkipPage, guidedUnSkipPage } from "../pageSkipping";

export const openPageDatasetStructure = async (targetPageID) => {
if (targetPageID === "guided-dataset-structure-intro-tab") {
// Handle whether or not the spreadsheet importation page should be skipped
// Note: this is done here to centralize the logic for skipping the page
// The page is unskipped only if the user has not added any subjects,
// indicated that they will be adding subjects, and the user is not starting from Pennsieve
if (
window.getExistingSubjectNames().length === 0 &&
window.sodaJSONObj["starting-point"]["type"] != "bf" &&
window.sodaJSONObj["button-config"]["dataset-contains-subjects"] === "yes"
) {
guidedUnSkipPage("guided-subject-structure-spreadsheet-importation-tab");
} else {
guidedSkipPage("guided-subject-structure-spreadsheet-importation-tab");
}
}
};
Loading

0 comments on commit 7a43e2d

Please sign in to comment.