|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -114,27 +144,24 @@ export class DocumentDirectory {
|
|
|
|
|
|
|
|
|
|
private static walkCards(d: DirectoryNode): Map<string, object[]> {
|
|
|
|
|
let cardsByCategory = new Map<string, object[]>();
|
|
|
|
|
for (let i = 0, l = d.children.length; i < l; i++) {
|
|
|
|
|
let child = d.children[i];
|
|
|
|
|
for (let child of d.children) {
|
|
|
|
|
if (child instanceof DirectoryNode) {
|
|
|
|
|
let dir = child as DirectoryNode;
|
|
|
|
|
if (dir.containsDirectory()) {
|
|
|
|
|
let childDirectories = dir.getDirectories();
|
|
|
|
|
for (let j = 0, k = childDirectories.length; j < k; j++) {
|
|
|
|
|
let dir = childDirectories[j];
|
|
|
|
|
for (let dir of childDirectories) {
|
|
|
|
|
let subCards = DocumentDirectory.walkCards(dir);
|
|
|
|
|
this.mergeMaps(cardsByCategory, subCards);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let sCards = dir.getDocuments();
|
|
|
|
|
let category = dir.getCategory();
|
|
|
|
|
for (let sCard in sCards) {
|
|
|
|
|
let scrd = sCards[sCard];
|
|
|
|
|
for (let sCard of sCards) {
|
|
|
|
|
let cards = cardsByCategory.get(category);
|
|
|
|
|
if (cards === undefined || cards === null) {
|
|
|
|
|
cards = [];
|
|
|
|
|
}
|
|
|
|
|
cards.push(scrd.toCard());
|
|
|
|
|
cards.push(sCard.toCard());
|
|
|
|
|
cardsByCategory.set(category, cards);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
@ -153,8 +180,7 @@ export class DocumentDirectory {
|
|
|
|
|
|
|
|
|
|
private static mergeMaps(a: Map<string, Object[]>, b: Map<string, Object[]>) {
|
|
|
|
|
let keys = Object.keys(b);
|
|
|
|
|
for (let z in keys) {
|
|
|
|
|
let key = keys[z];
|
|
|
|
|
for (let key of keys) {
|
|
|
|
|
let sa = a.get(key)
|
|
|
|
|
if (sa === undefined || sa === null) {
|
|
|
|
|
sa = [];
|
|
|
|
|
@ -192,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() {
|
|
|
|
|
@ -213,12 +238,12 @@ export class FileNode {
|
|
|
|
|
"imagePath": imageName,
|
|
|
|
|
"urlText": this.filePath,
|
|
|
|
|
"altText": "",
|
|
|
|
|
"fileCard": true
|
|
|
|
|
"fileCard": true,
|
|
|
|
|
"open": this.open
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let altKeys = Object.keys(altProps);
|
|
|
|
|
for (let kidx in altKeys) {
|
|
|
|
|
let key = altKeys[kidx];
|
|
|
|
|
for (let key of altKeys) {
|
|
|
|
|
cardObj[key] = altProps[key]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -251,9 +276,9 @@ export class DirectoryNode extends FileNode {
|
|
|
|
|
let stats = fs.lstatSync(filePath);
|
|
|
|
|
if (stats.isDirectory()) {
|
|
|
|
|
let contents = fs.readdirSync(filePath);
|
|
|
|
|
for (let i = 0, l = contents.length; i < l; i++) {
|
|
|
|
|
if (path.extname(contents[i]) === ".json") continue;
|
|
|
|
|
let childPath = path.join(filePath, contents[i]);
|
|
|
|
|
for (let fileName of contents) {
|
|
|
|
|
if (path.extname(fileName) === ".json") continue;
|
|
|
|
|
let childPath = path.join(filePath, fileName);
|
|
|
|
|
let childStats = fs.lstatSync(childPath);
|
|
|
|
|
if (childStats.isDirectory()) {
|
|
|
|
|
this.children.push(new DirectoryNode(childPath, this));
|
|
|
|
|
@ -282,8 +307,7 @@ export class DirectoryNode extends FileNode {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
containsDirectory(): Boolean {
|
|
|
|
|
for (let i = 0, l = this.children.length; i < l; i++) {
|
|
|
|
|
let child = this.children[i];
|
|
|
|
|
for (let child of this.children) {
|
|
|
|
|
if (child instanceof DirectoryNode) return true;
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
|