Delete ScriptAccounts from Filesystem
All checks were successful
E2E Testing / test (push) Successful in 1m36s

This commit is contained in:
Sebastian Böckelmann 2024-03-19 17:03:07 +01:00
parent 03bc18e679
commit c4085a7cf9
6 changed files with 54 additions and 8 deletions

14
app/DeleteModel.js Normal file
View File

@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeleteTransaction = void 0;
const path = require("node:path");
const fs = require("fs");
class DeleteTransaction {
static deleteScriptAccount(projectDir, componentName) {
const filename = path.join(projectDir, "script-accounts", componentName + ".json");
fs.unlinkSync(filename);
console.log("Delete ", filename);
}
}
exports.DeleteTransaction = DeleteTransaction;
//# sourceMappingURL=DeleteModel.js.map

10
app/DeleteModel.ts Normal file
View File

@ -0,0 +1,10 @@
import * as path from "node:path";
import * as fs from "fs";
export class DeleteTransaction {
static deleteScriptAccount(projectDir: string, componentName: string) {
const filename = path.join(projectDir, "script-accounts", componentName + ".json")
fs.unlinkSync(filename)
console.log("Delete ", filename)
}
}

View File

@ -1,9 +1,11 @@
import {app, BrowserWindow, screen, Menu, ipcMain, dialog, globalShortcut} from 'electron'; import {app, BrowserWindow, dialog, globalShortcut, ipcMain, Menu, screen} from 'electron';
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
import {json} from "node:stream/consumers";
import {StorageModel} from "../src/app/game-model/fs/StorageModel"; import {StorageModel} from "../src/app/game-model/fs/StorageModel";
import {SaveProject} from "./SaveProject"; import {SaveProject} from "./SaveProject";
import {DeleteModel} from "../src/app/game-model/fs/DeleteModel";
import {ModelComponentType} from "../src/app/game-model/ModelComponentType";
import {DeleteTransaction} from "./DeleteModel";
let win: BrowserWindow | null = null; let win: BrowserWindow | null = null;
const args = process.argv.slice(1), const args = process.argv.slice(1),
@ -99,6 +101,11 @@ function createWindow(): BrowserWindow {
SaveProject.saveProject(projectDirectory, storageModels); SaveProject.saveProject(projectDirectory, storageModels);
}) })
ipcMain.on('delete-component', (event, deletedComponent: DeleteModel) => {
console.log("Delete Model: ", deletedComponent)
deleteComponent(deletedComponent);
})
const menuTemplate = [ const menuTemplate = [
{ {
label: 'File', label: 'File',
@ -207,3 +214,10 @@ function openProjectFromFile(openProjectDir: string) {
function saveProject() { function saveProject() {
win!.webContents.send('get-project-data') win!.webContents.send('get-project-data')
} }
function deleteComponent(component: DeleteModel) {
console.log("Delete Component")
if(component.modeltype == ModelComponentType.SCRIPTACCOUNT) {
DeleteTransaction.deleteScriptAccount(projectDirectory, component.componentName);
}
}

View File

@ -18,6 +18,7 @@ import {LoadedProject} from "../../app/LoadedProject";
import {ProcessLoadedProject} from "./game-model/fs/ProcessLoadedProject"; import {ProcessLoadedProject} from "./game-model/fs/ProcessLoadedProject";
import {StoreProject} from "./game-model/fs/store/StoreProject"; import {StoreProject} from "./game-model/fs/store/StoreProject";
import {Gamesystem} from "./game-model/gamesystems/Gamesystem"; import {Gamesystem} from "./game-model/gamesystems/Gamesystem";
import {DeleteModel} from "./game-model/fs/DeleteModel";
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -115,6 +116,7 @@ export class AppComponent implements OnInit{
if(res != undefined && res) { if(res != undefined && res) {
if(affectedModelComponent instanceof ScriptAccount) { if(affectedModelComponent instanceof ScriptAccount) {
this.gameModel!.removeScriptAccount(affectedModelComponent); this.gameModel!.removeScriptAccount(affectedModelComponent);
this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT))
} else if(affectedModelComponent instanceof Gamesystem) { } else if(affectedModelComponent instanceof Gamesystem) {
this.gameModel!.removeGamesystem(affectedModelComponent); this.gameModel!.removeGamesystem(affectedModelComponent);
this.gamesystemOverview!.refresh() this.gamesystemOverview!.refresh()

View File

@ -0,0 +1,12 @@
import {ModelComponentType} from "../ModelComponentType";
export class DeleteModel {
componentName: string
modeltype: ModelComponentType
constructor(componentName: string, modeltype: ModelComponentType) {
this.componentName = componentName;
this.modeltype = modeltype;
}
}

View File

@ -1,6 +0,0 @@
{
"componentName": "Temperature",
"componentDescription": "",
"minValue": -50,
"maxValue": 70
}