Add offline caching for databases, database columns, and database entries
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
8de9db08a6
commit
02d8505b05
@ -0,0 +1,93 @@
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
public static getTableName() {
|
||||
return 'databases';
|
||||
}
|
||||
|
||||
public static getSchema() {
|
||||
return '++id, Name, NodeId, PageId, ColumnIds, UUID, Active, needsServerUpdate, deleted';
|
||||
}
|
||||
|
||||
constructor(
|
||||
Name: string,
|
||||
NodeId: string,
|
||||
PageId: string,
|
||||
ColumnIds: string[],
|
||||
UUID: string,
|
||||
Active: boolean,
|
||||
needsServerUpdate?: boolean,
|
||||
deleted?: boolean,
|
||||
id?: number
|
||||
) {
|
||||
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;
|
||||
}
|
||||
|
||||
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 }),
|
||||
};
|
||||
}
|
||||
|
||||
public getDatabase(): Dexie.Table<IDatabase, number> {
|
||||
return this.staticClass().dbService.table('databases') as Dexie.Table<IDatabase, number>;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
import {Model} from './Model';
|
||||
|
||||
export interface IDatabaseColumn {
|
||||
id?: number;
|
||||
headerName: string;
|
||||
field: string;
|
||||
DatabaseId: string;
|
||||
UUID: string;
|
||||
Type: string;
|
||||
additionalData: string;
|
||||
needsServerUpdate?: boolean;
|
||||
deleted?: boolean;
|
||||
}
|
||||
|
||||
export class DatabaseColumn extends Model<IDatabaseColumn> implements IDatabaseColumn {
|
||||
id?: number;
|
||||
headerName: string;
|
||||
field: string;
|
||||
DatabaseId: string;
|
||||
UUID: string;
|
||||
Type: string;
|
||||
additionalData: string;
|
||||
needsServerUpdate?: boolean;
|
||||
deleted?: boolean;
|
||||
|
||||
public static getTableName() {
|
||||
return 'databaseColumns';
|
||||
}
|
||||
|
||||
public static getSchema() {
|
||||
return '++id, headerName, field, DatabaseId, UUID, Type, additionalData, needsServerUpdate, deleted';
|
||||
}
|
||||
|
||||
constructor(
|
||||
headerName: string,
|
||||
field: string,
|
||||
DatabaseId: string,
|
||||
UUID: string,
|
||||
Type: string,
|
||||
additionalData: string,
|
||||
needsServerUpdate?: boolean,
|
||||
deleted?: boolean,
|
||||
id?: number
|
||||
) {
|
||||
super();
|
||||
|
||||
this.headerName = headerName;
|
||||
this.field = field;
|
||||
this.DatabaseId = DatabaseId;
|
||||
this.UUID = UUID;
|
||||
this.Type = Type;
|
||||
this.additionalData = additionalData;
|
||||
|
||||
if ( typeof needsServerUpdate !== 'undefined' ) {
|
||||
this.needsServerUpdate = needsServerUpdate;
|
||||
}
|
||||
|
||||
if ( typeof deleted !== 'undefined' ) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
if ( id ) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
public fillFromRecord(record: any) {
|
||||
this.headerName = record.headerName;
|
||||
this.field = record.field;
|
||||
this.DatabaseId = record.DatabaseId;
|
||||
this.UUID = record.UUID;
|
||||
this.Type = record.Type;
|
||||
this.additionalData = record.additionalData;
|
||||
}
|
||||
|
||||
public getSaveRecord(): any {
|
||||
return {
|
||||
...(this.id ? { id: this.id } : {}),
|
||||
headerName: this.headerName,
|
||||
field: this.field,
|
||||
DatabaseId: this.DatabaseId,
|
||||
UUID: this.UUID,
|
||||
Type: this.Type,
|
||||
additionalData: this.additionalData,
|
||||
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
|
||||
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
|
||||
};
|
||||
}
|
||||
|
||||
public getDatabase(): Dexie.Table<IDatabaseColumn, number> {
|
||||
return this.staticClass().dbService.table('databaseColumns') as Dexie.Table<IDatabaseColumn, number>;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
import {Model} from './Model';
|
||||
|
||||
export interface IDatabaseEntry {
|
||||
id?: number;
|
||||
DatabaseId: string;
|
||||
RowDataJSON: string;
|
||||
UUID: string;
|
||||
needsServerUpdate?: boolean;
|
||||
deleted?: boolean;
|
||||
}
|
||||
|
||||
export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEntry {
|
||||
id?: number;
|
||||
DatabaseId: string;
|
||||
RowDataJSON: string;
|
||||
UUID: string;
|
||||
needsServerUpdate?: boolean;
|
||||
deleted?: boolean;
|
||||
|
||||
public static getTableName() {
|
||||
return 'databaseEntries';
|
||||
}
|
||||
|
||||
public static getSchema() {
|
||||
return '++id, DatabaseId, RowDataJSON, UUID, needsServerUpdate, deleted';
|
||||
}
|
||||
|
||||
constructor(
|
||||
DatabaseId: string,
|
||||
RowDataJSON: string,
|
||||
UUID: string,
|
||||
needsServerUpdate?: boolean,
|
||||
deleted?: boolean,
|
||||
id?: number
|
||||
) {
|
||||
super();
|
||||
|
||||
this.DatabaseId = DatabaseId;
|
||||
this.RowDataJSON = RowDataJSON;
|
||||
this.UUID = UUID;
|
||||
|
||||
if ( typeof needsServerUpdate !== 'undefined' ) {
|
||||
this.needsServerUpdate = needsServerUpdate;
|
||||
}
|
||||
|
||||
if ( typeof deleted !== 'undefined' ) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
if ( id ) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
public fillFromRecord(record: any) {
|
||||
this.DatabaseId = record.DatabaseId;
|
||||
this.RowDataJSON = JSON.stringify(record.RowData);
|
||||
this.UUID = record.UUID;
|
||||
}
|
||||
|
||||
public inflateToRecord() {
|
||||
const record = this.getSaveRecord();
|
||||
record.RowData = JSON.parse(record.RowDataJSON);
|
||||
delete record.RowDataJSON;
|
||||
return record;
|
||||
}
|
||||
|
||||
public getSaveRecord(): any {
|
||||
return {
|
||||
...(this.id ? { id: this.id } : {}),
|
||||
DatabaseId: this.DatabaseId,
|
||||
RowDataJSON: this.RowDataJSON,
|
||||
UUID: this.UUID,
|
||||
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
|
||||
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
|
||||
};
|
||||
}
|
||||
|
||||
public getDatabase(): Dexie.Table<IDatabaseEntry, number> {
|
||||
return this.staticClass().dbService.table('databaseEntries') as Dexie.Table<IDatabaseEntry, number>;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue