Skip to content

Commit d0a831f

Browse files
committed
feat(docs) demo app improvements (#39)
Resolves #39 - no minimap in non-fullscreen mode - no toolbar collapse in non-fullscreen mode - fix exit fullscreen fab positioning - scroll position after exit fullscreen
1 parent 6232e82 commit d0a831f

File tree

12 files changed

+87
-17
lines changed

12 files changed

+87
-17
lines changed

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src-website/app/components/demo/demo.component.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ <h2>The actual app</h2>
1313
model.
1414
</p>
1515

16-
<h2>View in fullscreen</h2>
16+
<h2 #viewInFullscreen>View in fullscreen</h2>
1717
<p>
18-
Click the button below to make the demo app fullscreen. Otherwise there will be bugs with
19-
floating minimap and collapsed toolbar.
18+
Fullscreen mode lets you see how actual app looks like.
19+
Some features are available only in fullscreen mode, e.g. minimap and toolbar expand-collapse.
2020
</p>
2121
<button
2222
type="button"
2323
class="toggle-fullscreen-btn"
2424
md-raised-button
25-
(click)="fullscreen = !fullscreen">
26-
Toggle fullscreen
25+
(click)="toggleFullscreen()">
26+
<md-icon>fullscreen_enter</md-icon>
27+
Fullscreen
2728
</button>
2829
</section>
2930

30-
<efd-root></efd-root>
31+
<efd-root [allowToolbarCollapse]="fullscreen" (diagramLoad)="onDiagramLoaded($event)"></efd-root>
3132

3233
<button
3334
*ngIf="fullscreen"
@@ -36,7 +37,7 @@ <h2>View in fullscreen</h2>
3637
md-fab
3738
mdTooltip="Exit fullscreen mode"
3839
mdTooltipPosition="right"
39-
(click)="fullscreen = !fullscreen">
40+
(click)="toggleFullscreen()">
4041
<md-icon>fullscreen_exit</md-icon>
4142
</button>
4243

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src-website/app/components/demo/demo.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ main {
1919
.toggle-fullscreen-btn {
2020
position: fixed;
2121
bottom: 28px;
22-
left: 260px;
22+
left: calc(25% - 80px);
2323
}
2424
}
2525

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src-website/app/components/demo/demo.component.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, ElementRef, ViewChild } from '@angular/core';
22

3+
import { DiagramLayoutService } from '../../../../src/app/services/diagram-layout.service';
4+
import { DbModelLayout } from '../../../../src/app/models/db-model-layout';
5+
import { AppComponent } from '../../../../src/app/components/app/app.component';
36
import { environment } from '../../../../src/environments/environment';
47

58
@Component({
@@ -14,9 +17,34 @@ export class DemoComponent implements OnInit {
1417
commitSha = environment.versions.revision;
1518
commitLink = `${environment.versions.repository}commit/${environment.versions.revision}`;
1619

17-
constructor() { }
20+
@ViewChild('viewInFullscreen')
21+
viewInFullscreen: ElementRef;
22+
23+
constructor(private readonly _diagramLayout: DiagramLayoutService) {
24+
}
1825

1926
ngOnInit() {
2027
}
2128

29+
toggleFullscreen() {
30+
this.fullscreen = !this.fullscreen;
31+
32+
for (const modelLayout of this._diagramLayout.getModelLayouts()) {
33+
modelLayout.showMinimap = this.fullscreen;
34+
}
35+
36+
if (!this.fullscreen) {
37+
setTimeout(() => this.scrollToViewInFullscreen(), 16);
38+
}
39+
}
40+
41+
private scrollToViewInFullscreen() {
42+
const viewInFullscreen = this.viewInFullscreen.nativeElement as HTMLElement;
43+
window.document.body.scrollTop = viewInFullscreen.getBoundingClientRect().top - 8;
44+
}
45+
46+
onDiagramLoaded(modelLayout: DbModelLayout) {
47+
modelLayout.showMinimap = this.fullscreen;
48+
}
49+
2250
}

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src/app/components/app/app.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
<md-icon>folder_open</md-icon>
1111
</button>
1212
</ng-container>
13-
<button type="button" md-icon-button (click)="toolbarCollapsed = !toolbarCollapsed" [mdTooltip]="toolbarCollapsed ? 'Expand' : 'Collapse'">
13+
<button
14+
*ngIf="allowToolbarCollapse"
15+
type="button"
16+
md-icon-button
17+
(click)="toolbarCollapsed = !toolbarCollapsed"
18+
[mdTooltip]="toolbarCollapsed ? 'Expand' : 'Collapse'">
1419
<md-icon *ngIf="!toolbarCollapsed">expand_less</md-icon>
1520
<md-icon *ngIf="toolbarCollapsed">expand_more</md-icon>
1621
</button>

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src/app/components/app/app.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, Input, Output, EventEmitter, OnChanges } from '@angular/core';
22
import { MdDialog, MdDialogRef } from '@angular/material';
33
import { Observable } from 'rxjs/Observable';
44

55
import { ApiService } from '../../services/api.service';
66
import { DiagramLayoutService } from '../../services/diagram-layout.service';
77
import { DbModel } from '../../models/db-model';
8+
import { DbModelLayout } from '../../models/db-model-layout';
89
import { DbEntityLayout } from '../../models/db-entity-layout';
910
import { ExportDialogComponent } from '../export-dialog/export-dialog.component';
1011

@@ -13,7 +14,7 @@ import { ExportDialogComponent } from '../export-dialog/export-dialog.component'
1314
templateUrl: './app.component.html',
1415
styleUrls: ['./app.component.scss']
1516
})
16-
export class AppComponent implements OnInit {
17+
export class AppComponent implements OnInit, OnChanges {
1718

1819
model: DbModel = null;
1920
modelLoading = false;
@@ -23,6 +24,12 @@ export class AppComponent implements OnInit {
2324

2425
get modelLayout() { return this._diagramLayout.getModelLayout(this.model); }
2526

27+
@Input()
28+
allowToolbarCollapse = true;
29+
30+
@Output()
31+
diagramLoad = new EventEmitter<DbModelLayout>();
32+
2633
constructor(
2734
private readonly _api: ApiService,
2835
private readonly _diagramLayout: DiagramLayoutService,
@@ -36,10 +43,17 @@ export class AppComponent implements OnInit {
3643
.subscribe(e => this.onModel(e), e => this.onModelError(e));
3744
}
3845

46+
ngOnChanges(changes) {
47+
if ('allowToolbarCollapse' in changes && !this.allowToolbarCollapse && this.toolbarCollapsed) {
48+
this.toolbarCollapsed = false;
49+
}
50+
}
51+
3952
onModel(model: DbModel) {
4053
this.model = model;
4154
this.modelLoading = false;
4255
this.modelLoadError = null;
56+
this.diagramLoad.emit(this._diagramLayout.getModelLayout(model));
4357
}
4458

4559
onModelError(err) {
@@ -54,6 +68,7 @@ export class AppComponent implements OnInit {
5468

5569
restoreLayout() {
5670
this._diagramLayout.restoreLayout(this.model);
71+
this.diagramLoad.emit(this._diagramLayout.getModelLayout(this.model));
5772
}
5873

5974
toggleAllEntitiesVisibility() {
@@ -98,6 +113,7 @@ export class AppComponent implements OnInit {
98113
.do(() => {
99114
this.model = newModel;
100115
this.modelLoading = false;
116+
this.diagramLoad.emit(this._diagramLayout.getModelLayout(this.model));
101117
})
102118
.subscribe();
103119
}

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src/app/components/db-diagram/db-diagram.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ <h1 *ngIf="!model.entities || model.entities.length === 0">Database model is emp
5454

5555
</div>
5656

57-
<efd-minimap [targetElement]="scrollContainer"></efd-minimap>
57+
<efd-minimap [class.hidden]="!modelLayout.showMinimap" [targetElement]="scrollContainer"></efd-minimap>
5858

5959
</div>

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src/app/components/db-diagram/db-diagram.component.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,10 @@ $relation-color-normal: #cacaca;
7979
}
8080
}
8181
}
82+
83+
efd-minimap {
84+
&.hidden {
85+
display: none;
86+
}
87+
}
8288
}

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src/app/components/minimap/minimap.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ export class MinimapComponent implements OnInit, DoCheck {
7171
}
7272

7373
ngDoCheck() {
74-
const newSize = this.getMinimapSize();
75-
if (!areEqual(newSize, this.prevSize)) {
76-
this.updateMinimap(newSize);
74+
if (this.targetElement) {
75+
const newSize = this.getMinimapSize();
76+
if (!areEqual(newSize, this.prevSize)) {
77+
this.updateMinimap(newSize);
78+
}
7779
}
7880
}
7981

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src/app/models/db-model-layout.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export class DbModelLayout {
2424

2525
entitiesTableSettings = getDefaultEntityTableSettings();
2626

27+
showMinimap = true;
28+
2729
constructor(public readonly model: DbModel) {
2830
for (const entity of model.entities) {
2931
for (const fk of entity.foreignKeys) {
@@ -57,6 +59,7 @@ export class DbModelLayout {
5759
result.entities = this.entities.map(e => e.toDto());
5860
result.relations = this.relations.map(e => e.toDto());
5961
result.entitiesTableSettings = this.entitiesTableSettings;
62+
result.showMinimap = this.showMinimap;
6063
return result;
6164
}
6265

@@ -82,6 +85,8 @@ export class DbModelLayout {
8285
}
8386
this.entitiesTableSettings = dto.entitiesTableSettings;
8487

88+
this.showMinimap = dto.showMinimap;
89+
8590
this.updateVisibleObjects();
8691
}
8792

EntityFrameworkCore.Diagrams/EntityFrameworkCore.Diagrams.Frontend/src/app/models/dto/db-model-layout-dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class DbModelLayoutDto {
66
entities: DbEntityLayoutDto[] = [];
77
relations: DbEntityRelationLayoutDto[] = [];
88
entitiesTableSettings: TableSettings;
9+
showMinimap: boolean;
910

1011
static fromJSON(value: Object): DbModelLayoutDto {
1112
return Object.assign(

0 commit comments

Comments
 (0)