Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add textbox template type #37

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions grafana_dashboards/schema/template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from grafana_dashboards.schema.template.datasource import Datasource
from grafana_dashboards.schema.template.interval import Interval
from grafana_dashboards.schema.template.query import Query
from grafana_dashboards.schema.template.textbox import Textbox


class Template(object):
Expand Down Expand Up @@ -52,6 +53,8 @@ def f(data):
schema = Datasource().get_schema()
if template["type"] == "adhoc":
schema = Adhoc().get_schema()
if template["type"] == "textbox":
schema = Textbox().get_schema()

res["list"].append(schema(template))

Expand Down
8 changes: 7 additions & 1 deletion grafana_dashboards/schema/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def __init__(self):
self.base = {
v.Required("name"): v.All(str, v.Length(min=1)),
v.Required("type"): v.Any(
"query", "interval", "custom", "datasource", "adhoc", "constant"
"query",
"interval",
"custom",
"datasource",
"adhoc",
"constant",
"textbox",
),
v.Optional("description"): v.All(str),
}
Expand Down
29 changes: 29 additions & 0 deletions grafana_dashboards/schema/template/textbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2018 Delivery Hero SE.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import voluptuous as v

from grafana_dashboards.schema.template.base import Base


class Textbox(Base):
def get_schema(self):
query = {
v.Optional("hide"): v.All(int, v.Range(min=0, max=2)),
v.Optional("label", default=""): v.All(str),
v.Optional("name"): v.All(str),
v.Optional("query"): v.All(str),
}
query.update(self.base)
return v.Schema(query)