Skip to content

Commit

Permalink
refactor: GM file viewer rename file
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm-2112 committed Nov 9, 2023
1 parent 907ebb6 commit 5d295da
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 428 deletions.
54 changes: 27 additions & 27 deletions scripts/others/tab-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,9 @@ const nextPrev = (pageIndex) => {

if (Object.keys(sodaJSONObj["metadata-files"]).length > 0) {
Object.keys(sodaJSONObj["metadata-files"]).forEach((element) => {
let file_name = path.parse(element).name;
let file_name = window.path.parse(element).name;
if (!element.includes("-DELETED")) {
withoutExtMetadataArray.push(path.parse(element).name);
withoutExtMetadataArray.push(window.path.parse(element).name);
}
if (requiredFiles.includes(file_name)) {
let element_index = requiredFiles.indexOf(file_name);
Expand Down Expand Up @@ -1241,7 +1241,7 @@ const create_json_object = (action, sodaJSONObj, root_folder_path) => {
let stats = "";
// Get high level folders and metadata files first
fs.readdirSync(root_folder_path).forEach((file) => {
full_current_path = path.join(root_folder_path, file);
full_current_path = window.path.join(root_folder_path, file);
stats = fs.statSync(full_current_path);
if (stats.isDirectory()) {
if (highLevelFolders.includes(file) && !/(^|\/)\.[^\/\.]/g.test(file)) {
Expand Down Expand Up @@ -1271,8 +1271,8 @@ const create_json_object = (action, sodaJSONObj, root_folder_path) => {
for (folder in sodaJSONObj["dataset-structure"]["folders"]) {
sodaJSONObj["starting-point"][folder] = {};
sodaJSONObj["starting-point"][folder]["path"] = "";
temp_file_path_xlsx = path.join(root_folder_path, folder, "manifest.xlsx");
temp_file_path_csv = path.join(root_folder_path, folder, "manifest.csv");
temp_file_path_xlsx = window.path.join(root_folder_path, folder, "manifest.xlsx");
temp_file_path_csv = window.path.join(root_folder_path, folder, "manifest.csv");
if (fs.existsSync(temp_file_path_xlsx)) {
sodaJSONObj["starting-point"][folder]["path"] = temp_file_path_xlsx;
sodaJSONObj["starting-point"][folder]["manifest"] = excelToJson({
Expand All @@ -1289,7 +1289,7 @@ const create_json_object = (action, sodaJSONObj, root_folder_path) => {
action,
sodaJSONObj["dataset-structure"]["folders"][folder],
folder,
path.join(root_folder_path, folder)
window.path.join(root_folder_path, folder)
);
}
};
Expand Down Expand Up @@ -1319,7 +1319,7 @@ const create_json_object_include_manifest = (action, sodaJSONObj, root_folder_pa
let stats = "";
// Get high level folders and metadata files first
fs.readdirSync(root_folder_path).forEach((file) => {
full_current_path = path.join(root_folder_path, file);
full_current_path = window.path.join(root_folder_path, file);
stats = fs.statSync(full_current_path);
if (stats.isDirectory()) {
if (highLevelFolders.includes(file) && !/(^|\/)\.[^\/\.]/g.test(file)) {
Expand Down Expand Up @@ -1348,8 +1348,8 @@ const create_json_object_include_manifest = (action, sodaJSONObj, root_folder_pa
for (folder in sodaJSONObj["dataset-structure"]["folders"]) {
sodaJSONObj["starting-point"][folder] = {};
sodaJSONObj["starting-point"][folder]["path"] = "";
// temp_file_path_xlsx = path.join(root_folder_path, folder, "manifest.xlsx");
// temp_file_path_csv = path.join(root_folder_path, folder, "manifest.csv");
// temp_file_path_xlsx = window.path.join(root_folder_path, folder, "manifest.xlsx");
// temp_file_path_csv = window.path.join(root_folder_path, folder, "manifest.csv");
// if (fs.existsSync(temp_file_path_xlsx)) {
// sodaJSONObj["starting-point"][folder]["path"] = temp_file_path_xlsx;
// sodaJSONObj["starting-point"][folder]["manifest"] = excelToJson({
Expand All @@ -1365,16 +1365,16 @@ const create_json_object_include_manifest = (action, sodaJSONObj, root_folder_pa
action,
sodaJSONObj["dataset-structure"]["folders"][folder],
folder,
path.join(root_folder_path, folder)
window.path.join(root_folder_path, folder)
);
}
};

// replace any duplicate file names
// Modify for consistency with Pennsieve naming when the update their system
const check_file_name_for_pennsieve_duplicate = (dataset_folder, filepath) => {
file_name = path.parse(filepath).base;
file_extension = path.parse(filepath).ext;
file_name = window.path.parse(filepath).base;
file_extension = window.path.parse(filepath).ext;
var duplicateFileArray = [];

for (var item in dataset_folder) {
Expand All @@ -1385,7 +1385,7 @@ const check_file_name_for_pennsieve_duplicate = (dataset_folder, filepath) => {

var j = 1;
var fileBaseName = file_name;
var originalFileNameWithoutExt = path.parse(fileBaseName).name;
var originalFileNameWithoutExt = window.path.parse(fileBaseName).name;
var fileNameWithoutExt = originalFileNameWithoutExt;
while (fileBaseName in duplicateFileArray) {
fileNameWithoutExt = `${originalFileNameWithoutExt} (${j})`;
Expand All @@ -1412,16 +1412,16 @@ const recursive_structure_create = (
"file-type": "",
"additional-metadata": "",
};
current_file_path = path.join(current_folder_path, file);
current_file_path = window.path.join(current_folder_path, file);
let stats = fs.statSync(current_file_path);
if (
stats.isFile() &&
path.parse(current_file_path).name != "manifest" &&
window.path.parse(current_file_path).name != "manifest" &&
!/(^|\/)\.[^\/\.]/g.test(file) && //not a hidden file
high_level_folder != dataset_folder
) {
if (sodaJSONObj["starting-point"][high_level_folder]["path"] !== "") {
extension = path.extname(sodaJSONObj["starting-point"][high_level_folder]["path"]);
extension = window.path.extname(sodaJSONObj["starting-point"][high_level_folder]["path"]);
if (extension == ".xlsx") {
temp_current_file_path = current_file_path.replace(/\\/g, "/");
root_folder_path = root_folder_path.replace(/\\/g, "/");
Expand Down Expand Up @@ -1578,15 +1578,15 @@ const recursive_structure_create_include_manifest = (
"additional-metadata": "",
};
fs.readdirSync(current_folder_path).forEach((file) => {
current_file_path = path.join(current_folder_path, file);
current_file_path = window.path.join(current_folder_path, file);
let stats = fs.statSync(current_file_path);
if (
stats.isFile() &&
!/(^|\/)\.[^\/\.]/g.test(file) && //not a hidden file
high_level_folder != dataset_folder
) {
if (sodaJSONObj["starting-point"][high_level_folder]["path"] !== "") {
extension = path.extname(sodaJSONObj["starting-point"][high_level_folder]["path"]);
extension = window.path.extname(sodaJSONObj["starting-point"][high_level_folder]["path"]);
if (extension == ".xlsx") {
temp_current_file_path = current_file_path.replace("\\", "/");
relative_path = temp_current_file_path.replace(root_folder_path + "/", "");
Expand Down Expand Up @@ -1724,7 +1724,7 @@ const verify_sparc_folder = (root_folder_path, type) => {
if (type === "local") {
if (
highLevelFolders.includes(item) ||
possible_metadata_files.includes(path.parse(item).name)
possible_metadata_files.includes(window.path.parse(item).name)
) {
valid_dataset = true;
break;
Expand All @@ -1734,7 +1734,7 @@ const verify_sparc_folder = (root_folder_path, type) => {
} else {
if (
highLevelFolders.includes(item) ||
possible_metadata_files.includes(path.parse(item).name) ||
possible_metadata_files.includes(window.path.parse(item).name) ||
item.substring(0, 1) != "."
) {
valid_dataset = true;
Expand Down Expand Up @@ -2575,8 +2575,8 @@ async function switchMetadataSubmissionQuestion() {

// 5. manifest
async function switchMetadataManifestQuestion() {
var userpath1 = path.join(homeDirectory, "SODA", "SODA Manifest Files");
var userpath2 = path.join(homeDirectory, "SODA", "manifest_files");
var userpath1 = window.path.join(homeDirectory, "SODA", "SODA Manifest Files");
var userpath2 = window.path.join(homeDirectory, "SODA", "manifest_files");
if (
$("#Question-prepare-manifest-2").hasClass("show") ||
$("#Question-prepare-manifest-3").hasClass("show")
Expand Down Expand Up @@ -2974,7 +2974,7 @@ const populateMetadataObject = (optionList, metadataFilePath, metadataFile, obje
return;
}
if (!optionList.includes(metadataFilePath)) {
var mypath = path.basename(metadataFilePath);
var mypath = window.path.basename(metadataFilePath);
object["metadata-files"][mypath] = {
type: "local",
action: ["new"],
Expand All @@ -2995,7 +2995,7 @@ const populateMetadataObject = (optionList, metadataFilePath, metadataFile, obje
/// function to populate/reload Organize dataset UI when users move around between tabs and make changes
// (to high-level folders)
const populateOrganizeDatasetUI = (currentLocation, datasetFolder) => {
var baseName = path.basename(datasetFolder);
var baseName = window.path.basename(datasetFolder);
currentLocation = {
type: "local",
folders: {},
Expand All @@ -3005,8 +3005,8 @@ const populateOrganizeDatasetUI = (currentLocation, datasetFolder) => {

var myitems = fs.readdirSync(datasetFolder);
myitems.forEach((element) => {
var statsObj = fs.statSync(path.join(datasetFolder, element));
var addedElement = path.join(datasetFolder, element);
var statsObj = fs.statSync(window.path.join(datasetFolder, element));
var addedElement = window.path.join(datasetFolder, element);
if (statsObj.isDirectory()) {
currentLocation["folders"][element] = {
type: "local",
Expand Down Expand Up @@ -3590,7 +3590,7 @@ const saveSODAJSONProgress = (progressFileName) => {
log.error(error);
console.log(error);
}
var filePath = path.join(progressFilePath, progressFileName + ".json");
var filePath = window.path.join(progressFilePath, progressFileName + ".json");
// record all information listed in SODA JSON Object before saving
updateJSONObjectProgress();
// delete sodaJSONObj["dataset-structure"] value that was added only for the Preview tree view
Expand Down
3 changes: 3 additions & 0 deletions src/preload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ if (process.contextIsolated) {
},
extname: (filepath) => {
return path.extname(filepath)
},
parse: (filepath) => {
return path.parse(filepath)
}
})
contextBridge.exposeInMainWorld('log', {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import './scripts/others/renderer'
import './scripts/metadata-files/submission'
import './scripts/manage-dataset/manage-dataset'
import './scripts/organize-dataset/organizeDS'
import './scripts/organize-dataset/curate-functions'

// Application Lotties
import './assets/lotties/activate-lotties'
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/src/scripts/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ const updateDatasetList = (bfaccount) => {
}, 100)
}

window.removeOptions = (selectbox) => {
for (let i = selectbox.options.length - 1; i >= 0; i--) {
selectbox.remove(i);
}
};

// Function to add options to dropdown list
window.addOption = (selectbox, text, value) => {
var opt = document.createElement("OPTION");
opt.text = text;
opt.value = value;
selectbox.options.add(opt);
}



// global variables to be modularized
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/src/scripts/guided-mode/guided-curate-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ const guidedModifyPennsieveFolder = (folderJSONPath, action) => {
folderJSONPath["action"].push("deleted");
}

recursive_mark_sub_files_deleted(folderJSONPath, "delete");
window.recursive_mark_sub_files_deleted(folderJSONPath, "delete");
}
if (action === "restore") {
folderJSONPath["action"] = folderJSONPath["action"].filter(
(action) => action !== "recursive_deleted" || action !== "deleted"
);
recursive_mark_sub_files_deleted(folderJSONPath, "restore");
window.recursive_mark_sub_files_deleted(folderJSONPath, "restore");
}
};

Expand All @@ -237,7 +237,7 @@ const guidedMovePennsieveFolder = (movedFolderName, folderJSONPath, newFolderJSO
}

folderJSONPath["action"] = ["existing", "moved"];
addMovedRecursively(folderJSONPath);
window.addMovedRecursively(folderJSONPath);
newFolderJSONPath["folders"][movedFolderName] = folderJSONPath;
};

Expand Down Expand Up @@ -3891,7 +3891,7 @@ const guidedShowTreePreview = (new_dataset_name, targetElement) => {
};
}

const guidedJsTreePreviewData = create_child_node(
const guidedJsTreePreviewData = window.create_child_node(
dsJsonObjCopy,
new_dataset_name,
"folder",
Expand Down
Loading

0 comments on commit 5d295da

Please sign in to comment.