From 48506143acd6a7a48a7d97b38bbf96ea6188b4f1 Mon Sep 17 00:00:00 2001 From: M Kunde Date: Mon, 25 Nov 2024 15:37:20 +0200 Subject: [PATCH] wip --- ckanext/who_romania/schemas/dataset.yaml | 40 +++--- ckanext/who_romania/templates/group/edit.html | 12 ++ ckanext/who_romania/templates/group/new.html | 25 ++++ .../templates/group/snippets/group_form.html | 41 ++++++ .../who_romania/templates/package/read.html | 46 +++++++ .../snippets/package_basic_fields.html | 123 ++++++++++++++++++ 6 files changed, 270 insertions(+), 17 deletions(-) create mode 100644 ckanext/who_romania/templates/group/edit.html create mode 100644 ckanext/who_romania/templates/group/new.html create mode 100644 ckanext/who_romania/templates/group/snippets/group_form.html create mode 100644 ckanext/who_romania/templates/package/read.html create mode 100644 ckanext/who_romania/templates/package/snippets/package_basic_fields.html diff --git a/ckanext/who_romania/schemas/dataset.yaml b/ckanext/who_romania/schemas/dataset.yaml index 912c080..7649e3a 100644 --- a/ckanext/who_romania/schemas/dataset.yaml +++ b/ckanext/who_romania/schemas/dataset.yaml @@ -19,24 +19,29 @@ dataset_fields: - field_name: notes label: Description form_snippet: markdown.html - form_placeholder: eg. Some useful notes about the data + form_placeholder: eg. Some useful notes about the data or the document - field_name: program_area label: Program Area preset: select choices: - - value: Sexual and Reproductive Health - label: Sexual and Reproductive Health - - value: HIV & TB - label: HIV & TB - - value: Mental Health and Psychosocial Support - label: Mental Health and Psychosocial Support - - value: E-Health - label: E-Health - - value: Family Medicine - label: Family Medicine - - value: Gender Based Violence - label: Gender Based Violence + - value: General + label: General + - value: Admin + label: Admin + - value: Emergencies Program + label: Emergencies Program + - value: National Recovery and Resilience Plan (NRRP) + label: National Recovery and Resilience Plan (NRRP) + - value: Biennial Collaborative Agreement (BCA) + label: Biennial Collaborative Agreement (BCA) + - value: DTRA One Health + label: DTRA One Health + - value: DTRA Laboratory + label: DTRA Laboratory + - value: DTRA Emergency Coordination + label: DTRA Emergency Coordination + - field_name: tag_string label: Tags @@ -67,6 +72,7 @@ dataset_fields: label: English - value: ro label: Română + default: en - field_name: owner_org label: Organization @@ -81,7 +87,7 @@ dataset_fields: - value: false label: Public - value: true - label: Private + label: Internal default: true validators: boolean_validator output_validators: boolean_validator @@ -91,12 +97,12 @@ resource_fields: - field_name: name label: Name - form_placeholder: eg. Malawi HTC Scale Up Plan + form_placeholder: Name of the document - field_name: description label: Description - form_snippet: markdown.html - form_placeholder: Some useful notes about the data + form_snippet: markdown.htm + form_placeholder: Some useful notes about the document/data - field_name: format label: Format diff --git a/ckanext/who_romania/templates/group/edit.html b/ckanext/who_romania/templates/group/edit.html new file mode 100644 index 0000000..bd88874 --- /dev/null +++ b/ckanext/who_romania/templates/group/edit.html @@ -0,0 +1,12 @@ +{% extends "group/base_form_page.html" %} + +{% block breadcrumb_content %} +
  • {% link_for h.humanize_entity_type('group', group_type, 'breadcrumb') or _('Categories'), named_route=group_type+'.index' %}
  • + {% block breadcrumb_content_inner %} +
  • {% link_for group.display_name|truncate(35), named_route=group_type+'.read', id=group.name, title=group.display_name %}
  • +
  • {% link_for _('Manage'), named_route=group_type+'.edit', id=group.name %}
  • + {% endblock %} +{% endblock %} + +{% block page_heading_class %}hide-heading{% endblock %} +{% block page_heading %}{{ h.humanize_entity_type('group', group_type, 'edit label') or _('Edit Category') }}{% endblock %} diff --git a/ckanext/who_romania/templates/group/new.html b/ckanext/who_romania/templates/group/new.html new file mode 100644 index 0000000..c4a1773 --- /dev/null +++ b/ckanext/who_romania/templates/group/new.html @@ -0,0 +1,25 @@ +{% extends "group/base_form_page.html" %} + +{% set label = h.humanize_entity_type('group', group_type, 'create title') or _('Create a Category') %} + + +{% block subtitle %}{{ label }}{% endblock %} + +{% block page_heading %}{{ label }}{% endblock %} + +{% block breadcrumb_content %} +
  • {{ h.nav_link( + h.humanize_entity_type('group', group_type, 'breadcrumb') or _('Categories'), + named_route=group_type+'.index') }}
  • +
  • + {{ h.nav_link( + label, + named_route=group_type~'.new') }} +
  • +{% endblock %} + +{% block page_header %}{% endblock %} + +{% block secondary_content %} + {% snippet "group/snippets/helper.html", group_type=group_type %} +{% endblock %} diff --git a/ckanext/who_romania/templates/group/snippets/group_form.html b/ckanext/who_romania/templates/group/snippets/group_form.html new file mode 100644 index 0000000..03d60a6 --- /dev/null +++ b/ckanext/who_romania/templates/group/snippets/group_form.html @@ -0,0 +1,41 @@ +{% import 'macros/form.html' as form %} + + +
    + {{ h.csrf_input() }} + {% block error_summary %} + {{ form.errors(error_summary) }} + {% endblock %} + + {% block basic_fields %} + {% set attrs = {'data-module': 'slug-preview-target', 'class': 'form-control'} %} + {{ form.input('title', label=_('Name'), id='field-name', placeholder=h.humanize_entity_type('group', group_type, 'name placeholder') or _('My Group'), value=data.title, error=errors.title, classes=['control-full'], attrs=attrs) }} + + {# Perhaps these should be moved into the controller? #} + {% set prefix = h.url_for(group_type + '.read', id='') %} + {% set domain = h.url_for(group_type + '.read', id='', qualified=true) %} + {% set domain = domain|replace("http://", "")|replace("https://", "") %} + {% set attrs = {'data-module': 'slug-preview-slug', 'class': 'form-control input-sm', 'data-module-prefix': domain, 'data-module-placeholder': '<' + group_type + '>'} %} + + {{ form.prepend('name', label=_('URL'), prepend=prefix, id='field-url', placeholder=_('my-' + group_type), value=data.name, error=errors.name, attrs=attrs, is_required=true) }} + + {{ form.markdown('description', label=_('Description'), id='field-description', placeholder=h.humanize_entity_type('group', group_type, 'description placeholder') or _('A little information about my group...'), value=data.description, error=errors.description) }} + + {% set is_upload = data.image_url and not data.image_url.startswith('http') %} + {% set is_url = data.image_url and data.image_url.startswith('http') %} + + {{ form.image_upload(data, errors, is_upload_enabled=h.uploads_enabled(), is_url=is_url, is_upload=is_upload) }} + + {% endblock %} + + {{ form.required_message() }} + +
    + {% block delete_button %} + {% if h.check_access('group_delete', {'id': data.id}) %} + {% block delete_button_text %}{{ _('Delete') }}{% endblock %} + {% endif %} + {% endblock %} + +
    +
    diff --git a/ckanext/who_romania/templates/package/read.html b/ckanext/who_romania/templates/package/read.html new file mode 100644 index 0000000..e16dc00 --- /dev/null +++ b/ckanext/who_romania/templates/package/read.html @@ -0,0 +1,46 @@ +{% extends "package/read_base.html" %} + +{% block primary_content_inner %} + {{ super() }} + {% block package_description %} + {% if pkg.private %} + + + {{ _('Internal') }} + + {% endif %} +

    + {% block page_heading %} + {{ h.dataset_display_name(pkg) }} + {% if pkg.state.startswith('draft') %} + [{{ _('Draft') }}] + {% endif %} + {% if pkg.state == 'deleted' %} + [{{ _('Deleted') }}] + {% endif %} + {% endblock %} +

    + {% block package_notes %} + {% if pkg.notes %} +
    + {{ h.render_markdown(h.get_translated(pkg, 'notes')) }} +
    + {% endif %} + {% endblock %} + {# FIXME why is this here? seems wrong #} + + {% endblock %} + + {% block package_resources %} + {% snippet "package/snippets/resources_list.html", pkg=pkg, resources=pkg.resources %} + {% endblock %} + + {% block package_tags %} + {% snippet "package/snippets/tags.html", tags=pkg.tags %} + {% endblock %} + + {% block package_additional_info %} + {% snippet "package/snippets/additional_info.html", pkg_dict=pkg %} + {% endblock %} + +{% endblock %} diff --git a/ckanext/who_romania/templates/package/snippets/package_basic_fields.html b/ckanext/who_romania/templates/package/snippets/package_basic_fields.html new file mode 100644 index 0000000..fa8237e --- /dev/null +++ b/ckanext/who_romania/templates/package/snippets/package_basic_fields.html @@ -0,0 +1,123 @@ +{% import 'macros/form.html' as form %} + +{% set default_group_type = h.default_group_type('organization') %} + +{% block package_basic_fields_title %} + {{ form.input('title', id='field-title', label=_('Title'), placeholder=_('eg. A descriptive title'), value=data.title, error=errors.title, classes=['control-full', 'control-large'], attrs={'data-module': 'slug-preview-target', 'class': 'form-control'}) }} +{% endblock %} + +{% block package_basic_fields_url %} + {% set prefix = h.url_for('dataset.read', id='') %} + {% set domain = h.url_for('dataset.read', id='', qualified=true) %} + {% set domain = domain|replace("http://", "")|replace("https://", "") %} + {% set attrs = {'data-module': 'slug-preview-slug', 'data-module-prefix': domain, 'data-module-placeholder': '', 'class': 'form-control input-sm'} %} + + {{ form.prepend('name', id='field-name', label=_('URL'), prepend=prefix, placeholder=_('eg. my-dataset'), value=data.name, error=errors.name, attrs=attrs, is_required=true) }} +{% endblock %} + +{% block package_basic_fields_custom %}{% endblock %} + +{% block package_basic_fields_description %} + {{ form.markdown('notes', id='field-notes', label=_('Description'), placeholder=_('eg. Some useful notes about the data'), value=data.notes, error=errors.notes) }} +{% endblock %} + +{% block package_basic_fields_tags %} + {% set tag_attrs = {'data-module': 'autocomplete', 'data-module-tags': '', 'data-module-source': '/api/2/util/tag/autocomplete?incomplete=?'} %} + {{ form.input('tag_string', id='field-tags', label=_('Tags'), placeholder=_('eg. economy, mental health, government'), value=data.tag_string, error=errors.tags, classes=['control-full'], attrs=tag_attrs) }} +{% endblock %} + +{% block package_basic_fields_license %} +
    + {% set error = errors.license_id %} + +
    + + {% if error %}{{ error }}{% endif %} + + + {% trans %} + License definitions and additional information can be found + at opendefinition.org + {% endtrans %} + +
    +
    +{% endblock %} + +{% block package_basic_fields_org %} + {# if we have a default group then this wants remembering #} + {% if data.group_id %} + + {% endif %} + + {% set dataset_is_draft = data.get('state', 'draft').startswith('draft') or data.get('state', 'none') == 'none' %} + {% set dataset_has_organization = data.owner_org or data.group_id %} + {% set organizations_available = h.organizations_available('create_dataset') %} + {% set user_can_update_owner_org = h.can_update_owner_org(data, organizations_available) %} + {% set user_is_sysadmin = h.check_access('sysadmin') %} + {% set show_organizations_selector = organizations_available and user_can_update_owner_org %} + {% set show_visibility_selector = dataset_has_organization or (organizations_available and (user_is_sysadmin or dataset_is_draft)) %} + + {% if show_organizations_selector and show_visibility_selector %} +
    + {% endif %} + + {% if show_organizations_selector %} + {% set existing_org = data.owner_org or data.group_id %} +
    + +
    + +
    +
    + {% endif %} + + {% if show_visibility_selector %} + {% block package_metadata_fields_visibility %} +
    + +
    + +
    +
    + {% endblock %} + {% endif %} + + {% if show_organizations_selector and show_visibility_selector %} +
    + {% endif %} + + + {% if data.id and h.check_access('package_delete', {'id': data.id}) and data.state != 'active' %} +
    + +
    + +
    +
    + {% endif %} + + {% endblock %}