# Path: grafana_dashboards/common.py
# def get_component_type(clazz):
#     """
# 
#     :type clazz: type
#     """
#     return _all_cap_re.sub(r'\1-\2', _first_cap_re.sub(r'\1-\2', clazz.__name__)).lower()
# 
# Path: grafana_dashboards/components/annotations.py
# class Annotations(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Annotations, self).__init__(data, registry, AnnotationsItemBase)
# 
# Path: grafana_dashboards/components/base.py
# class JsonGenerator(ComponentBase):
# 
#     _copy_fields = set()
# 
#     def gen_json(self, context=Context()):
#         return self.gen_json_from_data(context.expand_placeholders(self.data), context)
# 
#     def gen_json_from_data(self, data, context):
#         component_type = get_component_type(type(self))
#         if self.name:
#             logger.debug("Processing component '%s' with name '%s' from template '%s'",
#                          component_type, context.expand_placeholders(self.name), self.name)
#         else:
#             logger.debug("Processing anonymous component '%s'", component_type)
#         json = {}
#         for field in self._copy_fields:
#             if field in data:
#                 json[field] = data[field]
#         return json
# 
# Path: grafana_dashboards/components/rows.py
# class Rows(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Rows, self).__init__(data, registry, RowsItemBase)
# 
# Path: grafana_dashboards/components/templates.py
# class Templates(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Templates, self).__init__(data, registry, TemplatesItemBase)


from grafana_dashboards.common import get_component_type
from grafana_dashboards.components.annotations import Annotations
from grafana_dashboards.components.base import JsonGenerator
from grafana_dashboards.components.rows import Rows
from grafana_dashboards.components.templates import Templates
    # noinspection PySetFunctionToLiteral
    _copy_fields = set(['sharedCrosshair'])

    def gen_json_from_data(self, data, context):
        json_data = super(Dashboard, self).gen_json_from_data(data, context)
        nav = {
            'type': 'timepicker'
        }
        json_data.update({
            'title': data.get('title', self.name),
            'nav': [
                nav
            ]
        })
        if 'time' in data:
            json_data['time'] = {
                'from': data['time']['from'],
                'to': data['time']['to']
            }
        if 'tags' in data:
            json_data['tags'] = data.get('tags')
        if 'time_options' in data:
            nav['time_options'] = data.get('time_options', [])
        if 'refresh_intervals' in data:
            nav['refresh_intervals'] = data.get('refresh_intervals', [])
        if 'refresh' in data:
            json_data['refresh'] = data.get('refresh')
        if 'folderId' in data:
            json_data['folderId'] = data.get('folderId')
        if get_component_type(Annotations) in data:

# Path: grafana_dashboards/common.py
# def get_component_type(clazz):
#     """
# 
#     :type clazz: type
#     """
#     return _all_cap_re.sub(r'\1-\2', _first_cap_re.sub(r'\1-\2', clazz.__name__)).lower()
# 
# Path: grafana_dashboards/components/annotations.py
# class Annotations(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Annotations, self).__init__(data, registry, AnnotationsItemBase)
# 
# Path: grafana_dashboards/components/base.py
# class JsonGenerator(ComponentBase):
# 
#     _copy_fields = set()
# 
#     def gen_json(self, context=Context()):
#         return self.gen_json_from_data(context.expand_placeholders(self.data), context)
# 
#     def gen_json_from_data(self, data, context):
#         component_type = get_component_type(type(self))
#         if self.name:
#             logger.debug("Processing component '%s' with name '%s' from template '%s'",
#                          component_type, context.expand_placeholders(self.name), self.name)
#         else:
#             logger.debug("Processing anonymous component '%s'", component_type)
#         json = {}
#         for field in self._copy_fields:
#             if field in data:
#                 json[field] = data[field]
#         return json
# 
# Path: grafana_dashboards/components/rows.py
# class Rows(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Rows, self).__init__(data, registry, RowsItemBase)
# 
# Path: grafana_dashboards/components/templates.py
# class Templates(JsonListGenerator):
#     def __init__(self, data, registry):
#         super(Templates, self).__init__(data, registry, TemplatesItemBase)


# Path: grafana_dashboards/components/dashboards.py
from grafana_dashboards.common import get_component_type
from grafana_dashboards.components.annotations import Annotations
from grafana_dashboards.components.base import JsonGenerator
from grafana_dashboards.components.rows import Rows
from grafana_dashboards.components.templates import Templates

    # noinspection PySetFunctionToLiteral
    _copy_fields = set(['sharedCrosshair'])

    def gen_json_from_data(self, data, context):
        json_data = super(Dashboard, self).gen_json_from_data(data, context)
        nav = {
            'type': 'timepicker'
        }
        json_data.update({
            'title': data.get('title', self.name),
            'nav': [
                nav
            ]
        })
        if 'time' in data:
            json_data['time'] = {
                'from': data['time']['from'],
                'to': data['time']['to']
            }
        if 'tags' in data:
            json_data['tags'] = data.get('tags')
        if 'time_options' in data:
            nav['time_options'] = data.get('time_options', [])
        if 'refresh_intervals' in data:
            nav['refresh_intervals'] = data.get('refresh_intervals', [])
        if 'refresh' in data:
            json_data['refresh'] = data.get('refresh')
        if 'folderId' in data:
            json_data['folderId'] = data.get('folderId')
        if get_component_type(Annotations) in data:

            json_data['annotations'] = {'list': self.registry.create_component(Annotations, data).gen_json()}