Handle top-level page creation for offline
This commit is contained in:
parent
fe7e955875
commit
8f5ad697b3
@ -303,10 +303,9 @@ export class AppComponent implements OnInit {
|
||||
{
|
||||
text: 'Create',
|
||||
handler: async args => {
|
||||
this.api.post('/page/create', args).subscribe(res => {
|
||||
this.router.navigate(['/editor', { id: res.data.UUID }]);
|
||||
this.reloadMenuItems().subscribe();
|
||||
});
|
||||
const page = await this.api.createPage(args.name);
|
||||
this.reloadMenuItems().subscribe();
|
||||
await this.router.navigate(['/editor', { id: page.UUID }]);
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -10,7 +10,9 @@ import {Codium} from './db/Codium';
|
||||
import {Database} from './db/Database';
|
||||
import {DatabaseColumn} from './db/DatabaseColumn';
|
||||
import {DatabaseEntry} from './db/DatabaseEntry';
|
||||
import {FileGroup} from "./db/FileGroup";
|
||||
import {FileGroup} from './db/FileGroup';
|
||||
import {Page} from './db/Page'
|
||||
import {PageNode} from "./db/PageNode";
|
||||
|
||||
export class ResourceNotAvailableOfflineError extends Error {
|
||||
constructor(msg = 'This resource is not yet available offline on this device.') {
|
||||
@ -868,4 +870,101 @@ export class ApiService {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public createPage(name: string): Promise<any> {
|
||||
return new Promise(async (res, rej) => {
|
||||
// If we're offline, create a stub page to be saved later
|
||||
if ( this.isOffline ) {
|
||||
const page = new Page(
|
||||
Page.getUUID(),
|
||||
'New Page',
|
||||
'OrgUserId',
|
||||
true,
|
||||
true,
|
||||
'0',
|
||||
[],
|
||||
String(new Date()),
|
||||
String(new Date()),
|
||||
true,
|
||||
'create user id',
|
||||
'update user id',
|
||||
[],
|
||||
false,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
const firstNode = new PageNode(
|
||||
PageNode.getUUID(),
|
||||
'paragraph',
|
||||
JSON.stringify({ Value: 'Click to edit...' }),
|
||||
page.UUID,
|
||||
String(new Date()),
|
||||
String(new Date()),
|
||||
'create user id',
|
||||
'update user id',
|
||||
true
|
||||
);
|
||||
|
||||
await firstNode.save();
|
||||
|
||||
page.NodeIds.push(firstNode.UUID);
|
||||
await page.save();
|
||||
|
||||
// Because we're offline, we need to manually create the menu item node
|
||||
const topLevelItem = await this.db.menuItems.where({
|
||||
serverId: 0,
|
||||
name: 'My Info Tree',
|
||||
}).first() as MenuItem;
|
||||
|
||||
if ( topLevelItem ) {
|
||||
const newItem = new MenuItem(
|
||||
page.Name,
|
||||
MenuItem.getUUID(),
|
||||
[],
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
'page',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
await newItem.save();
|
||||
|
||||
topLevelItem.childIds.push(newItem.serverId);
|
||||
await topLevelItem.save();
|
||||
}
|
||||
|
||||
return res(page.getSaveRecord());
|
||||
}
|
||||
|
||||
// If we're online, the server will handle all of that mess...
|
||||
this.post('/page/create', { name }).subscribe({
|
||||
next: async result => {
|
||||
const page = new Page(
|
||||
result.data.UUID,
|
||||
result.data.Name,
|
||||
result.data.OrgUserId,
|
||||
result.data.IsPublic,
|
||||
result.data.IsVisibleInMenu,
|
||||
result.data.ParentId,
|
||||
result.data.NodeIds,
|
||||
result.data.CreatedAt,
|
||||
result.data.UpdatedAt,
|
||||
true,
|
||||
result.data.CreatedUserId,
|
||||
result.data.UpdateUserId,
|
||||
result.data.ChildPageIds,
|
||||
result.data.noDelete,
|
||||
result.data.virtual
|
||||
);
|
||||
|
||||
await page.save();
|
||||
return res(result.data);
|
||||
},
|
||||
error: rej,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user