first path of file factory is finished

pull/3/head
David Tookey 5 years ago
parent 844a26e2a1
commit 7200099f12

@ -1,3 +1,6 @@
{ {
".pdf": "pdf-icon.svg" ".pdf": "pdf-icon-100x100.png",
".eps": "image-eps-icon.png",
".png": "image-png-icon.png",
".docx": "word-icon-100x100.png"
} }

@ -1,8 +1,9 @@
{ {
"grid-container": { "grid-container": {
"Resources": {
"description": "Top level resources",
"cards": []
},
"Human Resources": { "Human Resources": {
"description": "Policies, recruitment, onboarding, benefits and compensation", "description": "Policies, recruitment, onboarding, benefits and compensation",
"cards": [ "cards": [
@ -71,8 +72,6 @@
} }
] ]
}, },
"Marketing": { "Marketing": {
"description": "Client-facing media, publications, public relations and advertising", "description": "Client-facing media, publications, public relations and advertising",
"cards": [ "cards": [
@ -141,8 +140,6 @@
} }
] ]
}, },
"Productivity": { "Productivity": {
"description": "Basic work tools, e-mail, calendar, document applications and cloud storage", "description": "Basic work tools, e-mail, calendar, document applications and cloud storage",
"cards": [ "cards": [
@ -176,8 +173,6 @@
} }
] ]
}, },
"Training": { "Training": {
"description": "Career growth, skills development, online courses, manuals and references", "description": "Career growth, skills development, online courses, manuals and references",
"cards": [ "cards": [
@ -225,8 +220,6 @@
} }
] ]
}, },
"Workflow": { "Workflow": {
"description": "Project management, task assignment and status, client information, invoicing and reports", "description": "Project management, task assignment and status, client information, invoicing and reports",
"cards": [ "cards": [

@ -1,5 +1,4 @@
{ {
"description": "Coming soon pdf", "description": "Coming soon pdf",
"imagePath": "../resources/coming-soon.pdf",
"show": true "show": true
} }

@ -0,0 +1,5 @@
{
"title": "JDSfaulkner Logo - EPS",
"description": "Do you need to present the logo in your work? Here's an eps format to use in collateral and merchandise.",
"show": true
}

@ -1,5 +1,3 @@
let path = require('path') let path = require('path')
let fs = require('fs'); let fs = require('fs');
const shell = require('electron').shell; const shell = require('electron').shell;
@ -107,7 +105,7 @@ export class DocumentDirectory {
root: DirectoryNode; root: DirectoryNode;
getCards(): object { getCards(): Map<String, object[]> {
return DocumentDirectory.walkCards(this.root); return DocumentDirectory.walkCards(this.root);
} }
@ -189,6 +187,12 @@ export class FileNode {
return props 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);
} }
@ -198,11 +202,12 @@ export class FileNode {
} }
toCard(): object { toCard(): object {
let altProps = FileNode.loadAltProps(this.filePath) let altProps = FileNode.loadAltProps(this.filePath);
let imageName = FileNode.getImagePathFromDocumentName(this.filePath);
let cardObj = { let cardObj = {
"title": this.getTitle(), "title": this.getTitle(),
"description": "", "description": "",
"imagePath": "", "imagePath": imageName,
"urlText": this.filePath, "urlText": this.filePath,
"altText": "", "altText": "",
"fileCard": true "fileCard": true
@ -244,6 +249,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()) {

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

Loading…
Cancel
Save