Projekt

Obecné

Profil

« Předchozí | Další » 

Revize cba6f960

Přidáno uživatelem Pavel Fidranský před téměř 6 roky(ů)

make related archetype list always fully visible

Zobrazit rozdíly:

sources/src/main/webapp/css/components/sidebar.css
82 82

  
83 83
.sidebar .node {
84 84
    position: relative;
85
    display: flex;
85 86
	margin-top: 1em;
86 87
	margin-bottom: 1em;
87
    padding-left: 40px;
88 88
	user-select: none;
89 89
}
90 90

  
91 91
.sidebar .node > svg {
92
    position: absolute;
93
    left: -6px;
92
    position: relative;
94 93
    display: inline-block;
94
    margin-left: -6px;
95
    vertical-align: top;
95 96
}
96 97

  
97 98
.sidebar .node .related-archetype > text {
......
217 218
	top: 2em;
218 219
}
219 220

  
220
.unconnected-nodes .node > svg {
221
    display: none;
222
}
223

  
224 221
.unconnected-nodes .button-group .show-symbol-button {
225 222
    display: none;
226 223
}
sources/src/main/webapp/js/components/node.js
141 141
	 * @returns {object} Map with archetype indexes as keys and counters of their instances as values.
142 142
	 */
143 143
	get relatedArchetypeMap() {
144
		return this._relatedArchetypeListComponent.map;
144
		return this._relatedArchetypeListComponent.data;
145 145
	}
146 146

  
147 147
	/**
sources/src/main/webapp/js/components/nodeRelatedArchetypeList.js
5 5
class NodeRelatedArchetypeList {
6 6
	/**
7 7
	 * @constructor
8
	 * @param {Node} node Node this archetype list is bound to.
8 9
	 */
9 10
	constructor(node) {
10 11
		this._node = node;
11 12
		this._map = new Map;
13

  
12 14
		this._iconSize = 20;
13 15
	}
14 16

  
15
	get map() {
17
	get data() {
16 18
		return this._map;
17 19
	}
18 20

  
......
32 34
		}
33 35

  
34 36
		this._map.set(key, currentValue + value);
35
		
36
		this._renderIcons();
37

  
38
		if (this.isRendered) {
39
			this._rerender();
40
		}
37 41
	}
38 42

  
39 43
	remove(key, value = 1) {
......
46 50

  
47 51
		this._map.set(key, currentValue - value);
48 52

  
49
		this._renderIcons();
53
		if (this.isRendered) {
54
			this._rerender();
55
		}
50 56
	}
51 57

  
58
	/**
59
	 * Creates a new DOM element representing the list in memory.
60
	 * @public
61
	 * @returns {SVGElement} SVG DOM element
62
	 */
52 63
	render() {
53
		if (this._node.isExcluded === true) {
54
			this._rootElement = DOM.s('g', {
55
				transform: 'translate(10, 15)',
56
			});
57
		} else {
58
			this._rootElement = DOM.s('g', {
59
				transform: `translate(${this._node.size.width}, 0)`,
60
			});
61
		}
64
		this._rootElement = this._renderRoot();
62 65

  
63
		this._renderIcons();
66
		this._map.forEach((value, key) => {
67
			this._rootElement.appendChild(this._renderArchetypeIcon(key, value));
68
		});
64 69

  
65 70
		return this._rootElement;
66 71
	}
67
	
68
	_renderIcons() {
69
		if (Utils.isUndefined(this._rootElement)) return;
70
		
72

  
73
	/**
74
	 * @returns {boolean} true if this component has been already rendered, otherwise false
75
	 */
76
	get isRendered() {
77
		return Utils.isDefined(this._rootElement);
78
	}
79

  
80
	_rerender() {
71 81
		this._rootElement.innerHTML = '';
72 82

  
73
		let iconOrder = 0;
74 83
		this._map.forEach((value, key) => {
75
			if (this._node.isExcluded === true) {
76
				this._rootElement.appendChild(DOM.s('g', {
77
					class: 'related-archetype',
78
					transform: `translate(0, ${iconOrder * this._iconSize})`,
79
				}, [
80
					// counter
81
					DOM.s('text', {}, [
82
						DOM.t(value),
83
					]),
84
					// icon
85
					DOM.s('use', {
86
						href: '#vertexArchetypeIcon-' + app.archetype.vertex[key].name,
87
						class: 'archetype-icon',
88
						transform: `translate(15, -10)`,
89
						onClick: this._node.onRelatedArchetypeIconClick.bind(this._node, key), // TODO: when icon == null can not click on item
90
					}),
91
					// line
92
					DOM.s('line', {
93
						x1: 30,
94
						y1: -5,
95
						x2: 36,
96
						y2: -5,
97
					}),
98
				]));
99
			} else {
100
				this._rootElement.appendChild(DOM.s('use', {
101
					href: '#vertexArchetypeIcon-' + app.archetype.vertex[key].name,
84
			this._rootElement.appendChild(this._renderArchetypeIcon(key, value));
85
		});
86
		
87
		if (this._node.isExcluded) {
88
			this._rootElement.setAttribute('height', this.size.height);
89
		}
90
	}
91

  
92
	_renderRoot() {
93
		if (this._node.isExcluded) {
94
			return DOM.s('svg', {
95
				height: this.size.height,
96
				width: 46,
97
			});
98

  
99
		} else {
100
			return DOM.s('g', {
101
				transform: `translate(${this._node.size.width}, 0)`,
102
			});
103
		}
104
	}
105

  
106
	_renderArchetypeIcon(archetypeIndex, counter) {
107
		if (this._node.isExcluded) {
108
			return DOM.s('g', {
109
				class: 'related-archetype',
110
				'data-index': archetypeIndex,
111
				transform: `translate(10, ${15 + this._rootElement.childNodes.length * this._iconSize})`,
112
			}, [
113
				// counter
114
				DOM.s('text', {}, [
115
					DOM.t(counter),
116
				]),
117
				// icon
118
				DOM.s('use', {
119
					href: '#vertexArchetypeIcon-' + app.archetype.vertex[archetypeIndex].name,
102 120
					class: 'archetype-icon',
103
					transform: `translate(${iconOrder * this._iconSize}, 8)`,
104
					onClick: this._node.onRelatedArchetypeIconClick.bind(this._node, key), // TODO: when icon == null can not click on item
105
				}));
106
			}
121
					transform: `translate(15, -10)`,
122
					onClick: this._node.onRelatedArchetypeIconClick.bind(this._node, archetypeIndex), // TODO: when icon == null can not click on item
123
				}),
124
				// line
125
				DOM.s('line', {
126
					x1: 30,
127
					y1: -5,
128
					x2: 36,
129
					y2: -5,
130
				}),
131
			]);
107 132

  
108
			iconOrder++;
109
		});
133
		} else {
134
			// icon
135
			return DOM.s('use', {
136
				href: '#vertexArchetypeIcon-' + app.archetype.vertex[archetypeIndex].name,
137
				class: 'archetype-icon',
138
				'data-index': archetypeIndex,
139
				transform: `translate(${this._rootElement.childNodes.length * this._iconSize}, 8)`,
140
				onClick: this._node.onRelatedArchetypeIconClick.bind(this._node, archetypeIndex), // TODO: when icon == null can not click on item
141
			});
142
		}
110 143
	}
111 144
}
sources/src/main/webapp/js/components/vertex.js
265 265
			'data-id': this.id,
266 266
		}, [
267 267
			// related archetypes
268
			DOM.s('svg', {
269
				height: this._relatedArchetypeListComponent.size.height,
270
				width: 46,
271
			}, [
272
				this._relatedArchetypeListComponent.render(),
273
			]),
268
			this._relatedArchetypeListComponent.render(),
274 269
			// name
275 270
			DOM.h('div', {
276 271
				class: 'vertex-name',

Také k dispozici: Unified diff