Skip to content

Commit 7bc8c47

Browse files
variety of bug fixes and tweaks for terminus
1 parent 613f024 commit 7bc8c47

14 files changed

+165
-140
lines changed

lib/viewer/chartConfig.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,22 @@ WOQLChartConfig.prototype.constructor = Config.ViewConfig;
1212

1313

1414
WOQLChartConfig.prototype.prettyPrint = function(){
15-
var str = "view = View.chart();\n";
15+
var str = "view = View.chart();\n";
16+
str += this.getBasicPrettyPrint();
1617
for(var i = 0; i<this.rules.length ; i++){
1718
str += "view." + this.rules[i].prettyPrint() + "\n";
1819
}
1920
return str;
2021
}
2122

2223
WOQLChartConfig.prototype.json = function(){
23-
let jr = [];
24-
for(var i = 0; i<this.rules.length; i++){
25-
jr.push(this.rules[i].json());
26-
}
27-
var conf = {};
28-
let mj = {"chart" :conf, "rules": jr};
24+
let mj = {"chart" :this.getBasicJSON(), "rules": this.getRulesJSON()};
2925
return mj;
3026
}
3127

3228
WOQLChartConfig.prototype.loadJSON = function(config, rules){
33-
var jr = [];
29+
this.loadBasicJSON(config);
30+
var jr = [];
3431
for(var i = 0; i<rules.length; i++){
3532
var nr = new WOQLChartRule();
3633
nr.json(rules[i]);

lib/viewer/chooserConfig.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ WOQLChooserConfig.prototype.create = function(client){
1616
}
1717

1818
WOQLChooserConfig.prototype.prettyPrint = function(){
19-
var str = "view = View.chooser();\n";
19+
var str = "view = View.chooser();\n";
20+
str += this.getBasicPrettyPrint();
2021
if(typeof this.change() != "undefined"){
2122
str += "view.change(" + this.change() + ")\n";
2223
}
@@ -45,11 +46,7 @@ WOQLChooserConfig.prototype.prettyPrint = function(){
4546
}
4647

4748
WOQLChooserConfig.prototype.json = function(){
48-
let jr = [];
49-
for(var i = 0; i<this.rules.length; i++){
50-
jr.push(this.rules[i].json());
51-
}
52-
var conf = {};
49+
var conf = this.getBasicJSON();
5350
if(typeof this.change() != "undefined"){
5451
conf['change'] = this.change();
5552
}
@@ -71,7 +68,7 @@ WOQLChooserConfig.prototype.json = function(){
7168
if(typeof this.direction() != "undefined"){
7269
conf['direction'] = this.direction();
7370
}
74-
let mj = {"chooser" :conf, "rules": jr};
71+
let mj = {"chooser" :conf, "rules": this.getRulesJSON()};
7572
return mj;
7673
}
7774

@@ -82,7 +79,8 @@ WOQLChooserConfig.prototype.loadJSON = function(config, rules){
8279
nr.json(rules[i]);
8380
jr.push(nr);
8481
}
85-
this.rules = jr;
82+
this.rules = jr;
83+
this.loadBasicJSON(config);
8684
if(typeof config.change != "undefined"){
8785
this.change(config.change);
8886
}

lib/viewer/documentFrame.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const ObjectFrame = require("../objectFrame");
22
const FrameConfig = require("./frameConfig");
3+
const FrameHelper = require("../utils");
34

45
function DocumentFrame(client, config){
56
this.client = client;

lib/viewer/frameConfig.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ FrameConfig.prototype.create = function(client){
1717
}
1818

1919
FrameConfig.prototype.prettyPrint = function(){
20-
var str = "view = View.document();\n";
20+
var str = "view = View.document();\n";
21+
str += this.getBasicPrettyPrint();
2122
if(typeof this.load_schema() != "undefined"){
2223
str += "view.load_schema(" + this.load_schema() + ")\n";
2324
}
@@ -28,18 +29,11 @@ FrameConfig.prototype.prettyPrint = function(){
2829
}
2930

3031
FrameConfig.prototype.json = function(){
31-
let jr = [];
32-
for(var i = 0; i<this.rules.length; i++){
33-
jr.push(this.rules[i].json());
34-
}
35-
var conf = {};
36-
if(typeof this.renderer() != "undefined"){
37-
conf['renderer'] = this.renderer();
38-
}
32+
var conf = this.getBasicJSON();
3933
if(typeof this.load_schema() != "undefined"){
4034
conf['load_schema'] = this.load_schema();
4135
}
42-
let mj = {"frame" :conf, "rules": jr};
36+
let mj = {"frame" :conf, "rules": this.getRulesJSON()};
4337
return mj;
4438
}
4539

@@ -50,22 +44,14 @@ FrameConfig.prototype.loadJSON = function(config, rules){
5044
nr.json(rules[i]);
5145
jr.push(nr);
5246
}
53-
this.rules = jr;
54-
if(typeof config.renderer != "undefined"){
55-
this.renderer(config.renderer);
56-
}
47+
this.rules = jr;
48+
this.loadBasicJSON(config);
5749
if(typeof config.load_schema != "undefined"){
5850
this.load_schema(config.load_schema);
5951
}
6052
return this;
6153
}
6254

63-
FrameConfig.prototype.renderer = function(rend){
64-
if(typeof rend == "undefined") return this.trenderer;
65-
this.trenderer = rend;
66-
return this;
67-
}
68-
6955
FrameConfig.prototype.json_rules = function(){
7056
let jr = [];
7157
for(var i = 0; i<this.rules.length; i++){

lib/viewer/graphConfig.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ WOQLGraphConfig.prototype.edge = function(source, target){
108108
}
109109

110110
WOQLGraphConfig.prototype.node = function(...cols){
111-
let nr = new WOQLGraphRule().scope("node");
112-
nr.setVariables(cols);
111+
let nr = new WOQLGraphRule();
112+
if(cols && cols.length){
113+
nr.scope("node").setVariables(cols);
114+
}
115+
else {
116+
nr.scope("row");
117+
}
113118
this.rules.push(nr);
114119
return nr;
115120
}
@@ -155,7 +160,7 @@ WOQLGraphConfig.prototype.loadJSON = function(config, rules){
155160
}
156161

157162
WOQLGraphConfig.prototype.prettyPrint = function(){
158-
var str = "view = WOQL.graph();\n";
163+
var str = "view = View.graph();\n";
159164
if(typeof this.literals() != "undefined"){
160165
str += "view.literals('" + this.literals() + "')\n";
161166
}
@@ -295,7 +300,7 @@ WOQLGraphRule.prototype.weight = function(w){
295300
}
296301

297302
WOQLGraphRule.prototype.prettyPrint = function(type){
298-
var str = WOQLViewRule.prototype.prettyPrint.apply(this);
303+
var str = Config.WOQLViewRule.prototype.prettyPrint.apply(this);
299304
if(typeof this.charge() != "undefined"){
300305
str += ".charge('" + this.charge() + "')";
301306
}

lib/viewer/streamConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ WOQLStreamConfig.prototype.template = function(template){
2828

2929

3030
WOQLStreamConfig.prototype.prettyPrint = function(){
31-
var str = "view = WOQL.stream();\n";
31+
var str = "view = View.stream();\n";
3232
if(typeof this.template() != "undefined"){
3333
str += "view.template(" + JSON.stringify(this.template()) + ")\n";
3434
}

lib/viewer/tableConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ WOQLTableRule.prototype.header = function(hdr){
180180
}
181181

182182
WOQLTableRule.prototype.prettyPrint = function(type){
183-
var str = WOQLViewRule.prototype.prettyPrint.apply(this);
183+
var str = Config.WOQLViewRule.prototype.prettyPrint.apply(this);
184184
if(typeof this.header() != "undefined"){
185185
str += ".header(" + this.header() + ")";
186186
}

lib/viewer/viewConfig.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
11

22
const WOQLRule = require("../woqlRule");
33

4+
/**
5+
* Generic functions / configs that are available to all config types
6+
*/
47
function ViewConfig(){
58
this.rules = [];
69
}
710

11+
ViewConfig.prototype.render = function(func){
12+
if(func) this.view_render = func;
13+
return this.view_render;
14+
}
15+
16+
ViewConfig.prototype.renderer = function(val){
17+
if(val) this.view_renderer = val;
18+
return this.view_renderer;
19+
}
20+
21+
ViewConfig.prototype.getRulesJSON = function(){
22+
let jr = [];
23+
for(var i = 0; i<this.rules.length; i++){
24+
jr.push(this.rules[i].json());
25+
}
26+
return jr;
27+
}
28+
29+
ViewConfig.prototype.getBasicJSON = function(){
30+
let jr = {};
31+
if(this.view_render) jr.render = this.view_render;
32+
if(this.view_renderer) jr.renderer = this.view_renderer;
33+
return jr;
34+
}
35+
36+
ViewConfig.prototype.loadBasicJSON = function(json){
37+
if(json.render) this.view_render = json.view_render;
38+
if(json.renderer) this.view_renderer = json.view_renderer;
39+
}
40+
41+
ViewConfig.prototype.getBasicprettyPrint = function(){
42+
let str = "";
43+
if(typeof this.render() != "undefined"){
44+
str += "view.render(" + this.render() + ")\n";
45+
}
46+
if(typeof this.renderer() != "undefined"){
47+
str += "view.renderer('" + this.renderer() + "')\n";
48+
}
49+
return str;
50+
}
51+
52+
853
function WOQLViewRule(){
954
WOQLRule.call(this);
1055
this.rule = {};

lib/viewer/woqlChooser.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function WOQLChooser(client, config){
1010
this.client = client;
1111
this.config = (config ? config : new WOQLChooserConfig());
1212
this.selected = false;
13+
this.cursor = 0;
1314
return this;
1415
}
1516

@@ -36,6 +37,7 @@ WOQLChooser.prototype.setResult = function(result){
3637
const variables = result.getVariableList();
3738
if(!this.config.values() && variables.length){
3839
this.config.values(variables[0]);
40+
alert(variables[0]);
3941
}
4042
//sort it
4143
if(this.config.sort()){
@@ -44,7 +46,7 @@ WOQLChooser.prototype.setResult = function(result){
4446
while(row = this.result.next()){
4547
if(row && this.includeRow(row, this.result.cursor)){
4648
this.choices.push(this.rowToChoice(row, rows++));
47-
}
49+
}
4850
}
4951
return this;
5052
}
@@ -126,7 +128,7 @@ WOQLChooser.prototype.getSpecialRenderer = function(row, index, type){
126128

127129
WOQLChooser.prototype.renderSpecial = function(rule, row, rownum){
128130
if(rule && typeof rule == "function"){
129-
return render(row);
131+
return rule(row);
130132
}
131133
if(rule && typeof rule == "string"){
132134
return rule;
@@ -142,15 +144,17 @@ WOQLChooser.prototype.first = function(){
142144
return this.choices[this.cursor];
143145
}
144146

145-
WOQLChooser.prototype.prev = function(){
146-
if(this.cursor > 0) {
147-
return this.choices[--this.cursor];
148-
}
149-
}
150-
151-
WOQLChooser.prototype.next = function(){
152-
return this.choices[this.cursor++];
153-
}
147+
WOQLChooser.prototype.next = function () {
148+
const res = this.choices[this.cursor];
149+
this.cursor++;
150+
return res;
151+
};
154152

153+
WOQLChooser.prototype.prev = function () {
154+
if (this.cursor > 0) {
155+
this.cursor--;
156+
return this.choices[this.cursor];
157+
}
158+
};
155159

156160
module.exports = WOQLChooser;

0 commit comments

Comments
 (0)