lib/redis-browser/templates/coffee/app.coffee in redis-browser-0.1.2 vs lib/redis-browser/templates/coffee/app.coffee in redis-browser-0.2.0
- old
+ new
@@ -1,17 +1,37 @@
app = angular.module('browser', ['ui.bootstrap', 'LocalStorageModule'])
-# app.run ($rootScope) ->
+app.config ($httpProvider) ->
+ funShow = (data, headersGetter) ->
+ document.getElementById('http-loader').style.display = "block"
+ data
-angular.module('browser').factory 'API', ['$http', ($http) ->
+ $httpProvider.defaults.transformRequest.push(funShow)
+ $httpProvider.responseInterceptors.push('HttpLoader')
+
+app.factory 'HttpLoader', ['$q', ($q) ->
+ (promise) ->
+ promise.then (response) ->
+ document.getElementById('http-loader').style.display = "none"
+ response
+ , (response) ->
+ document.getElementById('http-loader').style.display = "none"
+ response
+]
+
+app.factory 'API', ['$http', ($http) ->
(connection, database) ->
ps = {connection: connection, database: database}
{
- keysTree: (pattern) -> $http.get("/keys_tree.json", {
+ ping: () -> $http.get("/ping.json", {
params: ps
}).then (e) -> e.data,
+ keys: (namespace) -> $http.get("/keys.json", {
+ params: angular.extend({}, ps, {namespace: namespace})
+ }).then (e) -> e.data,
+
get: (params) -> $http.get("/key.json", {
params: angular.extend({}, ps, params)
}).then (e) -> e.data
delete: (params) -> $http.delete("/key.json", {
@@ -51,19 +71,27 @@
open: ->
$scope.config.show = true
close: ->
$scope.config.show = false
save: ->
- db.add("connection", $scope.config.connection)
- db.add("database", $scope.config.database)
- $scope.api = API($scope.config.connection, $scope.config.database)
+ # Check connection
+ $scope.config.error = null
- $scope.fetchKeys()
- $scope.show($scope.key)
+ test = API($scope.config.connection, $scope.config.database)
+ test.ping().then (resp) ->
+ if resp.ok
+ db.add("connection", $scope.config.connection)
+ db.add("database", $scope.config.database)
+ $scope.api = API($scope.config.connection, $scope.config.database)
- $scope.config.close()
+ $scope.fetchKeys()
+ $scope.show($scope.key)
+ $scope.config.close()
+ else
+ $scope.config.error = resp.error
+
setHashView: (view) ->
$scope.config.hashView = view
db.add("hashView", view)
modalOpts:
@@ -73,14 +101,14 @@
$scope.api = API($scope.config.connection, $scope.config.database)
# Scope functions
$scope.fetchKeys = ->
- $scope.keys = $scope.api.keysTree()
+ $scope.keys = $scope.api.keys()
$scope.show = (key) ->
- key.open = true
+ $scope.keyOpen(key)
$scope.api.get(key: key.full).then((e) ->
$scope.key = e
switch e.type
when "list"
@@ -94,9 +122,20 @@
when "hash"
e.json = {}
for k,v of e.value
e.json[k] = v.value
)
+
+ $scope.keyOpen = (key) ->
+ console.log key.children
+ if key.count > 1 && !key.children
+ $scope.api.keys(key.full).then (keys) ->
+ key.children = keys
+
+ key.open = true
+
+ $scope.keyClose = (key) ->
+ key.open = false
$scope.setPerPage = (i) ->
db.add("per_page", i)
$scope.list.per_page = i