refactor: standardize frontend

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-02-24 17:38:48 -05:00
parent 20d3a46d7b
commit 0c4c9e52cd
24 changed files with 2448 additions and 1232 deletions
+131 -82
View File
@@ -2,50 +2,131 @@
* Class model for Collection Interface
*/
import type {
CollectionInterface,
CollectionContentsInterface,
CollectionPermissionsInterface,
CollectionRolesInterface
} from "@/types/collection";
import type { CollectionContentTypes, CollectionInterface, CollectionPropertiesInterface } from "@/types/collection";
export class CollectionObject implements CollectionInterface {
_data!: CollectionInterface;
constructor() {
this._data = {
'@type': 'people:collection',
provider: null,
service: null,
in: null,
id: null,
label: null,
description: null,
priority: null,
visibility: null,
color: null,
enabled: false,
provider: '',
service: '',
collection: null,
identifier: '',
signature: null,
permissions: {},
roles: {},
contents: {},
created: null,
modified: null,
properties: new CollectionPropertiesObject(),
};
}
fromJson(data: CollectionInterface) : CollectionObject {
fromJson(data: CollectionInterface): CollectionObject {
this._data = data;
if (data.properties) {
this._data.properties = new CollectionPropertiesObject().fromJson(data.properties as CollectionPropertiesInterface);
}
return this;
}
toJson(): CollectionInterface {
return this._data;
const json = { ...this._data };
if (this._data.properties instanceof CollectionPropertiesObject) {
json.properties = this._data.properties.toJson();
}
return json;
}
clone(): CollectionObject {
const cloned = new CollectionObject()
cloned._data = JSON.parse(JSON.stringify(this._data))
return cloned
const cloned = new CollectionObject();
cloned._data = { ...this._data };
cloned._data.properties = this.properties.clone();
return cloned;
}
/** Immutable Properties */
get provider(): string {
return this._data.provider;
}
get service(): string | number {
return this._data.service;
}
get collection(): string | number | null {
return this._data.collection;
}
get identifier(): string | number {
return this._data.identifier;
}
get signature(): string | null | undefined {
return this._data.signature;
}
get created(): string | null | undefined {
return this._data.created;
}
get modified(): string | null | undefined {
return this._data.modified;
}
get properties(): CollectionPropertiesObject {
if (this._data.properties instanceof CollectionPropertiesObject) {
return this._data.properties;
}
if (this._data.properties) {
const hydrated = new CollectionPropertiesObject().fromJson(this._data.properties as CollectionPropertiesInterface);
this._data.properties = hydrated;
return hydrated;
}
return new CollectionPropertiesObject();
}
set properties(value: CollectionPropertiesObject) {
if (value instanceof CollectionPropertiesObject) {
this._data.properties = value as any;
} else {
this._data.properties = value;
}
}
}
export class CollectionPropertiesObject implements CollectionPropertiesInterface {
_data!: CollectionPropertiesInterface;
constructor() {
this._data = {
'@type': 'people:collection',
version: 1,
content: [],
label: '',
description: null,
rank: null,
visibility: null,
color: null,
};
}
fromJson(data: CollectionPropertiesInterface): CollectionPropertiesObject {
this._data = data;
return this;
}
toJson(): CollectionPropertiesInterface {
return this._data;
}
clone(): CollectionPropertiesObject {
const cloned = new CollectionPropertiesObject();
cloned._data = { ...this._data };
return cloned;
}
/** Immutable Properties */
@@ -54,86 +135,54 @@ export class CollectionObject implements CollectionInterface {
return this._data['@type'];
}
get provider(): string | null {
return this._data.provider
get version(): number {
return this._data.version;
}
get service(): string | null {
return this._data.service
}
get in(): number | string | null {
return this._data.in
}
get id(): number | string | null {
return this._data.id
}
get signature(): string | null {
return this._data.signature
}
get permissions(): CollectionPermissionsInterface {
return this._data.permissions
}
get roles(): CollectionRolesInterface {
return this._data.roles
}
get contents(): CollectionContentsInterface {
return this._data.contents
get content(): CollectionContentTypes[] {
return this._data.content || [];
}
/** Mutable Properties */
get label(): string | null {
return this._data.label
}
get label(): string {
return this._data.label || '';
}
set label(value: string ) {
this._data.label = value
}
set label(value: string) {
this._data.label = value;
}
get description(): string | null {
return this._data.description
return this._data.description;
}
set description(value: string ) {
this._data.description = value
set description(value: string | null) {
this._data.description = value;
}
get priority(): number | null {
return this._data.priority
get rank(): number | null {
return this._data.rank;
}
set priority(value: number ) {
this._data.priority = value
set rank(value: number | null) {
this._data.rank = value;
}
get visibility(): string | null {
return this._data.visibility
get visibility(): boolean | null {
return this._data.visibility;
}
set visibility(value: string ) {
this._data.visibility = value
set visibility(value: boolean | null) {
this._data.visibility = value;
}
get color(): string | null {
return this._data.color
return this._data.color;
}
set color(value: string ) {
this._data.color = value
set color(value: string | null) {
this._data.color = value;
}
get enabled(): boolean {
return this._data.enabled
}
set enabled(value: boolean ) {
this._data.enabled = value
}
}