From ba5588fe2df75162bbd61f3faa2568e0069363b2 Mon Sep 17 00:00:00 2001 From: trampfox Date: Tue, 2 Jul 2019 14:27:45 +0200 Subject: [PATCH] Add support for "All" value setting on current property for Custom templated variables. --- grafana_dashboards/components/templates.py | 17 ++++++++++++----- samples/project.yaml | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/grafana_dashboards/components/templates.py b/grafana_dashboards/components/templates.py index 01e3d53..261c679 100644 --- a/grafana_dashboards/components/templates.py +++ b/grafana_dashboards/components/templates.py @@ -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 diff --git a/samples/project.yaml b/samples/project.yaml index debc2ba..2b5e712 100644 --- a/samples/project.yaml +++ b/samples/project.yaml @@ -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: