Skip to content

Commit

Permalink
implement user chart builder view
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Jun 17, 2024
1 parent 8c45f12 commit 99355cf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
14 changes: 7 additions & 7 deletions ckanext/charts/assets/js/charts-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ ckan.module("charts-global", function ($, _) {
initialize: function () {
$.proxyAll(this, /_/);

// // initialize CKAN modules for HTMX loaded pages
// htmx.on("htmx:afterSettle", function (event) {
// var elements = event.target.querySelectorAll("[data-module]");
// initialize CKAN modules for HTMX loaded pages
htmx.on("htmx:afterSettle", function (event) {
var elements = event.target.querySelectorAll("[data-module]");

// for (let node of elements) {
// ckan.module.initializeElement(node);
// }
// });
for (let node of elements) {
ckan.module.initializeElement(node);
}
});
}
};
});
40 changes: 40 additions & 0 deletions ckanext/charts/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,43 @@ def before_resource_delete(
cache.invalidate_by_key(
fetchers.DatastoreDataFetcher(resource["id"]).make_cache_key(),
)


class ChartsBuilderViewPlugin(p.SingletonPlugin):
p.implements(p.IResourceView)

# IResourceView

def info(self) -> dict[str, Any]:
return {
"name": "charts_builder_view",
"title": tk._("Chart Builder"),
"schema": settings_schema(),
"icon": "chart-line",
"iframed": False,
"filterable": False,
"preview_enabled": False,
"requires_datastore": True,
}

def can_view(self, data_dict: dict[str, Any]) -> bool:
if data_dict["resource"].get("datastore_active"):
return True

return False

def setup_template_variables(
self,
context: types.Context,
data_dict: dict[str, Any],
) -> dict[str, Any]:
return {
"settings": {},
"resource_id": data_dict["resource"]["id"],
}

def view_template(self, context: types.Context, data_dict: dict[str, Any]) -> str:
return "charts/charts_view.html"

def form_template(self, context: types.Context, data_dict: dict[str, Any]) -> str:
return "charts/charts_builder_form.html"
9 changes: 9 additions & 0 deletions ckanext/charts/templates/charts/charts_builder_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% import 'macros/form.html' as form %}

{% set data = data or {} %}
{% set errors = errors or {} %}

{{ form.errors(error_summary) }}

{{ form.input('title', id='field-title', label=_('Title'), placeholder=_('eg. My View'), value=data.title, error=errors.title, classes=['control-full', 'control-large'], is_required=true) }}
{{ form.markdown('description', id='field-description', label=_('Description'), placeholder=_('eg. Information about my view'), value=data.description, error=errors.description) }}
2 changes: 1 addition & 1 deletion ckanext/charts/templates/package/snippets/view_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{{ form.errors(error_summary) }}

{% if data.view_type == "charts_view" %}
{% if data.view_type in ["charts_view", "charts_builder_view"] %}
{% include form_template %}
{% else %}
{{ form.input('title', id='field-title', label=_('Title'), placeholder=_('eg. My View'), value=data.title, error=errors.title, classes=['control-full', 'control-large'], is_required=true) }}
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ckanext-charts
version = 0.0.2
version = 1.0.0
description =
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down Expand Up @@ -29,6 +29,7 @@ include_package_data = True
[options.entry_points]
ckan.plugins =
charts_view = ckanext.charts.plugin:ChartsViewPlugin
charts_builder_view = ckanext.charts.plugin:ChartsBuilderViewPlugin

babel.extractors =
ckan = ckan.lib.extract:extract_ckan
Expand Down

0 comments on commit 99355cf

Please sign in to comment.