added history
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<app-graphs [config]="config" (svgChange)="prepareSvgExport($event)"></app-graphs>
|
<app-graphs [config]="config" [restoredHistory]="restoredHistory" (svgChange)="prepareSvgExport($event)"></app-graphs>
|
||||||
|
|
||||||
<aside class="col-sm-4 col-lg-3 col-xl-3">
|
<aside class="col-sm-4 col-lg-3 col-xl-3">
|
||||||
<div class="aside-inner">
|
<div class="aside-inner">
|
||||||
@@ -98,25 +98,35 @@
|
|||||||
<button type="submit" class="btn btn-lg btn-primary btn-block" [disabled]="configForm.invalid">Aktualisieren</button>
|
<button type="submit" class="btn btn-lg btn-primary btn-block" [disabled]="configForm.invalid">Aktualisieren</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="dropdown-divider"></div>
|
<div class="row mt-4">
|
||||||
|
<div class="col-sm">
|
||||||
<button class="btn btn-secondary btn-block" (click)="exportSvg()">Download</button>
|
<button class="btn btn-secondary btn-block" (click)="exportSvg()">Download</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm mt-xs-2 mt-sm-2 mt-md-0">
|
||||||
|
<button class="btn btn-secondary btn-block" (click)="toggleList()">
|
||||||
|
Chronik <span class="badge badge-light badge-pill">{{ list.length }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="dropdown-divider"></div>
|
<div *ngIf="showList" class="list-group mt-4">
|
||||||
|
<a href="#" *ngFor="let item of list.reverse(); let i = index" class="list-group-item d-flex flex-row " (click)="restoreGraph(item)">
|
||||||
<button class="btn btn-secondary btn-block" (click)="toggleList()">Chronik <span class="badge badge-light">{{ list.length }}</span></button>
|
<span class="text-muted pr-3">#{{ list.length - i }}</span>
|
||||||
|
<div class="d-flex flex-column">
|
||||||
<ul *ngIf="showList" class="list-group list-group-flush mt-4">
|
<div>
|
||||||
<li *ngFor="let item of list" class="list-group-item d-flex justify-content-between align-items-center" (click)="restoreGraph(item)">
|
{{ item.date | date:'HH:mm:ss' }} Uhr
|
||||||
{{ item.date | date:'dd.MM.y · HH:mm:ss' }} Uhr
|
</div>
|
||||||
<span class="badge badge-primary badge-pill">
|
<div class="">
|
||||||
|
<span class="badge badge-primary mr-2">
|
||||||
{{ item.config.nodes }} Knoten
|
{{ item.config.nodes }} Knoten
|
||||||
</span>
|
</span>
|
||||||
<span class="badge badge-primary badge-pill">
|
<span class="badge badge-primary">
|
||||||
{{ item.config.spread }} Linien
|
{{ item.config.spread }} Linien
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</div>
|
||||||
</ul>
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import { Param } from './models/param.model';
|
|||||||
import { Config } from './models/config.model';
|
import { Config } from './models/config.model';
|
||||||
import { CanvasService } from './services/canvas.service';
|
import { CanvasService } from './services/canvas.service';
|
||||||
import { HistoryService } from './services/history.service';
|
import { HistoryService } from './services/history.service';
|
||||||
|
import { Graph } from './models/graph.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@@ -38,6 +39,7 @@ export class AppComponent implements OnInit {
|
|||||||
public url: any;
|
public url: any;
|
||||||
public list: any[];
|
public list: any[];
|
||||||
public showList: boolean;
|
public showList: boolean;
|
||||||
|
public restoredHistory: any;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private canvasService: CanvasService,
|
private canvasService: CanvasService,
|
||||||
@@ -46,12 +48,13 @@ export class AppComponent implements OnInit {
|
|||||||
this.config = env.formDefaults;
|
this.config = env.formDefaults;
|
||||||
this.configForm = ConfigForm;
|
this.configForm = ConfigForm;
|
||||||
this.list = [];
|
this.list = [];
|
||||||
this.showList = false;
|
this.showList = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.configForm.reset({...this.config});
|
this.configForm.reset({...this.config});
|
||||||
this.list = this.historyService.list();
|
this.list = this.historyService.list();
|
||||||
|
// console.log(this.graphs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateGraphs() {
|
public updateGraphs() {
|
||||||
@@ -85,7 +88,8 @@ export class AppComponent implements OnInit {
|
|||||||
this.showList = !this.showList;
|
this.showList = !this.showList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public restoreGraph(item) {
|
public restoreGraph(history) {
|
||||||
console.log(item);
|
this.configForm.reset({...history.config});
|
||||||
|
this.restoredHistory = history;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,16 @@ import { Point } from '../models/point.model';
|
|||||||
})
|
})
|
||||||
export class GraphsComponent implements OnChanges {
|
export class GraphsComponent implements OnChanges {
|
||||||
|
|
||||||
public graphs: Graph[];
|
|
||||||
public canvas: any | null;
|
public canvas: any | null;
|
||||||
public matrix: any | null;
|
public matrix: any | null;
|
||||||
|
public graphs: Graph[];
|
||||||
|
|
||||||
private genShiftPoint: any | null;
|
private genShiftPoint: any | null;
|
||||||
private genLoadedAllGraphs: any | null;
|
private genLoadedAllGraphs: any | null;
|
||||||
|
private hash: string;
|
||||||
|
|
||||||
@Input() config: any;
|
@Input() config: any;
|
||||||
|
@Input() restoredHistory: any;
|
||||||
@Output() svgChange = new EventEmitter();
|
@Output() svgChange = new EventEmitter();
|
||||||
@Output() graphChange = new EventEmitter();
|
@Output() graphChange = new EventEmitter();
|
||||||
@ViewChild('svg') svgElementRef;
|
@ViewChild('svg') svgElementRef;
|
||||||
@@ -54,37 +56,25 @@ export class GraphsComponent implements OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
this.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
private init() {
|
|
||||||
this.updateCanvas();
|
this.updateCanvas();
|
||||||
this.updateMatrix();
|
this.updateMatrix();
|
||||||
|
|
||||||
|
if (changes.restoredHistory) {
|
||||||
|
if (changes.restoredHistory.currentValue) {
|
||||||
|
if (this.restoredHistory.hash !== this.hash) {
|
||||||
|
this.graphs = this.restoredHistory.graphs;
|
||||||
|
this.hash = this.restoredHistory.hash;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.updateGraphs();
|
this.updateGraphs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private saveHistory() {
|
||||||
this.historyService.save(this.graphs, this.config);
|
this.historyService.save(this.graphs, this.config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public prepareGuillocheExport(guillocheElement) {
|
|
||||||
if (this.genLoadedAllGraphs.next().value) {
|
|
||||||
this.svgChange.emit(this.svgElementRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private *countLoadedGraphs() {
|
|
||||||
let cycles = 1;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
if (cycles < this.graphs.length) {
|
|
||||||
yield false;
|
|
||||||
cycles++;
|
|
||||||
} else {
|
|
||||||
yield true;
|
|
||||||
cycles = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateGraphs(): void {
|
private updateGraphs(): void {
|
||||||
const genShiftStart = this.shiftPoint(this.matrix.start, this.config.vectors.start);
|
const genShiftStart = this.shiftPoint(this.matrix.start, this.config.vectors.start);
|
||||||
const genShiftEnd = this.shiftPoint(this.matrix.end, this.config.vectors.end);
|
const genShiftEnd = this.shiftPoint(this.matrix.end, this.config.vectors.end);
|
||||||
@@ -103,6 +93,8 @@ export class GraphsComponent implements OnChanges {
|
|||||||
];
|
];
|
||||||
|
|
||||||
this.graphs = curveList.map(curve => this.adjustGraph(curve));
|
this.graphs = curveList.map(curve => this.adjustGraph(curve));
|
||||||
|
this.hash = this.historyService.hash(this.graphs);
|
||||||
|
this.saveHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private adjustGraph(curve) {
|
private adjustGraph(curve) {
|
||||||
@@ -235,4 +227,24 @@ export class GraphsComponent implements OnChanges {
|
|||||||
yield sign = sign * (-1);
|
yield sign = sign * (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public prepareGuillocheExport(guillocheElement) {
|
||||||
|
if (this.genLoadedAllGraphs.next().value) {
|
||||||
|
this.svgChange.emit(this.svgElementRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private *countLoadedGraphs() {
|
||||||
|
let cycles = 1;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (cycles < this.graphs.length) {
|
||||||
|
yield false;
|
||||||
|
cycles++;
|
||||||
|
} else {
|
||||||
|
yield true;
|
||||||
|
cycles = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,15 +32,22 @@ export class HistoryService {
|
|||||||
this.history.push({
|
this.history.push({
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
graphs: graphs,
|
graphs: graphs,
|
||||||
config: config
|
config: config,
|
||||||
|
hash: this.hash(graphs)
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log(config);
|
public hash(graphs) {
|
||||||
|
return btoa(JSON.stringify([graphs]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public list() {
|
public list() {
|
||||||
return this.history;
|
return this.history;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public restore(graphs: Graph[]) {
|
||||||
|
console.log(graphs);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user