Skip to content

Commit

Permalink
- added :config command for changing app settings
Browse files Browse the repository at this point in the history
- heartbeat value for server status pings using HTTP OPTIONS /db/data
  • Loading branch information
akollegger committed May 14, 2014
1 parent ebbd9f7 commit e2ca213
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 8 deletions.
59 changes: 56 additions & 3 deletions community/browser/app/scripts/init/commandInterpreters.coffee
Expand Up @@ -110,6 +110,59 @@ angular.module('neo4jApp')
q.promise
]

FrameProvider.interpreters.push
type: 'account'
templateUrl: 'views/frame-login.html'
matches: ["#{cmdchar}login"]
exec: ['NTN', (NTN) ->
(input, q) ->
NTN.open()
.then(q.resolve, ->
q.reject(message: "Unable to log in")
)
q.promise
]

FrameProvider.interpreters.push
type: 'account'
templateUrl: 'views/frame-logout.html'
matches: ["#{cmdchar}logout"]
exec: ['NTN', (NTN) ->
(input, q) ->
p = NTN.logout()
p.then(q.resolve, -> q.reject(message: "Unable to log out"))
q.promise
]

FrameProvider.interpreters.push
type: 'config'
templateUrl: 'views/frame-config.html'
matches: ["#{cmdchar}config"]
exec: ['Settings', (Settings) ->
(input, q) ->
matches = /^[^\w]*config\s+([^:]+):?([\S\s]+)?$/.exec(input)

if (matches?)
[key, value] = [matches[1], matches[2]]
if (value?)
try
value = eval(value)
catch

Settings[key] = value
else
value = Settings[key]

property = {}
property[key] = value
q.resolve(property)
else
q.resolve(Settings)

q.promise

]

# about handler
# FrameProvider.interpreters.push
# type: 'info'
Expand All @@ -132,10 +185,10 @@ angular.module('neo4jApp')
FrameProvider.interpreters.push
type: 'http'
templateUrl: 'views/frame-rest.html'
matches: ["#{cmdchar}get", "#{cmdchar}post", "#{cmdchar}delete", "#{cmdchar}put"]
matches: ["#{cmdchar}get", "#{cmdchar}post", "#{cmdchar}delete", "#{cmdchar}put", "#{cmdchar}head"]
exec: ['Server', (Server) ->
(input, q) ->
regex = /^[^\w]*(get|GET|put|PUT|post|POST|delete|DELETE)\s+(\S+)\s*([\S\s]+)?$/i
regex = /^[^\w]*(get|GET|put|PUT|post|POST|delete|DELETE|head|HEAD)\s+(\S+)\s*([\S\s]+)?$/i
result = regex.exec(input)

try
Expand All @@ -146,7 +199,7 @@ angular.module('neo4jApp')

verb = verb?.toLowerCase()
if not verb
q.reject(error("Invalid verb, expected 'GET, PUT, POST or DELETE'"))
q.reject(error("Invalid verb, expected 'GET, PUT, POST, HEAD or DELETE'"))
return q.promise

if not url?.length > 0
Expand Down
7 changes: 4 additions & 3 deletions community/browser/app/scripts/init/statusCheck.coffee
Expand Up @@ -23,7 +23,8 @@ angular.module('neo4jApp').run([
'$http'
'$timeout'
'Server'
($scope, $http, $timeout, Server) ->
'Settings'
($scope, $http, $timeout, Server, Settings) ->
timer = null
check = ->
$timeout.cancel(timer)
Expand All @@ -35,11 +36,11 @@ angular.module('neo4jApp').run([
Server.status('?t='+ts).then(
->
$scope.offline = no
timer = $timeout(check, 5000)
timer = $timeout(check, Settings.hearbeat)
,
->
$scope.offline = yes
timer = $timeout(check, 5000)
timer = $timeout(check, Settings.hearbeat)
)
check()
])
12 changes: 11 additions & 1 deletion community/browser/app/scripts/services/Server.coffee
Expand Up @@ -52,6 +52,16 @@ angular.module('neo4jApp.services')
#
# Basic HTTP methods
#
options: (path = '', options = {}) ->
path = Settings.host + path unless path.indexOf(Settings.host) is 0
options.method = 'OPTIONS'
options.url = path
$http(options)

head: (path = '', options) ->
path = Settings.host + path unless path.indexOf(Settings.host) is 0
$http.head(path, options or httpOptions)

delete: (path = '', data = null) ->
path = Settings.host + path unless path.indexOf(Settings.host) is 0
$http.delete(path, httpOptions)
Expand Down Expand Up @@ -113,7 +123,7 @@ angular.module('neo4jApp.services')
status: (params = '')->
# User a smaller timeout for status requests so IE10 detects when the
# server goes down faster.
@get '/db/manage/server/monitor/fetch' + params, {timeout: 3000}
@options '/db/data', { timeout: Settings.heartbeat }

log: (path) ->
@get(path).then((r)-> console.log (r))
Expand Down
3 changes: 2 additions & 1 deletion community/browser/app/scripts/settings.coffee
Expand Up @@ -32,7 +32,8 @@ angular.module('neo4jApp.settings', [])
cypher: "#{restAPI}/cypher"
transaction: "#{restAPI}/transaction"
host: baseURL
maxExecutionTime: 60000
maxExecutionTime: 3600000
heartbeat: 60000
maxFrames: 50
maxHistory: 100
maxNeighbours: 100
Expand Down
12 changes: 12 additions & 0 deletions community/browser/app/views/frame-config.jade
@@ -0,0 +1,12 @@
div(fullscreen)
include partials/frame-common-actions
.inner
.view-result.help(ng-hide='frame.hasErrors')
pre(output-raw = "frame.response")


.status-bar.error(ng-show='frame.hasErrors')
div
span
.icon-warning-sign
{{frame.errorText}}

0 comments on commit e2ca213

Please sign in to comment.