modified file cards to place a copy of the employee resource in the my documents folder of the user's home directory and open the directory instead of opening the canonical file

RebeccaBranch
David Tookey 5 years ago
parent a89f9b728e
commit 14db1cd007

@ -1,5 +1,6 @@
let path = require('path')
let fs = require('fs');
let os = require('os');
const shell = require('electron').shell;
let fileExtensionToImage: object;
@ -59,6 +60,7 @@ export module FileUtils {
export function getPathToView(templateName: string): string {
return path.join(getPathToAssets(), "views", templateName + ".mustache")
}
export function getPathToPage(pageName: string): string {
return path.join(getPathToAssets(), "pages", pageName)
}
@ -95,6 +97,34 @@ export module FileUtils {
fs.mkdirSync(dirPath);
}
}
export function showFileInDir(resourcePath: string) {
let localFile = copyFileToUserDocuments(resourcePath);
shell.showItemInFolder(localFile);
}
/**
* @param resourcePath pathlike of system resource
* @private
* @returns pathlike of local user resource
*/
function copyFileToUserDocuments(resourcePath: string): string {
let fileName = path.basename(resourcePath);
let userFilePath = getPathToUserDocumentDir(fileName);
if(!fs.existsSync(userFilePath)){
fs.copyFileSync(resourcePath, userFilePath);
}
return userFilePath;
}
function getPathToUserDocumentDir(fileName: string): string {
let homeDir = os.homedir();
let parent = path.join(homeDir, "Documents", "Employee Resources");
if(!fs.existsSync(parent)){
fs.mkdirSync(parent);
}
return path.join(parent, fileName);
}
}
@ -188,8 +218,7 @@ export class FileNode {
private static getImagePathFromDocumentName(name: string): string {
let ext = FileUtils.getFileExtension(name);
let thumbnail = Configurator.getFileExtensionToImageMap()[ext];
return thumbnail;
return Configurator.getFileExtensionToImageMap()[ext];
}
open() {

@ -37,15 +37,19 @@ export function buildFileCard(elem: JQuery<HTMLElement>, obj, append: boolean =
elem.html(content)
}
if (model["show"] !== undefined) {
$(`#${id}`).on("click", () => {
shell.showItemInFolder(model.resourcePath)
});
} else {
$(`#${id}`).on("click", () => {
shell.openItem(model.resourcePath)
});
}
$(`#${id}`).on("click", () => {
FileUtils.showFileInDir(model.resourcePath);
});
// if (model["show"] !== undefined) {
// $(`#${id}`).on("click", () => {
// shell.showItemInFolder(model.resourcePath)
// });
// } else {
// $(`#${id}`).on("click", () => {
// shell.openItem(model.resourcePath)
// });
// }
});
}

Loading…
Cancel
Save