hieraviz 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/app/apiv1.rb +89 -20
- data/app/common.rb +73 -14
- data/app/public/css/main.css +97 -6
- data/app/public/js/farms.js +59 -19
- data/app/public/js/nodes.js +160 -3
- data/app/views/farms.erb +2 -2
- data/app/views/user.erb +6 -0
- data/app/web.rb +24 -23
- data/lib/hieraviz/auth_gitlab.rb +1 -3
- data/lib/hieraviz/config.rb +1 -1
- data/lib/hieraviz/facts.rb +27 -0
- data/lib/hieraviz/puppetdb.rb +13 -0
- data/lib/hieraviz/version.rb +1 -1
- data/lib/hieraviz.rb +2 -0
- data/spec/app/apiv1_spec.rb +10 -3
- data/spec/app/web_spec.rb +4 -2
- data/spec/files/config.yml +1 -0
- data/spec/files/config_dummy.yml +27 -0
- data/spec/files/config_gitlab.yml +1 -0
- data/spec/files/config_multi.yml +27 -0
- data/spec/files/puppet2/enc/node1.example.com.yaml +7 -0
- data/spec/files/puppet2/farm_modules/farm1/manifests/init.pp +3 -0
- data/spec/files/puppet2/hiera.yml +10 -0
- data/spec/files/puppet2/modules/module1/init.pp +2 -0
- data/spec/files/puppet2/params/common/common.yaml +4 -0
- data/spec/files/puppet2/params/nodes/node1.example.com.yaml +2 -0
- data/spec/lib/config_spec.rb +52 -13
- data/spec/lib/facts_spec.rb +41 -0
- data/spec/sinatra_helper.rb +7 -1
- data/spec/spec_helper.rb +0 -2
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4ae953c395227dd73942bc1faa14ab82e0d670c
|
4
|
+
data.tar.gz: 5a1e231af94bedf3f98770dab19e305d022c938d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8866fb2b55e06453abfbc2c22a6ec425c20c16c0aff3a4692baa11a495256bd8082eb8579507ab1bc310094b97d78518d2054a25bcdf6df9f6bae07878953f6c
|
7
|
+
data.tar.gz: b34d079696205abd7f81902f796cef8e1577b0215ae004532ae867195152d2117b87c7b5e0cf16fb84cf8504f7e73dcceee582720763e64009c9af0460afc619
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
Hieraviz Changelog
|
2
2
|
========================
|
3
3
|
|
4
|
+
### v0.1.2 - 2016-02-22
|
5
|
+
- add a way to write custom local facts
|
6
|
+
- add display of nodes info on node panel
|
7
|
+
- make possible to change hiera variables per node
|
8
|
+
- fix farms list to read local files instead of puppetdb
|
9
|
+
- show actual number of nodes in farms list
|
10
|
+
- add storage of custom params per user
|
11
|
+
|
4
12
|
### v0.1.1 - 2016-01-29
|
5
13
|
- add multibase ability
|
6
14
|
- fix node navigation info/params/allparams
|
data/app/apiv1.rb
CHANGED
@@ -17,20 +17,33 @@ module HieravizApp
|
|
17
17
|
enable :sessions
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
case settings.configdata['auth_method']
|
21
|
+
when 'dummy'
|
22
|
+
helpers do
|
23
|
+
def check_authorization
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
when 'gitlab', 'http'
|
28
|
+
helpers do
|
29
|
+
def check_authorization
|
30
|
+
if !session['access_token'] && !request.env['HTTP_X_AUTH']
|
31
|
+
redirect '/v1/not_logged'
|
32
|
+
else
|
33
|
+
token = session['access_token'] || request.env['HTTP_X_AUTH']
|
34
|
+
session_info = Hieraviz::Store.get(token, settings.configdata['session_renew'])
|
35
|
+
if !session_info
|
36
|
+
redirect '/v1/unauthorized'
|
37
|
+
end
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
43
|
+
helpers do
|
44
|
+
|
45
|
+
end
|
46
|
+
|
34
47
|
get %r{^/?([-_\.a-zA-Z0-9]+)?/nodes} do |base|
|
35
48
|
check_authorization
|
36
49
|
hieracles_config = prepare_config(base)
|
@@ -46,21 +59,43 @@ module HieravizApp
|
|
46
59
|
|
47
60
|
get %r{^/?([-_\.a-zA-Z0-9]+)?/node/([-_\.a-zA-Z0-9]+)/params} do |base, node|
|
48
61
|
check_authorization
|
49
|
-
hieracles_config = prepare_config(base)
|
62
|
+
hieracles_config = prepare_config(base, node)
|
50
63
|
node = Hieracles::Node.new(node, hieracles_config)
|
51
64
|
json node.params
|
52
65
|
end
|
53
66
|
|
54
67
|
get %r{^/?([-_\.a-zA-Z0-9]+)?/node/([-_\.a-zA-Z0-9]+)/allparams} do |base, node|
|
55
68
|
check_authorization
|
56
|
-
hieracles_config = prepare_config(base)
|
69
|
+
hieracles_config = prepare_config(base, node)
|
57
70
|
node = Hieracles::Node.new(node, hieracles_config)
|
58
71
|
json node.params(false)
|
59
72
|
end
|
60
73
|
|
74
|
+
get %r{^/?([-_\.a-zA-Z0-9]+)?/node/([-_\.a-zA-Z0-9]+)/facts} do |base, node|
|
75
|
+
check_authorization
|
76
|
+
hieracles_config = prepare_config(base, node)
|
77
|
+
facts = Hieraviz::Facts.new(settings.configdata['tmpdir'], base, node, get_username)
|
78
|
+
json facts.read
|
79
|
+
end
|
80
|
+
|
81
|
+
post %r{^/?([-_\.a-zA-Z0-9]+)?/node/([-_\.a-zA-Z0-9]+)/facts} do |base, node|
|
82
|
+
check_authorization
|
83
|
+
hieracles_config = prepare_config(base, node)
|
84
|
+
facts = Hieraviz::Facts.new(settings.configdata['tmpdir'], base, node, get_username)
|
85
|
+
data = JSON.parse(request.body.read.to_s)
|
86
|
+
json facts.write(data)
|
87
|
+
end
|
88
|
+
|
89
|
+
delete %r{^/?([-_\.a-zA-Z0-9]+)?/node/([-_\.a-zA-Z0-9]+)/facts} do |base, node|
|
90
|
+
check_authorization
|
91
|
+
hieracles_config = prepare_config(base, node)
|
92
|
+
facts = Hieraviz::Facts.new(settings.configdata['tmpdir'], base, node, get_username)
|
93
|
+
json facts.remove
|
94
|
+
end
|
95
|
+
|
61
96
|
get %r{^/?([-_\.a-zA-Z0-9]+)?/node/([-_\.a-zA-Z0-9]+)$} do |base, node|
|
62
97
|
check_authorization
|
63
|
-
hieracles_config = prepare_config(base)
|
98
|
+
hieracles_config = prepare_config(base, node)
|
64
99
|
node = Hieracles::Node.new(node, hieracles_config)
|
65
100
|
json node.params
|
66
101
|
end
|
@@ -68,15 +103,49 @@ module HieravizApp
|
|
68
103
|
get %r{^/?([-_\.a-zA-Z0-9]+)?/farms} do |base|
|
69
104
|
check_authorization
|
70
105
|
hieracles_config = prepare_config(base)
|
71
|
-
json Hieracles::Registry.
|
106
|
+
json Hieracles::Registry.farms_counted(hieracles_config, base)
|
107
|
+
end
|
108
|
+
|
109
|
+
get %r{^/?([-_\.a-zA-Z0-9]+)?/vars} do |base|
|
110
|
+
check_authorization
|
111
|
+
hieracles_config = prepare_config(base)
|
112
|
+
hiera = Hieracles::Hiera.new(hieracles_config)
|
113
|
+
json hiera.params
|
114
|
+
end
|
115
|
+
|
116
|
+
get %r{^/?([-_\.a-zA-Z0-9]+)?/node/([-_\.a-zA-Z0-9]+)/hierarchy} do |base, node|
|
117
|
+
check_authorization
|
118
|
+
hieracles_config = prepare_config(base, node)
|
119
|
+
hiera = Hieracles::Hiera.new(hieracles_config)
|
120
|
+
nodeinfo = Hieracles::Node.new(node, hieracles_config)
|
121
|
+
facts = Hieraviz::Facts.new(settings.configdata['tmpdir'], base, node, get_username)
|
122
|
+
puts facts.instance_variable_get(:@filename)
|
123
|
+
res = {
|
124
|
+
'hiera' => hiera.hierarchy,
|
125
|
+
'vars' => hiera.params,
|
126
|
+
'info' => nodeinfo.info,
|
127
|
+
'files' => nodeinfo.files,
|
128
|
+
'facts' => facts.read,
|
129
|
+
'defaults' => settings.configdata['defaultscope']
|
130
|
+
}
|
131
|
+
json res
|
132
|
+
end
|
133
|
+
|
134
|
+
get %r{^/?([-_\.a-zA-Z0-9]+)?/farm/([-_\.a-zA-Z0-9]+)$} do |base, farm|
|
135
|
+
check_authorization
|
136
|
+
hieracles_config = prepare_config(base)
|
137
|
+
nodes = Hieracles::Registry.nodes_data(hieracles_config, base).reduce({}) do |a, (k, v)|
|
138
|
+
a[k] = v if v['farm'] == farm
|
139
|
+
a
|
140
|
+
end
|
141
|
+
json nodes
|
72
142
|
end
|
73
143
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
# end
|
144
|
+
get '/ppdb/events' do
|
145
|
+
check_authorization
|
146
|
+
puppetdb = Hieraviz::Puppetdb.new settings.configdata['puppetdb']
|
147
|
+
json puppetdb.events
|
148
|
+
end
|
80
149
|
|
81
150
|
get '/not_logged' do
|
82
151
|
json({ error: "Not connected." })
|
@@ -87,7 +156,7 @@ module HieravizApp
|
|
87
156
|
end
|
88
157
|
|
89
158
|
not_found do
|
90
|
-
json({ error: "
|
159
|
+
json({ error: "endpoint not found" })
|
91
160
|
end
|
92
161
|
|
93
162
|
end
|
data/app/common.rb
CHANGED
@@ -14,23 +14,74 @@ module HieravizApp
|
|
14
14
|
end
|
15
15
|
|
16
16
|
helpers do
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
case settings.configdata['auth_method']
|
19
|
+
when 'dummy'
|
20
|
+
|
21
|
+
def get_username
|
22
|
+
'Dummy'
|
23
|
+
end
|
24
|
+
def get_userinfo
|
25
|
+
{ 'username' => 'Dummy' }
|
26
|
+
end
|
27
|
+
|
28
|
+
when 'http'
|
29
|
+
|
30
|
+
def get_username
|
31
|
+
settings.configdata['http_auth']['username']
|
32
|
+
end
|
33
|
+
def get_userinfo
|
34
|
+
{ 'username' => settings.configdata['http_auth']['username'] }
|
35
|
+
end
|
36
|
+
|
37
|
+
when 'gitlab'
|
38
|
+
|
39
|
+
def get_username
|
40
|
+
if session['access_token']
|
41
|
+
session_info = Hieraviz::Store.get(session['access_token'], settings.configdata['session_renew'])
|
42
|
+
if session_info
|
43
|
+
session_info['username']
|
44
|
+
else
|
45
|
+
''
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_userinfo
|
51
|
+
Hieraviz::Store.get(session['access_token'], settings.configdata['session_renew'])
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def prepare_config(e, node = nil)
|
57
|
+
e ||= File.basename(settings.configdata['basepath'])
|
19
58
|
path = get_path(e)[0]
|
20
59
|
if path
|
21
60
|
@base = get_base(path)
|
22
61
|
@base_name = @base.gsub(/\//,'')
|
23
|
-
get_config(path)
|
62
|
+
get_config(path, cached_params(e, node))
|
24
63
|
end
|
25
64
|
end
|
65
|
+
|
66
|
+
def cached_params(base, node)
|
67
|
+
if node
|
68
|
+
cache = Hieraviz::Facts.new settings.configdata['tmpdir'], base, node, get_username
|
69
|
+
if cache.exist?
|
70
|
+
return cache.read
|
71
|
+
end
|
72
|
+
end
|
73
|
+
{}
|
74
|
+
end
|
75
|
+
|
26
76
|
def prepare_params(e)
|
27
|
-
e
|
77
|
+
e ||= File.basename(settings.configdata['basepath'])
|
28
78
|
path = get_path(e)[0]
|
29
79
|
if path
|
30
80
|
settings.configdata['basepath'] = path
|
31
81
|
settings.configdata
|
32
82
|
end
|
33
83
|
end
|
84
|
+
|
34
85
|
def get_path(path)
|
35
86
|
if settings.basepaths
|
36
87
|
settings.basepaths.select do |p|
|
@@ -40,21 +91,29 @@ module HieravizApp
|
|
40
91
|
[ settings.configdata['basepath'] ]
|
41
92
|
end
|
42
93
|
end
|
43
|
-
|
94
|
+
|
95
|
+
def get_config(path, extra)
|
96
|
+
args = { config: Hieraviz::Config.configfile }
|
44
97
|
if path
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
config: Hieraviz::Config.configfile
|
52
|
-
})
|
53
|
-
end
|
98
|
+
args[:basepath] = path
|
99
|
+
end
|
100
|
+
if extra.length > 0
|
101
|
+
args[:params] = format_params(extra)
|
102
|
+
end
|
103
|
+
Hieracles::Config.new args
|
54
104
|
end
|
105
|
+
|
55
106
|
def get_base(path)
|
56
107
|
"/#{File.basename(path)}"
|
57
108
|
end
|
109
|
+
|
110
|
+
def format_params(params)
|
111
|
+
params.reduce([]) do |a, (k, v)|
|
112
|
+
a << "#{k}=#{v}"
|
113
|
+
a
|
114
|
+
end.join(',')
|
115
|
+
end
|
116
|
+
|
58
117
|
end
|
59
118
|
|
60
119
|
end
|
data/app/public/css/main.css
CHANGED
@@ -171,7 +171,7 @@ input {
|
|
171
171
|
font-size: 1.2em;
|
172
172
|
line-height: 1.4em;
|
173
173
|
height: 1.4em;
|
174
|
-
width:
|
174
|
+
width: 330px;
|
175
175
|
position: fixed;
|
176
176
|
}
|
177
177
|
.side .filter input {
|
@@ -198,8 +198,14 @@ input {
|
|
198
198
|
.side ul li.focus {
|
199
199
|
background-color: #fff;
|
200
200
|
}
|
201
|
-
|
202
|
-
|
201
|
+
.side ul li.none {
|
202
|
+
color: #999;
|
203
|
+
}
|
204
|
+
.side ul li .count {
|
205
|
+
float: right;
|
206
|
+
font-family: monospace;
|
207
|
+
}
|
208
|
+
/* ----- Meat ---- */
|
203
209
|
.meat {
|
204
210
|
border: 2px solid #999;
|
205
211
|
background-color: #fff;
|
@@ -271,6 +277,7 @@ input {
|
|
271
277
|
}
|
272
278
|
.meat .rows {
|
273
279
|
margin-top: 3.8em;
|
280
|
+
margin-right: 330px;
|
274
281
|
}
|
275
282
|
.meat .row {
|
276
283
|
word-wrap: break-word;
|
@@ -296,8 +303,9 @@ input {
|
|
296
303
|
}
|
297
304
|
.meat .row .value {
|
298
305
|
font-family: monospace;
|
299
|
-
padding: .1em 1em .
|
306
|
+
padding: .1em 1em .4em;
|
300
307
|
margin: 0;
|
308
|
+
margin-bottom: .2em;
|
301
309
|
}
|
302
310
|
.meat .row:hover {
|
303
311
|
background-color: #f3f3de;
|
@@ -308,12 +316,95 @@ input {
|
|
308
316
|
.meat .row:hover .data {
|
309
317
|
background-color: #dd6;
|
310
318
|
}
|
311
|
-
.meat.farms
|
319
|
+
.meat.farms .node {
|
312
320
|
padding: .5em 1em;
|
313
321
|
}
|
314
|
-
.meat.farms
|
322
|
+
.meat.farms .node:hover {
|
315
323
|
background-color: #f3f3de;
|
316
324
|
}
|
325
|
+
.meat .hierarchy {
|
326
|
+
margin-top: 3.8em;
|
327
|
+
background-color: #ccc;
|
328
|
+
position: fixed;
|
329
|
+
display: inline-block;
|
330
|
+
float: right;
|
331
|
+
width: 330px;
|
332
|
+
right: 0;
|
333
|
+
height: 80%;
|
334
|
+
overflow-y: auto;
|
335
|
+
overflow-x: hidden;
|
336
|
+
}
|
337
|
+
.meat .hierarchy .hierafiles {
|
338
|
+
padding: 1em;
|
339
|
+
font-family: monospace;
|
340
|
+
}
|
341
|
+
.meat .hierarchy .hierafiles div {
|
342
|
+
padding: .2em 0;
|
343
|
+
}
|
344
|
+
.meat .hierarchy .nodeinfo {
|
345
|
+
padding: 1em;
|
346
|
+
}
|
347
|
+
.meat .hierarchy .nodeinfo .var {
|
348
|
+
padding: .2em 0;
|
349
|
+
}
|
350
|
+
.meat .hierarchy .nodeinfo .label {
|
351
|
+
padding: 0 .5em;
|
352
|
+
}
|
353
|
+
.meat .hierarchy .nodeinfo input {
|
354
|
+
width: 100%;
|
355
|
+
padding: .2em .5em;
|
356
|
+
}
|
357
|
+
.meat .hierarchy .factinfo {
|
358
|
+
padding: 1em;
|
359
|
+
}
|
360
|
+
.meat .hierarchy .factinfo .var {
|
361
|
+
padding: .2em 0;
|
362
|
+
}
|
363
|
+
.meat .hierarchy .factinfo .label {
|
364
|
+
padding: 0 .5em;
|
365
|
+
}
|
366
|
+
.meat .hierarchy .factinfo .label i {
|
367
|
+
font-size: .8em;
|
368
|
+
color: #666;
|
369
|
+
}
|
370
|
+
.meat .hierarchy .factinfo input {
|
371
|
+
width: 100%;
|
372
|
+
padding: .2em .5em;
|
373
|
+
}
|
374
|
+
.meat .hierarchy .updateinfo {
|
375
|
+
padding: 0 1em 1em;
|
376
|
+
}
|
377
|
+
.meat .hierarchy .updateinfo button#updateinfo {
|
378
|
+
-webkit-box-shadow: 0px 0px 2px 3px rgba(0,0,0,0.7);
|
379
|
+
-moz-box-shadow: 0px 0px 2px 3px rgba(0,0,0,0.7);
|
380
|
+
box-shadow: 0px 0px 2px 3px rgba(0,0,0,0.7);
|
381
|
+
border-radius: .2em;
|
382
|
+
cursor: pointer;
|
383
|
+
margin-right: 1em;
|
384
|
+
}
|
385
|
+
|
386
|
+
.meat .hierarchy .updateinfo button {
|
387
|
+
-webkit-box-shadow: 0px 0px 2px 3px rgba(0,0,0,0.3);
|
388
|
+
-moz-box-shadow: 0px 0px 2px 3px rgba(0,0,0,0.3);
|
389
|
+
box-shadow: 0px 0px 2px 3px rgba(0,0,0,0.3);
|
390
|
+
border-radius: .2em;
|
391
|
+
cursor: pointer;
|
392
|
+
margin-right: 1em;
|
393
|
+
}
|
394
|
+
|
395
|
+
.meat .hierarchy .updateinfo button:hover {
|
396
|
+
-webkit-box-shadow: 0px 0px 0px 3px rgba(34,168,230,1);
|
397
|
+
-moz-box-shadow: 0px 0px 0px 3px rgba(34,168,230,1);
|
398
|
+
box-shadow: 0px 0px 0px 3px rgba(34,168,230,1);
|
399
|
+
}
|
400
|
+
.meat .hierarchy .nodefiles {
|
401
|
+
padding: 1em;
|
402
|
+
font-family: monospace;
|
403
|
+
}
|
404
|
+
.meat .hierarchy .nodefiles div {
|
405
|
+
padding: .2em 0;
|
406
|
+
}
|
407
|
+
|
317
408
|
/* ----- info ---- */
|
318
409
|
.meat .info {
|
319
410
|
margin-top: 4.8em;
|
data/app/public/js/farms.js
CHANGED
@@ -18,44 +18,84 @@ function ready(fn) {
|
|
18
18
|
}
|
19
19
|
|
20
20
|
ready( () => {
|
21
|
-
focusNav('farms');
|
22
|
-
|
23
21
|
var farms = document.querySelectorAll('li.farm');
|
24
22
|
var meat = document.querySelector('div.meat');
|
23
|
+
var base = window.location.pathname.split('/')[1];
|
24
|
+
focusNav('farms');
|
25
|
+
filterBox(".side .filter input", farms);
|
26
|
+
|
27
|
+
function restore_url(list) {
|
28
|
+
if (window.location.hash != '') {
|
29
|
+
var target = window.location.hash.replace(/#/,'');
|
30
|
+
var parts = target.split('/');
|
31
|
+
Array.prototype.forEach.call(list, (item, i) => {
|
32
|
+
if (item.textContent == parts[0]) {
|
33
|
+
if (parts[1] != undefined) {
|
34
|
+
Farm[parts[1]](parts[0]);
|
35
|
+
} else {
|
36
|
+
var event = document.createEvent('HTMLEvents');
|
37
|
+
event.initEvent('click', true, false);
|
38
|
+
item.dispatchEvent(event);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
});
|
42
|
+
}
|
43
|
+
}
|
25
44
|
|
26
|
-
filterBox(".filter input", farms);
|
27
45
|
|
28
|
-
function build_list(top, title,
|
46
|
+
function build_list(top, title, hash) {
|
29
47
|
window.location.hash = '#'+title;
|
30
48
|
top.innerHTML = "<h3>Farm "+title+"</h3>";
|
31
|
-
if (
|
32
|
-
Array.prototype.forEach.call(
|
33
|
-
|
34
|
-
|
35
|
-
|
49
|
+
if (Object.keys(hash).length > 0)
|
50
|
+
Array.prototype.forEach.call(Object.keys(hash), (item, i) => {
|
51
|
+
var node = document.createElement('div');
|
52
|
+
node.className = "node";
|
53
|
+
top.appendChild(node);
|
54
|
+
var node_title = document.createElement('div');
|
55
|
+
node_title.innerHTML = '<div><a href="/'+base+'/nodes#'+ item +'">' + item + '</a></div>';
|
56
|
+
node.appendChild(node_title);
|
57
|
+
Array.prototype.forEach.call(Object.keys(hash[item]), (itemvar, i) => {
|
58
|
+
addTo(node, "<div>"+itemvar+": "+hash[item][itemvar]+"</div>")
|
59
|
+
});
|
36
60
|
});
|
37
61
|
else
|
38
62
|
addTo(top, "<div>There is no node in this farm.</div>\n");
|
39
63
|
}
|
40
64
|
|
41
|
-
|
42
|
-
|
65
|
+
function show_error(meat, message) {
|
66
|
+
meat.innerHTML = "<div class=\"error\">" + message + "</div>\n";
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
var Farm = {
|
71
|
+
show: function(el) {
|
43
72
|
addClass(meat, 'wait');
|
44
|
-
|
45
|
-
fetch('/v1/farm/' +
|
73
|
+
farm = el.dataset.item;
|
74
|
+
fetch('/v1/' + base + '/farm/' + farm, auth_header()).
|
46
75
|
then(res => res.json()).
|
47
76
|
then(j => {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
77
|
+
if (j.error != undefined) {
|
78
|
+
show_error(meat, j['error']);
|
79
|
+
} else {
|
80
|
+
build_list(meat, farm, j);
|
81
|
+
Array.prototype.forEach.call(farms, (item, i) => {
|
82
|
+
removeClass(item, 'focus');
|
83
|
+
});
|
84
|
+
addClass(el, 'focus');
|
85
|
+
update_footer('/v1/' + base + '/farm/' + farm);
|
86
|
+
}
|
54
87
|
removeClass(meat, 'wait');
|
55
88
|
});
|
89
|
+
},
|
90
|
+
};
|
91
|
+
|
92
|
+
Array.prototype.forEach.call(farms, (item, i) => {
|
93
|
+
item.addEventListener('click', (ev) => {
|
94
|
+
Farm.show(ev.target);
|
56
95
|
});
|
57
96
|
});
|
58
97
|
|
98
|
+
update_footer('/v1/' + base + '/farms');
|
59
99
|
restore_url(farms);
|
60
100
|
|
61
101
|
});
|