2020-10-22 03:40:20 +00:00
|
|
|
import {Model} from './Model';
|
|
|
|
|
|
|
|
export interface IDatabase {
|
|
|
|
id?: number;
|
|
|
|
Name: string;
|
|
|
|
NodeId: string;
|
|
|
|
PageId: string;
|
|
|
|
ColumnIds: string[];
|
|
|
|
UUID: string;
|
|
|
|
Active: boolean;
|
|
|
|
needsServerUpdate?: boolean;
|
|
|
|
deleted?: boolean;
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string;
|
2020-10-22 03:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Database extends Model<IDatabase> implements IDatabase {
|
|
|
|
id?: number;
|
|
|
|
Name: string;
|
|
|
|
NodeId: string;
|
|
|
|
PageId: string;
|
|
|
|
ColumnIds: string[];
|
|
|
|
UUID: string;
|
|
|
|
Active: boolean;
|
|
|
|
needsServerUpdate?: boolean;
|
|
|
|
deleted?: boolean;
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string;
|
2020-10-22 03:40:20 +00:00
|
|
|
|
|
|
|
public static getTableName() {
|
|
|
|
return 'databases';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getSchema() {
|
2020-10-31 03:26:42 +00:00
|
|
|
return '++id, Name, NodeId, PageId, ColumnIds, UUID, Active, needsServerUpdate, deleted, offlineUpdatedAt';
|
2020-10-22 03:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
Name: string,
|
|
|
|
NodeId: string,
|
|
|
|
PageId: string,
|
|
|
|
ColumnIds: string[],
|
|
|
|
UUID: string,
|
|
|
|
Active: boolean,
|
|
|
|
needsServerUpdate?: boolean,
|
|
|
|
deleted?: boolean,
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string,
|
|
|
|
id?: number,
|
2020-10-22 03:40:20 +00:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.Name = Name;
|
|
|
|
this.NodeId = NodeId;
|
|
|
|
this.PageId = PageId;
|
|
|
|
this.ColumnIds = ColumnIds;
|
|
|
|
this.UUID = UUID;
|
|
|
|
this.Active = Active;
|
|
|
|
|
|
|
|
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-22 03:40:20 +00:00
|
|
|
if ( id ) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public fillFromRecord(record: any) {
|
|
|
|
this.Name = record.Name;
|
|
|
|
this.NodeId = record.NodeId;
|
|
|
|
this.PageId = record.PageId;
|
|
|
|
this.ColumnIds = record.ColumnIds;
|
|
|
|
this.UUID = record.UUID;
|
|
|
|
this.Active = record.Active;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getSaveRecord(): any {
|
|
|
|
return {
|
|
|
|
...(this.id ? { id: this.id } : {}),
|
|
|
|
Name: this.Name,
|
|
|
|
NodeId: this.NodeId,
|
|
|
|
PageId: this.PageId,
|
|
|
|
ColumnIds: this.ColumnIds,
|
|
|
|
UUID: this.UUID,
|
|
|
|
Active: this.Active,
|
|
|
|
...(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-22 03:40:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public getDatabase(): Dexie.Table<IDatabase, number> {
|
|
|
|
return this.staticClass().dbService.table('databases') as Dexie.Table<IDatabase, number>;
|
|
|
|
}
|
|
|
|
}
|