Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
wip: add file uploader (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChasNelson1990 committed Aug 28, 2024
1 parent 1e948cc commit 030bc2f
Show file tree
Hide file tree
Showing 7 changed files with 18,261 additions and 41,824 deletions.
1 change: 1 addition & 0 deletions ckanext/zarr/react/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.17.0
47,889 changes: 18,068 additions & 29,821 deletions ckanext/zarr/react/package-lock.json

Large diffs are not rendered by default.

11,996 changes: 0 additions & 11,996 deletions ckanext/zarr/react/yarn.lock

This file was deleted.

48 changes: 41 additions & 7 deletions ckanext/zarr/schemas/dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,6 @@ dataset_fields:

resource_fields:

- field_name: url
label: URL
preset: resource_url_upload

- field_name: name
label: Name
form_placeholder:
Expand All @@ -326,6 +322,44 @@ resource_fields:
label: Availability
help_text: Indicates how long it is planned to keep the resource available.

- field_name: license
label: License
help_text: License in which the resource is made available. If not provided will be inherited from the dataset.
- field_name: data_standard
label: Data Standard
preset: tag_string_autocomplete
form_placeholder: eg. DCAT, Dublin Core, ISO 19115
help_text: The metadata standards or schemas used for this dataset. Add multiple standards separated by commas.
display_group: Additional Metadata

- field_name: provenance
label: Provenance
form_snippet: markdown.html
help_text: Detailed information about the origin and processing history of the dataset
display_group: Additional Metadata

- field_name: quality_indicator
label: Quality Indicator
preset: select
choices:
- value: "1"
label: 1 star
- value: "2"
label: 2 stars
- value: "3"
label: 3 stars
- value: "4"
label: 4 stars
- value: "5"
label: 5 stars
help_text: Indicator of the dataset's quality or reliability based on a 5-star rating system.
display_group: Additional Metadata

- field_name: quality_comment
label: Quality Details
form_snippet: markdown.html
help_text: Additional details about the quality assessment of this dataset.
display_group: Additional Metadata

- field_name: preservation_statement
label: Preservation Statement
form_snippet: markdown.html
help_text: Information about long-term preservation plans for this dataset
display_group: Additional Metadata
24 changes: 24 additions & 0 deletions ckanext/zarr/templates/package/new_resource.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "package/base_form_page.html" %}

{% set logged_in = true if c.userobj else false %}

{% block subtitle %}{{ _('Add data to the dataset') }}{% endblock %}

{% block breadcrumb_content_selected %}{% endblock %}
{% block breadcrumb_content %}
{{ super() }}
{% if pkg %}
<li class="active"><a href="#">{{ _('Add New Resource') }}</a></li>
{% endif %}
{% endblock %}

{% block form %}{% snippet resource_form_snippet, data=data, errors=errors, error_summary=error_summary, include_metadata=false, pkg_name=pkg_name, stage=stage, dataset_type=dataset_type %}{% endblock %}

{% block secondary_content %}
{% snippet 'package/snippets/resource_help.html' %}
{% endblock %}

{% block scripts %}
{{ super() }}
{% asset 'vendor/fileupload' %}
{% endblock %}
46 changes: 46 additions & 0 deletions ckanext/zarr/templates/package/snippets/resource_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% ckan_extends %}

{% set dataset = h.get_dataset_from_id(pkg_name) %}

{% block basic_fields_url %}
{% asset 'zarr/FileInputComponentStyles' %}
<div
id="FileInputComponent"
data-lfsServer="{{ h.blob_storage_server_url() }}"
data-maxResourceSize="{{ h.max_resource_size() }}"
data-orgId="{{ dataset.organization.name }}"
data-datasetName="{{ dataset.name }}"
data-existingUrlType="{{ data.url_type if data else '' }}"
data-existingUrl="{{ data.url if data else '' }}"
data-existingSha256="{{ data.sha256 if data else '' }}"
data-existingFileName="{{ h.blob_storage_resource_filename(data) if data else '' }}"
data-existingSize="{{ data.size if data else '' }}"
>
{% if data.url %}
{% if data.url_type == 'upload' %}
<h3 class="text-muted">
<span><i class="fa fa-spinner fa-spin"></i> {{ _('Loading') }}</span>
</h3>
{% else %}
<div>
<label class="control-label">{{ _('URL')}}</label>
<div class="input-group field-url-input-group">
<input
type="text"
placeholder="{{ _('Loading') }}..."
class="form-control"
/>
<span class="input-group-btn">
<button class="btn btn-danger" type="button">{{ _('Remove') }}</button>
</span>
</div>
</div>
{% endif %}
{% else %}
<div class="dropzone text-muted">
<h3><i class="fa fa-spinner fa-spin"></i> {{ _('Loading') }}</h3>
</div>
{% endif %}
</div>
{% asset 'zarr/FileInputComponentScripts' %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{% ckan_extends %}

{% block basic_fields %}

{% asset 'zarr/FileInputComponentStyles' %}
{% set dataset = h.get_dataset_from_id(pkg_name) %}
<div
id="FileInputComponent"
data-lfsServer="{{ h.blob_storage_server_url() }}"
data-maxResourceSize="{{ h.max_resource_size() }}"
data-orgId="{{ dataset.organization.name }}"
data-datasetName="{{ dataset.name }}"
data-existingUrlType="{{ data.url_type if data else '' }}"
data-existingUrl="{{ data.url if data else '' }}"
data-existingSha256="{{ data.sha256 if data else '' }}"
data-existingFileName="{{ h.blob_storage_resource_filename(data) if data else '' }}"
data-existingSize="{{ data.size if data else '' }}"
>
{% if data.url %}
{% if data.url_type == 'upload' %}
<h3 class="text-muted">
<span><i class="fa fa-spinner fa-spin"></i> {{ _('Loading') }}</span>
</h3>
{% else %}
<div>
<label class="control-label">{{ _('URL')}}</label>
<div class="input-group field-url-input-group">
<input
type="text"
placeholder="{{ _('Loading') }}..."
class="form-control"
/>
<span class="input-group-btn">
<button class="btn btn-danger" type="button">{{ _('Remove') }}</button>
</span>
</div>
</div>
{% endif %}
{% else %}
<div class="dropzone text-muted">
<h3><i class="fa fa-spinner fa-spin"></i> {{ _('Loading') }}</h3>
</div>
{% endif %}
</div>
{% asset 'zarr/FileInputComponentScripts' %}

{%- if not dataset_type -%}
<p>
dataset_type not passed to template. your version of CKAN
might not be compatible with ckanext-scheming
</p>
{%- endif -%}
{%- set dataset = h.get_dataset_from_id(pkg_name, validate=True) -%}
{%- set schema = h.scheming_get_dataset_schema(dataset_type) -%}
{%- for field in schema.resource_fields -%}
{%- if field.form_snippet is not none -%}
{%- if field.field_name not in data %}
{# Set the field default value before rendering but only if
it doesn't already exist in data which would mean the form
has been submitted. #}
{% if field.default_jinja2 %}
{% do data.__setitem__(
field.field_name,
h.scheming_render_from_string(field.default_jinja2)) %}
{% elif field.default %}
{% do data.__setitem__(field.field_name, field.default) %}
{% endif %}
{% endif -%}
{%- snippet 'scheming/snippets/form_field.html',
field=field,
data=data,
errors=errors,
licenses=c.licenses,
entity_type='dataset',
object_type=dataset_type,
dataset=dataset
-%}
{%- endif -%}
{%- endfor -%}

{% endblock %}

0 comments on commit 030bc2f

Please sign in to comment.