Revize 556ddd42
Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)
sources/src/main/webapp/js/components/groupVertexList.js | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Class representing a list of vertices added to a group. |
3 | 3 |
* @see Group |
4 |
* @constructor |
|
5 |
* @param {Group} parentalGroup Group this vertex list is bound to. |
|
6 | 4 |
*/ |
7 |
function GroupVertexList(parentalGroup) { |
|
8 |
const lineHeight = 18; |
|
5 |
class GroupVertexList { |
|
6 |
/** |
|
7 |
* @constructor |
|
8 |
* @param {Group} group Group this vertex list is bound to. |
|
9 |
*/ |
|
10 |
constructor(group) { |
|
11 |
this._group = group; |
|
9 | 12 |
|
10 |
var rootElement; |
|
11 |
var listItemCounter = 0; |
|
13 |
this._lineHeight = 18; |
|
14 |
this._listItemCounter = 0; |
|
15 |
} |
|
16 |
|
|
17 |
/** |
|
18 |
* Creates a new DOM element representing the list in memory. |
|
19 |
* @public |
|
20 |
* @returns {Element} HTML or SVG DOM element depending on whether the group is excluded. |
|
21 |
*/ |
|
22 |
render() { |
|
23 |
if (this._group.isExcluded()) { |
|
24 |
this._rootElement = DOM.h('ul'); |
|
25 |
} else { |
|
26 |
this._rootElement = DOM.s('g', { |
|
27 |
transform: 'translate(70, 30)', |
|
28 |
}); |
|
29 |
} |
|
30 |
|
|
31 |
this._rootElement.setAttribute('class', 'group-vertex-list'); |
|
32 |
|
|
33 |
return this._rootElement; |
|
34 |
}; |
|
12 | 35 |
|
13 | 36 |
/** |
14 | 37 |
* Adds a new vertex to the list. Binds user interactions to local handler functions. |
38 |
* @public |
|
15 | 39 |
* @param {vertex} vertex Vertex to be added to this list. |
16 | 40 |
*/ |
17 |
this.appendChild = function(vertex) {
|
|
18 |
var listItemElement;
|
|
19 |
if (parentalGroup.isExcluded()) {
|
|
20 |
listItemElement = DOM.createHtmlElement('li');
|
|
41 |
appendChild(vertex) {
|
|
42 |
let listItemElement;
|
|
43 |
if (this._group.isExcluded()) {
|
|
44 |
listItemElement = DOM.h('li');
|
|
21 | 45 |
} else { |
22 |
listItemElement = DOM.createSvgElement('text', {
|
|
23 |
'y': listItemCounter * lineHeight,
|
|
46 |
listItemElement = DOM.s('text', {
|
|
47 |
y: this._listItemCounter * this._lineHeight,
|
|
24 | 48 |
}); |
25 | 49 |
} |
26 | 50 |
|
27 | 51 |
listItemElement.setAttribute('data-id', vertex.id); |
28 | 52 |
listItemElement.appendChild(document.createTextNode(vertex.name)); |
29 |
listItemElement.addEventListener('click', listItemClick.bind(vertex)); |
|
53 |
listItemElement.addEventListener('click', this._listItemClick.bind(vertex));
|
|
30 | 54 |
|
31 |
rootElement.appendChild(listItemElement); |
|
55 |
this._rootElement.appendChild(listItemElement);
|
|
32 | 56 |
|
33 |
listItemCounter++; |
|
34 |
};
|
|
57 |
this._listItemCounter++;
|
|
58 |
} |
|
35 | 59 |
|
36 | 60 |
/** |
37 | 61 |
* Removes a vertex from the list. |
62 |
* @public |
|
38 | 63 |
* @param {Vertex} vertex Vertex to be removed from this list. |
39 | 64 |
*/ |
40 |
this.removeChild = function(vertex) {
|
|
41 |
var listItemElement = rootElement.querySelector('[data-id="' + vertex.id + '"]');
|
|
65 |
removeChild(vertex) {
|
|
66 |
let listItemElement = this._rootElement.querySelector('[data-id="' + vertex.id + '"]');
|
|
42 | 67 |
|
43 | 68 |
listItemElement.remove(); |
44 |
}; |
|
45 |
|
|
46 |
/** |
|
47 |
* Creates a new DOM element representing the list in memory. |
|
48 |
* @returns {Element} HTML or SVG DOM element depending on whether the group is excluded. |
|
49 |
*/ |
|
50 |
this.render = function() { |
|
51 |
if (parentalGroup.isExcluded()) { |
|
52 |
rootElement = DOM.createHtmlElement('ul'); |
|
53 |
} else { |
|
54 |
rootElement = DOM.createSvgElement('g', { |
|
55 |
'transform': 'translate(70, 30)', |
|
56 |
}); |
|
57 |
} |
|
58 |
|
|
59 |
rootElement.setAttribute('class', 'group-vertex-list'); |
|
60 |
|
|
61 |
return rootElement; |
|
62 |
}; |
|
69 |
} |
|
63 | 70 |
|
64 | 71 |
/** |
65 | 72 |
* Vertex list item click interaction. |
73 |
* @private |
|
66 | 74 |
* @param {Event} e Click event. |
67 | 75 |
*/ |
68 |
function listItemClick(e) {
|
|
76 |
_listItemClick(e) {
|
|
69 | 77 |
e.stopPropagation(); |
70 | 78 |
|
71 | 79 |
console.log('TODO: highlight vertex on click'); |
Také k dispozici: Unified diff
reworked GroupVertexList to ES6 class