refactor: complete application rewrite with modern UI
This commit is contained in:
@@ -1,60 +1,151 @@
|
||||
import { EnvParam } from "./EnvParam";
|
||||
import { NamedId } from "./NamedId";
|
||||
import { EnvParam } from './EnvParam';
|
||||
import { NamedEntity } from './types';
|
||||
|
||||
/**
|
||||
* Environment configuration containing parameters
|
||||
*/
|
||||
export class Env implements NamedEntity {
|
||||
constructor(
|
||||
public id?: number,
|
||||
public name?: string,
|
||||
public params: EnvParam[] = []
|
||||
) {}
|
||||
|
||||
export class Env implements NamedId {
|
||||
constructor(
|
||||
public id?: number,
|
||||
public name?: string,
|
||||
public params: EnvParam[] = []
|
||||
) { }
|
||||
/**
|
||||
* Checks if this is the DEFAULT environment
|
||||
*/
|
||||
public isDefault(): boolean {
|
||||
return this.name === 'DEFAULT';
|
||||
}
|
||||
|
||||
public isDefault() {
|
||||
return this.name === "DEFAULT";
|
||||
/**
|
||||
* Adds a new parameter to the environment (backward compatibility)
|
||||
*/
|
||||
public addParams(param: EnvParam): Env {
|
||||
return this.addParam(param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new parameter to the environment
|
||||
*/
|
||||
public addParam(param: EnvParam): Env {
|
||||
const newParam = new EnvParam(
|
||||
param.id ?? this.generateId(),
|
||||
param.name,
|
||||
param.value,
|
||||
param.isChanged
|
||||
);
|
||||
return new Env(this.id, this.name, [...this.params, newParam]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a parameter by ID
|
||||
*/
|
||||
public delParam(paramIdOrParam: number | EnvParam): Env {
|
||||
const paramId = typeof paramIdOrParam === 'number' ? paramIdOrParam : paramIdOrParam.id;
|
||||
return this.removeParam(paramId!);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a parameter by ID
|
||||
*/
|
||||
public removeParam(paramId: number): Env {
|
||||
return new Env(
|
||||
this.id,
|
||||
this.name,
|
||||
this.params.filter(p => p.id !== paramId)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing parameter (backward compatibility)
|
||||
*/
|
||||
public updateParams(updatedParam: EnvParam): Env {
|
||||
return this.updateParam(updatedParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing parameter
|
||||
*/
|
||||
public updateParam(updatedParam: EnvParam): Env {
|
||||
const index = this.params.findIndex(p => p.id === updatedParam.id);
|
||||
if (index === -1) {
|
||||
return this;
|
||||
}
|
||||
|
||||
addParams(payload: EnvParam): Env {
|
||||
payload.id = Math.random() * 10000;
|
||||
this.params.push(payload);
|
||||
return new Env(this.id, this.name, [...this.params]);
|
||||
}
|
||||
const newParams = [...this.params];
|
||||
newParams[index] = updatedParam;
|
||||
return new Env(this.id, this.name, newParams);
|
||||
}
|
||||
|
||||
delParam(param: EnvParam): Env {
|
||||
let idx = this.params.findIndex(el => el.id === param.id);
|
||||
if (idx > -1) {
|
||||
const newP = this.params.filter(el => el.id !== param.id);
|
||||
return new Env(this.id, this.name, newP);
|
||||
}
|
||||
/**
|
||||
* Gets a parameter by name
|
||||
*/
|
||||
public getParamByName(name: string): EnvParam | undefined {
|
||||
return this.params.find(p => p.name === name);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Gets all parameter names
|
||||
*/
|
||||
public getParamNames(): string[] {
|
||||
return this.params.map(p => p.name).filter((n): n is string => !!n);
|
||||
}
|
||||
|
||||
public updateParams(param: EnvParam): Env {
|
||||
let idx = this.params.findIndex(el => el.id === param.id);
|
||||
if (idx > -1) {
|
||||
let newP = [...this.params];
|
||||
newP[idx] = param;
|
||||
return new Env(this.id, this.name, newP);
|
||||
}
|
||||
/**
|
||||
* Creates a copy with updated values
|
||||
*/
|
||||
public update(updates: Partial<Env>): Env {
|
||||
return new Env(
|
||||
updates.id ?? this.id,
|
||||
updates.name ?? this.name,
|
||||
updates.params ?? this.params
|
||||
);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Generates a unique ID for new parameters
|
||||
*/
|
||||
private generateId(): number {
|
||||
return Date.now() % 100000 + Math.floor(Math.random() * 10000);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for environment events (backward compatibility)
|
||||
*/
|
||||
export class AppEvent<T> {
|
||||
protected constructor(public payload: T) { }
|
||||
constructor(public payload: T) {}
|
||||
|
||||
public static add<T>(payload: T): AppEvent<T> {
|
||||
return new AddEvent(payload);
|
||||
}
|
||||
public static del<T>(payload: T): AppEvent<T> {
|
||||
return new DelEvent(payload);
|
||||
}
|
||||
public static update<T>(payload: T): AppEvent<T> {
|
||||
return new UpdateEvent(payload);
|
||||
}
|
||||
public static add<T>(payload: T): AppEvent<T> {
|
||||
return new AddEvent(payload);
|
||||
}
|
||||
|
||||
public static del<T>(payload: T): AppEvent<T> {
|
||||
return new RemoveEvent(payload);
|
||||
}
|
||||
|
||||
public static update<T>(payload: T): AppEvent<T> {
|
||||
return new UpdateEvent(payload);
|
||||
}
|
||||
}
|
||||
|
||||
export class AddEvent<T> extends AppEvent<T> { }
|
||||
export class UpdateEvent<T> extends AppEvent<T> { }
|
||||
export class DelEvent<T> extends AppEvent<T> { }
|
||||
/**
|
||||
* Event for adding a parameter
|
||||
*/
|
||||
export class AddEvent<T> extends AppEvent<T> {}
|
||||
|
||||
/**
|
||||
* Event for updating a parameter
|
||||
*/
|
||||
export class UpdateEvent<T> extends AppEvent<T> {}
|
||||
|
||||
/**
|
||||
* Event for removing a parameter (backward compatibility)
|
||||
*/
|
||||
export class DelEvent<T> extends AppEvent<T> {}
|
||||
|
||||
/**
|
||||
* Event for removing a parameter
|
||||
*/
|
||||
export class RemoveEvent<T> extends AppEvent<T> {}
|
||||
|
||||
Reference in New Issue
Block a user