From 3c4db7d05e6ae2e24529bdbf8f49992cd703442f Mon Sep 17 00:00:00 2001 From: dtookey-at-783322121474 Date: Thu, 10 Dec 2020 15:58:05 -0500 Subject: [PATCH] began implementation of map merge between web and file cards. --- gulpfile.js | 10 +++- package-lock.json | 6 +-- package.json | 1 + src/ts_source/fileutils.ts | 93 +++++++++++++++++++++++++++++++++++++- src/ts_source/themes.ts | 2 +- tests/fileutils-test.ts | 20 ++++++-- 6 files changed, 122 insertions(+), 10 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 27d02a0..679125c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -64,6 +64,11 @@ function scss() { .pipe(dest('build/assets/pages/styles/')); } +function tests() { + return src('tests/*',) + .pipe(dest('build/tests/')); +} + function root() { return src('src/*.js') .pipe(dest('build/')); @@ -115,4 +120,7 @@ exports.clean = clean; exports.default = series(validateConfigSources, conf, style, scss, root, pkg, typescript, dependencies); -exports.runFast = series(validateConfigSources, conf, style, scss, root, pkg) \ No newline at end of file +exports.tests = series(validateConfigSources, conf, style, scss, root, pkg, typescript, dependencies, tests); + +exports.runFast = series(validateConfigSources, conf, style, scss, root, pkg) + diff --git a/package-lock.json b/package-lock.json index a72d8ad..68fb319 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3540,9 +3540,9 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", + "version": "1.3.7", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.7.tgz", + "integrity": "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==", "dev": true }, "interpret": { diff --git a/package.json b/package.json index 5324dba..8e6f233 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "gulp-typescript": "^6.0.0-alpha.1", "gulp-exec": "^5.0.0", "del": "^6.0.0", + "mocha": "^8.2.1", "electron-mocha": "^9.3.1", "chai": "^4.2.0", "nyc": "^15.1.0", diff --git a/src/ts_source/fileutils.ts b/src/ts_source/fileutils.ts index c730e23..1c00146 100644 --- a/src/ts_source/fileutils.ts +++ b/src/ts_source/fileutils.ts @@ -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 { + let cardsByCategory = new Map(); + 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, b: Map) { + 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(" ") + } } diff --git a/src/ts_source/themes.ts b/src/ts_source/themes.ts index a931774..2f8b9ec 100644 --- a/src/ts_source/themes.ts +++ b/src/ts_source/themes.ts @@ -73,4 +73,4 @@ export module Themes { } } -Themes.initTheme(); +Themes.initTheme(); \ No newline at end of file diff --git a/tests/fileutils-test.ts b/tests/fileutils-test.ts index 0513e92..f98ba57 100644 --- a/tests/fileutils-test.ts +++ b/tests/fileutils-test.ts @@ -7,6 +7,7 @@ describe('fileutils', () => { it('DocumentDirectory Constructor fail-on-not-exist', testDocumentDirectoryFailNoExist) it('DocumentDirectory Constructor fail-on-file', testDocumentDirectoryFailFile) it('documentDirectoryConstructor - debug', testDocumentDirectoryConstructor); + it('pass by test', passBy); }); function testDocumentDirectoryFailNoExist() { @@ -24,9 +25,22 @@ function testDocumentDirectoryFailFile() { } function testDocumentDirectoryConstructor() { - let directoryPath = path.join(__dirname, "../src/assets/documents"); + let directoryPath = path.join(__dirname, "../src/assets/resources"); let documents = new DocumentDirectory(directoryPath); - console.log(documents); - console.log((documents.root.getDirectories()[0].children)); + documents.getCards() } + +function passBy(){ + let a = ["a", "b"]; + let b = ["c", "d"]; + testCopy(a, b); + for(let c in a){ + console.log(c); + } +} + + +function testCopy(a: String[], b: String[]){ + a.push(...b); +}