Skip to content

Commit 91de3e0

Browse files
adding cell rendering for react
1 parent f8e3e3b commit 91de3e0

File tree

5 files changed

+78
-32
lines changed

5 files changed

+78
-32
lines changed

lib/connectionCapabilities.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ ConnectionCapabilities.prototype.updateDatabasePrefixes = function(dbrec, newps)
148148
dbrec.jsonld_context = _jsonld_context_from_prefixes(newps)
149149
}
150150

151-
152151
function _jsonld_context_from_prefixes(pps){
153152
let basic = {}
154153
for(var key in UTILS.standard_urls){
@@ -164,7 +163,7 @@ function _jsonld_context_from_prefixes(pps){
164163

165164
ConnectionCapabilities.prototype.getContextForOutboundQuery = function(woql, dbid, orgid) {
166165
let ob = {}
167-
if (woql.getContext()) {
166+
if (woql && woql.getContext()) {
168167
ob = woql.getContext()
169168
}
170169
else {

lib/utils.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ Utils.validURL = function(str) {
155155
return false
156156
}
157157

158+
/**
159+
* Tests a string to see if it is a valid URL -
160+
* Valid URLs are those that start with http:// or https://
161+
*/
162+
Utils.isIRI = function(str, context, allow_shorthand) {
163+
if(!str) return false
164+
if(allow_shorthand && context && context[str.split(":")[0]]) return true
165+
if(context){
166+
for(pref in context){
167+
if(str.substring(0, context[pref].length) == context[pref]) return true
168+
}
169+
}
170+
let prot = str.split(":")[0]
171+
let valids = ["http", "https", "terminusdb"]
172+
if(valids.indexOf(prot) != -1) return true
173+
return false
174+
}
175+
176+
158177
/**
159178
* Generates a text label from a URL
160179
*/
@@ -307,6 +326,15 @@ Utils.TypeHelper.numberWithCommas = function(value, separator) {
307326
return value
308327
}
309328

329+
Utils.TypeHelper.formatBytes = function (bytes, decimals = 2) {
330+
if (bytes === 0) return '0 Bytes'
331+
const k = 1024
332+
const dm = decimals < 0 ? 0 : decimals
333+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
334+
const i = Math.floor(Math.log(bytes) / Math.log(k))
335+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
336+
}
337+
310338
/**
311339
* List of supported datatypes
312340
*/

lib/viewer/tableConfig.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,23 @@ WOQLTableRule.prototype.minWidth = function(wid){
209209
return this;
210210
}
211211

212-
WOQLTableRule.prototype.sortable = function(sortable){
213-
if(typeof sortable == "undefined"){
214-
return this.rule.sortable;
212+
WOQLTableRule.prototype.unsortable = function(unsortable){
213+
if(typeof unsortable == "undefined"){
214+
return this.rule.unsortable;
215215
}
216-
this.rule.sortable = sortable;
216+
this.rule.unsortable = unsortable;
217217
return this;
218218
}
219219

220+
WOQLTableRule.prototype.uncompressed = function(uncompressed){
221+
if(typeof uncompressed == "undefined"){
222+
return this.rule.uncompressed;
223+
}
224+
this.rule.uncompressed = uncompressed;
225+
return this;
226+
}
227+
228+
220229

221230
WOQLTableRule.prototype.prettyPrint = function(type){
222231
var str = Config.WOQLViewRule.prototype.prettyPrint.apply(this);

lib/viewer/woqlResult.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,47 @@ function WOQLResult(results, query, config) {
2020
//console.log(results, this.variable_names)
2121
this.query = query ? query : WOQL.query()
2222
this.cursor = 0
23-
if (!(config && config.no_compress)) {
24-
const context = config && config.context ? config.context : false
25-
this.compress(context)
26-
}
23+
//if (!(config && config.no_compress)) {
24+
// const context = results && results.prefixes ? results.prefixes : false
25+
// this.compress(context)
26+
//}
2727
}
2828

2929
/**
3030
* @param {Object} [context] optional context to use for compression - if ommitted query context is used
3131
*/
3232
WOQLResult.prototype.compress = function(context) {
3333
context = context || this.query.getContext()
34-
for (let i = 0; i < this.bindings.length; i++) {
35-
for (const prop of Object.keys(this.bindings[i])) {
36-
const nprop = UTILS.shorten(prop, context)
37-
var nval = this.bindings[i][prop]
38-
if (typeof this.bindings[i][prop] == 'string') {
39-
nval = UTILS.shorten(this.bindings[i][prop], context)
40-
} else if (Array.isArray(this.bindings[i][prop])) {
41-
nval = []
42-
for (var j = 0; j < this.bindings[i][prop].length; j++) {
43-
let oval = this.bindings[i][prop][j]
44-
if (typeof oval == 'string') oval = UTILS.shorten(oval, context)
45-
else if (Array.isArray(oval)) {
46-
let noval = []
47-
for (var k = 0; k < oval.length; k++) {
48-
let kval = oval[k]
49-
if (typeof kval == 'string') kval = UTILS.shorten(kval, context)
50-
noval.push(kval)
34+
if(context){
35+
for (let i = 0; i < this.bindings.length; i++) {
36+
for (const prop of Object.keys(this.bindings[i])) {
37+
const nprop = UTILS.shorten(prop, context)
38+
var nval = this.bindings[i][prop]
39+
if (typeof this.bindings[i][prop] == 'string') {
40+
nval = UTILS.shorten(this.bindings[i][prop], context)
41+
} else if (Array.isArray(this.bindings[i][prop])) {
42+
nval = []
43+
for (var j = 0; j < this.bindings[i][prop].length; j++) {
44+
let oval = this.bindings[i][prop][j]
45+
if (typeof oval == 'string') oval = UTILS.shorten(oval, context)
46+
else if (Array.isArray(oval)) {
47+
let noval = []
48+
for (var k = 0; k < oval.length; k++) {
49+
let kval = oval[k]
50+
if (typeof kval == 'string') kval = UTILS.shorten(kval, context)
51+
noval.push(kval)
52+
}
53+
oval = noval
5154
}
52-
oval = noval
55+
nval.push(oval)
5356
}
54-
nval.push(oval)
5557
}
58+
delete this.bindings[i][prop]
59+
this.bindings[i][nprop] = nval
5660
}
57-
delete this.bindings[i][prop]
58-
this.bindings[i][nprop] = nval
5961
}
6062
}
63+
//console.log(this.bindings)
6164
return this
6265
}
6366

lib/viewer/woqlTable.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ WOQLTable.prototype.getRowClick = function(row){
159159
return re;
160160
}
161161

162+
WOQLTable.prototype.uncompressed = function(row, col){
163+
let re = this.getDefinedEvent(row, col, "row", "uncompressed");
164+
return re;
165+
}
166+
167+
162168
WOQLTable.prototype.getCellClick = function(row, col){
163169
let cc = this.getDefinedEvent(row, col, "column", "click");
164170
return cc;
@@ -209,7 +215,8 @@ WOQLTable.prototype.getRenderer = function(key, row, rownum){
209215
}
210216

211217
WOQLTable.prototype.isSortableColumn = function(key){
212-
return this.getDefinedEvent(false, key, "column", "sortable") || false
218+
if(this.getDefinedEvent(false, key, "column", "unsortable")) return false
219+
return true
213220
}
214221

215222

0 commit comments

Comments
 (0)