-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwoqlView.js
107 lines (96 loc) · 3.35 KB
/
woqlView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const WOQLTableConfig = require('./tableConfig');
const WOQLChooserConfig = require('./chooserConfig');
const WOQLGraphConfig = require('./graphConfig');
const WOQLChartConfig = require('./chartConfig');
const WOQLStreamConfig = require('./streamConfig');
const FrameConfig = require('./frameConfig');
const { WOQLRule } = require('./woqlRule');
const { FrameRule } = require('./frameRule');
/**
* We bundle the useful functions in a View object and just export that for ease of consumption
* @constructor
* View
*/
const View = {};
View.table = function () { return new WOQLTableConfig(); };
View.chart = function () { return new WOQLChartConfig(); };
View.graph = function () { return new WOQLGraphConfig(); };
View.chooser = function () { return new WOQLChooserConfig(); };
View.stream = function () { return new WOQLStreamConfig(); };
View.document = function () { return new FrameConfig(); };
View.loadConfig = function (config) {
let view;
if (config.table) {
view = new WOQLTableConfig();
view.loadJSON(config.table, config.rules);
} else if (config.chooser) {
view = new WOQLChooserConfig();
view.loadJSON(config.chooser, config.rules);
} else if (config.graph) {
view = new WOQLGraphConfig();
view.loadJSON(config.graph, config.rules);
} else if (config.chart) {
view = new WOQLChartConfig();
view.loadJSON(config.chart, config.rules);
} else if (config.stream) {
view = new WOQLStreamConfig();
view.loadJSON(config.stream, config.rules);
} else if (config.frame) {
view = new FrameConfig();
view.loadJSON(config.frame, config.rules);
}
return view;
};
/**
* Shorthand functions for accessing the pattern matching capabilities
*/
View.rule = function (type) {
if (type && type === 'frame') return new FrameRule();
return new WOQLRule();
};
View.pattern = function (type) {
if (type && type === 'woql') return new WOQLRule().pattern;
return new FrameRule().pattern;
};
/**
* Called to match an entire row of results is matched by a set of rules
* returns array of rules that matched
*/
View.matchRow = function (rules, row, rownum, action) {
return new WOQLRule().matchRow(rules, row, rownum, action);
};
/**
* Called to test whether an entire column of results is matched by a set of rules
* returns array of rules that matched
*/
View.matchColumn = function (rules, key, action) {
return new WOQLRule().matchColumn(rules, key, action);
};
/**
* Called to test whether a specific cell is matched by a set of rules
* returns array of rules that matched
*/
View.matchCell = function (rules, row, key, rownum, action) {
return new WOQLRule().matchCell(rules, row, key, rownum, action);
};
/**
* Called to test whether a specific node is matched by a set of rules
* returns array of rules that matched
*/
View.matchNode = function (rules, row, key, nid, action) {
return new WOQLRule().matchNode(rules, row, key, nid, action);
};
/**
* Called to test whether a specific edge (source -> target) is matched by a set of rules
* returns array of rules that matched
*/
View.matchEdge = function (rules, row, keya, keyb, action) {
return new WOQLRule().matchPair(rules, row, keya, keyb, action);
};
/**
* Called to test whether a specific frame is matched by a set of rules
*/
View.matchFrame = function (rules, frame, onmatch) {
return new FrameRule().testRules(rules, frame, onmatch);
};
module.exports = View;