Projekt

Obecné

Profil

« Předchozí | Další » 

Revize be9216bb

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

modified Edge popover to display its attributes

Zobrazit rozdíly:

sources/src/main/webapp/js/components/edge.js
6 6
function Edge(props) {
7 7
	/** @prop {integer} id Unique identifier of the edge. */
8 8
	this.id = props.id;
9
	/** @prop {integer} archetype Archetype of the edge. */
10
	this.archetype = app.archetype.edge[props.subedgeInfo.archetype];
9 11

  
10 12
	var rootElement;
11 13

  
......
241 243
	 * @param {Event} e Click event.
242 244
	 */
243 245
	function click(e) {
246
		app.viewportComponent.edgePopoverComponent.setContent(props.subedgeInfo);
247
		app.viewportComponent.edgePopoverComponent.setPosition(new Coordinates(e.clientX, e.clientY));
248
		app.viewportComponent.edgePopoverComponent.open();
244 249

  
245 250
		// unhighlight other edges
246 251
		app.edgeList.filter(function(edge) {
sources/src/main/webapp/js/components/edgePopover.js
5 5
 */
6 6
function EdgePopover() {
7 7
	var rootElement;
8
	var popoverContentElement;
8
	var detailsListElement;
9 9

  
10 10
	/**
11
	 * Sets compatibility information held by the edge.
12
	 * @param {object} compatibilityInfo Compatibility information of the edge.
11
	 * Sets the contents of the popover.
12
	 * @param {array} subedgeInfoList List of various edge information.
13 13
	 */
14
	this.setContent = function(compatibilityInfo) {
15
		popoverContentElement.appendChild(createHtmlTree(compatibilityInfo));
16

  
17
		$.jstree.create(popoverContentElement, {
18
			core : {
19
				'animation': 25,
20
			},
21
			themes : {
22
				'theme': 'classic',
23
				'dots': true,
24
				'icons': false,
25
			},
26
			plugins : [ 'themes', 'html_data' ],
14
	this.setContent = function(subedgeInfoList) {
15
		if (subedgeInfoList.length === 0) return;
16

  
17
		subedgeInfoList.filter(function(subedgeInfo) {
18
			return subedgeInfo.attributes.length > 0;
19
		}).forEach(function(subedgeInfo) {
20
			var listItem = app.dom.createHtmlElement('li', {});
21
			listItem.appendChild(app.dom.createTextElement(app.archetype.edge[subedgeInfo.archetype].name));
22

  
23
			var sublist = app.dom.createHtmlElement('ul', {});
24
			listItem.appendChild(sublist);
25

  
26
			detailsListElement.appendChild(listItem);
27

  
28
			subedgeInfo.attributes.forEach(function(attribute) {
29
				var listItem = app.dom.createHtmlElement('li', {});
30
				listItem.appendChild(app.dom.createTextElement(`${attribute[0]}: ${attribute[1]}`));
31

  
32
				sublist.appendChild(listItem);
33
			});
27 34
		});
28 35
	};
29 36

  
......
49 56
	this.close = function() {
50 57
		rootElement.classList.add('hidden');
51 58

  
52
		$.jstree.destroy(popoverContentElement);
53

  
54
		popoverContentElement.innerHTML = '';
59
		detailsListElement.innerHTML = '';
55 60
	};
56 61

  
57 62
	/**
......
69 74
		var popoverTitle = app.utils.createHtmlElement('span', {
70 75
			'class': 'popover-title',
71 76
		});
72
		popoverTitle.appendChild(document.createTextNode('Incompatibility details'));
77
		popoverTitle.appendChild(document.createTextNode('Edge details'));
73 78
		rootElement.appendChild(popoverTitle);
74 79

  
75
		popoverContentElement = app.utils.createHtmlElement('div', {
80
		var popoverContent = app.utils.createHtmlElement('div', {
76 81
			'class': 'popover-content',
77 82
		});
78
		rootElement.appendChild(popoverContentElement);
83
		rootElement.appendChild(popoverContent);
84

  
85
		detailsListElement = app.utils.createHtmlElement('ul', {});
86
		popoverContent.appendChild(detailsListElement);
79 87

  
80 88
		return rootElement;
81 89
	};
......
88 96
		e.stopPropagation();
89 97
	}
90 98

  
91
	/**
92
	 * Creates a new list displaying the compatibility information as tree in memory.
93
	 * @param {array<object>} compatibilityInfoList List of compatibility information held by the edge.
94
	 * @returns {Element} HTML DOM element.
95
	 */
96
	function createHtmlTree(compatibilityInfoList) {
97
		var incompatibilityNameList = [];
98
		var list = app.utils.createHtmlElement('ul', {});
99

  
100
		compatibilityInfoList.forEach(function(compatibilityInfo) {
101
			if (compatibilityInfo.incomps.length === 0) return;
102

  
103
			compatibilityInfo.incomps.forEach(function(incompatibility) {
104
				if (!incompatibility.desc.isIncompCause && incompatibility.subtree.length === 0) return;
105

  
106
				if (incompatibilityNameList.indexOf(incompatibility.desc.name) > -1) return;
107
				incompatibilityNameList.push(incompatibility.desc.name);
108

  
109
				var label;
110
				if (incompatibility.desc.isIncompCause) {
111
					label = app.dom.htmlStringToElement(`<span>${incompatibility.desc.incompName}</span>`);
112
				} else {
113
					label = document.createTextNode(incompatibility.desc.name);
114
				}
115

  
116
				var listItem = app.utils.createHtmlElement('li', {});
117
				listItem.appendChild(label);
118
				list.appendChild(listItem);
119

  
120
				var subList = app.utils.createHtmlElement('ul', {});
121
				listItem.appendChild(subList);
122

  
123
				appendHtmlSubtree(subList, incompatibility.subtree);
124
			});
125
		});
126

  
127
		return list;
128
	}
129

  
130
	/**
131
	 * Appends a new list item displaying a single incompatibility to the list passed as a parameter.
132
	 * @param {Element} list HTML DOM element to append this tree to.
133
	 * @param {array<object>} incompatibilityList List of incompatibility information.
134
	 */
135
	function appendHtmlSubtree(list, incompatibilityList) {
136
		incompatibilityList.forEach(function(incompatibility) {
137
			if (!incompatibility.desc.isIncompCause && incompatibility.subtree.length === 0) return;
138

  
139
			var label;
140
			if (incompatibility.desc.isIncompCause) {
141
				label = app.dom.htmlStringToElement(`<span>${incompatibility.desc.incompName}</span>`);
142
			} else {
143
				label = document.createTextNode(incompatibility.desc.name);
144
			}
145

  
146
			var listItem = app.utils.createHtmlElement('li', {});
147
			listItem.appendChild(label);
148
			list.appendChild(listItem);
149

  
150
			if (incompatibility.desc.isIncompCause && incompatibility.desc.difference !== 'DEL') {
151
				var subList = app.utils.createHtmlElement('ul', {});
152
				listItem.appendChild(subList);
153

  
154
				var subListItemProvided = app.utils.createHtmlElement('li', {});
155
				subListItemProvided.appendChild(app.dom.htmlStringToElement(`<span><img src="images/efp_qtip/provided.png"> <span class="second">${incompatibility.desc.objectNameSecond}</span></span>`));
156
				subList.appendChild(subListItemProvided);
157

  
158
				var subListItemRequired = app.utils.createHtmlElement('li', {});
159
				subListItemRequired.appendChild(app.dom.htmlStringToElement(`<span><img src="images/efp_qtip/required.png"> <span class="first">${incompatibility.desc.objectNameFirst}</span></span>`));
160
				subList.appendChild(subListItemRequired);
161
			}
162

  
163
			if (incompatibility.subtree.length !== 0) {
164
				var subList = app.utils.createHtmlElement('ul', {});
165
				listItem.appendChild(subList);
166

  
167
				appendHtmlSubtree(subList, incompatibility.subtree);
168
			}
169
		});
170
	}
171

  
172 99
}

Také k dispozici: Unified diff