|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import {Configurator, FileUtils} from './fileutils'
|
|
|
|
|
import {Configurator, DocumentDirectory, FileUtils} from './fileutils'
|
|
|
|
|
import {loadTemplate, loadTemplateSingle} from "./templates"
|
|
|
|
|
import * as path from "path";
|
|
|
|
|
|
|
|
|
|
const shell = require('electron').shell;
|
|
|
|
|
|
|
|
|
|
@ -18,29 +19,43 @@ export class CardModel {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function buildFileCard(filePath: string, elem: Element, append: boolean = false, $: any = require('jquery')) {
|
|
|
|
|
// let model = new CardModel(getImagePathFromDocumentName(filePath), fileNameToPrettyString(filePath));
|
|
|
|
|
// loadTemplateSingle("file-card.mustache", model, (content: string, id: string) => {
|
|
|
|
|
// let snip = $(content);
|
|
|
|
|
// let container = $("#" + elem.id);
|
|
|
|
|
//
|
|
|
|
|
// if (append) {
|
|
|
|
|
// container.append(snip);
|
|
|
|
|
// } else {
|
|
|
|
|
// container.empty().append(snip);
|
|
|
|
|
// }
|
|
|
|
|
// setTimeout(() => {
|
|
|
|
|
// $(`#${id}`).on("click", () => {
|
|
|
|
|
// launchDocument(filePath);
|
|
|
|
|
// });
|
|
|
|
|
// }, 1); //for some reason we have to let the dom breathe before it will let us do this?
|
|
|
|
|
// });
|
|
|
|
|
export function buildFileCard(elem: JQuery<HTMLElement>, obj, append: boolean = false, $: any = require('jquery')) {
|
|
|
|
|
console.log(obj);
|
|
|
|
|
let model = new CardModel(
|
|
|
|
|
obj["title"],
|
|
|
|
|
obj["description"],
|
|
|
|
|
FileUtils.getPathToImage(obj["imagePath"]),
|
|
|
|
|
obj["urlText"]
|
|
|
|
|
);
|
|
|
|
|
model["show"] = obj["show"];
|
|
|
|
|
|
|
|
|
|
loadTemplateSingle("web-card.mustache", model, (content: string, id: string) => {
|
|
|
|
|
if (append) {
|
|
|
|
|
elem.append(content);
|
|
|
|
|
} else {
|
|
|
|
|
elem.html(content)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model["show"] !== undefined) {
|
|
|
|
|
$(`#${id}`).on("click", () => {
|
|
|
|
|
console.log("showing")
|
|
|
|
|
shell.showItemInFolder(model.resourcePath)
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$(`#${id}`).on("click", () => {
|
|
|
|
|
console.log("opening")
|
|
|
|
|
shell.openItem(model.resourcePath)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function buildWebCardsFromConfig(configName: string) {
|
|
|
|
|
let elementConfig = Configurator.loadAppConfig(configName);
|
|
|
|
|
let $ = require('jquery')
|
|
|
|
|
let containers = Object.keys(elementConfig);
|
|
|
|
|
let directoryPath = path.join(__dirname, "../assets/resources");
|
|
|
|
|
let fileCards = new DocumentDirectory(directoryPath).getCards();
|
|
|
|
|
for (let i = 0, l = containers.length; i < l; i++) {
|
|
|
|
|
|
|
|
|
|
let containerName = containers[i];
|
|
|
|
|
@ -48,11 +63,15 @@ export function buildWebCardsFromConfig(configName: string) {
|
|
|
|
|
let containerElem = $(`#${containerName}`);
|
|
|
|
|
|
|
|
|
|
let containerCategories = Object.keys(containerObject);
|
|
|
|
|
containerCategories.push("Resources");
|
|
|
|
|
|
|
|
|
|
for (let j = 0, m = containerCategories.length; j < m; j++) {
|
|
|
|
|
let categoryMetaObjectKey = containerCategories[j];
|
|
|
|
|
let categoryMetaObject = containerObject[categoryMetaObjectKey];
|
|
|
|
|
|
|
|
|
|
let contentList = categoryMetaObject["cards"];//should be array of objects to render
|
|
|
|
|
let files = fileCards.get(categoryMetaObjectKey);
|
|
|
|
|
|
|
|
|
|
let categoryDescription = categoryMetaObject["description"];
|
|
|
|
|
let categoryKey = categoryMetaObjectKey.replace(/[\s,]/ig, '-').toLowerCase();
|
|
|
|
|
let categoryObject = {
|
|
|
|
|
@ -84,10 +103,17 @@ export function buildWebCardsFromConfig(configName: string) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (let j in files) {
|
|
|
|
|
let file = files[j];
|
|
|
|
|
buildFileCard(view, file, true, $)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let j = 0, m = contentList.length; j < m; j++) {
|
|
|
|
|
let content = contentList[j];
|
|
|
|
|
buildWebCard(view, content, true, $);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -128,12 +154,6 @@ function fileNameToPrettyString(fileName: string): string {
|
|
|
|
|
return buffer.join('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getImagePathFromDocumentName(name: string): string {
|
|
|
|
|
let ext = FileUtils.getFileExtension(name);
|
|
|
|
|
let thumbnail = Configurator.getFileExtensionToImageMap()[ext];
|
|
|
|
|
return FileUtils.getPathToImage(thumbnail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function launchDocument(filename: string) {
|
|
|
|
|
let fullPath = FileUtils.getPathToDocument(filename);
|
|
|
|
|
shell.openItem(fullPath);
|
|
|
|
|
|