Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmixmix committed Nov 25, 2024
1 parent af5a577 commit 4850614
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 17 deletions.
40 changes: 23 additions & 17 deletions ckanext/who_romania/schemas/dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,6 +72,7 @@ dataset_fields:
label: English
- value: ro
label: Română
default: en

- field_name: owner_org
label: Organization
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions ckanext/who_romania/templates/group/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "group/base_form_page.html" %}

{% block breadcrumb_content %}
<li>{% link_for h.humanize_entity_type('group', group_type, 'breadcrumb') or _('Categories'), named_route=group_type+'.index' %}</li>
{% block breadcrumb_content_inner %}
<li>{% link_for group.display_name|truncate(35), named_route=group_type+'.read', id=group.name, title=group.display_name %}</li>
<li class="active">{% link_for _('Manage'), named_route=group_type+'.edit', id=group.name %}</li>
{% 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 %}
25 changes: 25 additions & 0 deletions ckanext/who_romania/templates/group/new.html
Original file line number Diff line number Diff line change
@@ -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 %}
<li>{{ h.nav_link(
h.humanize_entity_type('group', group_type, 'breadcrumb') or _('Categories'),
named_route=group_type+'.index') }}</li>
<li class="active">
{{ h.nav_link(
label,
named_route=group_type~'.new') }}
</li>
{% endblock %}

{% block page_header %}{% endblock %}

{% block secondary_content %}
{% snippet "group/snippets/helper.html", group_type=group_type %}
{% endblock %}
41 changes: 41 additions & 0 deletions ckanext/who_romania/templates/group/snippets/group_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% import 'macros/form.html' as form %}


<form id="group-edit" class="dataset-form" method="post" data-module="basic-form" enctype="multipart/form-data">
{{ 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() }}

<div class="form-actions">
{% block delete_button %}
{% if h.check_access('group_delete', {'id': data.id}) %}
<a class="btn btn-danger pull-left" href="{% url_for group_type+'.delete', id=data.id %}" data-module="confirm-action" data-module-content="{{ h.humanize_entity_type('group', group_type, 'delete confirmation') or _('Are you sure you want to delete this Group?') }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
{% endif %}
{% endblock %}
<button class="btn btn-primary" name="save" type="submit">{% block save_text %}{{ h.humanize_entity_type('group', group_type, 'save label') or _('Save Group') }}{% endblock %}</button>
</div>
</form>
46 changes: 46 additions & 0 deletions ckanext/who_romania/templates/package/read.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends "package/read_base.html" %}

{% block primary_content_inner %}
{{ super() }}
{% block package_description %}
{% if pkg.private %}
<span class="dataset-private badge badge-inverse pull-right">
<i class="fa fa-lock"></i>
{{ _('Internal') }}
</span>
{% endif %}
<h1>
{% block page_heading %}
{{ h.dataset_display_name(pkg) }}
{% if pkg.state.startswith('draft') %}
[{{ _('Draft') }}]
{% endif %}
{% if pkg.state == 'deleted' %}
[{{ _('Deleted') }}]
{% endif %}
{% endblock %}
</h1>
{% block package_notes %}
{% if pkg.notes %}
<div class="notes embedded-content">
{{ h.render_markdown(h.get_translated(pkg, 'notes')) }}
</div>
{% endif %}
{% endblock %}
{# FIXME why is this here? seems wrong #}
<span class="insert-comment-thread"></span>
{% 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 %}
Original file line number Diff line number Diff line change
@@ -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': '<dataset>', '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 %}
<div class="form-group control-full">
{% set error = errors.license_id %}
<label class="form-label" for="field-license">{{ _("License") }}</label>
<div class="controls">
<select id="field-license" name="license_id" data-module="autocomplete">
{% set existing_license_id = data.get('license_id') %}
{% set empty_license = _('Please select the license') %}
<option value="">{{ empty_license }}</option>
{% for license_id, license_desc in h.license_options(existing_license_id) %}
<option value="{{ license_id }}" {% if existing_license_id == license_id %}selected="selected"{% endif %}>{{ license_desc }}</option>
{% endfor %}
</select>
{% if error %}<span class="error-block">{{ error }}</span>{% endif %}
<span class="info-block">
<i class="fa fa-info-circle"></i>
{% trans %}
License definitions and additional information can be found
at <a href="http://opendefinition.org/licenses/">opendefinition.org</a>
{% endtrans %}
</span>
</div>
</div>
{% endblock %}

{% block package_basic_fields_org %}
{# if we have a default group then this wants remembering #}
{% if data.group_id %}
<input type="hidden" name="groups__0__id" value="{{ 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 %}
<div data-module="dataset-visibility">
{% endif %}

{% if show_organizations_selector %}
{% set existing_org = data.owner_org or data.group_id %}
<div class="form-group control-medium">
<label for="field-organizations" class="form-label">{{ h.humanize_entity_type('organization', default_group_type, 'default label') or _('Organization') }}</label>
<div class="controls">
<select id="field-organizations" name="owner_org" data-module="autocomplete">
{% if h.check_config_permission('create_unowned_dataset') %}
<option value="" {% if not selected_org and data.id %} selected="selected" {% endif %}>{{ h.humanize_entity_type('organization', default_group_type, 'no label') or _('No Organization') }}</option>
{% endif %}
{% for organization in organizations_available %}
{# get out first org from users list only if there is not an existing org #}
{% set selected_org = (existing_org and existing_org == organization.id) or (not existing_org and not data.id and organization.id == organizations_available[0].id) %}
<option value="{{ organization.id }}" {% if selected_org %} selected="selected" {% endif %}>{{ organization.display_name }}</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}

{% if show_visibility_selector %}
{% block package_metadata_fields_visibility %}
<div class="form-group control-medium">
<label for="field-private" class="form-label">{{ _('Visibility') }}</label>
<div class="controls">
<select id="field-private" name="private" class="form-control">
{% for option in [('True', _('Internal')), ('False', _('Public'))] %}
<option value="{{ option[0] }}" {% if option[0] == data.private|trim %}selected="selected"{% endif %}>{{ option[1] }}</option>
{% endfor %}
</select>
</div>
</div>
{% endblock %}
{% endif %}

{% if show_organizations_selector and show_visibility_selector %}
</div>
{% endif %}


{% if data.id and h.check_access('package_delete', {'id': data.id}) and data.state != 'active' %}
<div class="form-group control-medium">
<label for="field-state" class="form-label">{{ _('State') }}</label>
<div class="controls">
<select class="form-control" id="field-state" name="state">
<option value="active" {% if data.get('state', 'none') == 'active' %} selected="selected" {% endif %}>{{ _('Active') }}</option>
<option value="deleted" {% if data.get('state', 'none') == 'deleted' %} selected="selected" {% endif %}>{{ _('Deleted') }}</option>
</select>
</div>
</div>
{% endif %}

{% endblock %}

0 comments on commit 4850614

Please sign in to comment.