Save page on name change & refresh sidebar (#20)
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

master
Garrett Mills 4 years ago
parent 292bf6c729
commit 07664e29cd
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -13,6 +13,7 @@ import {SelectorComponent} from './components/sharing/selector/selector.componen
import {SessionService} from './service/session.service'; import {SessionService} from './service/session.service';
import {SearchComponent} from './components/search/Search.component'; import {SearchComponent} from './components/search/Search.component';
import {NodeTypeIcons} from './structures/node-types'; import {NodeTypeIcons} from './structures/node-types';
import {NavigationService} from './service/navigation.service';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -88,6 +89,7 @@ export class AppComponent implements OnInit {
protected modal: ModalController, protected modal: ModalController,
protected session: SessionService, protected session: SessionService,
protected loading: LoadingController, protected loading: LoadingController,
protected navService: NavigationService,
) { ) {
this.initializeApp(); this.initializeApp();
} }
@ -104,6 +106,10 @@ export class AppComponent implements OnInit {
ngOnInit() { ngOnInit() {
if ( !this.initialized$.getValue() ) { if ( !this.initialized$.getValue() ) {
this.navService.sidebarRefresh$.subscribe(([_, quiet]) => {
this.onMenuRefresh(quiet);
});
const sub = this.initialized$.subscribe((didInit) => { const sub = this.initialized$.subscribe((didInit) => {
if (didInit) { if (didInit) {
this._doInit(); this._doInit();
@ -201,7 +207,7 @@ export class AppComponent implements OnInit {
}); });
} else if ( result.data === 'export_html' ) { } else if ( result.data === 'export_html' ) {
this.exportTargetAsHTML(); this.exportTargetAsHTML();
} };
}); });
await popover.present(); await popover.present();
@ -335,11 +341,17 @@ export class AppComponent implements OnInit {
await alert.present(); await alert.present();
} }
onMenuRefresh() { onMenuRefresh(quiet = false) {
this.refreshingMenu = true; if ( !quiet ) {
this.refreshingMenu = true;
}
this.reloadMenuItems().subscribe(); this.reloadMenuItems().subscribe();
setTimeout(() => { setTimeout(() => {
this.refreshingMenu = false; if ( !quiet ) {
this.refreshingMenu = false;
}
}, 2000); }, 2000);
} }

@ -4,6 +4,7 @@ import PageRecord from '../structures/PageRecord';
import HostRecord from '../structures/HostRecord'; import HostRecord from '../structures/HostRecord';
import {EditorNodeContract} from '../components/nodes/EditorNode.contract'; import {EditorNodeContract} from '../components/nodes/EditorNode.contract';
import {BehaviorSubject, Subscription} from 'rxjs'; import {BehaviorSubject, Subscription} from 'rxjs';
import {NavigationService} from './navigation.service';
export class NoPageLoadedError extends Error { export class NoPageLoadedError extends Error {
constructor(msg = 'There is no page open for editing.') { constructor(msg = 'There is no page open for editing.') {
@ -73,6 +74,7 @@ export class EditorService {
if ( this.currentPage && this.canEdit() ) { if ( this.currentPage && this.canEdit() ) {
if ( this.currentPage.Name !== name ) { if ( this.currentPage.Name !== name ) {
this.dirtyOverride = true; this.dirtyOverride = true;
this.triggerSave();
} }
this.currentPage.Name = name; this.currentPage.Name = name;
@ -81,6 +83,7 @@ export class EditorService {
constructor( constructor(
protected api: ApiService, protected api: ApiService,
protected nav: NavigationService,
) { } ) { }
async startEditing(pageId: string) { async startEditing(pageId: string) {
@ -122,9 +125,11 @@ export class EditorService {
await editor.writeChangesToNode(); await editor.writeChangesToNode();
})); }));
await this.savePage(this.currentPage);
await this.saveNodesAsPage(this.currentPage, this.currentNodes); await this.saveNodesAsPage(this.currentPage, this.currentNodes);
this.dirtyOverride = false; this.dirtyOverride = false;
this.saving = false; this.saving = false;
this.nav.requestSidebarRefresh({ quiet: true });
} }
async moveNode(node: HostRecord, direction: 'up' | 'down') { async moveNode(node: HostRecord, direction: 'up' | 'down') {
@ -153,6 +158,20 @@ export class EditorService {
this.triggerSave(); this.triggerSave();
} }
async savePage(page: PageRecord): Promise<void> {
await new Promise((res, rej) => {
const saveData = page.toSave();
this.api.post(`/page/${page.UUID}/save`, saveData).subscribe({
next: result => {
console.log('save result', result);
res();
},
error: rej,
});
});
}
async saveNodesAsPage(page: PageRecord, nodes: HostRecord[]): Promise<HostRecord[]> { async saveNodesAsPage(page: PageRecord, nodes: HostRecord[]): Promise<HostRecord[]> {
return new Promise((res, rej) => { return new Promise((res, rej) => {
const saveNodes = nodes.map(x => { const saveNodes = nodes.map(x => {

@ -0,0 +1,15 @@
import { Injectable } from '@angular/core';
import {BehaviorSubject} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class NavigationService {
protected refreshCount = 0;
public readonly sidebarRefresh$: BehaviorSubject<[number, boolean]> = new BehaviorSubject<[number, boolean]>([this.refreshCount, true]);
requestSidebarRefresh({ quiet = false }) {
this.refreshCount += 1;
this.sidebarRefresh$.next([this.refreshCount, quiet]);
}
}
Loading…
Cancel
Save