parent
8a53bc2888
commit
3861c1e72f
@ -1,13 +1,13 @@
|
||||
<ng-container>
|
||||
<div
|
||||
*ngIf="record.type === 'paragraph' || record.type === 'header1' || record.type === 'header2' || record.type === 'header3' || record.type === 'header4' || record.type === 'block_code'"
|
||||
*ngIf="record.type === 'paragraph' || record.type === 'header1' || record.type === 'header2' || record.type === 'header3' || record.type === 'header4' || record.type === 'block_code' || record.type === 'click_link'"
|
||||
class="host-host ion-padding"
|
||||
contenteditable="true"
|
||||
(keyup)="onKeyUp($event)"
|
||||
(blur)="record.value=hostContainer.innerText"
|
||||
(blur)="record.value=hostContainer.innerHTML"
|
||||
(dblclick)="onHostDblClick()"
|
||||
#hostContainer
|
||||
[ngClass]="{'paragraph': record.type === 'paragraph', 'header1': record.type === 'header1', 'header2': record.type === 'header2', 'header3': record.type === 'header3', 'header4': record.type === 'header4', 'block_code': record.type === 'block_code'}"
|
||||
>
|
||||
{{ record.value }}
|
||||
</div>
|
||||
[ngClass]="{'paragraph': record.type === 'paragraph', 'header1': record.type === 'header1', 'header2': record.type === 'header2', 'header3': record.type === 'header3', 'header4': record.type === 'header4', 'block_code': record.type === 'block_code', 'click_link': record.type === 'click_link'}"
|
||||
[innerHTML]="record.value.replace('\n', '<br>')"
|
||||
></div>
|
||||
</ng-container>
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@ -1,9 +1,54 @@
|
||||
export default class HostRecord {
|
||||
public value = '';
|
||||
public type: 'paragraph'|'header1'|'header2'|'header3'|'header4'|'block_code'|'click_link' = 'paragraph';
|
||||
|
||||
public type: 'paragraph'|'header1'|'header2'|'header3'|'header4'|'block_code' = 'paragraph';
|
||||
public CreatedAt: string;
|
||||
public PageId: string;
|
||||
public UUID: string;
|
||||
public UpdatedAt: string;
|
||||
public Value: any;
|
||||
|
||||
constructor(value = '') {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
load(data: any) {
|
||||
this.type = data.Type;
|
||||
|
||||
[
|
||||
'CreatedAt',
|
||||
'PageId',
|
||||
'UUID',
|
||||
'UpdatedAt',
|
||||
'Value',
|
||||
].forEach(field => {
|
||||
if ( field in data ) {
|
||||
this[field] = data[field];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toSave() {
|
||||
const data: any = {
|
||||
Type: this.type
|
||||
};
|
||||
|
||||
[
|
||||
'CreatedAt',
|
||||
'PageId',
|
||||
'UUID',
|
||||
'UpdatedAt',
|
||||
'Value',
|
||||
].forEach(field => {
|
||||
if ( field in this ) {
|
||||
data[field] = this[field];
|
||||
}
|
||||
});
|
||||
|
||||
if ( !data.Value ) {
|
||||
data.Value = {};
|
||||
}
|
||||
data.Value.Value = this.value;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
export default class PageRecord {
|
||||
public UUID: string;
|
||||
public Name: string;
|
||||
public OrgUserId: string;
|
||||
public IsPublic = true;
|
||||
public IsVisibleInMenu = true;
|
||||
public ParentId: string;
|
||||
public NodeIds: Array<string>;
|
||||
public CreatedAt: Date;
|
||||
public UpdatedAt: Date;
|
||||
public CreatedUserId: string;
|
||||
public UpdateUserId: string;
|
||||
public ChildPageIds: Array<string>;
|
||||
|
||||
constructor(data: any = {Name: 'Click to edit title...'}) {
|
||||
[
|
||||
'UUID',
|
||||
'Name',
|
||||
'OrgUserId',
|
||||
'IsPublic',
|
||||
'IsVisibleInMenu',
|
||||
'ParentId',
|
||||
'NodeIds',
|
||||
'CreatedAt',
|
||||
'UpdatedAt',
|
||||
'CreatedUserId',
|
||||
'UpdateUserId',
|
||||
'ChildPageIds'
|
||||
].forEach(field => {
|
||||
if ( field in data ) {
|
||||
this[field] = data[field];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toSave() {
|
||||
const data = {};
|
||||
[
|
||||
'UUID',
|
||||
'Name',
|
||||
'OrgUserId',
|
||||
'IsPublic',
|
||||
'IsVisibleInMenu',
|
||||
'ParentId',
|
||||
'NodeIds',
|
||||
'CreatedAt',
|
||||
'UpdatedAt',
|
||||
'CreatedUserId',
|
||||
'UpdateUserId',
|
||||
'ChildPageIds'
|
||||
].forEach(field => {
|
||||
if ( field in this ) {
|
||||
data[field] = this[field];
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
export const environment = {
|
||||
production: true,
|
||||
backendBase: '/',
|
||||
backendBase: '/api/v1',
|
||||
};
|
||||
|
Loading…
Reference in new issue