enable sidebar nav; fix build error

This commit is contained in:
garrettmills 2020-02-08 13:35:07 -06:00
parent bf1be4d3d6
commit 7a504bb8de
6 changed files with 108 additions and 40 deletions

View File

@ -1,47 +1,43 @@
import { Component } from "@angular/core"; import {Component, OnInit} from '@angular/core';
import { Platform } from "@ionic/angular"; import { Platform } from '@ionic/angular';
import { SplashScreen } from "@ionic-native/splash-screen/ngx"; import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from "@ionic-native/status-bar/ngx"; import { StatusBar } from '@ionic-native/status-bar/ngx';
import { ApiService } from "./service/api.service"; import { ApiService } from './service/api.service';
import {Router} from '@angular/router';
@Component({ @Component({
selector: "app-root", selector: 'app-root',
templateUrl: "app.component.html", templateUrl: 'app.component.html',
styleUrls: ["app.component.scss"] styleUrls: ['app.component.scss']
}) })
export class AppComponent { export class AppComponent implements OnInit {
public appPages = [
{
title: "Home",
url: "/home",
icon: "home"
},
{
title: "List",
url: "/list",
icon: "list"
},
{
title: "Editor",
url: "/editor",
icon: "edit"
}
];
public nodes = []; public nodes = [];
public options = {
actionMapping: {
mouse: {
dblClick: (tree, node, $event) => {
console.log({tree, node, $event});
const id = node.data.id;
this.router.navigate(['/editor', {id}]);
}
}
}
};
constructor( constructor(
private platform: Platform, private platform: Platform,
private splashScreen: SplashScreen, private splashScreen: SplashScreen,
private statusBar: StatusBar, private statusBar: StatusBar,
private api: ApiService private api: ApiService,
protected router: Router,
) { ) {
this.initializeApp(); this.initializeApp();
} }
ionViewDidEnter() { ngOnInit() {
this.api.get("/menu/items").subscribe(result => { this.api.get('/menu/items').subscribe(result => {
this.nodes = result.data; this.nodes = result.data;
}); });
} }

View File

@ -10,4 +10,17 @@
[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'}" [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>')" [innerHTML]="record.value.replace('\n', '<br>')"
></div> ></div>
<ul
*ngIf="record.type === 'ul'"
class="host-host ion-padding"
>
<li
contenteditable="true"
*ngFor="let line of listLines; let i = index"
#liItems
(keyup)="onLIKeyUp($event, i)"
(blur)="listLines[i]=liItems.innerHTML"
[innerHTML]="listLines[i]"
></li>
</ul>
</ng-container> </ng-container>

View File

@ -1,4 +1,4 @@
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild, ViewChildren} from '@angular/core';
import HostRecord from '../../../structures/HostRecord'; import HostRecord from '../../../structures/HostRecord';
@Component({ @Component({
@ -12,6 +12,9 @@ export class HostComponent implements OnInit {
@Output() newHostRequested = new EventEmitter<HostComponent>(); @Output() newHostRequested = new EventEmitter<HostComponent>();
@Output() destroyHostRequested = new EventEmitter<HostComponent>(); @Output() destroyHostRequested = new EventEmitter<HostComponent>();
@ViewChild('hostContainer', {static: false}) hostContainer: ElementRef; @ViewChild('hostContainer', {static: false}) hostContainer: ElementRef;
@ViewChildren('liItems') liItems;
public listLines: Array<string> = [];
constructor() { } constructor() { }
@ -42,11 +45,59 @@ export class HostComponent implements OnInit {
this.record.type = 'block_code'; this.record.type = 'block_code';
} else if ( innerText.startsWith('http') ) { } else if ( innerText.startsWith('http') ) {
this.record.type = 'click_link'; this.record.type = 'click_link';
} else if ( innerText.startsWith('-') || innerText.startsWith(' -') ) {
this.record.type = 'ul';
this.listLines = [this.record.value];
setTimeout(() => {
const item = this.liItems.toArray()[0].nativeElement;
const s = window.getSelection();
const r = document.createRange();
r.setStart(item, 0);
r.setEnd(item, 0);
s.removeAllRanges();
s.addRange(r);
}, 0);
} else { } else {
this.record.type = 'paragraph'; this.record.type = 'paragraph';
} }
} }
onLIKeyUp($event, i) {
console.log({$event});
if ( $event.code === 'Enter' ) {
const newListLines = [];
this.liItems.forEach((li, index) => {
newListLines.push(li.nativeElement.innerText.trim());
if ( index === i ) {
newListLines.push('');
}
});
this.listLines = newListLines;
// this.listLines[i] = this.liItems[i].innerText.trim()
// const newLines = []
// this.listLines.forEach((rec, x) => {
// newLines.push(rec.trim());
// if ( i === x ) {
// newLines.push('');
// }
// })
// this.listLines = newLines;
// setTimeout(() => {
// const item = this.liItems.toArray()[i + 1].nativeElement;
// const s = window.getSelection();
// const r = document.createRange();
// r.setStart(item, 0);
// r.setEnd(item, 0);
// s.removeAllRanges();
// s.addRange(r);
// }, 10);
}
}
onHostDblClick() { onHostDblClick() {
if ( this.record.type === 'click_link' ) { if ( this.record.type === 'click_link' ) {
window.open(this.record.value.trim(), '_blank'); window.open(this.record.value.trim(), '_blank');

View File

@ -15,7 +15,7 @@
<ng-container> <ng-container>
<div class="editor-root ion-padding"> <div class="editor-root ion-padding">
<div class="host-container ion-padding"> <div class="host-container ion-padding">
<editor-host #editorHosts *ngFor="let record of hostRecords" [(record)]="record" <editor-host #editorHosts *ngFor="let record of hostRecords; let i = index" [(record)]="hostRecords[i]"
(newHostRequested)="onNewHostRequested($event)" (destroyHostRequested)="onDestroyHostRequested($event)"> (newHostRequested)="onNewHostRequested($event)" (destroyHostRequested)="onDestroyHostRequested($event)">
</editor-host> </editor-host>
</div> </div>
@ -25,4 +25,4 @@
<ion-button (click)="onSaveClick()" class="ion-padding ion-margin">Save</ion-button> <ion-button (click)="onSaveClick()" class="ion-padding ion-margin">Save</ion-button>
</div> </div>
</ng-container> </ng-container>
</ion-content> </ion-content>

View File

@ -2,6 +2,7 @@ import {Component, Host, OnInit, ViewChild, ViewChildren} from '@angular/core';
import HostRecord from '../../structures/HostRecord'; import HostRecord from '../../structures/HostRecord';
import PageRecord from '../../structures/PageRecord'; import PageRecord from '../../structures/PageRecord';
import {PageService} from '../../service/page.service'; import {PageService} from '../../service/page.service';
import {ActivatedRoute} from '@angular/router';
@Component({ @Component({
selector: 'app-editor', selector: 'app-editor',
@ -11,26 +12,33 @@ import {PageService} from '../../service/page.service';
export class EditorPage implements OnInit { export class EditorPage implements OnInit {
public hostRecords: Array<HostRecord> = [new HostRecord('Click to edit page...')]; public hostRecords: Array<HostRecord> = [new HostRecord('Click to edit page...')];
public pageRecord: PageRecord = new PageRecord(); public pageRecord: PageRecord = new PageRecord();
public pageId: string;
@ViewChildren('editorHosts') editorHosts; @ViewChildren('editorHosts') editorHosts;
@ViewChild('titleBar', {static: false}) titleBar; @ViewChild('titleBar', {static: false}) titleBar;
constructor( constructor(
protected pages: PageService, protected pages: PageService,
) { } protected route: ActivatedRoute,
) {
this.route.params.subscribe(params => {
this.pageId = params.id;
});
}
ngOnInit() { ngOnInit() {
console.log('Editor component: ', this); console.log('Editor component: ', this);
} }
ionViewDidEnter() { ionViewDidEnter() {
const pageId = prompt('What is the ID of the page to load?'); if ( this.pageId ) {
this.pages.load(pageId).subscribe(pageRecord => { this.pages.load(this.pageId).subscribe(pageRecord => {
this.pageRecord = pageRecord; this.pageRecord = pageRecord;
this.pages.get_nodes(pageRecord).subscribe((hosts: Array<HostRecord>) => { this.pages.get_nodes(pageRecord).subscribe((hosts: Array<HostRecord>) => {
this.hostRecords = hosts; this.hostRecords = hosts;
});
}); });
}); }
} }
onAddClick() { onAddClick() {

View File

@ -1,6 +1,6 @@
export default class HostRecord { export default class HostRecord {
public value = ''; public value = '';
public type: 'paragraph'|'header1'|'header2'|'header3'|'header4'|'block_code'|'click_link' = 'paragraph'; public type: 'paragraph'|'header1'|'header2'|'header3'|'header4'|'block_code'|'click_link'|'ul' = 'paragraph';
public CreatedAt: string; public CreatedAt: string;
public PageId: string; public PageId: string;