Initial commit
This commit is contained in:
@@ -8,7 +8,7 @@ export class AbstractService<In, Out> {
|
||||
throw new Error(NOT_IMPEMENTED_YET);
|
||||
}
|
||||
|
||||
process(_input: In): Out {
|
||||
process(_input: In): Promise<Out> {
|
||||
throw new Error(NOT_IMPEMENTED_YET);
|
||||
}
|
||||
}
|
||||
|
||||
43
workspaces/electron-app/main/services/door-service.ts
Normal file
43
workspaces/electron-app/main/services/door-service.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { WindowApiConst, Door } from 'shared-lib';
|
||||
import { AbstractService } from './abstract-service';
|
||||
import { readFile, set_fs } from 'xlsx';
|
||||
import * as fs from 'node:fs';
|
||||
set_fs(fs);
|
||||
|
||||
export class DoorService extends AbstractService<string, Door[]> {
|
||||
receptionChannel(): string {
|
||||
return WindowApiConst.PROJECT_INPUT;
|
||||
}
|
||||
|
||||
sendingChannel(): string {
|
||||
return WindowApiConst.PROJECT_OUTPUT;
|
||||
}
|
||||
|
||||
process(input: string): Promise<Door[]> {
|
||||
return new Promise((resolve) => {
|
||||
const workbook = readFile(`./assets/${input}`);
|
||||
const workingSheet = workbook.Sheets['DEURLIJST'];
|
||||
const doorList: Door[] = [];
|
||||
|
||||
// remove 2 top rows
|
||||
// stop at 19
|
||||
|
||||
for (let index = 4; index < 19; index++) {
|
||||
const door: Door = {};
|
||||
door.nr = workingSheet[`A${index}`]?.v;
|
||||
if (door.nr) {
|
||||
door.lr = workingSheet[`H${index}`]?.v;
|
||||
door.krukSlot = workingSheet[`K${index}`]?.v;
|
||||
door.pivot = workingSheet[`Q${index}`]?.v;
|
||||
door.type = workingSheet[`S${index}`]?.v;
|
||||
door.modelKruk = workingSheet[`T${index}`]?.v;
|
||||
door.remark = workingSheet[`U${index}`]?.v;
|
||||
|
||||
doorList.push(door);
|
||||
}
|
||||
}
|
||||
|
||||
resolve(doorList);
|
||||
});
|
||||
}
|
||||
}
|
||||
51
workspaces/electron-app/main/services/file-list-service.ts
Normal file
51
workspaces/electron-app/main/services/file-list-service.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { readdir } from 'node:fs';
|
||||
import { WindowApiConst } from 'shared-lib';
|
||||
import { AbstractService } from './abstract-service';
|
||||
|
||||
export class FileListService extends AbstractService<void, any[]> {
|
||||
private _paths: string[] = ['./assets'];
|
||||
|
||||
receptionChannel(): string {
|
||||
return WindowApiConst.FILELIST_INPUT;
|
||||
}
|
||||
|
||||
sendingChannel(): string {
|
||||
return WindowApiConst.FILELIST_OUTPUT;
|
||||
}
|
||||
|
||||
process(): Promise<any[]> {
|
||||
return new Promise((resolve) => {
|
||||
const projects: any[] = [];
|
||||
Promise.all(this._paths.map((path) => this.readPath(path))).then((result: any) => {
|
||||
for (const entry of result.entries()) {
|
||||
for (const file of entry[1].result) {
|
||||
projects.push({
|
||||
path: entry[1].path,
|
||||
name: file,
|
||||
});
|
||||
}
|
||||
}
|
||||
resolve(projects);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
private readPath(path: string): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
readdir(path, (error, fileList: string[]) => {
|
||||
if (!error) {
|
||||
const newList: string[] = [];
|
||||
for (const file of fileList) {
|
||||
newList.push(file);
|
||||
}
|
||||
return resolve({
|
||||
path,
|
||||
result: newList,
|
||||
});
|
||||
}
|
||||
|
||||
return {};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { WindowApiConst } from 'shared-lib';
|
||||
import { AbstractService } from './abstract-service';
|
||||
|
||||
export class MultiplesService extends AbstractService<number, number[]> {
|
||||
receptionChannel(): string {
|
||||
return WindowApiConst.MULTIPLES_INPUT;
|
||||
}
|
||||
|
||||
sendingChannel(): string {
|
||||
return WindowApiConst.MULTIPLES_OUTPUT;
|
||||
}
|
||||
|
||||
process(input: number): number[] {
|
||||
// From 1 to 10, return input multiples
|
||||
const multiples = [];
|
||||
for (let n = 1; n <= 10; n++) {
|
||||
multiples.push(n * input);
|
||||
}
|
||||
return multiples;
|
||||
}
|
||||
}
|
||||
27
workspaces/electron-app/main/services/print-service.ts
Normal file
27
workspaces/electron-app/main/services/print-service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { BrowserWindow } from 'electron';
|
||||
import { WindowApiConst } from 'shared-lib';
|
||||
import { AbstractService } from './abstract-service';
|
||||
|
||||
export class PrintService extends AbstractService<string, void> {
|
||||
private _browserWindow: BrowserWindow;
|
||||
sendingChannel(): string {
|
||||
return WindowApiConst.PRINT_OUTPUT;
|
||||
}
|
||||
|
||||
receptionChannel(): string {
|
||||
return WindowApiConst.PRINT_INPUT;
|
||||
}
|
||||
|
||||
process(): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
if (this._browserWindow) {
|
||||
this._browserWindow.webContents.print({ silent: true });
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
public setWindow(window: BrowserWindow): void {
|
||||
this._browserWindow = window;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user