Task #11, Task #6 - add click_link type, saving/restore support to the editor

This commit is contained in:
garrettmills
2020-02-08 11:19:00 -06:00
parent 8a53bc2888
commit 3861c1e72f
11 changed files with 255 additions and 31 deletions

View File

@@ -1,12 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { ApiService } from './api.service';
describe('ApiService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: ApiService = TestBed.get(ApiService);
expect(service).toBeTruthy();
});
});

View File

@@ -24,11 +24,11 @@ export class ApiService {
public request(endpoint, params = {}, method: 'get'|'post' = 'get'): Observable<ApiResponse> {
return new Observable<ApiResponse>(sub => {
const data: any = {}
let data: any = {}
if ( method === 'get' ) {
data.params = params;
} else {
data.body = params;
data = params;
}
this.http[method](this._build_url(endpoint), data).subscribe({

View File

@@ -0,0 +1,74 @@
import {Host, Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import PageRecord from '../structures/PageRecord';
import {ApiService} from './api.service';
import HostRecord from '../structures/HostRecord';
@Injectable({
providedIn: 'root'
})
export class PageService {
constructor(
protected api: ApiService,
) { }
load(id: string): Observable<PageRecord> {
return new Observable<PageRecord>(sub => {
this.api.get(`/page/${id}`).subscribe(response => {
if ( response.status === 200 ) {
sub.next(new PageRecord(response.data));
sub.complete();
} else {
throw new Error(response.message);
}
});
});
}
save(page: PageRecord): Observable<PageRecord> {
return new Observable<PageRecord>(sub => {
this.api.post(`/page/${page.UUID}/save`, page.toSave()).subscribe(res => {
sub.next(new PageRecord(res.data));
sub.complete();
});
});
}
get_nodes(page: PageRecord): Observable<Array<HostRecord>> {
return new Observable<Array<HostRecord>>(sub => {
this.api.get(`/page/${page.UUID}/nodes`).subscribe(res => {
const returns = [];
res.data.forEach(rec => {
const host = new HostRecord(rec.Value.Value);
host.load(rec);
returns.push(host);
});
sub.next(returns);
sub.complete();
});
});
}
save_nodes(page: PageRecord, nodes: Array<HostRecord>): Observable<Array<HostRecord>> {
return new Observable<Array<HostRecord>>(sub => {
nodes = nodes.map(x => {
x.PageId = page.UUID;
return x.toSave();
});
this.api.post(`/page/${page.UUID}/nodes/save`, nodes).subscribe(res => {
const returns = [];
res.data.forEach(rec => {
const host = new HostRecord(rec.Value.Value);
host.load(rec);
returns.push(host);
});
sub.next(returns);
sub.complete();
});
});
}
}