|
|
|
|
@ -2,7 +2,6 @@ let path = require('path')
|
|
|
|
|
let fs = require('fs');
|
|
|
|
|
const shell = require('electron').shell;
|
|
|
|
|
let fileExtensionToImage: object;
|
|
|
|
|
import {Themes} from "./themes";
|
|
|
|
|
|
|
|
|
|
export enum ConfigPaths {
|
|
|
|
|
ApplicationConfigName = "dashboard.json",
|
|
|
|
|
@ -49,7 +48,7 @@ export module Configurator {
|
|
|
|
|
|
|
|
|
|
function buildDefaultConfig(): object {
|
|
|
|
|
let userConfig = {};
|
|
|
|
|
userConfig['theme'] = Themes.AppTheme.Dark;
|
|
|
|
|
userConfig['theme'] = "theme-dark";
|
|
|
|
|
saveUserConfig(ConfigPaths.UserConfigName, userConfig)
|
|
|
|
|
return userConfig
|
|
|
|
|
}
|
|
|
|
|
@ -106,6 +105,57 @@ export class DocumentDirectory {
|
|
|
|
|
|
|
|
|
|
root: DirectoryNode;
|
|
|
|
|
|
|
|
|
|
getCards(): 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()
|
|
|
|
|
} 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 || sa === null) {
|
|
|
|
|
sb = [];
|
|
|
|
|
}
|
|
|
|
|
sa.push(...sb);
|
|
|
|
|
a[key] = sa;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class FileNode {
|
|
|
|
|
@ -122,6 +172,26 @@ export class FileNode {
|
|
|
|
|
shell.openItem(this.filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toCard(): object {
|
|
|
|
|
let cardObj = {
|
|
|
|
|
"title": this.getTitle(),
|
|
|
|
|
"description": "",
|
|
|
|
|
"imagePath": "",
|
|
|
|
|
"urlText": this.filePath,
|
|
|
|
|
"altText": ""
|
|
|
|
|
}
|
|
|
|
|
return cardObj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getTitle(): String {
|
|
|
|
|
let name = path.basename(this.filePath);
|
|
|
|
|
return name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isDescriptor() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static compare(a: FileNode, b: FileNode): number {
|
|
|
|
|
return a.filePath.localeCompare(b.filePath);
|
|
|
|
|
}
|
|
|
|
|
@ -164,6 +234,25 @@ export class DirectoryNode extends FileNode {
|
|
|
|
|
return x instanceof 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(" ")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|