Skip to content

Commit

Permalink
Add includeAll management and All metavalue.
Browse files Browse the repository at this point in the history
  • Loading branch information
trampfox committed Jun 28, 2019
1 parent cf5a219 commit 00d387a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
17 changes: 12 additions & 5 deletions grafana_dashboards/components/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,22 @@ def gen_json_from_data(self, data, context):
'query': ','.join([str(options) for options in data['options']]),
'refresh': self._refresh
})

for key in ['regex', 'multi', 'includeAll', 'hide', 'allFormat', 'allValue']:
if key in data:
template_json[key] = data[key]

if 'current' in data:
current = data['current']
template_json['current'] = {
'text': current,
'value': current
'text': data['current'],
'value': '$__all' if data['current'] == 'All' else data['current']
}
if 'options' in data:
template_json['options'] = [{'text': option, 'value': option} for option in
(data['options'])]
template_json['options'] = [{'text': option, 'value': option} for option
in (data['options'])]
if 'includeAll' in data and data['includeAll'] == True:
all_option = {'selected': True, 'text': 'All', 'value': '$__all'}
template_json.setdefault('options', []).insert(0,all_option)
return template_json


Expand Down
20 changes: 20 additions & 0 deletions samples/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@
options:
- first
- last
- custom-template:
name: service
options:
- service1
- service2
- service3
- service4
includeAll: true
multi: true
current: All
- custom-template:
name: service-w-all
options:
- service1
- service2
- service3
- service4
includeAll: false
multi: true
current: service2

- name: 'some dashboard'
dashboard:
Expand Down

0 comments on commit 00d387a

Please sign in to comment.