-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
271 lines (241 loc) · 11.3 KB
/
index.html
File metadata and controls
271 lines (241 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!--
title: Redis
-->
{{ 'limit,q,key,type,call,connection,host,port,db,password' | importRequestParams }}
{{ limit ?? 100 | assignTo: limit }}
{{ q ?? '' | assignTo: q }}
{{ key ?? '' | assignTo: key }}
{{ type ?? 'string' | assignTo: type }}
{{ "?" | addQueryString({ q, limit }) | assignTo: baseUrl }}
{{ ['GET','LRANGE','SMEMBERS','ZRANGE','HGETALL'] | any: startsWith(call, it)
| assignTo: isViewCommand }}
{{ `<script>
var baseUrl = "${baseUrl}";
var key = "${key}";
var limit = "${limit}";
var type = "${type}";
var call = "${escapeDoubleQuotes(call)}";
var isViewCommand = ${lower(isViewCommand)};
</script>` | raw }}
{{#raw appendTo scripts}}
<script>
$('input[name=q]').on('input', function(){
if (isViewCommand) $("[name=call]").val('')
$(this).closest('form').submit()
})
$('.details tbody tr').on('click', function(){
var key = $(this).find('td:first').html()
var type = $(this).find('td:nth-child(2)').html()
var call = type == "string" ?
"GET " + key
: type == "list" ?
"LRANGE " + key + " 0 -1"
: type == "set" ?
"SMEMBERS " + key
: type == "zset" ?
"ZRANGE " + key + " 0 -1 WITHSCORES"
: type == "hash" ?
"HGETALL " + key : null;
location.href = baseUrl + '&key=' + encodeURIComponent(key) + "&type=" + type + "&call=" + encodeURIComponent(call)
})
$('.action.edit').on('click', function(){
if (!key) return
$("#type-string").trigger('click')
$('#value').val(window.keyValue)
})
$('.action.delete').on('click', function(){
location.href = baseUrl + '&call=' + encodeURIComponent("DEL " + key)
})
$('.action.q').on('click', function(){
location.href = '?q=' + encodeURIComponent(key.split(':').slice(0, $(this).data('pos') + 1).join(':'))
})
$('#key,#value').on('input', function(){
$('#key').val($('#key').val().replace(/\\s+/g,''))
$('#btn-key-type').attr('disabled', !$('#key').val() || !$('#value').val() || ($('#key').val() == key && $('#value').val() == window.keyValue))
})
$('#key-types').submit(function(e){
e.preventDefault()
var key = $(this).find('#key').val(), value = $(this).find('#value').val(), type = this.className.split('-')[1];
var url = '?q=' + encodeURIComponent(key) + '&key=' + encodeURIComponent(key) + '&type=' + type + '&call='
+ (type == 'list'
? encodeURIComponent("RPUSH " + key + " " + value)
: type == 'set'
? encodeURIComponent("SADD " + key + " " + value)
: type == 'zset'
? encodeURIComponent("ZADD " + key + " " + $("#score").val() + " " + value)
: type == 'hash'
? encodeURIComponent("HSET " + key + " " + $("#field").val() + " " + value)
: encodeURIComponent("SET " + key + " " + value))
location.href = url
})
$("#search-results tr td:first-child").each(function(){
if ($(this).html() == key) $(this).parent().addClass('active')
})
$(".type-buttons button").on('click', function(){
$("#key-types").removeClass().addClass(this.id).find('.btn-success').html($(this).data('label'))
var isForKey = type == this.id.split('-')[1]
$("#key").val(isForKey ? key : '')
$("#value").val(isForKey && (call || "").toUpperCase().startsWith("GET") ? keyValue : '')
$('#btn-key-type').attr('disabled', !$('#key').val() || !$('#value').val() || ($('#key').val() == key && $('#value').val() == window.keyValue && type == "string"));
if (isViewCommand) $("#key-types input:text:visible,#value").filter(function(){ return !this.value || this.id == "value" }).first().focus()
})
$("#type-" + type).trigger('click')
</script>
{{/raw}}
<form>
<div class="row">
<div class="col-4">
<input type="hidden" name="type" value="{{ type }}">
<input type="text" name="q" class="form-control" placeholder="Search for key, e.g. urn..." aria-label="Search for key..." value="{{ q }}"
autofocus onfocus="var hold=this.value; this.value=''; this.value=hold"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>
<div class="col-auto">
<input type="text" name="limit" id="limit" class="form-control" placeholder="limit" value="{{ limit }}"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" style="width:70px">
</div>
<div class="col-auto">
<label for="limit" style="width:30px;line-height:2rem;margin: 0 0 0 -10px">results</label>
</div>
<div class="col-6">
<div class="input-group">
<input type="text" name="call" class="form-control" placeholder="Redis Command" value="{{ call | ifExists }}"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<span class="input-group-btn"><button class="btn btn-primary" type="submit">Go!</button></span>
</div>
</div>
</div>
</form>
{{#if Request.Verb == "POST" }}
{{ { host, port, db, password } | withoutEmptyValues | redisChangeConnection | end }}
{{/if}}
<h6 id="connection"><a href="?connection">@ {{ redisConnectionString }}</a></h6>
{{#if connection != null }}
{{#with redisConnection}}
<div class="container" style="position:absolute;max-width:440px;margin:65px 0 0 0">
<form action="/" method="POST">
<div class="form-group row">
<label for="host" class="col-sm-3 col-form-label">Host</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="host" name="host" placeholder="host" value="{{ host }}">
</div>
</div>
<div class="form-group row">
<label for="port" class="col-sm-3 col-form-label">Port</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="port" name="port" placeholder="port" value="{{ port }}">
</div>
</div>
<div class="form-group row">
<label for="db" class="col-sm-3 col-form-label">Database</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="db" name="db" placeholder="db" value="{{ db }}">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-sm-3 col-form-label">Password</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="password" name="password" placeholder="password" value="">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label"></label>
<div class="col-sm-9">
<button type="submit" class="btn btn-primary">Change Connection</button>
</div>
</div>
</form>
</div>
{{/with}}
{{/if}}
{{ ['flush','monitor','brpop','blpop'] | ifNotEmpty(call) | any: contains(lower(call), it)
| assignTo: illegalCommand }}
{{#if call and !illegalCommand }}
{{ call | redisCall | assignTo: json }}
{{ parseJson(json) ?? json | assignTo: obj }}
{{/if}}
<script>window.keyValue = '{{ json | onlyIfExists | jsString }}';</script>
<div id="details">
<table class="table table-bordered auto-width">
<caption>
{{#if key }}
{{ key | split(':') | assignTo: parts }}
{{#if parts.Length >= 2 }}
{{#each parts}}{{#if index > 0}}>{{/if}}<span class="action q" data-pos="{{index}}">{{it}}</span>{{/each}}
{{/if}}
{{/if}}
</caption>
{{#if !isEmpty(obj) }}
{{ obj | htmlDump({ className: "table table-striped" }) | assignTo: html }}
{{#if html}}<tr><td>{{html}}</td></tr>{{/if}}
{{#if obj and isViewCommand}} {{ 'delete' | addTo: actions }} {{/if}}
{{/if}}
{{#if actions }}
{{#if type == 'string' }}
{{ 'edit' | addTo: actions }}
{{/if}}
{{#if actions }}
<tr>
<td colspan="2" style="text-align:right">
{{#each actions}}<span class="action {{it}}">{{it}}</span>{{/each}}
</td>
</tr>
{{/if}}
{{/if}}
</table>
{{#if illegalCommand}}<div class="alert alert-danger">Command is not allowed.</div>{{/if}}
{{ htmlErrorMessage }}
{{ ifError | select: <a href="{ baseUrl }">clear command</a> }}
<div class="type-{{ type }}" id="key-types">
<div class="type-buttons">
<button id="type-string" type="button" class="btn btn-outline-secondary" data-label="Set String">Strings</button>
<button id="type-list" type="button" class="btn btn-outline-secondary" data-label="Add to List">Lists</button>
<button id="type-set" type="button" class="btn btn-outline-secondary" data-label="Add to Set">Sets</button>
<button id="type-zset" type="button" class="btn btn-outline-secondary" data-label="Add to Sorted Set">Sorted Sets</button>
<button id="type-hash" type="button" class="btn btn-outline-secondary" data-label="Set Hash Entry">Hashes</button>
</div>
<form>
<div class="form-group">
<div class="input-group input-group-lg">
<input id="key" type="text" class="form-control" placeholder="key" value="" style="min-width:200px"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<input id="field" type="text" class="form-control" placeholder="field" value="" style="max-width:130px"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<input id="score" type="text" class="form-control" placeholder="score" value="" style="max-width:130px"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>
</div>
<div class="form-group">
<div class="input-group input-group-lg">
<textarea id="value" class="form-control" placeholder="value" value="" style="min-width:400px;min-height:300px"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
</div>
</div>
<div class="form-group">
<span class="input-group-btn"><button id="btn-key-type" class="btn btn-success btn-lg" disabled>Set String</button></span>
</div>
</form>
</div>
</div>
<div id="search-results">
{{#if !q}}
{{#if connection == null }}
<table class="table table-striped" style="width:450px">
<tbody>
{{#each toList(redisInfo) }}
<tr><th>{{ it.Key | replace('_',' ') }}</th><td title="{{it.Value}}">{{ it.Value | substringWithEllipsis(32) }}</td></tr>
{{/each}}
</tbody>
</table>
{{/if}}
{{else}}
{{ `${q}*` | redisSearchKeys({ limit }) | map: toObjectDictionary(it)
| assignTo: searchResults }}
<h3>Results for '{{q}}'</h3>
{{#if !isEmpty(searchResults) }}
{{ searchResults | htmlDump({ className: "table table-striped details auto-width" }) }}
{{else if q}}
Your search did not match any keys..
{{/if}}
{{/if}}
</div>