2020-10-22 04:12:57 +00:00
|
|
|
import {Model} from './Model';
|
|
|
|
|
|
|
|
export interface IFileGroup {
|
|
|
|
id?: number;
|
|
|
|
NodeId: string;
|
|
|
|
PageId: string;
|
|
|
|
FileIds: string[];
|
|
|
|
filesJSON: string;
|
|
|
|
UUID: string;
|
|
|
|
needsServerUpdate?: boolean;
|
|
|
|
deleted?: boolean;
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string;
|
2020-10-22 04:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class FileGroup extends Model<IFileGroup> implements IFileGroup {
|
|
|
|
id?: number;
|
|
|
|
NodeId: string;
|
|
|
|
PageId: string;
|
|
|
|
FileIds: string[];
|
|
|
|
filesJSON: string;
|
|
|
|
UUID: string;
|
|
|
|
needsServerUpdate?: boolean;
|
|
|
|
deleted?: boolean;
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string;
|
2020-10-22 04:12:57 +00:00
|
|
|
|
|
|
|
public static getTableName() {
|
|
|
|
return 'fileGroups';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static getSchema() {
|
2020-10-31 03:26:42 +00:00
|
|
|
return '++id, NodeId, PageId, FileIds, filesJSON, UUID, needsServerUpdate, deleted, offlineUpdatedAt';
|
2020-10-22 04:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
NodeId: string,
|
|
|
|
PageId: string,
|
|
|
|
FileIds: string[],
|
|
|
|
filesJSON: string,
|
|
|
|
UUID: string,
|
|
|
|
needsServerUpdate?: boolean,
|
|
|
|
deleted?: boolean,
|
2020-10-31 03:26:42 +00:00
|
|
|
offlineUpdatedAt?: string,
|
|
|
|
id?: number,
|
2020-10-22 04:12:57 +00:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.NodeId = NodeId;
|
|
|
|
this.PageId = PageId;
|
|
|
|
this.FileIds = FileIds;
|
|
|
|
this.filesJSON = filesJSON;
|
|
|
|
this.UUID = UUID;
|
|
|
|
|
|
|
|
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 04:12:57 +00:00
|
|
|
if ( id ) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public fillFromRecord(record: any) {
|
|
|
|
this.NodeId = record.NodeId;
|
|
|
|
this.PageId = record.PageId;
|
|
|
|
this.FileIds = record.FileIds;
|
|
|
|
this.filesJSON = JSON.stringify(record.files);
|
|
|
|
this.UUID = record.UUID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public inflateToRecord() {
|
|
|
|
return {
|
|
|
|
NodeId: this.NodeId,
|
|
|
|
PageId: this.PageId,
|
|
|
|
FileIds: this.FileIds,
|
|
|
|
files: JSON.parse(this.filesJSON),
|
|
|
|
UUID: this.UUID,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public getSaveRecord(): any {
|
|
|
|
return {
|
|
|
|
...(this.id ? { id: this.id } : {}),
|
|
|
|
NodeId: this.NodeId,
|
|
|
|
PageId: this.PageId,
|
|
|
|
FileIds: this.FileIds,
|
|
|
|
filesJSON: this.filesJSON,
|
|
|
|
UUID: this.UUID,
|
|
|
|
...(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 04:12:57 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public getDatabase(): Dexie.Table<IFileGroup, number> {
|
|
|
|
return this.staticClass().dbService.table('fileGroups') as Dexie.Table<IFileGroup, number>;
|
|
|
|
}
|
|
|
|
}
|