Skip to content

Commit a791720

Browse files
committed
review table
1 parent 99221c1 commit a791720

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

lib/viewer/tableConfig.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ WOQLTableConfig.prototype.json = function () {
3131
if (typeof this.renderer() !== 'undefined') {
3232
conf.renderer = this.renderer();
3333
}
34+
if (typeof this.filter() !== 'undefined') {
35+
conf.filter = this.filter();
36+
}
37+
if (typeof this.filterable() !== 'undefined') {
38+
conf.filterable = this.filterable();
39+
}
3440
if (typeof this.pager() !== 'undefined') {
3541
conf.pager = this.pager();
3642
}
@@ -68,6 +74,12 @@ WOQLTableConfig.prototype.loadJSON = function (config, rules) {
6874
if (typeof config.renderer !== 'undefined') {
6975
this.renderer(config.renderer);
7076
}
77+
if (typeof config.filter !== 'undefined') {
78+
this.filter(config.filter);
79+
}
80+
if (typeof config.filterable !== 'undefined') {
81+
this.filterable(config.filterable);
82+
}
7183
if (typeof config.bindings !== 'undefined') {
7284
this.bindings(config.bindings);
7385
}
@@ -111,6 +123,27 @@ WOQLTableConfig.prototype.prettyPrint = function () {
111123
return str;
112124
};
113125

126+
/**
127+
* @param {boolean} canfilter
128+
* @returns WOQLTableConfig
129+
*/
130+
131+
WOQLTableConfig.prototype.filterable = function (canfilter) {
132+
if (!canfilter && canfilter !== false) return this.tfilterable;
133+
this.tfilterable = canfilter;
134+
return this;
135+
};
136+
137+
/*
138+
* default is string
139+
* filter type number | list | date
140+
*/
141+
WOQLTableConfig.prototype.filter = function (filter) {
142+
if (!filter) return this.tfilter;
143+
this.tfilter = filter;
144+
return this;
145+
};
146+
114147
WOQLTableConfig.prototype.renderer = function (rend) {
115148
if (!rend) return this.trenderer;
116149
this.trenderer = rend;
@@ -196,6 +229,22 @@ WOQLTableRule.prototype.header = function (hdr) {
196229
return this;
197230
};
198231

232+
WOQLTableRule.prototype.filter = function (hdr) {
233+
if (typeof hdr === 'undefined') {
234+
return this.rule.filter;
235+
}
236+
this.rule.filter = hdr;
237+
return this;
238+
};
239+
240+
WOQLTableRule.prototype.filterable = function (hdr) {
241+
if (typeof hdr === 'undefined') {
242+
return this.rule.filterable;
243+
}
244+
this.rule.filterable = hdr;
245+
return this;
246+
};
247+
199248
WOQLTableRule.prototype.width = function (wid) {
200249
if (typeof wid === 'undefined') {
201250
return this.rule.width;

lib/viewer/terminusRule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ TerminusPattern.prototype.testBasics = function (scope, value) {
112112
};
113113

114114
TerminusPattern.prototype.testValue = function (value, constraint) {
115+
if (!value) return null;
115116
const vundertest = (value['@value'] ? value['@value'] : value);
116117
if (typeof constraint === 'function') return constraint(vundertest);
117118
// eslint-disable-next-line no-param-reassign

lib/viewer/woqlTable.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,15 @@ WOQLTable.prototype.getDefinedEvent = function (row, key, scope, action, rownum)
191191
} else {
192192
var matched_rules = new WOQLRule().matchCell(this.config.rules, row, key, rownum, action);
193193
}
194-
if (matched_rules && matched_rules.length) {
195-
const l = matched_rules.length - 1;
196-
return matched_rules[l].rule[action];
194+
// I get more than one rule it is not always the last
195+
if (Array.isArray(matched_rules) && matched_rules.length > 0) {
196+
// if I have only one rule
197+
if (matched_rules.length === 1) return matched_rules[0].rule[action];
198+
// eslint-disable-next-line max-len
199+
const findRule = matched_rules.find((item) => item.rule[action] !== undefined || item.rule[action] === false);
200+
return findRule && findRule.rule ? findRule.rule[action] : undefined;
197201
}
202+
return undefined;
198203
};
199204

200205
WOQLTable.prototype.getRowClick = function (row) {
@@ -228,6 +233,15 @@ WOQLTable.prototype.bindings = function () {
228233
return this.config.bindings();
229234
};
230235

236+
WOQLTable.prototype.getColumnFilter = function (colid) {
237+
const filter = new WOQLRule().matchColumn(this.config.rules, colid, 'filter');
238+
// console.log('getColumnFilter', filter);
239+
if (Array.isArray(filter) && filter.length > 0 && filter[0].rule) {
240+
return filter[0].rule.filter;
241+
}
242+
return null;
243+
};
244+
231245
WOQLTable.prototype.getColumnDimensions = function (key) {
232246
const cstyle = {};
233247
const w = new WOQLRule().matchColumn(this.config.rules, key, 'width');
@@ -266,6 +280,11 @@ WOQLTable.prototype.isSortableColumn = function (key) {
266280
return true;
267281
};
268282

283+
WOQLTable.prototype.isFilterableColumn = function (key) {
284+
if (this.getDefinedEvent(false, key, 'column', 'filterable') === false) return false;
285+
return true;
286+
};
287+
269288
WOQLTable.prototype.renderValue = function (renderer, val, key, row) {
270289
if (val && val['@type']) {
271290
renderer.type = val['@type'];

lib/woql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const WOQL = {};
3333
/**
3434
* Query running against any specific commit Id
3535
* @param {string} refPath - path to specific reference Id or commit Id
36-
* @param {WOQLQuery} subquery - subquery for the specific commit point
36+
* @param {WOQLQuery} [subquery] - subquery for the specific commit point
3737
* @returns {WOQLQuery}
3838
* @example
3939
* let [a, b, c] = vars("a", "b", "c")

0 commit comments

Comments
 (0)