began implementation of map merge between web and file cards.

pull/3/head
dtookey-at-783322121474 5 years ago
parent ea7ff55eae
commit 3c4db7d05e

@ -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)
exports.tests = series(validateConfigSources, conf, style, scss, root, pkg, typescript, dependencies, tests);
exports.runFast = series(validateConfigSources, conf, style, scss, root, pkg)

6
package-lock.json generated

@ -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": {

@ -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",

@ -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(" ")
}
}

@ -73,4 +73,4 @@ export module Themes {
}
}
Themes.initTheme();
Themes.initTheme();

@ -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);
}

Loading…
Cancel
Save