Skip to content

Commit

Permalink
Merge branch '2.2' into 2.3
Browse files Browse the repository at this point in the history
Conflicts:
	community/browser/app/index.jade
	community/browser/app/scripts/utils.coffee
  • Loading branch information
apcj committed Jul 6, 2015
2 parents 1781831 + ce6a948 commit e2333c7
Show file tree
Hide file tree
Showing 14 changed files with 403 additions and 115 deletions.
25 changes: 21 additions & 4 deletions community/browser/Gruntfile.coffee
Expand Up @@ -71,8 +71,8 @@ module.exports = (grunt) ->

watch:
coffee:
files: ["<%= yeoman.app %>/scripts/{,*/}*.coffee", "<%= yeoman.lib %>/visualization/**/*.coffee"]
tasks: ["coffee:dist", "coffee:visualization"]
files: ["<%= yeoman.app %>/scripts/{,*/}*.coffee", "<%= yeoman.lib %>/visualization/**/*.coffee", "<%= yeoman.lib %>/*.coffee"]
tasks: ["coffee:dist", "coffee:visualization", "coffee:lib"]
coffeeTest:
files: ["test/spec/{,*/}*.coffee"]
tasks: ["coffee:test"]
Expand Down Expand Up @@ -177,6 +177,14 @@ module.exports = (grunt) ->
'<%= yeoman.lib %>/visualization/init.coffee'
]
]
lib:
files: [
expand: true
cwd: "<%= yeoman.lib %>"
src: "*.coffee"
dest: ".tmp/lib"
ext: ".js"
]

stylus:
compile:
Expand Down Expand Up @@ -271,19 +279,28 @@ module.exports = (grunt) ->
dest: "<%= yeoman.dist %>/fonts"
src: ["components/**/*.{otf,woff,ttf,svg}"]
}]
shell:
dirListing:
command: 'ls',
options:
stdout: true

replace:
dist:
find: 'url(/images'
replace: 'url(/browser/images'
src: ["<%= yeoman.dist %>/styles/main.css"]

exec:
csv_test_prep:
command: 'mkdir -p target/test-classes/ && cat .tmp/lib/helpers.js .tmp/lib/serializer.js src/test/javascript/prepareCSVTest.js >target/test-classes/CsvExportImportRoundTripTest.js'

# load all grunt tasks
require("matchdep").filterDev("grunt-*").forEach grunt.loadNpmTasks

grunt.registerTask "server", ["clean:server", "coffee", "configureProxies", "stylus", "jade", "connect:livereload", "watch"]
grunt.registerTask "test", ["clean:server", "coffee", "connect:test", "karma"]
grunt.registerTask "build", ["clean:dist", "test", "coffee", "jade", "stylus", "useminPrepare", "concat", "copy", "imagemin", "cssmin", "htmlmin", "uglify", "rev", "usemin", "replace"]
grunt.registerTask "test", ["clean:server", "coffee", "connect:test", "karma", "exec:csv_test_prep"]
grunt.registerTask "build", ["clean:dist", "coffee", "test", "jade", "stylus", "useminPrepare", "concat", "copy", "imagemin", "cssmin", "htmlmin", "uglify", "rev", "usemin", "replace"]
grunt.registerTask "server:dist", ["build", "configureProxies", "connect:dist:keepalive"]
grunt.registerTask "default", ["build"]

Expand Down
2 changes: 2 additions & 0 deletions community/browser/app/index.jade
Expand Up @@ -186,6 +186,8 @@ html(class="no-js", lang="en", ng-app="neo4jApp", ng-controller="MainCtrl")
script(src='scripts/controllers/SysinfoController.js')
script(src='scripts/controllers/Frame.js')
script(src='scripts/controllers/FrameNotification.js')
script(src='lib/helpers.js')
script(src='lib/serializer.js')
//endbuild
script.
Expand Down
34 changes: 2 additions & 32 deletions community/browser/app/scripts/services/CSV.coffee
Expand Up @@ -21,38 +21,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
'use strict';

angular.module('neo.csv', [])
.factory 'CSV', [
() ->
class Serializer
constructor: (opts = {}) ->
@options = angular.extend(opts,
delimiter: ','
)

@_output = ""
@_columns = null

append: (row) ->
if not angular.isArray(row) and row.length is @_columns?.length
throw 'CSV: Row must an Array of column size'

@_output += "\n"
@_output += (@_escape(cell) for cell in row).join(@options.delimiter)

columns: (cols) ->
return @_columns unless cols?
throw 'CSV: Columns must an Array' unless angular.isArray(cols)
@_columns = (@_escape(c) for c in cols)
@_output = @_columns.join(@options.delimiter);

output: -> @_output

_escape: (string) ->
string = JSON.stringify(string) unless angular.isString(string)
if string.indexOf(@options.delimiter) > 0 or string.indexOf('"') >= 0
string = '"' + string.replace(/"/g, '""') + '"'

string
.factory 'CSV', [ ->
Serializer = neo.serializer

return {
Serializer: Serializer
Expand Down
83 changes: 7 additions & 76 deletions community/browser/app/scripts/utils.coffee
Expand Up @@ -21,11 +21,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
'use strict';

angular.module('neo4jApp.utils', [])
.service('Utils', ['$timeout', ($timeout)->
@argv = (input) ->
rv = input.toLowerCase().split(' ')
rv or []
@debounce = (func, wait, immediate) ->
.service('Utils', ['$timeout', ($timeout) ->

utils = new neo.helpers()
that = utils.extend utils, this

that.debounce = (func, wait, immediate) ->
result = undefined
timeout = null
->
Expand All @@ -41,75 +42,5 @@ angular.module('neo4jApp.utils', [])
result = func.apply(context, args) if callNow
result

@throttle = (func, wait) ->
last_timestamp = null
limit = wait
->
context = @
args = arguments
now = Date.now()
if !last_timestamp || now - last_timestamp >= limit
last_timestamp = now
func.apply(context, args)

@parseId = (resource = "") ->
id = resource.substr(resource.lastIndexOf("/")+1)
return parseInt(id, 10)

@stripComments = (input) ->
rows = input.split("\n")
rv = []
rv.push row for row in rows when row.indexOf('//') isnt 0
rv.join("\n")

@firstWord = (input) ->
input.split(/\n| /)[0]

@extendDeep = (dst) =>
that = @
angular.forEach(arguments, (obj) ->
if (obj != dst)
angular.forEach(obj, (value, key) ->
if (dst[key] && angular.isObject(dst[key]))
that.extendDeep(dst[key], value)
else if(!angular.isFunction(dst[key]))
dst[key] = value
)
)
dst

@parseTimeMillis = ( timeWithOrWithoutUnit ) =>
timeWithOrWithoutUnit += '' #Cast to string

# Parses human-readable units like "12h", "2s" and returns milliseconds.
# This maps to TimeUtil#parseTimeMillis in the main Neo4j code base, please ensure they are kept in sync
unit = timeWithOrWithoutUnit.match /\D+/
value = parseInt timeWithOrWithoutUnit

if unit?.length is 1
switch unit[0]
when "ms" then return value
when "s" then return value * 1000
when "m" then return value * 1000 * 60
else return 0
else return value*1000


@ua2text = (ua) ->
s = ''
for i in [0..ua.length]
s = s + "" + String.fromCharCode ua[i]
s

@escapeHTML = (string) ->
entityMap =
"&": "&amp;"
"<": "&lt;"
">": "&gt;"
'"': '&quot;'
"'": '&#39;'
"/": '&#x2F;'
String(string).replace(/[&<>"'\/]/g, (s) -> entityMap[s])

@
that
])
2 changes: 2 additions & 0 deletions community/browser/karma.conf.js
Expand Up @@ -6,6 +6,7 @@ module.exports = function(config) {

preprocessors: {
'app/scripts/**/*.coffee': ['coffee'],
'lib/*.coffee': ['coffee'],
'test/spec/**/*.coffee': ['coffee']
},

Expand Down Expand Up @@ -65,6 +66,7 @@ module.exports = function(config) {
'app/components/UUID.js/src/uuid.js',
'app/components/angular-base64/angular-base64.min.js',
'app/scripts/*.coffee',
'lib/*.coffee',
'app/scripts/**/*.coffee',
'test/spec/**/*.coffee'
],
Expand Down
112 changes: 112 additions & 0 deletions community/browser/lib/helpers.coffee
@@ -0,0 +1,112 @@
###!
Copyright (c) 2002-2015 "Neo Technology,"
Network Engine for Objects in Lund AB [http://neotechnology.com]
This file is part of Neo4j.
Neo4j is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
###

'use strict'

window = window || {}
window.neo = window.neo || {}
neo = window.neo

class neo.helpers
constructor: ->
@argv = (input) ->
rv = input.toLowerCase().split(' ')
rv or []

@parseId = (resource = "") ->
id = resource.substr(resource.lastIndexOf("/")+1)
return parseInt(id, 10)

@stripComments = (input) ->
rows = input.split("\n")
rv = []
rv.push row for row in rows when row.indexOf('//') isnt 0
rv.join("\n")

@firstWord = (input) ->
input.split(/\n| /)[0]

@extendDeep = (dst) =>
that = @
angular.forEach(arguments, (obj) ->
if (obj != dst)
angular.forEach(obj, (value, key) ->
if (dst[key] && angular.isObject(dst[key]))
that.extendDeep(dst[key], value)
else if(!angular.isFunction(dst[key]))
dst[key] = value
)
)
dst

@extend = (objects) ->
extended = {}
merge = (obj) ->
for index, prop of obj
if Object.prototype.hasOwnProperty.call obj, index
extended[index] = obj[index]
merge arguments[0]
for i in [1...arguments.length]
obj = arguments[i]
merge obj
extended

@throttle = (func, wait) ->
last_timestamp = null
limit = wait
->
context = @
args = arguments
now = Date.now()
if !last_timestamp || now - last_timestamp >= limit
last_timestamp = now
func.apply(context, args)

@parseTimeMillis = ( timeWithOrWithoutUnit ) =>
timeWithOrWithoutUnit += '' #Cast to string

# Parses human-readable units like "12h", "2s" and returns milliseconds.
# This maps to TimeUtil#parseTimeMillis in the main Neo4j code base, please ensure they are kept in sync
unit = timeWithOrWithoutUnit.match /\D+/
value = parseInt timeWithOrWithoutUnit

if unit?.length is 1
switch unit[0]
when "ms" then return value
when "s" then return value * 1000
when "m" then return value * 1000 * 60
else return 0
else return value*1000

@ua2text = (ua) ->
s = ''
for i in [0..ua.length]
s = s + "" + String.fromCharCode ua[i]
s

@escapeHTML = (string) ->
entityMap =
"&": "&amp;"
"<": "&lt;"
">": "&gt;"
'"': '&quot;'
"'": '&#39;'
"/": '&#x2F;'
String(string).replace(/[&<>"'\/]/g, (s) -> entityMap[s])
55 changes: 55 additions & 0 deletions community/browser/lib/serializer.coffee
@@ -0,0 +1,55 @@
###!
Copyright (c) 2002-2015 "Neo Technology,"
Network Engine for Objects in Lund AB [http://neotechnology.com]
This file is part of Neo4j.
Neo4j is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
###

'use strict'

window = window || {}
window.neo = window.neo || {}
neo = window.neo

class neo.serializer
constructor: (opts = {}) ->
@options = (new neo.helpers()).extend(opts,
delimiter: ','
)
@_output = ""
@_columns = null

@append = (row) ->
if not Array.isArray(row) and row.length is @_columns?.length
throw 'CSV: Row must an Array of column size'
@_output += "\n"
@_output += (@_escape(cell) for cell in row).join(@options.delimiter)

@columns = (cols) ->
return @_columns unless cols?
throw 'CSV: Columns must an Array' unless Array.isArray(cols)
@_columns = (@_escape(c) for c in cols)
@_output = @_columns.join(@options.delimiter);

@output = -> @_output

@_escape = (string) ->
return '' unless string?
string = JSON.stringify(string) unless typeof string is 'string'
return '""' unless string.length
if string.indexOf(@options.delimiter) > 0 or string.indexOf('"') >= 0
string = '"' + string.replace(/"/g, '""') + '"'
string
2 changes: 1 addition & 1 deletion community/browser/lib/visualization/neod3.coffee
Expand Up @@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

'use strict'

window.neo = {}
window.neo = window.neo || {}

neo.models = {}

Expand Down

0 comments on commit e2333c7

Please sign in to comment.