Skip to content

Commit

Permalink
Add support for "All" value setting on current property for Custom te…
Browse files Browse the repository at this point in the history
…mplated variables.
  • Loading branch information
trampfox committed Jul 2, 2019
1 parent cf5a219 commit 008f9dd
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'] is 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 008f9dd

Please sign in to comment.