Cache pages and page nodes for offline use
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
380a139de3
commit
fe7e955875
@ -0,0 +1,150 @@
|
||||
import {Model} from './Model';
|
||||
|
||||
export interface IPage {
|
||||
id?: number;
|
||||
UUID: string;
|
||||
Name: string;
|
||||
OrgUserId: string;
|
||||
IsPublic: boolean;
|
||||
IsVisibleInMenu: boolean;
|
||||
ParentId: string;
|
||||
NodeIds: string[];
|
||||
CreatedAt: string;
|
||||
UpdatedAt: string;
|
||||
Active: boolean;
|
||||
CreatedUserId: string;
|
||||
UpdateUserId: string;
|
||||
ChildPageIds: string[];
|
||||
noDelete: boolean;
|
||||
virtual: boolean;
|
||||
needsServerUpdate?: boolean;
|
||||
deleted?: boolean;
|
||||
}
|
||||
|
||||
export class Page extends Model<IPage> implements IPage {
|
||||
id?: number;
|
||||
UUID: string;
|
||||
Name: string;
|
||||
OrgUserId: string;
|
||||
IsPublic: boolean;
|
||||
IsVisibleInMenu: boolean;
|
||||
ParentId: string;
|
||||
NodeIds: string[];
|
||||
CreatedAt: string;
|
||||
UpdatedAt: string;
|
||||
Active: boolean;
|
||||
CreatedUserId: string;
|
||||
UpdateUserId: string;
|
||||
ChildPageIds: string[];
|
||||
noDelete: boolean;
|
||||
virtual: boolean;
|
||||
needsServerUpdate?: boolean;
|
||||
deleted?: boolean;
|
||||
|
||||
public static getTableName() {
|
||||
return 'pages';
|
||||
}
|
||||
|
||||
public static getSchema() {
|
||||
// tslint:disable-next-line:max-line-length
|
||||
return '++id, UUID, Name, OrgUserId, IsPublic, IsVisibleInMenu, ParentId, NodeIds, CreatedAt, UpdatedAt, Active, CreatedUserId, UpdateUserId, ChildPageIds, noDelete, virtual, needsServerUpdate, deleted';
|
||||
}
|
||||
|
||||
constructor(
|
||||
UUID: string,
|
||||
Name: string,
|
||||
OrgUserId: string,
|
||||
IsPublic: boolean,
|
||||
IsVisibleInMenu: boolean,
|
||||
ParentId: string,
|
||||
NodeIds: string[],
|
||||
CreatedAt: string,
|
||||
UpdatedAt: string,
|
||||
Active: boolean,
|
||||
CreatedUserId: string,
|
||||
UpdateUserId: string,
|
||||
ChildPageIds: string[],
|
||||
noDelete: boolean,
|
||||
virtual: boolean,
|
||||
needsServerUpdate?: boolean,
|
||||
deleted?: boolean,
|
||||
id?: number
|
||||
) {
|
||||
super();
|
||||
|
||||
this.UUID = UUID;
|
||||
this.Name = Name;
|
||||
this.OrgUserId = OrgUserId;
|
||||
this.IsPublic = IsPublic;
|
||||
this.IsVisibleInMenu = IsVisibleInMenu;
|
||||
this.ParentId = ParentId;
|
||||
this.NodeIds = NodeIds;
|
||||
this.CreatedAt = CreatedAt;
|
||||
this.UpdatedAt = UpdatedAt;
|
||||
this.Active = Active;
|
||||
this.CreatedUserId = CreatedUserId;
|
||||
this.UpdateUserId = UpdateUserId;
|
||||
this.ChildPageIds = ChildPageIds;
|
||||
this.noDelete = noDelete;
|
||||
this.virtual = virtual;
|
||||
|
||||
if ( typeof needsServerUpdate !== 'undefined' ) {
|
||||
this.needsServerUpdate = needsServerUpdate;
|
||||
}
|
||||
|
||||
if ( typeof deleted !== 'undefined' ) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
if ( id ) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
public fillFromRecord(record: any) {
|
||||
console.log('page fill from record', record);
|
||||
this.UUID = record.UUID;
|
||||
this.Name = record.Name;
|
||||
this.OrgUserId = record.OrgUserId;
|
||||
this.IsPublic = record.IsPublic;
|
||||
this.IsVisibleInMenu = record.IsVisibleInMenu;
|
||||
this.ParentId = record.ParentId;
|
||||
this.NodeIds = record.NodeIds;
|
||||
console.log('setting node ids', this.NodeIds, record.NodeIds);
|
||||
this.CreatedAt = String(record.CreatedAt);
|
||||
this.UpdatedAt = String(record.UpdatedAt);
|
||||
this.Active = record.Active;
|
||||
this.CreatedUserId = record.CreatedUserId;
|
||||
this.UpdateUserId = record.UpdateUserId;
|
||||
this.ChildPageIds = record.ChildPageIds;
|
||||
this.noDelete = record.noDelete;
|
||||
this.virtual = record.virtual;
|
||||
}
|
||||
|
||||
public getSaveRecord(): any {
|
||||
return {
|
||||
...(this.id ? { id: this.id } : {}),
|
||||
UUID: this.UUID,
|
||||
Name: this.Name,
|
||||
OrgUserId: this.OrgUserId,
|
||||
IsPublic: this.IsPublic,
|
||||
IsVisibleInMenu: this.IsVisibleInMenu,
|
||||
ParentId: this.ParentId,
|
||||
NodeIds: this.NodeIds,
|
||||
CreatedAt: new Date(this.CreatedAt),
|
||||
UpdatedAt: new Date(this.UpdatedAt),
|
||||
Active: this.Active,
|
||||
CreatedUserId: this.CreatedUserId,
|
||||
UpdateUserId: this.UpdateUserId,
|
||||
ChildPageIds: this.ChildPageIds,
|
||||
noDelete: this.noDelete,
|
||||
virtual: this.virtual,
|
||||
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
|
||||
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
|
||||
};
|
||||
}
|
||||
|
||||
public getDatabase(): Dexie.Table<IPage, number> {
|
||||
return this.staticClass().dbService.table('pages') as Dexie.Table<IPage, number>;
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
public static getTableName() {
|
||||
return 'pageNodes';
|
||||
}
|
||||
|
||||
public static getSchema() {
|
||||
// tslint:disable-next-line:max-line-length
|
||||
return '++id, UUID, Type, ValueJSON, PageId, CreatedAt, UpdatedAt, CreatedUserId, UpdateUserId, needsServerUpdate, deleted';
|
||||
}
|
||||
|
||||
constructor(
|
||||
UUID: string,
|
||||
Type: string,
|
||||
ValueJSON: string,
|
||||
PageId: string,
|
||||
CreatedAt: string,
|
||||
UpdatedAt: string,
|
||||
CreatedUserId: string,
|
||||
UpdateUserId: string,
|
||||
needsServerUpdate?: boolean,
|
||||
deleted?: boolean,
|
||||
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;
|
||||
}
|
||||
|
||||
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 }),
|
||||
};
|
||||
}
|
||||
|
||||
public getDatabase(): Dexie.Table<IPageNode, number> {
|
||||
return this.staticClass().dbService.table('pageNodes') as Dexie.Table<IPageNode, number>;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue