Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4d6d7dea

Přidáno uživatelem Vít Mazín před téměř 6 roky(ů)

Filter - rework (refs #7559)

Zobrazit rozdíly:

sources/imiger-core/src/main/webapp/js/components/filterModalWindow.js
500 500
				break;
501 501
		}
502 502

  
503
		const filterValues = formData.getAll('value').map(value => parseInt(value));
503
		let foundNodes = [];
504 504
		nodeFilter.run(app.nodeList).forEach(node => {
505
				foundNodes.push(node);
506
		});
507

  
508
		const filterValues = formData.getAll('value').map(value => parseInt(value));
509
		app.nodeList.filter(node => foundNodes.indexOf(node) === -1).forEach(node => {
505 510
			if(node instanceof Group) {
506
				let outEdges = node.outEdgeList;
507
				let inEdges = node.inEdgeList;
508
				this._hideEdges(outEdges);
509
				this._hideEdges(inEdges);
511
			let outEdges = node.outEdgeList;
512
			let inEdges = node.inEdgeList;
513
			this._hideEdges(outEdges);
514
			this._hideEdges(inEdges);
515
			node._rootElement.style.display = 'none';
516
		} else {
517
			if(node._group !== null) {
518
				if(baseFilter !== 'nodeType' || (filterValues[0] === 1 && operation === "NEQ") || (filterValues[0] === 0 && operation === "EQ")) {
519
					node._group._rootElement.style.display = 'none';
520
					this._hideEdges(node._group.outEdgeList);
521
					this._hideEdges(node._group.inEdgeList);
522
				}
510 523
				node._rootElement.style.display = 'none';
511 524
			} else {
512
				if(node._group !== null) {
513
					if(baseFilter !== 'nodeType' || filterValues[0] !== 1) {
514
						node._group._rootElement.style.display = 'none';
515
						this._hideEdges(node._group.outEdgeList);
516
						this._hideEdges(node._group.inEdgeList);
517
					}
518
					node._rootElement.style.display = 'none';
519
				} else {
520
					node._rootElement.style.display = 'none';
521
					app.edgeList.forEach(edge => {
522
						if(edge.from.id === node.id || edge.to.id === node.id) {
525
				node._rootElement.style.display = 'none';
526
				app.edgeList.forEach(edge => {
527
					if(edge.from.id === node.id || edge.to.id === node.id) {
523 528
						edge._rootElement.style.display = 'none';
524
						}
525
					});
529
					}
530
				});
526 531
				}
527 532
			}
528 533
			app.viewportComponent.removeNode(node);
......
561 566

  
562 567
	_hideEdges(edges) {
563 568
		edges.forEach(edge => {
564
			edge._rootElement.style.display = 'none';
569
				edge._rootElement.style.display = 'none';
565 570
		});
566 571
	}
567 572

  
sources/imiger-core/src/main/webapp/js/services/filters/NodeTypeFilter.js
28 28
		switch (this._operation) {
29 29
			case EnumFilterOperation.EQ:
30 30
				filterFn = node => {
31
					return (node instanceof Vertex && filterValues.indexOf(NodeTypeFilter.VERTEX) < 0)
32
						|| (node instanceof Group && filterValues.indexOf(NodeTypeFilter.GROUP) < 0);
33
				};
31
				return (node instanceof Vertex && filterValues.indexOf(NodeTypeFilter.VERTEX) > -1)
32
					|| (node instanceof Group && filterValues.indexOf(NodeTypeFilter.GROUP) > -1);
33
			};
34 34
				break;
35 35

  
36 36
			case EnumFilterOperation.NEQ:
37 37
				filterFn = node => {
38
					return (node instanceof Vertex && filterValues.indexOf(NodeTypeFilter.VERTEX) > -1)
39
						|| (node instanceof Group && filterValues.indexOf(NodeTypeFilter.GROUP) > -1);
40
				};
38
				return (node instanceof Vertex && filterValues.indexOf(NodeTypeFilter.VERTEX) < 0)
39
					|| (node instanceof Group && filterValues.indexOf(NodeTypeFilter.GROUP) < 0);
40
			};
41 41
				break;
42 42

  
43 43
			default:
......
49 49
}
50 50

  
51 51
NodeTypeFilter.VERTEX = 0;
52
NodeTypeFilter.GROUP = 1;
52
NodeTypeFilter.GROUP = 1;
sources/imiger-core/src/main/webapp/js/services/filters/VertexArchetypeFilter.js
17 17
	run(nodeList) {
18 18
		// prefilter
19 19
		nodeList = nodeList.filter(node => {
20
			return node instanceof Vertex;
20
				return node instanceof Vertex;
21 21
		});
22 22

  
23 23
		// filter
......
34 34
		switch (this._operation) {
35 35
			case EnumFilterOperation.EQ:
36 36
				filterFn = vertex => {
37
					return filterValues.indexOf(vertex.archetype) < 0;
38
				};
37
				return filterValues.indexOf(vertex.archetype) > -1;
38
			};
39 39
				break;
40 40

  
41 41
			case EnumFilterOperation.NEQ:
42 42
				filterFn = vertex => {
43
					return filterValues.indexOf(vertex.archetype) > -1;
44
				};
43
				return filterValues.indexOf(vertex.archetype) < 0;
44
			};
45 45
				break;
46 46

  
47 47
			default:
sources/imiger-core/src/main/webapp/js/services/filters/VertexAttributeFilter.js
1 1
class VertexAttributeFilter extends AbstractFilter {
2 2
	/**
3 3
	 * @constructor
4
	 * @param {string} additionalFilter 
5
	 * @param {string} dataType 
4
	 * @param {string} additionalFilter
5
	 * @param {string} dataType
6 6
	 * @param {string} operation Filtering operation.
7 7
	 * @param {FormData} formData Raw, unprocessed form content.
8 8
	 */
......
23 23
		// prefilter
24 24
		nodeList = nodeList.filter(node => {
25 25
			return node instanceof Vertex;
26
		}).filter(vertex => {
26
	}).filter(vertex => {
27 27
			return vertex.attributes.some(attribute => attribute[0] === this._filterAttributeName);
28
		});
28
	});
29 29

  
30 30
		// filter
31 31
		return nodeList.filter(this._getFilterFunction());
......
66 66
		let comparatorFn;
67 67
		switch (operation) {
68 68
			case StringFilterOperation.EQ:
69
				comparatorFn = (a, b) => a !== b;
69
				comparatorFn = (a, b) => a === b;
70 70
				break;
71 71

  
72 72
			case StringFilterOperation.NEQ:
73
				comparatorFn = (a, b) => a === b;
73
				comparatorFn = (a, b) => a !== b;
74 74
				break;
75 75

  
76 76
			case StringFilterOperation.CONTAINS:
77
				comparatorFn = (a, b) => !(a.includes(b));
77
				comparatorFn = (a, b) => a.includes(b);
78 78
				break;
79 79

  
80 80
			case StringFilterOperation.STARTS_WITH:
81
				comparatorFn = (a, b) => !(a.startsWith(b));
81
				comparatorFn = (a, b) => a.startsWith(b);
82 82
				break;
83 83

  
84 84
			case StringFilterOperation.ENDS_WITH:
85
				comparatorFn = (a, b) => !(a.endsWith(b));
85
				comparatorFn = (a, b) => a.endsWith(b);
86 86
				break;
87 87

  
88 88
			case StringFilterOperation.REGEXP:
89
				comparatorFn = (a, b) => !(a.match(new RegExp(b, 'i')));
89
				comparatorFn = (a, b) => a.match(new RegExp(b, 'i'));
90 90
				break;
91 91

  
92 92
			default:
......
106 106
		switch (operation) {
107 107
			case EnumFilterOperation.EQ:
108 108
				filterFn = vertex => {
109
					const attribute = vertex.attributes.find(attribute => attribute[0] === filterAttributeName);
110
					const attributeValues = attribute[1].split(', ');
111

  
112
					// some (at least one) of the attribute items should be contained in the filters
113
					 let count = 0;
114
					 attributeValues.forEach(value => {
115
						if(filterValues.indexOf(value) > -1) {
116
							count++;
117
						}
118
					 });
119

  
120
					 return count === 0;
121
				};
109
				const attribute = vertex.attributes.find(attribute => attribute[0] === filterAttributeName);
110
				const attributeValues = attribute[1].split(', ');
111

  
112
				// some (at least one) of the attribute items should be contained in the filters
113
				return attributeValues.some(attributeValue => {
114
					return filterValues.indexOf(attributeValue) > -1;
115
			});
116
			};
122 117
				break;
123 118

  
124 119
			case EnumFilterOperation.NEQ:
125 120
				filterFn = vertex => {
126
					const attribute = vertex.attributes.find(attribute => attribute[0] === filterAttributeName);
127
					const attributeValues = attribute[1].split(', ');
128

  
129
					// every of the attribute items should not be contained in the filters (translated: none of the items should be contained in the filters)
130
					let count = 0;
131
					attributeValues.forEach(value => {
132
						if(filterValues.indexOf(value) > -1) {
133
						count++;
134
					}
135
					});
136

  
137
					return count > 0;
138
				};
121
				const attribute = vertex.attributes.find(attribute => attribute[0] === filterAttributeName);
122
				const attributeValues = attribute[1].split(', ');
123

  
124
				// every of the attribute items should not be contained in the filters (translated: none of the items should be contained in the filters)
125
				return attributeValues.every(attributeValue => {
126
					return filterValues.indexOf(attributeValue) < 0;
127
			});
128
			};
139 129
				break;
140 130

  
141 131
			default:
......
154 144
			filterFn = vertex => {
155 145
				const attribute = vertex.attributes.find(attribute => attribute[0] === filterAttributeName);
156 146
				const attributeValue = parseInt(attribute[1]);
157

  
158
				return (attributeValue < filterValueFrom) || (attributeValue > filterValueTo);
147
				return (attributeValue >= filterValueFrom) && (attributeValue <= filterValueTo);
159 148
			};
160 149

  
161 150
		} else {
......
163 152

  
164 153
			let comparatorFn;
165 154
			switch (operation) {
166
				case DateFilterOperation.NEQ:
155
				case DateFilterOperation.EQ:
167 156
					comparatorFn = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
168 157
					break;
169 158

  
170
				case DateFilterOperation.EQ:
159
				case DateFilterOperation.NEQ:
171 160
					comparatorFn = (a, b) => a.getFullYear() !== b.getFullYear() || a.getMonth() !== b.getMonth() || a.getDate() !== b.getDate();
172 161
					break;
173 162

  
......
194 183
			filterFn = vertex => {
195 184
				const attribute = vertex.attributes.find(attribute => attribute[0] === filterAttributeName);
196 185
				const attributeValue = parseFloat(attribute[1]);
197
				return (attributeValue < filterValueFrom) || (attributeValue > filterValueTo);
186
				return (attributeValue >= filterValueFrom) && (attributeValue <= filterValueTo);
198 187
			};
199 188

  
200 189
		} else {

Také k dispozici: Unified diff