Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d01645a2

Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)

#3, #10: update frontend to display Graph loaded from JSON file correctly and to display its filename

Zobrazit rozdíly:

sources/src/main/webapp/js/components/navbar.js
344 344
				class: 'btn save-diagram',
345 345
				title: 'Save diagram as PNG',
346 346
				onClick: () => {
347
					let fileName = `imiger-${app.diagram === null ? 'diagram' : app.diagram.name}.png`;
347
					let fileName = `imiger-${app.diagram.name !== null ? app.diagram.name : 'diagram'}.png`;
348 348

  
349 349
					saveSvgAsPng(document.getElementById('svg1'), fileName, {
350 350
						backgroundColor: '#fff',
......
387 387
		});
388 388

  
389 389
		document.addEventListener(DiagramUpdatedEvent.name, e => {
390
			refreshDiagramLink.setAttribute('href', app.homeUrl + 'graph?diagramId=' + e.detail.id);
390
			if (Utils.isDefined(e.detail.id)) {
391
				refreshDiagramLink.setAttribute('href', app.homeUrl + 'graph?diagramId=' + e.detail.id);
392
			}
391 393
		});
392 394

  
393 395
		return DOM.h('li', {}, [
sources/src/main/webapp/js/components/saveDiagramModalWindow.js
70 70
	open() {
71 71
		super.open();
72 72

  
73
		if (app.diagram !== null) {
74
			this._form.diagramName.value = app.diagram.name;
75
			this._form.diagramPublic.checked = app.diagram.public;
76
		}
73
		this._form.diagramName.value = app.diagram.name !== null ? app.diagram.name : '';
74
		this._form.diagramPublic.checked = app.diagram.public !== null ? app.diagram.public : false;
77 75

  
78 76
		this._form.diagramName.focus();
79 77
	}
......
95 93
		e.preventDefault();
96 94

  
97 95
		const body = new URLSearchParams;
98
		body.set('id', app.diagram === null ? '' : app.diagram.id);
96
		body.set('id', app.diagram.id !== null ? app.diagram.id : '');
99 97
		body.set('name', e.target.diagramName.value);
100 98
		body.set('graphJson', JSON.stringify(app.graphExporter.run()));
101 99
		body.set('public', (e.target.diagramPublic.checked | 0).toString());
sources/src/main/webapp/js/showGraphApp.js
118 118
		document.addEventListener(DiagramUpdatedEvent.name, e => {
119 119
			this.diagram = new Diagram(e.detail);
120 120

  
121
			document.title = this.name + ' - ' + this.diagram.name;
122
			history.replaceState({} , document.title, this.homeUrl + 'graph?diagramId=' + this.diagram.id);
121
			if (this.diagram.name !== null) {
122
				document.title = this.name + ' - ' + this.diagram.name;
123
			}
124

  
125
			if (this.diagram.id !== null) {
126
				history.replaceState({} , document.title, this.homeUrl + 'graph?diagramId=' + this.diagram.id);
127
			}
123 128
		});
124 129

  
125 130
		// context menu
......
146 151
		this.spinLoaderComponent.enable();
147 152

  
148 153
		let loadGraphDataPromise;
149

  
150 154
		if (diagramId === '') {
151 155
			loadGraphDataPromise = AJAX.getJSON(Constants.API.loadGraphData);
152

  
153 156
		} else {
154
			const diagramData = await AJAX.getJSON(Constants.API.getDiagram + '?id=' + diagramId);
155

  
156
			document.dispatchEvent(new DiagramUpdatedEvent(diagramData));
157

  
158
			loadGraphDataPromise = Promise.resolve(JSON.parse(diagramData.graph_json));
157
			loadGraphDataPromise = AJAX.getJSON(Constants.API.getDiagram + '?id=' + diagramId);
159 158
		}
160 159

  
161 160
		try {
162
			// get vertex position data
161
			// get graph data
163 162
			const graphData = await loadGraphDataPromise;
164 163

  
164
			// update diagram information in the app
165
			document.dispatchEvent(new DiagramUpdatedEvent(graphData));
166

  
165 167
			// construct graph
166
			this.graphLoader.run(graphData);
168
			this.graphLoader.run(JSON.parse(graphData.graph_json));
167 169

  
168 170
			this.spinLoaderComponent.disable();
169 171

  
sources/src/main/webapp/js/valueObjects/diagram.js
7 7
	 * @param {object} props Object loaded from database holding properties of the diagram.
8 8
	 */
9 9
	constructor(props) {
10
		this.id = parseInt(props.id);
11
		this.name = props.name;
12
		this.public = props.public === '1';
10
		this.id = Utils.isDefined(props.id) ? parseInt(props.id) : null;
11
		this.name = Utils.isDefined(props.name) ? props.name : null;
12
		this.public = Utils.isDefined(props.public) ? (props.public === '1') : null;
13 13
	}
14 14
}

Také k dispozici: Unified diff