diff --git a/grafana_dashboards/components/templates.py b/grafana_dashboards/components/templates.py index 01e3d53..1d2066d 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'] == 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: