Skip to content

Commit 3eaca14

Browse files
committed
Maintain big integers from Bolt until ready to present or export them
1 parent bfaa764 commit 3eaca14

File tree

12 files changed

+192
-37
lines changed

12 files changed

+192
-37
lines changed

app/index.jade

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ html(class="no-js", lang="en", ng-app="neo4jApp", ng-controller="MainCtrl")
114114
script(src='scripts/services/Timer.js')
115115
script(src='scripts/directives/focusOn.js')
116116
script(src='scripts/services/CSV.js')
117+
script(src='scripts/services/BoltIntHelpers.js')
117118
script(src='scripts/directives/resizable.js')
118119
script(src='scripts/directives/fileUpload.js')
119120
script(src='scripts/directives/neoTable.js')
@@ -210,5 +211,6 @@ html(class="no-js", lang="en", ng-app="neo4jApp", ng-controller="MainCtrl")
210211
script(src='scripts/services/ProtocolFactory.js')
211212
script(src='scripts/controllers/SyncSigninController.js')
212213
script(src='lib/helpers.js')
214+
script(src='lib/boltIntHelpers.js')
213215
script(src='lib/serializer.js')
214216
//endbuild

app/scripts/app.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ angular.module('neo4jApp.services', [
3131
'AsciiTableModule',
3232
'auth0',
3333
'firebase',
34-
'angular-jwt'
34+
'angular-jwt',
35+
'neo.boltint'
3536
])
3637

3738
app = angular.module('neo4jApp', [

app/scripts/controllers/CypherResult.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
'use strict'
2222

2323
angular.module('neo4jApp.controllers')
24-
.controller 'CypherResultCtrl', ['$rootScope', '$scope', 'AsciiTableFactory', ($rootScope, $scope, AsciiTableFactory) ->
24+
.controller 'CypherResultCtrl', ['$rootScope', '$scope', 'AsciiTableFactory', 'BoltIntHelpers', ($rootScope, $scope, AsciiTableFactory, BoltIntHelpers) ->
2525
$scope.displayInternalRelationships = $rootScope.stickyDisplayInternalRelationships ? true
2626
$scope.availableModes = []
2727
$scope.slider = {min: 4, max: 20}
@@ -64,7 +64,7 @@ angular.module('neo4jApp.controllers')
6464

6565
$scope.loadAscii = () ->
6666
return if not tableData or not tableData.data
67-
rows = tableData.data.map((data_obj) -> return data_obj.row)
67+
rows = tableData.data.map((data_obj) -> return BoltIntHelpers.mapBoltIntsToStrings(data_obj.row))
6868
rows.splice(0, 0, tableData.columns)
6969
res = asciiTable.get(rows, {maxColumnWidth: $scope.ascii_col_width})
7070
$scope.slider.max = asciiTable.maxWidth

app/scripts/directives/neoTable.coffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
'use strict';
2222
angular.module('neo4jApp.directives')
2323
.directive('neoTable', ['Utils', (Utils) ->
24+
bolt = window.neo4j.v1
2425
replace: yes
2526
restrict: 'E'
2627
link: (scope, elm, attr) ->
@@ -40,7 +41,9 @@ angular.module('neo4jApp.directives')
4041
html
4142

4243
cell2html = (cell) ->
43-
if angular.isString(cell)
44+
if bolt.isInt cell
45+
return cell.toString()
46+
else if angular.isString(cell)
4447
return emptyMarker() unless cell.length
4548
Utils.escapeHTML(cell)
4649
else if angular.isArray(cell)

app/scripts/services/Bolt.coffee

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ angular.module('neo4jApp.services')
2929
'$location'
3030
'$q'
3131
'Utils'
32-
(Settings, AuthDataService, localStorageService, $rootScope, $location, $q, Utils) ->
32+
'BoltIntHelpers'
33+
(Settings, AuthDataService, localStorageService, $rootScope, $location, $q, Utils, BoltIntHelpers) ->
3334
bolt = window.neo4j.v1
3435
_driver = null
3536
_errorStatus = null
@@ -47,7 +48,7 @@ angular.module('neo4jApp.services')
4748

4849
testQuery = (driver) ->
4950
q = $q.defer()
50-
driver.onError = (e) ->
51+
driver.onError = (e) ->
5152
if e instanceof Event and e.type is 'error'
5253
q.reject getSocketErrorObj()
5354
else if e.code and e.message # until Neo4jError is in drivers public API
@@ -66,11 +67,11 @@ angular.module('neo4jApp.services')
6667
testConnection = (withoutCredentials = no) ->
6768
q = $q.defer()
6869
driver = getDriverObj withoutCredentials
69-
testQuery(driver).then((r) ->
70+
testQuery(driver).then((r) ->
7071
q.resolve r
7172
_errorStatus = null
7273
driver.close()
73-
).catch((e) ->
74+
).catch((e) ->
7475
q.reject e
7576
_errorStatus = e
7677
driver.close()
@@ -82,7 +83,7 @@ angular.module('neo4jApp.services')
8283
_driver = getDriverObj withoutCredentials
8384
testQuery(_driver)
8485
.then((r) -> q.resolve r)
85-
.catch((e) ->
86+
.catch((e) ->
8687
_driver = null unless e.fields[0].code is 'Neo.ClientError.Security.CredentialsExpired'
8788
q.reject e
8889
)
@@ -120,12 +121,12 @@ angular.module('neo4jApp.services')
120121
else
121122
if tx
122123
# We need to look for error messages from
123-
# the commit() call even though run()
124+
# the commit() call even though run()
124125
# reported a successful operation
125126
p = tx.run statement, parameters
126-
p.then((r) ->
127+
p.then((r) ->
127128
if tx # The tx might have been terminated
128-
tx.commit().then((txr) ->
129+
tx.commit().then((txr) ->
129130
session.close()
130131
q.resolve r
131132
).catch((txe) ->
@@ -174,21 +175,20 @@ angular.module('neo4jApp.services')
174175

175176
jmxResultToRESTResult = (r, whatToGet = []) ->
176177
return {data: []} unless r.records
177-
r.records = itemIntToString r.records
178178
filtered = r.records.filter((record) -> whatToGet.indexOf(record.get('name')) > -1)
179-
.map((record) ->
179+
.map((record) ->
180180
origAttributes = record.get('attributes')
181181
return {
182-
name: record.get('name'),
183-
description: record.get('description'),
182+
name: record.get('name'),
183+
description: record.get('description'),
184184
attributes: Object.keys(record.get('attributes')).map((attributeName) -> {
185185
name: attributeName,
186186
description: origAttributes[attributeName].description,
187187
value: origAttributes[attributeName].value
188188
})
189189
}
190190
)
191-
{data: filtered}
191+
{data: BoltIntHelpers.mapBoltIntsToStrings filtered}
192192

193193
schemaResultToRESTResult = (indexes, constraints) ->
194194
indexString = ""
@@ -234,7 +234,7 @@ angular.module('neo4jApp.services')
234234
obj.data.results[0].plan = boltPlanToRESTPlan result.summary.plan if result.summary and result.summary.plan
235235
obj.data.results[0].plan = boltPlanToRESTPlan result.summary.profile if result.summary and result.summary.profile
236236
obj.data.results[0].stats = boltStatsToRESTStats result.summary
237-
res = itemIntToString res
237+
# res = itemIntToString res
238238
rows = res.map((record) ->
239239
return {
240240
row: getRESTRowsFromBolt record, keys
@@ -282,6 +282,7 @@ angular.module('neo4jApp.services')
282282
return item.properties if item instanceof bolt.types.Relationship
283283
return [].concat.apply([], extractPathForRowsFormat(item)) if item instanceof bolt.types.Path
284284
return item if item is null
285+
return item if bolt.isInt item
285286
return item.map((subitem) -> extractDataForRowsFormat subitem) if Array.isArray item
286287
if typeof item is 'object'
287288
out = {}
@@ -312,29 +313,14 @@ angular.module('neo4jApp.services')
312313
return item if item instanceof bolt.types.Relationship
313314
return [].concat.apply([], extractPathsForGraphFormat(item)) if item instanceof bolt.types.Path
314315
return no if item is null
316+
return item if bolt.isInt item
315317
return item.map((subitem) -> extractDataForGraphFormat subitem).filter((i) -> i) if Array.isArray item
316318
if typeof item is 'object'
317319
out = Object.keys(item).map((key) -> extractDataForGraphFormat(item[key])).filter((i) -> i)
318320
return no if not out.length
319321
return out
320322
no
321323

322-
itemIntToString = (item) ->
323-
return arrayIntToString item if Array.isArray(item)
324-
return item if typeof item in ['number', 'string', 'boolean']
325-
return item if item is null
326-
return item.toString() if bolt.isInt item
327-
return objIntToString item if typeof item is 'object'
328-
329-
arrayIntToString = (arr) ->
330-
arr.map((item) -> itemIntToString item)
331-
332-
objIntToString = (obj) ->
333-
Object.keys(obj).forEach((key) ->
334-
obj[key] = itemIntToString obj[key]
335-
)
336-
obj
337-
338324
boltPlanToRESTPlan = (plan) ->
339325
obj = boltPlanToRESTPlanShared plan
340326
obj['runtime-impl'] = plan.arguments['runtime-impl']
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
###!
2+
Copyright (c) 2002-2016 "Neo Technology,"
3+
Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
5+
This file is part of Neo4j.
6+
7+
Neo4j is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
###
20+
21+
'use strict'
22+
23+
angular.module('neo.boltint', [])
24+
.service 'BoltIntHelpers', [ ->
25+
return new neo.boltIntHelpers()
26+
]

app/scripts/services/GraphStyle.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ angular.module('neo4jApp.services')
112112
@props[attr] or ''
113113

114114
class GraphStyle
115+
bolt = window.neo4j.v1
115116
constructor: (@storage) ->
116117
@rules = []
117118
try
@@ -327,6 +328,7 @@ angular.module('neo4jApp.services')
327328
/\{([^{}]*)\}/g,
328329
(a, b) ->
329330
r = item.propertyMap[b]
331+
return r.toString() if bolt.isInt r
330332
if typeof r is 'object'
331333
r = r.join(', ')
332334
return if (typeof r is 'string' or typeof r is 'number') then r else ''
@@ -340,6 +342,7 @@ angular.module('neo4jApp.services')
340342
/^<(id|type)>$/,
341343
(a,b) ->
342344
r = item[b]
345+
return r.toString() if bolt.isInt r
343346
return if (typeof r is 'string' or typeof r is 'number') then r else ''
344347
)
345348

app/views/partials/frame-common-actions.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
a(exportable ng-click='exportGraphPNG()', ng-show='isActive("graph")') Export PNG
2020
a(exportable ng-click='exportPlanPNG()', ng-show='isActive("plan")') Export PNG
2121
a(exportable ng-click='exportJSON(frame.response.raw.summary ? frame.response.raw : frame.response.table._response)') Export JSON
22-
a(ng-hide="frame.response.protocol=='bolt'", exportable ng-click='exportCSV(frame.response.table)') Export CSV
22+
a(exportable ng-click='exportCSV(frame.response.table)') Export CSV
2323
li
2424
a.button.sl.sl-pin(ng-click='pin(frame)', ng-class="{pinned: pinned}", tooltip-placement='bottom', tooltip='Pin at top')
2525
li

lib/boltIntHelpers.coffee

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
###!
2+
Copyright (c) 2002-2016 "Neo Technology,"
3+
Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
5+
This file is part of Neo4j.
6+
7+
Neo4j is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
###
20+
21+
'use strict'
22+
if global? then global.neo = global.neo || {};
23+
if window? then window.neo = window.neo || {};
24+
25+
neo = global?.neo || window?.neo
26+
bolt = window.neo4j.v1
27+
28+
class neo.boltIntHelpers
29+
stringify = (val) ->
30+
return val.toString() if bolt.isInt val
31+
return "[" + val.map((item) -> stringify(item)).join() + "]" if Array.isArray(val)
32+
return 'null' if val is null
33+
if typeof val == 'object'
34+
return "{" + Object.keys(val).map((key) -> '"' + key + '"' + ":" + stringify(val[key])).join() + "}"
35+
return '"' + val + '"' if typeof val == 'string'
36+
return val.toString()
37+
38+
39+
mapBoltIntsToStrings = (val) ->
40+
return val.toString() if bolt.isInt val
41+
return val.map(mapBoltIntsToStrings) if Array.isArray(val)
42+
return val if val is null
43+
if typeof val == 'object'
44+
out = {}
45+
Object.keys(val).forEach((key) ->
46+
out[key] = mapBoltIntsToStrings(val[key]))
47+
return out
48+
return val
49+
50+
constructor: ->
51+
@stringify = stringify
52+
@mapBoltIntsToStrings = mapBoltIntsToStrings

lib/serializer.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ class neo.serializer
4747

4848
@output = -> @_output
4949

50+
5051
@_escape = (string) ->
5152
return '' unless string?
52-
string = JSON.stringify(string) unless typeof string is 'string'
53+
string = new neo.boltIntHelpers().stringify(string) unless typeof string is 'string'
5354
return '""' unless string.length
5455
if string.indexOf(@options.delimiter) > 0 or string.indexOf('"') >= 0
5556
string = '"' + string.replace(/"/g, '""') + '"'

0 commit comments

Comments
 (0)