|
|
|
@ -318,7 +318,6 @@ export class ApiService {
|
|
|
|
|
const uuidMap = await new Promise(async (res, rej) => {
|
|
|
|
|
this.post('/offline/sync', { dirtyRecords }).subscribe({
|
|
|
|
|
next: async result => {
|
|
|
|
|
console.log('sync result', result);
|
|
|
|
|
res(result.data);
|
|
|
|
|
},
|
|
|
|
|
error: rej,
|
|
|
|
@ -812,14 +811,14 @@ export class ApiService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getCodium(PageId: string, NodeId: string, CodiumId: string): Promise<any> {
|
|
|
|
|
public getCodium(PageId: string, NodeId: string, CodiumId: string, version?: number): Promise<any> {
|
|
|
|
|
return new Promise(async (res, rej) => {
|
|
|
|
|
const existingLocalCodiums = await this.db.codiums.where({ UUID: CodiumId }).toArray();
|
|
|
|
|
const existingLocalCodium = existingLocalCodiums.length > 0 ? existingLocalCodiums[0] as Codium : undefined;
|
|
|
|
|
|
|
|
|
|
// If offline, try to load it from the local DB
|
|
|
|
|
if ( this.isOffline ) {
|
|
|
|
|
if ( existingLocalCodium ) {
|
|
|
|
|
if ( existingLocalCodium && !version ) {
|
|
|
|
|
return res(existingLocalCodium.getSaveRecord());
|
|
|
|
|
} else {
|
|
|
|
|
return rej(new ResourceNotAvailableOfflineError());
|
|
|
|
@ -827,8 +826,12 @@ export class ApiService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If online, fetch the codium and store/update it locally
|
|
|
|
|
this.get(`/code/${PageId}/${NodeId}/get/${CodiumId}`).subscribe({
|
|
|
|
|
this.get(`/code/${PageId}/${NodeId}/get/${CodiumId}?version=${version}`).subscribe({
|
|
|
|
|
next: async result => {
|
|
|
|
|
if ( version ) {
|
|
|
|
|
return res(result.data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( existingLocalCodium ) {
|
|
|
|
|
existingLocalCodium.fillFromRecord(result.data);
|
|
|
|
|
|
|
|
|
@ -915,20 +918,28 @@ export class ApiService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getDatabaseColumns(PageId: string, NodeId: string, DatabaseId: string): Promise<any[]> {
|
|
|
|
|
public getDatabaseColumns(PageId: string, NodeId: string, DatabaseId: string, databaseVersion?: number): Promise<any[]> {
|
|
|
|
|
return new Promise(async (res, rej) => {
|
|
|
|
|
// If offline, fetch the columns from the local database
|
|
|
|
|
if ( this.isOffline ) {
|
|
|
|
|
if ( databaseVersion ) {
|
|
|
|
|
return rej(new ResourceNotAvailableOfflineError());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const columns = (await this.db.databaseColumns.where({ DatabaseId }).toArray()) as DatabaseColumn[];
|
|
|
|
|
return res(columns.filter(x => !x.deleted).map(x => x.getSaveRecord()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If online, fetch the columns and sync the local database
|
|
|
|
|
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/columns`).subscribe({
|
|
|
|
|
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}/columns?database_version=${databaseVersion}`).subscribe({
|
|
|
|
|
next: async results => {
|
|
|
|
|
// Resolve this first, so the UI doesn't need to wait for the db sync to render
|
|
|
|
|
res(results.data);
|
|
|
|
|
|
|
|
|
|
if ( databaseVersion ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( const def of results.data ) {
|
|
|
|
|
const existingColumnDef = await this.db.databaseColumns.where({
|
|
|
|
|
DatabaseId, UUID: def.UUID,
|
|
|
|
@ -992,21 +1003,25 @@ export class ApiService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getDatabase(PageId: string, NodeId: string, DatabaseId: string): Promise<any> {
|
|
|
|
|
public getDatabase(PageId: string, NodeId: string, DatabaseId: string, version?: number): Promise<any> {
|
|
|
|
|
return new Promise(async (res, rej) => {
|
|
|
|
|
const existingLocalDatabases = await this.db.databases.where({ UUID: DatabaseId }).toArray();
|
|
|
|
|
const existingLocalDatabase = existingLocalDatabases.length > 0 ? existingLocalDatabases[0] as Database : undefined;
|
|
|
|
|
|
|
|
|
|
if ( this.isOffline ) {
|
|
|
|
|
if ( existingLocalDatabase ) {
|
|
|
|
|
if ( existingLocalDatabase && !version ) {
|
|
|
|
|
return res(existingLocalDatabase.getSaveRecord());
|
|
|
|
|
} else {
|
|
|
|
|
return rej(new ResourceNotAvailableOfflineError());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}`).subscribe({
|
|
|
|
|
this.get(`/db/${PageId}/${NodeId}/get/${DatabaseId}?version=${version}`).subscribe({
|
|
|
|
|
next: async result => {
|
|
|
|
|
if ( version ) {
|
|
|
|
|
return res(result.data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( existingLocalDatabase ) {
|
|
|
|
|
existingLocalDatabase.fillFromRecord(result.data);
|
|
|
|
|
|
|
|
|
|