2020-10-25 23:42:27 +00:00
|
|
|
import {Model} from './Model';
|
|
|
|
|
|
|
|
export interface IPageNode {
|
|
|
|
id?: number;
|
|
|
|
UUID: string;
|
|
|
|
Type: string;
|
|
|
|
ValueJSON: string;
|
|
|
|
PageId: string;
|
|
|
|
CreatedAt: string;
|
|
|
|
UpdatedAt: string;
|
|
|
|
CreatedUserId: string;
|
|
|
|
UpdateUserId: string;
|
|
|
|
needsServerUpdate?: boolean;
|
|
|
|
deleted?: boolean;
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string;
|
2020-10-25 23:42:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class PageNode extends Model<IPageNode> implements IPageNode {
|
|
|
|
id?: number;
|
|
|
|
UUID: string;
|
|
|
|
Type: string;
|
|
|
|
ValueJSON: string;
|
|
|
|
PageId: string;
|
|
|
|
CreatedAt: string;
|
|
|
|
UpdatedAt: string;
|
|
|
|
CreatedUserId: string;
|
|
|
|
UpdateUserId: string;
|
|
|
|
needsServerUpdate?: boolean;
|
|
|
|
deleted?: boolean;
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string;
|
2020-10-25 23:42:27 +00:00
|
|
|
|
|
|
|
public static getTableName() {
|
|
|
|
return 'pageNodes';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getSchema() {
|
|
|
|
// tslint:disable-next-line:max-line-length
|
2020-10-31 03:26:42 +00:00
|
|
|
return '++id, UUID, Type, ValueJSON, PageId, CreatedAt, UpdatedAt, CreatedUserId, UpdateUserId, needsServerUpdate, deleted, offlineUpdatedAt';
|
2020-10-25 23:42:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
UUID: string,
|
|
|
|
Type: string,
|
|
|
|
ValueJSON: string,
|
|
|
|
PageId: string,
|
|
|
|
CreatedAt: string,
|
|
|
|
UpdatedAt: string,
|
|
|
|
CreatedUserId: string,
|
|
|
|
UpdateUserId: string,
|
|
|
|
needsServerUpdate?: boolean,
|
|
|
|
deleted?: boolean,
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string,
|
2020-10-25 23:42:27 +00:00
|
|
|
id?: number
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.UUID = UUID;
|
|
|
|
this.Type = Type;
|
|
|
|
this.ValueJSON = ValueJSON;
|
|
|
|
this.PageId = PageId;
|
|
|
|
this.CreatedAt = CreatedAt;
|
|
|
|
this.UpdatedAt = UpdatedAt;
|
|
|
|
this.CreatedUserId = CreatedUserId;
|
|
|
|
this.UpdateUserId = UpdateUserId;
|
|
|
|
|
|
|
|
if ( typeof needsServerUpdate !== 'undefined' ) {
|
|
|
|
this.needsServerUpdate = needsServerUpdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof deleted !== 'undefined' ) {
|
|
|
|
this.deleted = deleted;
|
|
|
|
}
|
|
|
|
|
2020-10-31 03:26:42 +00:00
|
|
|
if ( typeof offlineUpdatedAt !== 'undefined' ) {
|
|
|
|
this.offlineUpdatedAt = offlineUpdatedAt;
|
|
|
|
}
|
|
|
|
|
2020-10-25 23:42:27 +00:00
|
|
|
if ( id ) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public fillFromRecord(record: any) {
|
|
|
|
this.UUID = record.UUID;
|
|
|
|
this.Type = record.Type;
|
|
|
|
this.ValueJSON = JSON.stringify(record.Value);
|
|
|
|
this.PageId = record.PageId;
|
|
|
|
this.CreatedAt = String(record.CreatedAt);
|
|
|
|
this.UpdatedAt = String(record.UpdatedAt);
|
|
|
|
this.CreatedUserId = record.CreatedUserId;
|
|
|
|
this.UpdateUserId = record.UpdateUserId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public inflateToRecord() {
|
|
|
|
const record = this.getSaveRecord();
|
|
|
|
record.Value = JSON.parse(record.ValueJSON);
|
|
|
|
delete record.ValueJSON;
|
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getSaveRecord(): any {
|
|
|
|
return {
|
|
|
|
...(this.id ? { id: this.id } : {}),
|
|
|
|
UUID: this.UUID,
|
|
|
|
Type: this.Type,
|
|
|
|
ValueJSON: this.ValueJSON,
|
|
|
|
PageId: this.PageId,
|
|
|
|
CreatedAt: new Date(this.CreatedAt),
|
|
|
|
UpdatedAt: new Date(this.UpdatedAt),
|
|
|
|
CreatedUserId: this.CreatedUserId,
|
|
|
|
UpdateUserId: this.UpdateUserId,
|
|
|
|
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
|
|
|
|
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
|
2020-10-31 03:26:42 +00:00
|
|
|
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
|
2020-10-25 23:42:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public getDatabase(): Dexie.Table<IPageNode, number> {
|
|
|
|
return this.staticClass().dbService.table('pageNodes') as Dexie.Table<IPageNode, number>;
|
|
|
|
}
|
|
|
|
}
|