refactor: complete application rewrite with modern UI
This commit is contained in:
@@ -1,32 +1,73 @@
|
||||
import { NamedId } from "./NamedId";
|
||||
import { NamedEntity } from './types';
|
||||
|
||||
export class EnvParam implements NamedId {
|
||||
constructor(
|
||||
public id?: number,
|
||||
public name?: string,
|
||||
public value?: string,
|
||||
public isChanged: boolean = false
|
||||
) { }
|
||||
/**
|
||||
* Environment parameter representing a key-value configuration pair
|
||||
*/
|
||||
export class EnvParam implements NamedEntity {
|
||||
constructor(
|
||||
public id?: number,
|
||||
public name?: string,
|
||||
public value?: string,
|
||||
public isChanged: boolean = false
|
||||
) {}
|
||||
|
||||
public Changed(v: boolean = true): EnvParam {
|
||||
return new EnvParam(
|
||||
this.id,
|
||||
this.name,
|
||||
this.value,
|
||||
v);
|
||||
}
|
||||
/**
|
||||
* Marks the parameter as changed (backward compatibility)
|
||||
*/
|
||||
public Changed(changed: boolean = true): EnvParam {
|
||||
return this.markChanged(changed);
|
||||
}
|
||||
|
||||
public sanitize(v?: string): string {
|
||||
return v?.replace(/&/g, "&")
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
?? "";
|
||||
}
|
||||
/**
|
||||
* Marks the parameter as changed
|
||||
*/
|
||||
public markChanged(changed: boolean = true): EnvParam {
|
||||
return new EnvParam(this.id, this.name, this.value, changed);
|
||||
}
|
||||
|
||||
public humanize(v?: string): string {
|
||||
return v ?? "";
|
||||
}
|
||||
/**
|
||||
* Creates a copy of this parameter with updated values
|
||||
*/
|
||||
public update(updates: Partial<EnvParam>): EnvParam {
|
||||
return new EnvParam(
|
||||
updates.id ?? this.id,
|
||||
updates.name ?? this.name,
|
||||
updates.value ?? this.value,
|
||||
updates.isChanged ?? this.isChanged
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes HTML special characters (instance method for backward compatibility)
|
||||
*/
|
||||
public sanitize(value?: string): string {
|
||||
const v = value ?? this.value ?? '';
|
||||
return EnvParam.sanitize(v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes HTML special characters (static method)
|
||||
*/
|
||||
public static sanitize(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
/**
|
||||
* Humanizes the value (backward compatibility)
|
||||
*/
|
||||
public humanize(value?: string): string {
|
||||
return value ?? this.value ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the parameter has required fields
|
||||
*/
|
||||
public isValid(): boolean {
|
||||
return !!(this.name && this.name.trim() !== '');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user