# Copyright (c) 2019, JINGROW
# License: MIT. See LICENSE

import os

import jingrow
from jingrow.model.page import Page
from jingrow.modules import get_module_path, scrub
from jingrow.modules.export_file import export_to_files


@jingrow.whitelist()
def get_config(name):
	pg = jingrow.get_pg("Dashboard Chart Source", name)
	with open(
		os.path.join(
			get_module_path(pg.module), "dashboard_chart_source", scrub(pg.name), scrub(pg.name) + ".js"
		),
	) as f:
		return f.read()


class DashboardChartSource(Page):
	# begin: auto-generated types
	# This code is auto-generated. Do not modify anything in this block.

	from typing import TYPE_CHECKING

	if TYPE_CHECKING:
		from jingrow.types import DF

		module: DF.Link
		source_name: DF.Data
		timeseries: DF.Check

	# end: auto-generated types
	def on_update(self):
		export_to_files(record_list=[[self.pagetype, self.name]], record_module=self.module, create_init=True)
