Added config concept

This commit is contained in:
Arne
2023-04-02 21:59:10 +02:00
parent 7611f10b1c
commit 11bdecc6d3
7 changed files with 34 additions and 14 deletions

View File

5
config.json Normal file
View File

@@ -0,0 +1,5 @@
{
"filePaths": [
"./assets"
]
}

View File

@@ -9,7 +9,7 @@
<mat-form-field appearance="fill" class="doors">
<mat-label>Deuren</mat-label>
<mat-select [(value)]="door" [disabled]="!project">
<mat-select [(value)]="door" [disabled]="!project" (selectionChange)="focus()">
<mat-option *ngFor="let doorOption of doors" [value]="doorOption">
{{ doorOption?.nr }}
</mat-option>

View File

@@ -35,7 +35,7 @@ export class MultiplesComponent implements OnInit {
);
this.electronIpc.receive<void>(WindowApiConst.PRINT_OUTPUT, () => {
console.log('received');
this.focus();
});
this.refreshProjects();
@@ -45,14 +45,9 @@ export class MultiplesComponent implements OnInit {
this.electronIpc.send(WindowApiConst.FILELIST_INPUT, 'refresh');
}
loadProject(project: string): void {
this.electronIpc.send(WindowApiConst.PROJECT_INPUT, project);
}
projectChange(event: any): void {
this.door = undefined;
console.log(event);
// this.project = event.value;
this.project = this.projects.find(x => x.name === event.value);
this.electronIpc.send(WindowApiConst.PROJECT_INPUT, this.project);
}
@@ -75,7 +70,10 @@ export class MultiplesComponent implements OnInit {
focus(): void {
setTimeout(() => {
// eslint-disable-next-line unicorn/prefer-query-selector
document.getElementById('textsearch')?.focus();
const input = document.getElementById('textsearch');
(input as any).value = "";
input?.focus();
}, 0);
}
}

View File

@@ -7,6 +7,7 @@ import { FileListService } from '../services/file-list-service';
import { PrintService } from './../services/print-service';
import { Logger } from '../utils/logger';
import { DoorService } from '../services/door-service';
import { readFile } from 'node:fs';
declare const global: Global;
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
@@ -18,8 +19,20 @@ export class Window {
constructor() {
this.createWindow();
this.loadRenderer();
this.registerService<void, any[]>(new FileListService());
this.registerService<string, Door[]>(new DoorService());
const fileListService = new FileListService();
this.registerService<void, any[]>(fileListService);
this.registerService<any, Door[]>(new DoorService());
readFile('./config.json', 'utf8', (error, data) => {
if(error){
console.log(error);
return;
}
const config = JSON.parse(data);
fileListService.setPaths(config.filePaths);
});
}
private createWindow(): void {

View File

@@ -4,7 +4,7 @@ import { readFile, set_fs } from 'xlsx';
import * as fs from 'node:fs';
set_fs(fs);
export class DoorService extends AbstractService<string, Door[]> {
export class DoorService extends AbstractService<any, Door[]> {
receptionChannel(): string {
return WindowApiConst.PROJECT_INPUT;
}
@@ -13,9 +13,9 @@ export class DoorService extends AbstractService<string, Door[]> {
return WindowApiConst.PROJECT_OUTPUT;
}
process(input: string): Promise<Door[]> {
process(input: {name: string, path: string}): Promise<Door[]> {
return new Promise((resolve) => {
const workbook = readFile(`./assets/${input}`);
const workbook = readFile(`${input.path}/${input.name}`);
const workingSheet = workbook.Sheets['DEURLIJST'];
const doorList: Door[] = [];

View File

@@ -48,4 +48,8 @@ export class FileListService extends AbstractService<void, any[]> {
});
});
}
public setPaths(inputPaths: string[]) {
this._paths = inputPaths;
}
}