redis-browser 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff7e71ad7ca6d00fdd7bf652d7a0905cf04b3c3e
4
- data.tar.gz: 9ba1d711f8db4b1500c834e6d6ec13f4a6cf15a9
3
+ metadata.gz: be0e2ba8d6a3009374dc91c621899fbb8d247ba5
4
+ data.tar.gz: c37ef89c7903b1902a1b8b86ea2851ae09182647
5
5
  SHA512:
6
- metadata.gz: 7a1773a0652654b6759e2dcdb52e6fdf3763a5c8a929ddc8b00594d5bcd3554b44551713d329bbc4586e3c6d9cd14cf92dc1ef22fcf5b957d5a52c6e8705d6c8
7
- data.tar.gz: b0913ff743bcb6b8ee038f4708e9cdcf9b1b6a89c6376ceebcf3aad1eb1a6416394b2cdee612eb137411a9e5ef759f0452c62e60acd7636ff9e4413950bc4c79
6
+ metadata.gz: 0302aa3ad6b395a35e4de6b04fb159e9df086834d14c6f7f5748c271db56923cb52607e748db48b71e215f443abd808d9268fd0c6f1e0110b6112735e9674d37
7
+ data.tar.gz: 87a612ae892bb71b4099b03f64e7b2edb1d6635cbd1d6f72df24372c8a157200baa617c382863fea4eff526410569f6112dc017dd88bf5a01b381437d1b7a117
@@ -21,34 +21,38 @@ class Browser
21
21
  @db = db
22
22
  end
23
23
 
24
- def keys_tree(sep = /:+|\//)
25
- keys = {}
26
- full = {}
27
-
28
- redis.keys.each do |key|
29
- chunks = key.split(sep, 7)
30
- full[chunks] = key
31
- chunks.inject([keys,[]]) do |(xs,n), x|
32
- xs[x] ||= {}
33
- xs[x]
34
-
35
- [xs[x], n]
36
- end
24
+ def split_key(key)
25
+ if key =~ /^(.+?)(:+|\/+|\.+).+$/
26
+ [$1, $2]
27
+ else
28
+ [key, nil]
29
+ end
30
+ end
31
+
32
+ def keys(namespace = nil)
33
+ if namespace.to_s.strip.empty?
34
+ pattern = "*"
35
+ namespace = ""
36
+ else
37
+ pattern = namespace + "*"
37
38
  end
38
39
 
39
- f = lambda do |prefix, hash|
40
+ redis.keys(pattern).inject({}) do |acc, key|
41
+ key.slice!(namespace) if namespace
40
42
 
41
- hash.map do |k,v|
42
- np = (prefix + [k])
43
- {
44
- :name => k,
45
- :full => full[np] || np.join("*"),
46
- :children => f.call(np, v)
43
+ ns, sep = split_key(key)
44
+
45
+ unless ns.strip.empty?
46
+ acc[ns] ||= {
47
+ :name => ns,
48
+ :full => namespace + ns + sep.to_s,
49
+ :count => 0
47
50
  }
48
- end.sort_by {|k| k[:name] }
49
- end
51
+ acc[ns][:count] += 1
52
+ end
50
53
 
51
- f.call([], keys)
54
+ acc
55
+ end.values.sort_by {|e| e[:name] }
52
56
  end
53
57
 
54
58
  def item_type(e)
@@ -137,6 +141,13 @@ class Browser
137
141
  }.merge(data)
138
142
  end
139
143
 
144
+ def ping
145
+ redis.ping == "PONG"
146
+ {:ok => 1}
147
+ rescue => ex
148
+ {:error => ex.message}
149
+ end
150
+
140
151
  def redis
141
152
  @redis ||= begin
142
153
  conn = @conn || "127.0.0.1:6379"
@@ -167,12 +178,12 @@ class App < Sinatra::Base
167
178
  slim :index
168
179
  end
169
180
 
170
- get '/keys_tree.json' do
171
- json browser.keys_tree
181
+ get '/ping.json' do
182
+ json browser.ping
172
183
  end
173
184
 
174
185
  get '/keys.json' do
175
- json browser.keys(params[:pattern])
186
+ json browser.keys(params[:namespace])
176
187
  end
177
188
 
178
189
  get '/key.json' do
@@ -40,3 +40,14 @@ body {
40
40
  .per-page { margin-top: 25px; }
41
41
  .connection-info { padding-right: 20px; }
42
42
  .keys-search { width: 100px; }
43
+
44
+ #http-loader {
45
+ position: fixed;
46
+ left: 0;
47
+ top: 0;
48
+ display: none;
49
+ background: gold;
50
+ padding: 5px 10px;
51
+ font-weight: bold;
52
+ z-index: 10000;
53
+ }
@@ -1,15 +1,35 @@
1
1
  app = angular.module('browser', ['ui.bootstrap', 'LocalStorageModule'])
2
2
 
3
- # app.run ($rootScope) ->
3
+ app.config ($httpProvider) ->
4
+ funShow = (data, headersGetter) ->
5
+ document.getElementById('http-loader').style.display = "block"
6
+ data
7
+
8
+ $httpProvider.defaults.transformRequest.push(funShow)
9
+ $httpProvider.responseInterceptors.push('HttpLoader')
10
+
11
+ app.factory 'HttpLoader', ['$q', ($q) ->
12
+ (promise) ->
13
+ promise.then (response) ->
14
+ document.getElementById('http-loader').style.display = "none"
15
+ response
16
+ , (response) ->
17
+ document.getElementById('http-loader').style.display = "none"
18
+ response
19
+ ]
4
20
 
5
- angular.module('browser').factory 'API', ['$http', ($http) ->
21
+ app.factory 'API', ['$http', ($http) ->
6
22
  (connection, database) ->
7
23
  ps = {connection: connection, database: database}
8
24
  {
9
- keysTree: (pattern) -> $http.get("/keys_tree.json", {
25
+ ping: () -> $http.get("/ping.json", {
10
26
  params: ps
11
27
  }).then (e) -> e.data,
12
28
 
29
+ keys: (namespace) -> $http.get("/keys.json", {
30
+ params: angular.extend({}, ps, {namespace: namespace})
31
+ }).then (e) -> e.data,
32
+
13
33
  get: (params) -> $http.get("/key.json", {
14
34
  params: angular.extend({}, ps, params)
15
35
  }).then (e) -> e.data
@@ -53,14 +73,22 @@ angular.module('browser').factory 'API', ['$http', ($http) ->
53
73
  close: ->
54
74
  $scope.config.show = false
55
75
  save: ->
56
- db.add("connection", $scope.config.connection)
57
- db.add("database", $scope.config.database)
58
- $scope.api = API($scope.config.connection, $scope.config.database)
76
+ # Check connection
77
+ $scope.config.error = null
59
78
 
60
- $scope.fetchKeys()
61
- $scope.show($scope.key)
79
+ test = API($scope.config.connection, $scope.config.database)
80
+ test.ping().then (resp) ->
81
+ if resp.ok
82
+ db.add("connection", $scope.config.connection)
83
+ db.add("database", $scope.config.database)
84
+ $scope.api = API($scope.config.connection, $scope.config.database)
85
+
86
+ $scope.fetchKeys()
87
+ $scope.show($scope.key)
62
88
 
63
- $scope.config.close()
89
+ $scope.config.close()
90
+ else
91
+ $scope.config.error = resp.error
64
92
 
65
93
  setHashView: (view) ->
66
94
  $scope.config.hashView = view
@@ -75,10 +103,10 @@ angular.module('browser').factory 'API', ['$http', ($http) ->
75
103
 
76
104
  # Scope functions
77
105
  $scope.fetchKeys = ->
78
- $scope.keys = $scope.api.keysTree()
106
+ $scope.keys = $scope.api.keys()
79
107
 
80
108
  $scope.show = (key) ->
81
- key.open = true
109
+ $scope.keyOpen(key)
82
110
  $scope.api.get(key: key.full).then((e) ->
83
111
  $scope.key = e
84
112
 
@@ -97,6 +125,17 @@ angular.module('browser').factory 'API', ['$http', ($http) ->
97
125
  e.json[k] = v.value
98
126
  )
99
127
 
128
+ $scope.keyOpen = (key) ->
129
+ console.log key.children
130
+ if key.count > 1 && !key.children
131
+ $scope.api.keys(key.full).then (keys) ->
132
+ key.children = keys
133
+
134
+ key.open = true
135
+
136
+ $scope.keyClose = (key) ->
137
+ key.open = false
138
+
100
139
 
101
140
  $scope.setPerPage = (i) ->
102
141
  db.add("per_page", i)
@@ -12,12 +12,15 @@ html ng-app="browser"
12
12
  link rel="stylesheet" href="/css/app.css"
13
13
 
14
14
  script type="text/ng-template" id="nav-tree-item.html"
15
- span ng-show="key.children.length > 0"
16
- button.btn.tree-toggle ng-hide="key.open" ng-click="key.open = true" +
17
- button.btn.tree-toggle ng-show="key.open" ng-click="key.open = false" -
18
- span ng-show="key.children.length == 0" -&nbsp;
15
+ span ng-show="key.count > 1"
16
+ button.btn.tree-toggle ng-hide="key.open" ng-click="keyOpen(key)" +
17
+ button.btn.tree-toggle ng-show="key.open" ng-click="keyClose(key)" -
18
+ span ng-show="key.count == 1" -&nbsp;
19
19
 
20
- a href="#" ng-click="show(key)" {{ key.name }}
20
+ a href="#" ng-click="show(key)"
21
+ ' {{ key.name }}
22
+ small ng-show="key.count > 1"
23
+ | ({{ key.count }})
21
24
 
22
25
  ul.tree ng-show="key.open"
23
26
  li ng-repeat="key in key.children" ng-include="'nav-tree-item.html'"
@@ -25,6 +28,7 @@ html ng-app="browser"
25
28
 
26
29
 
27
30
  body ng-controller="BrowserCtrl"
31
+ #http-loader Loading...
28
32
  div modal="config.show" close="config.close()" options="config.modalOpts"
29
33
  .form-horizontal
30
34
  .modal-header
@@ -48,6 +52,8 @@ html ng-app="browser"
48
52
  select id="config-database" ng-model="config.database" ng-options="i for i in config.databases"
49
53
 
50
54
  .modal-footer
55
+ span.alert.alert-error.pull-left ng-show="config.error"
56
+ ' {{ config.error }}
51
57
  button.btn.btn-success type="submit" ng-click="config.save()" Save
52
58
 
53
59
  .navbar.navbar-inverse.navbar-fixed-top
@@ -63,7 +69,10 @@ html ng-app="browser"
63
69
  button.btn.btn-success ng-click="config.open()" Configure
64
70
  p.navbar-text.pull-right.connection-info
65
71
  ' Connected to
66
- strong {{ config.connection }}
72
+ strong
73
+ ' {{ config.connection }}
74
+ small
75
+ ' ({{ config.database }})
67
76
 
68
77
 
69
78
  .container-fluid
@@ -1,3 +1,3 @@
1
1
  module RedisBrowser
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tymon Tobolski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-20 00:00:00.000000000 Z
11
+ date: 2013-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler