Projekt

Obecné

Profil

« Předchozí | Další » 

Revize f8bc80fe

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

reworked ShowGraphApp to ES6 class

Zobrazit rozdíly:

sources/src/main/webapp/js/components/navbar.js
281 281
	_createBackToUploadListItem() {
282 282
		return DOM.h('li', {}, [
283 283
			DOM.h('a', {
284
				href: app.HOME_URL,
284
				href: app.homeUrl,
285 285
				class: 'btn btn-block back-to-upload',
286 286
				id: 'backToUpload',
287 287
				title: 'Back to upload',
......
362 362
		});
363 363

  
364 364
		document.addEventListener(DiagramUpdatedEvent.name, e => {
365
			refreshDiagramLink.setAttribute('href', app.HOME_URL + 'graph?diagramId=' + e.detail.id);
365
			refreshDiagramLink.setAttribute('href', app.homeUrl + 'graph?diagramId=' + e.detail.id);
366 366
		});
367 367

  
368 368
		return DOM.h('li', {}, [
sources/src/main/webapp/js/showGraphApp.js
1 1
/**
2
 * Main class of the application.
3
 * @constructor
2
 * Application running on the ShowGraph page.
4 3
 */
5
function ShowGraphApp(appName, appHomeUrl) {
6
	/** @prop {Constants} constants */
7
	this.constants = new Constants;
8
	/** @prop {GraphLoader} graphLoader */
9
	this.graphLoader = new GraphLoader;
10
	/** @prop {GraphExporter} graphExporter */
11
	this.graphExporter = new GraphExporter;
12
	/** @prop {Loader} loader */
13
	this.loader = new Loader;
14
	/** @prop {Zoom} zoom */
15
	this.zoom = new Zoom(0.8);
16
	/** @prop {MarkSymbol} markSymbol */
17
	this.markSymbol = new MarkSymbol;
18

  
19
	/** @prop {string} NAME Application name. */
20
	this.NAME = appName;
21
	/** @prop {string} HOME_URL Application home URL. */
22
	this.HOME_URL = appHomeUrl;
23

  
24
	/** @prop {Sidebar} sidebarComponent */
25
	this.sidebarComponent = null;
26
	/** @prop {Viewport} viewportComponent */
27
	this.viewportComponent = null;
28
	/** @prop {SaveDiagramModalWindow} modalWindowComponent */
29
	this.modalWindowComponent = null;
30

  
31
	/** @prop {array<Edge>} edgeList */
32
	this.edgeList = [];
33
	/** @prop {array<(Vertex|Group)>} nodeList */
34
	this.nodeList = [];
35
	/** @prop {array<Vertex>} vertexList */
36
	this.vertexList = [];
37
	/** @prop {array<Group>} groupList */
38
	this.groupList = [];
39

  
40
	/** @prop {Diagram} diagram */
41
	this.diagram = null;
42

  
43
	/** @prop {object} archetype Object containing all vertex and edge archetypes used in currently displayed diagram. */
44
	this.archetype = {
45
		vertex: [],
46
		edge: [],
47
	};
48

  
49
	/** @prop {array} attributeTypeList Array containing all possible types of vertex/edge attributes. */
50
	this.attributeTypeList = [];
51
	/** @prop {array} possibleEnumValues Array containing all possible values of attributes with datatype ENUM. */
52
	this.possibleEnumValues = {};
53

  
4
class ShowGraphApp extends App {
54 5
	/**
55
	 * Loads graph using diagram (if available).
56
	 * @param diagramId Diagram identifier.
6
	 * @inheritdoc
57 7
	 */
58
	this.diagramLoader = function(diagramId) {
59
		return loadGraphData.bind(this, diagramId);
60
	};
8
	constructor(appName, appHomeUrl) {
9
		super(appName, appHomeUrl);
10

  
11
		this.constants = new Constants;
12
		this.graphLoader = new GraphLoader;
13
		this.graphExporter = new GraphExporter;
14
		this.loader = new Loader;
15
		this.zoom = new Zoom(0.8);
16
		this.markSymbol = new MarkSymbol;
17

  
18
		/** @prop {array<Edge>} edgeList */
19
		this.edgeList = [];
20
		/** @prop {array<(Vertex|Group)>} nodeList */
21
		this.nodeList = [];
22
		/** @prop {array<Vertex>} vertexList */
23
		this.vertexList = [];
24
		/** @prop {array<Group>} groupList */
25
		this.groupList = [];
26

  
27
		/** @prop {Diagram} diagram */
28
		this.diagram = null;
29

  
30
		/** @prop {object} archetype Object containing all vertex and edge archetypes used in currently displayed diagram. */
31
		this.archetype = {
32
			vertex: [],
33
			edge: [],
34
		};
35

  
36
		/** @prop {array} attributeTypeList Array containing all possible types of vertex/edge attributes. */
37
		this.attributeTypeList = [];
38
		/** @prop {array} possibleEnumValues Array containing all possible values of attributes with datatype ENUM. */
39
		this.possibleEnumValues = {};
40
	}
61 41

  
62 42
	/**
63 43
	 * Initiates the application.
64 44
	 * @param {function} startFn Function to be run to load graph data.
65 45
	 */
66
	this.run = function(startFn) {
46
	run(diagramId) {
67 47
		console.log('running...');
68 48

  
69
		bootstrap.call(this);
70
		startFn.call(this);
71
	};
49
		this._bootstrap();
50
		this._loadGraphData(diagramId);
51
	}
72 52

  
73 53
	/**
74 54
	 * Resets the application to the state as it was when the graph was loaded for the first time.
75 55
	 */
76
	this.reset = function() {
77
		app.viewportComponent.reset();
78
		app.sidebarComponent.reset();
79

  
80
		app.edgeList = [];
81
		app.nodeList = [];
82
		app.vertexList = [];
83
		app.groupList = [];
84
	};
56
	reset() {
57
		this.viewportComponent.reset();
58
		this.sidebarComponent.reset();
59

  
60
		this.edgeList = [];
61
		this.nodeList = [];
62
		this.vertexList = [];
63
		this.groupList = [];
64
	}
85 65

  
86 66
	/**
87 67
	 * Finds a vertex by its name.
88 68
	 * @param {string} name Name of the searched vertex.
89 69
	 */
90
	this.findVertexByName = function(name) {
91
		return app.vertexList.find(function(existingVertex) {
92
			return existingVertex.name == this;
93
		}, name);
70
	findVertexByName(name) {
71
		return this.vertexList.find(existingVertex => {
72
			return existingVertex.name == name;
73
		});
94 74
	}
95 75

  
96 76
	/**
97 77
	 * Closes components floating above viewport (context menu and popovers).
98 78
	 */
99
	this.closeFloatingComponents = function() {
100
		app.viewportComponent.contextMenuComponent.close();
101
		app.viewportComponent.vertexPopoverComponent.close();
102
		app.viewportComponent.edgePopoverComponent.close();
103
	};
79
	closeFloatingComponents() {
80
		this.viewportComponent.contextMenuComponent.close();
81
		this.viewportComponent.vertexPopoverComponent.close();
82
		this.viewportComponent.edgePopoverComponent.close();
83
	}
104 84

  
105 85
	/**
106 86
	 * Redraws edges leading from viewport to sidebar.
107 87
	 */
108
	this.redrawEdges = function() {
109
		app.sidebarComponent.refreshFloaters();
110
	};
88
	redrawEdges() {
89
		this.sidebarComponent.refreshFloaters();
90
	}
111 91

  
112 92
	/**
113 93
	 * Binds user interactions to local handler functions.
114 94
	 */
115
	function bootstrap() {
116
		this.loader.enable();
117

  
95
	_bootstrap() {
118 96
		this.headerComponent = new Header;
119 97
		this.navbarComponent = new Navbar;
120 98
		this.viewportComponent = new Viewport;
......
139 117
		document.addEventListener(DiagramUpdatedEvent.name, e => {
140 118
			this.diagram = new Diagram(e.detail);
141 119

  
142
			document.title = this.NAME + ' - ' + this.diagram.name;
143
			history.replaceState({} , document.title, this.HOME_URL + 'graph?diagramId=' + this.diagram.id);
120
			document.title = this.name + ' - ' + this.diagram.name;
121
			history.replaceState({} , document.title, this.homeUrl + 'graph?diagramId=' + this.diagram.id);
144 122
		});
145 123

  
146 124
		// context menu
......
163 141
	 * Loads graph data of a diagram.
164 142
	 * @param {string} diagramId Identifier of the diagram to be loaded.
165 143
	 */
166
	async function loadGraphData(diagramId) {
144
	async _loadGraphData(diagramId) {
167 145
		this.loader.enable();
168 146

  
169 147
		let loadGraphDataPromise;
......
176 154

  
177 155
			this.diagram = new Diagram(diagramData);
178 156

  
179
			document.title = this.NAME + ' - ' + this.diagram.name;
157
			document.title = this.name + ' - ' + this.diagram.name;
180 158

  
181 159
			loadGraphDataPromise = Promise.resolve(JSON.parse(diagramData.graph_json));
182 160
		}
sources/src/main/webapp/showGraph.jsp
72 72

  
73 73
		<script src="js/markSymbol.js"></script>
74 74
		<script src="js/constants.js"></script>
75

  
76
		<script src="js/app.js"></script>
75 77
		<script src="js/showGraphApp.js"></script>
76 78

  
77 79
		<title>IMiGEr</title>
......
90 92
			const app = new ShowGraphApp('${APP_NAME}', '${APP_HOME_URL}');
91 93

  
92 94
			document.addEventListener('DOMContentLoaded', () => {
93
				let loaderFn = app.diagramLoader('${param.diagramId}');
94

  
95
				app.run(loaderFn);
95
				app.run('${param.diagramId}');
96 96

  
97 97
				// user is logged in
98 98
				if ('${user}' !== '') {

Také k dispozici: Unified diff