|
|
|
@ -2,7 +2,6 @@ let path = require('path')
|
|
|
|
let fs = require('fs');
|
|
|
|
let fs = require('fs');
|
|
|
|
const shell = require('electron').shell;
|
|
|
|
const shell = require('electron').shell;
|
|
|
|
let fileExtensionToImage: object;
|
|
|
|
let fileExtensionToImage: object;
|
|
|
|
import {Themes} from "./themes";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export enum ConfigPaths {
|
|
|
|
export enum ConfigPaths {
|
|
|
|
ApplicationConfigName = "dashboard.json",
|
|
|
|
ApplicationConfigName = "dashboard.json",
|
|
|
|
@ -49,7 +48,7 @@ export module Configurator {
|
|
|
|
|
|
|
|
|
|
|
|
function buildDefaultConfig(): object {
|
|
|
|
function buildDefaultConfig(): object {
|
|
|
|
let userConfig = {};
|
|
|
|
let userConfig = {};
|
|
|
|
userConfig['theme'] = Themes.AppTheme.Dark;
|
|
|
|
userConfig['theme'] = "theme-dark";
|
|
|
|
saveUserConfig(ConfigPaths.UserConfigName, userConfig)
|
|
|
|
saveUserConfig(ConfigPaths.UserConfigName, userConfig)
|
|
|
|
return userConfig
|
|
|
|
return userConfig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -109,6 +108,66 @@ export class DocumentDirectory {
|
|
|
|
|
|
|
|
|
|
|
|
root: DirectoryNode;
|
|
|
|
root: DirectoryNode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getCards(): Map<String, object[]> {
|
|
|
|
|
|
|
|
return DocumentDirectory.walkCards(this.root);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
let cards = cardsByCategory.get(category);
|
|
|
|
|
|
|
|
if (cards === undefined || cards === null) {
|
|
|
|
|
|
|
|
cards = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cards.push(scrd.toCard());
|
|
|
|
|
|
|
|
cardsByCategory.set(category, cards);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let category = (child.parent as DirectoryNode).getCategory();
|
|
|
|
|
|
|
|
let cards = cardsByCategory.get(category);
|
|
|
|
|
|
|
|
if (cards === undefined || cards === null) {
|
|
|
|
|
|
|
|
cards = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cards.push(child.toCard());
|
|
|
|
|
|
|
|
cardsByCategory.set(category, cards);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cardsByCategory;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
let sa = a.get(key)
|
|
|
|
|
|
|
|
if (sa === undefined || sa === null) {
|
|
|
|
|
|
|
|
sa = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let sb = b.get(key)
|
|
|
|
|
|
|
|
if (sb === undefined) {
|
|
|
|
|
|
|
|
sb = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sa.push(...sb);
|
|
|
|
|
|
|
|
a[key] = sa;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export class FileNode {
|
|
|
|
export class FileNode {
|
|
|
|
@ -121,10 +180,63 @@ export class FileNode {
|
|
|
|
this.parent = parent;
|
|
|
|
this.parent = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static loadAltProps(path: String): object {
|
|
|
|
|
|
|
|
let props = {};
|
|
|
|
|
|
|
|
let jsonPath = path + ".json"
|
|
|
|
|
|
|
|
if (fs.existsSync(jsonPath)) {
|
|
|
|
|
|
|
|
let raw = fs.readFileSync(jsonPath);
|
|
|
|
|
|
|
|
props = JSON.parse(raw.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return props
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static getImagePathFromDocumentName(name: string): string {
|
|
|
|
|
|
|
|
let ext = FileUtils.getFileExtension(name);
|
|
|
|
|
|
|
|
let thumbnail = Configurator.getFileExtensionToImageMap()[ext];
|
|
|
|
|
|
|
|
return thumbnail;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
open() {
|
|
|
|
open() {
|
|
|
|
shell.openItem(this.filePath);
|
|
|
|
shell.openItem(this.filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
show() {
|
|
|
|
|
|
|
|
shell.showItemInFolder(this.filePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toCard(): object {
|
|
|
|
|
|
|
|
let altProps = FileNode.loadAltProps(this.filePath);
|
|
|
|
|
|
|
|
let imageName = FileNode.getImagePathFromDocumentName(this.filePath);
|
|
|
|
|
|
|
|
let cardObj = {
|
|
|
|
|
|
|
|
"title": this.getTitle(),
|
|
|
|
|
|
|
|
"description": "",
|
|
|
|
|
|
|
|
"imagePath": imageName,
|
|
|
|
|
|
|
|
"urlText": this.filePath,
|
|
|
|
|
|
|
|
"altText": "",
|
|
|
|
|
|
|
|
"fileCard": true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let altKeys = Object.keys(altProps);
|
|
|
|
|
|
|
|
for (let kidx in altKeys) {
|
|
|
|
|
|
|
|
let key = altKeys[kidx];
|
|
|
|
|
|
|
|
cardObj[key] = altProps[key]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cardObj
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getTitle(): String {
|
|
|
|
|
|
|
|
let name = path.basename(this.filePath);
|
|
|
|
|
|
|
|
let ext = path.extname(name);
|
|
|
|
|
|
|
|
let cName = name.replace(ext, "");
|
|
|
|
|
|
|
|
cName = cName.replace(/[\-._]/ig, " ")
|
|
|
|
|
|
|
|
return `${cName} (${ext.substr(1).toUpperCase()})`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isDescriptor() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static compare(a: FileNode, b: FileNode): number {
|
|
|
|
static compare(a: FileNode, b: FileNode): number {
|
|
|
|
return a.filePath.localeCompare(b.filePath);
|
|
|
|
return a.filePath.localeCompare(b.filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -140,6 +252,7 @@ export class DirectoryNode extends FileNode {
|
|
|
|
if (stats.isDirectory()) {
|
|
|
|
if (stats.isDirectory()) {
|
|
|
|
let contents = fs.readdirSync(filePath);
|
|
|
|
let contents = fs.readdirSync(filePath);
|
|
|
|
for (let i = 0, l = contents.length; i < l; i++) {
|
|
|
|
for (let i = 0, l = contents.length; i < l; i++) {
|
|
|
|
|
|
|
|
if (path.extname(contents[i]) === ".json") continue;
|
|
|
|
let childPath = path.join(filePath, contents[i]);
|
|
|
|
let childPath = path.join(filePath, contents[i]);
|
|
|
|
let childStats = fs.lstatSync(childPath);
|
|
|
|
let childStats = fs.lstatSync(childPath);
|
|
|
|
if (childStats.isDirectory()) {
|
|
|
|
if (childStats.isDirectory()) {
|
|
|
|
@ -167,6 +280,25 @@ export class DirectoryNode extends FileNode {
|
|
|
|
return x instanceof DirectoryNode
|
|
|
|
return x instanceof DirectoryNode
|
|
|
|
}) as DirectoryNode[]
|
|
|
|
}) as DirectoryNode[]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
containsDirectory(): Boolean {
|
|
|
|
|
|
|
|
for (let i = 0, l = this.children.length; i < l; i++) {
|
|
|
|
|
|
|
|
let child = this.children[i];
|
|
|
|
|
|
|
|
if (child instanceof DirectoryNode) return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getCategory(): String {
|
|
|
|
|
|
|
|
let rawName = path.basename(this.filePath);
|
|
|
|
|
|
|
|
let parts = rawName.split("-");
|
|
|
|
|
|
|
|
for (let i = 0, l = parts.length; i < l; i++) {
|
|
|
|
|
|
|
|
let part = parts[i].split('');
|
|
|
|
|
|
|
|
part[0] = part[0].toUpperCase();
|
|
|
|
|
|
|
|
parts[i] = part.join('')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return parts.join(" ")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|