diff --git a/src/ts_source/fileutils.ts b/src/ts_source/fileutils.ts index af42c14..a7c3d86 100644 --- a/src/ts_source/fileutils.ts +++ b/src/ts_source/fileutils.ts @@ -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() { diff --git a/src/ts_source/viewFactory.ts b/src/ts_source/viewFactory.ts index f89ef73..4860c48 100644 --- a/src/ts_source/viewFactory.ts +++ b/src/ts_source/viewFactory.ts @@ -37,15 +37,19 @@ export function buildFileCard(elem: JQuery, 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) + // }); + // } }); }