feat(aio): add DtComponent to view/change the raw contents
This commit is contained in:
parent
1e623a3710
commit
ae70293df3
@ -17,7 +17,8 @@
|
|||||||
</md-sidenav>
|
</md-sidenav>
|
||||||
|
|
||||||
<section class="sidenav-content" [id]="pageId">
|
<section class="sidenav-content" [id]="pageId">
|
||||||
<aio-doc-viewer [doc]="currentDocument" (docRendered)="onDocRendered($event)"></aio-doc-viewer>
|
<aio-doc-viewer [doc]="currentDocument" (docRendered)="onDocRendered()"></aio-doc-viewer>
|
||||||
|
<aio-dt [on]="dtOn" [(doc)]="currentDocument"></aio-dt>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</md-sidenav-container>
|
</md-sidenav-container>
|
||||||
|
@ -21,6 +21,7 @@ const sideNavView = 'SideNav';
|
|||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit {
|
||||||
|
|
||||||
currentNode: CurrentNode;
|
currentNode: CurrentNode;
|
||||||
|
dtOn = false;
|
||||||
pageId: string;
|
pageId: string;
|
||||||
currentDocument: DocumentContents;
|
currentDocument: DocumentContents;
|
||||||
footerNodes: NavigationNode[];
|
footerNodes: NavigationNode[];
|
||||||
@ -98,7 +99,7 @@ export class AppComponent implements OnInit {
|
|||||||
this.autoScrollService.scroll(this.docViewer.nativeElement.offsetParent);
|
this.autoScrollService.scroll(this.docViewer.nativeElement.offsetParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDocRendered(doc: DocumentContents) {
|
onDocRendered() {
|
||||||
// This handler is needed because the subscription to the `currentUrl` in `ngOnInit`
|
// This handler is needed because the subscription to the `currentUrl` in `ngOnInit`
|
||||||
// gets triggered too early before the doc-viewer has finished rendering the doc
|
// gets triggered too early before the doc-viewer has finished rendering the doc
|
||||||
this.autoScroll();
|
this.autoScroll();
|
||||||
@ -109,8 +110,8 @@ export class AppComponent implements OnInit {
|
|||||||
this.isSideBySide = width > this.sideBySideWidth;
|
this.isSideBySide = width > this.sideBySideWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('click', ['$event.target', '$event.button', '$event.ctrlKey', '$event.metaKey'])
|
@HostListener('click', ['$event.target', '$event.button', '$event.ctrlKey', '$event.metaKey', '$event.altKey'])
|
||||||
onClick(eventTarget: HTMLElement, button: number, ctrlKey: boolean, metaKey: boolean): boolean {
|
onClick(eventTarget: HTMLElement, button: number, ctrlKey: boolean, metaKey: boolean, altKey: boolean): boolean {
|
||||||
|
|
||||||
// Hide the search results if we clicked outside both the search box and the search results
|
// Hide the search results if we clicked outside both the search box and the search results
|
||||||
if (this.searchResults) {
|
if (this.searchResults) {
|
||||||
@ -120,6 +121,10 @@ export class AppComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventTarget.tagName === 'FOOTER' && metaKey && altKey) {
|
||||||
|
this.dtOn = !this.dtOn;
|
||||||
|
}
|
||||||
|
|
||||||
// Deal with anchor clicks
|
// Deal with anchor clicks
|
||||||
if (eventTarget instanceof HTMLImageElement) {
|
if (eventTarget instanceof HTMLImageElement) {
|
||||||
eventTarget = eventTarget.parentElement; // assume image wrapped in Anchor
|
eventTarget = eventTarget.parentElement; // assume image wrapped in Anchor
|
||||||
@ -133,5 +138,4 @@ export class AppComponent implements OnInit {
|
|||||||
sideNavToggle(value?: boolean) {
|
sideNavToggle(value?: boolean) {
|
||||||
this.sidenav.toggle(value);
|
this.sidenav.toggle(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import { SwUpdatesModule } from 'app/sw-updates/sw-updates.module';
|
|||||||
import { AppComponent } from 'app/app.component';
|
import { AppComponent } from 'app/app.component';
|
||||||
import { ApiService } from 'app/embedded/api/api.service';
|
import { ApiService } from 'app/embedded/api/api.service';
|
||||||
import { DocViewerComponent } from 'app/layout/doc-viewer/doc-viewer.component';
|
import { DocViewerComponent } from 'app/layout/doc-viewer/doc-viewer.component';
|
||||||
|
import { DtComponent } from 'app/layout/doc-viewer/dt.component';
|
||||||
import { EmbeddedModule } from 'app/embedded/embedded.module';
|
import { EmbeddedModule } from 'app/embedded/embedded.module';
|
||||||
import { GaService } from 'app/shared/ga.service';
|
import { GaService } from 'app/shared/ga.service';
|
||||||
import { Logger } from 'app/shared/logger.service';
|
import { Logger } from 'app/shared/logger.service';
|
||||||
@ -54,6 +55,7 @@ import { AutoScrollService } from 'app/shared/auto-scroll.service';
|
|||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
DocViewerComponent,
|
DocViewerComponent,
|
||||||
|
DtComponent,
|
||||||
FooterComponent,
|
FooterComponent,
|
||||||
TopMenuComponent,
|
TopMenuComponent,
|
||||||
NavMenuComponent,
|
NavMenuComponent,
|
||||||
|
@ -35,7 +35,7 @@ export class DocViewerComponent implements DoCheck, OnDestroy {
|
|||||||
private hostElement: HTMLElement;
|
private hostElement: HTMLElement;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
docRendered = new EventEmitter<DocumentContents>();
|
docRendered = new EventEmitter();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
componentFactoryResolver: ComponentFactoryResolver,
|
componentFactoryResolver: ComponentFactoryResolver,
|
||||||
@ -60,7 +60,7 @@ export class DocViewerComponent implements DoCheck, OnDestroy {
|
|||||||
this.ngOnDestroy();
|
this.ngOnDestroy();
|
||||||
if (newDoc) {
|
if (newDoc) {
|
||||||
this.build(newDoc);
|
this.build(newDoc);
|
||||||
this.docRendered.emit(newDoc);
|
this.docRendered.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
aio/src/app/layout/doc-viewer/dt.component.ts
Normal file
30
aio/src/app/layout/doc-viewer/dt.component.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
|
||||||
|
import { DocumentContents } from 'app/documents/document.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'aio-dt',
|
||||||
|
template: `
|
||||||
|
<div *ngIf="on">
|
||||||
|
<hr>
|
||||||
|
<textarea #dt [value]="text" rows="10" cols="80"></textarea>
|
||||||
|
<br/>
|
||||||
|
<button (click)="dtextSet()">Show change</button>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
export class DtComponent {
|
||||||
|
|
||||||
|
@Input() on = false;
|
||||||
|
@Input('doc') doc: DocumentContents;
|
||||||
|
@Output() docChange = new EventEmitter<DocumentContents>();
|
||||||
|
|
||||||
|
@ViewChild('dt', { read: ElementRef })
|
||||||
|
dt: ElementRef;
|
||||||
|
|
||||||
|
get text() { return this.doc && this.doc.contents; }
|
||||||
|
|
||||||
|
dtextSet() {
|
||||||
|
this.doc.contents = this.dt.nativeElement.value;
|
||||||
|
this.docChange.emit({ ...this.doc });
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user