Skip to content

Commit

Permalink
added functionality to keep current diagram on refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Teun de Wijs committed Jan 20, 2020
1 parent 0a7104d commit 0fec007
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Component } from '@angular/core';
import { UtilityService } from './services/utility.service';
import Swal from 'sweetalert2';
import { generate } from 'rxjs';
import { GenerateService } from './services/generate.service';
import { ImportExportService } from './services/importexport.service';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(public util: UtilityService) { }
constructor(public util: UtilityService, public gen: GenerateService, private impoexpo: ImportExportService) { }
title = 'plantUml';
resizableArea;
text;
Expand All @@ -16,6 +20,14 @@ export class AppComponent {
mousemove;
hide;
ngOnInit() {
window.addEventListener('load', e => {
console.log("loading previous");
this.gen.text = localStorage.getItem('code');
this.impoexpo.loadStyle(localStorage.getItem('style'));
setTimeout(() => {
this.gen.generateSVG(this.gen.text)
}, );
})
window.addEventListener('dragover', e => {
e && e.preventDefault();
}, false);
Expand All @@ -25,6 +37,27 @@ export class AppComponent {
window.addEventListener('resize', e => {
this.util.calcWidth(this.util.pageX);
});
window.addEventListener('beforeunload', e => {
this.beforePageClose();
});


let disableConfirmation = false;
window.addEventListener('beforeunload', event => {
const confirmationText = 'Are you sure?';
if (!disableConfirmation) {
event.returnValue = confirmationText; // Gecko, Trident, Chrome 34+
return confirmationText; // Gecko, WebKit, Chrome <34
} else {
// Set flag back to false, just in case
// user stops loading page after clicking a link.
disableConfirmation = false;
}
});




this.resizableArea = document.getElementById('resizableTextarea');
this.util.diagram = document.getElementById('diagram');
this.util.text = document.getElementById('text');
Expand Down Expand Up @@ -55,4 +88,9 @@ export class AppComponent {
return this.util.diagram.style.height / 2;
}

beforePageClose() {
localStorage.setItem('code', this.gen.text);
localStorage.setItem('style', this.impoexpo.saveConfig(true));
}

}
58 changes: 58 additions & 0 deletions src/app/services/importexport.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,64 @@ export class ImportExportService {
this.gen.participantShapes = json.participantShapes;
this.gen.participantImages = json.participantImages;

if (!this.gen.isThemed) {
this.gen.selectedTheme = 'No theme';
}
if (this.gen.halfwayDoneProcessing) {
this.gen.isDoneProcessing = true;
this.gen.generateSVG(this.gen.text);
} else {
this.gen.halfwayDoneProcessing = true;
}
}
loadStyle(jsonstring) {
const json = JSON.parse(jsonstring);
this.gen.color1 = json.color1;
this.gen.color2 = json.color2;
this.gen.color3 = json.color3;
this.gen.color4 = json.color4;
this.gen.color5 = json.color5;
this.gen.color6 = json.color6;
this.gen.color7 = json.color7;
this.gen.color8 = json.color8;
this.gen.color9 = json.color9;
this.gen.colorBoxBack = json.colorBoxBack;
this.gen.colorBoxStroke = json.colorBoxStroke;
this.gen.selectedSize = json.selectedSize;
this.gen.selectedTheme = json.selectedTheme;
this.gen.selectedFont = json.selectedFont;
this.gen.selectedBreak = json.selectedBreak;
this.gen.selectedActor = json.selectedActor;
this.gen.selectedShape = json.selectedShape;
this.gen.selectedNumber = json.selectedNumber;
this.gen.hiddenNotes = json.hiddenNotes;
this.gen.footnotes = json.hiddenFootnotes;
this.gen.hiddenShadows = json.hiddenShadows;
this.gen.isThemed = json.isThemed;
this.gen.textImages = json.textImages;
this.gen.participantpadding = json.participantpadding;
this.gen.participantfontsize = json.participantfontsize;
this.gen.participantstroke = json.participantstroke;
this.gen.sequencetextsize = json.sequencetextsize;
this.gen.themedBreak = json.themedBreak;
this.gen.themedNumber = json.themedNumber;
this.gen.themedShape = json.themedShape;
this.gen.themedActor = json.themedActor;
this.gen.themedFont = json.themedFont;
this.gen.themedFootnotes = json.themedHiddenFootnotes;
this.gen.themedHiddenShadows = json.themedHiddenShadows;
this.gen.themedParticipantfontsize = json.themedParticipantfontsize;
this.gen.themedSequencetextsize = json.themedSequencetextsize;
this.gen.themedParticipantstroke = json.themedParticipantstroke;
this.gen.lineThickness = json.lineThickness;
this.gen.themedLineThickness = json.themedLineThickness;
this.gen.multicount = json.multicount;
this.gen.multi = json.multi;
this.gen.participants = json.participants;
this.gen.participantColors = json.participantColors;
this.gen.participantShapes = json.participantShapes;
this.gen.participantImages = json.participantImages;

if (!this.gen.isThemed) {
this.gen.selectedTheme = 'No theme';
}
Expand Down

0 comments on commit 0fec007

Please sign in to comment.