From 5cabd5149b0274d64ec0f691e0ce0acc3fc68b71 Mon Sep 17 00:00:00 2001 From: Svetozar Stojkovic Date: Fri, 5 Jul 2019 19:35:07 +0200 Subject: [PATCH 1/7] [init][m]: organizations page implemented --- themes/eds/views/collections-home.html | 84 ++++++++++++++++++++++++++ themes/eds/views/home.html | 50 +++++++++------ 2 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 themes/eds/views/collections-home.html diff --git a/themes/eds/views/collections-home.html b/themes/eds/views/collections-home.html new file mode 100644 index 00000000..27481651 --- /dev/null +++ b/themes/eds/views/collections-home.html @@ -0,0 +1,84 @@ +{% extends "base.html" %} + +{% block title%}{{title}}{% endblock %} + +{% block bodyclass %}awesome{% endblock %} + +{% block content %} + + +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+

Organizations

+
+
+
+
    +
  • +
  • + +
  • +
+
+
+
+
+

{{ collections|length }} organization{{ "s" if collections|length != 1 else ""}} found

+
+
+
+
    + {% for collection in collections %} +
  • + {{ collection.name }} +

    {{ collection.title }}

    + {{ collection.count }} Dataset{{ 's' if collection.count > 1 else '' }} + + View {{ collection.title }} + +
  • + {% endfor %} +
  • +
+
+
+
+
+
+
+
+ +{% endblock %} diff --git a/themes/eds/views/home.html b/themes/eds/views/home.html index 7f348964..124f2d21 100644 --- a/themes/eds/views/home.html +++ b/themes/eds/views/home.html @@ -254,25 +254,37 @@

{{__('News')}}

-
-

April 10, 2019

-
- Opdatering til ny version d. 10. april 2019/update to new version the 10th of April 2019 - - > - -
-
- -
-

February 5, 2019

-
- Der kan nu downloades igen / You can now download again - - > - -
-
+ {% for post in posts %} +
+

{{ post.published }}

+
+ {{ post.title }} + + > + +
+
+ {% endfor %} + + + + + + + + + + + + + + + + + + + + {{__('See all news')}} From 19379740b04ac65d2b5666bb05edea0807fd67d6 Mon Sep 17 00:00:00 2001 From: Svetozar Stojkovic Date: Sun, 7 Jul 2019 15:16:11 +0200 Subject: [PATCH 2/7] [organization, search][l]: organization page and search page WIP --- themes/eds/views/collection.html | 65 ++++++ themes/eds/views/collections-home.html | 16 +- themes/eds/views/search.html | 295 +++++++++++++++++++++++++ 3 files changed, 368 insertions(+), 8 deletions(-) create mode 100644 themes/eds/views/collection.html create mode 100644 themes/eds/views/search.html diff --git a/themes/eds/views/collection.html b/themes/eds/views/collection.html new file mode 100644 index 00000000..858b5ad5 --- /dev/null +++ b/themes/eds/views/collection.html @@ -0,0 +1,65 @@ +{% extends "base.html" %} +{% import '_snippets.html' as snippets %} + +{% block title %} +{{ item.title }} +{% endblock %} + +{% block bodyclass %}search{% endblock %} + +{% block content %} + +
+
+
+ +
+
+
+ +
+
+

{{ item.name }}

+ {% if item.title %} +

{{ item.title }}

+ {% endif %} + {% if item.created %} +

Since {{ item.created }}

+ {% endif %} +
+
+
+ +
+
+
+

Datasets {{result.count}}

+
+
+
+ +
+
+
+ +
+ + {% if result.count > 0 %} +
+
+ {{ snippets.package_list_show(result.results) }} +
+
+ + {% if result.count > 10 %} + {% set path = 'collections/' + item.name %} + {{ snippets.pagination(query.q, pages, result, path) }} + {% endif %} + + {% endif %} +
+
+
+
+
+{% endblock %} diff --git a/themes/eds/views/collections-home.html b/themes/eds/views/collections-home.html index 27481651..d2e9c81b 100644 --- a/themes/eds/views/collections-home.html +++ b/themes/eds/views/collections-home.html @@ -13,7 +13,7 @@
@@ -27,11 +27,11 @@

- What are Organizations? + What are {{ title }}?

- All datasets are attached to an organization/company. The organization is responsible for publishing and maintaining data and for data quality in general. The organization is also responsible for providing data support and to support data usage. + {{ description }}

@@ -39,8 +39,8 @@

-

Organizations

-
+

{{ title }}

+
    @@ -56,7 +56,7 @@

    Organizations

-

{{ collections|length }} organization{{ "s" if collections|length != 1 else ""}} found

+

{{ collections|length }} {{ "organization" if slug=="organization" else "collection" }}{{ "s" if collections|length != 1 else ""}} found

@@ -65,8 +65,8 @@

{{ collections|length }} organization{{ "s" if collections|length != 1 else
  • {{ collection.name }}

    {{ collection.title }}

    - {{ collection.count }} Dataset{{ 's' if collection.count > 1 else '' }} - + {{ collection.count }} Dataset{{ 's' if collection.count != 1 else '' }} + View {{ collection.title }}
  • diff --git a/themes/eds/views/search.html b/themes/eds/views/search.html new file mode 100644 index 00000000..d3d3ceff --- /dev/null +++ b/themes/eds/views/search.html @@ -0,0 +1,295 @@ +{% extends "base.html" %} +{% import '_snippets.html' as snippets %} + +{% block title %} +{{ title }} +{% endblock %} + +{% block bodyclass %}search{% endblock %} + +{% block content %} +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
      +
    • +
    • + +
    • +
    + +
    +
    +
    +
    +

    {{ result.count }} dataset{{ "s" if result.count != 1 else ""}} found

    +
    +
    +
    +
      + {% for dataset in result.results %} +
    • +
      +
      +
      +

      + {{ dataset.title }} + +

      +
      Daily commercial flow in the Danish gas market. The commercial flow + can vary slightly from the physical flow. +
      +
      + +
      +
      +
    • + {% endfor %} +
    +
    + + +
    +
      + {% for page in pages %} +
    • {{ page }}
    • + {% endfor %} +
    • »
    • +
    +
    + +
    + + +
    + + +
    + +
    +
    + +
    +{% endblock %} From 7b354aa821503e66f0e55a0714279c381ece9773 Mon Sep 17 00:00:00 2001 From: Svetozar Stojkovic Date: Mon, 8 Jul 2019 22:33:59 +0200 Subject: [PATCH 3/7] [html,translations][l]: initial version implemented --- themes/eds/i18n/da.json | 15 +- themes/eds/i18n/en.json | 14 +- themes/eds/views/collection.html | 237 ++++++++++++++++++++----- themes/eds/views/collections-home.html | 128 ++++++------- themes/eds/views/owner.html | 216 ++++++++++++++++++++++ themes/eds/views/search.html | 185 ++++++------------- 6 files changed, 548 insertions(+), 247 deletions(-) create mode 100644 themes/eds/views/owner.html diff --git a/themes/eds/i18n/da.json b/themes/eds/i18n/da.json index bea8f5b0..a2a708ec 100644 --- a/themes/eds/i18n/da.json +++ b/themes/eds/i18n/da.json @@ -77,7 +77,7 @@ "E.g. environment": "F.eks. environment", "Search through the Energinet DataStore datasets": "Søg i Energinet Data Service datasæt", "Search": "Søg", - "What are Organizations?": "Hvad er en organisation", + "What are Organizations?": "Hvad er en organisation?", "All datasets are attached to an organization/company. The organization is responsible for publishing and maintaining data and for data quality in general. The organization is also responsible for providing data support and to support data usage.": "Alle datasæt er tilknyttet én organisation/selskab. Organisationen er ansvarlig for at udgive og vedligeholde data og for datakvaliteten generelt. Organisationen er også ansvarlig for at yde support på datasættet og understøtte, at data bringes i anvendelse.", "View {organization_name}": "Se {organization_name}", "Unsubscribe": "Følg ikke", @@ -160,5 +160,14 @@ "Transmission Lines": "Transmission", "CO2 Emissions": "CO2 Emissioner", "Gas": "Gas", - "Highlighted data": "Highlighted data" -} + "Highlighted data": "Highlighted data", + "Tags": "Tags", + "Formats": "Formater", + "Licenses": "Licenser", + "Organization": "Organisationer", + "Relevance": "Relevans", + "Last Modified": "Sidst modificeret", + "What are Dataset Collections?": "Hvad er grupper?", + "Dataset Collections": "Grupper", + "Show More Groups": "Show More Groups" +} \ No newline at end of file diff --git a/themes/eds/i18n/en.json b/themes/eds/i18n/en.json index 772667f2..4244e6ae 100644 --- a/themes/eds/i18n/en.json +++ b/themes/eds/i18n/en.json @@ -28,5 +28,15 @@ "Subscribe to news and get notified when new data are released": "Subscribe to news and get notified when new data are released", "Help Energinet to provide better service and support": "Help Energinet to provide better service and support", "Register": "Register", - "Energinet has a lot of energy data and through Energi Data Service, we want to make these data available. The portal will be expanded regularly. We hope you will join us on the journey, and will contribute with advice and feedback.": "Energinet has a lot of energy data and through Energi Data Service, we want to make these data available. The portal will be expanded regularly. We hope you will join us on the journey, and will contribute with advice and feedback." -} + "Energinet has a lot of energy data and through Energi Data Service, we want to make these data available. The portal will be expanded regularly. We hope you will join us on the journey, and will contribute with advice and feedback.": "Energinet has a lot of energy data and through Energi Data Service, we want to make these data available. The portal will be expanded regularly. We hope you will join us on the journey, and will contribute with advice and feedback.", + "Tags": "Tags", + "Formats": "Formats", + "Licenses": "Licenses", + "Organization": "Organization", + "Name Ascending": "Name Ascending", + "Name Descending": "Name Descending", + "What are Organizations?": "What are Organizations?", + "Order by": "Order by", + "Dataset Collections": "Dataset Collections", + "What are Dataset Collections?": "What are Dataset Collections?" +} \ No newline at end of file diff --git a/themes/eds/views/collection.html b/themes/eds/views/collection.html index 858b5ad5..f25d1252 100644 --- a/themes/eds/views/collection.html +++ b/themes/eds/views/collection.html @@ -9,55 +9,206 @@ {% block content %} -
    -
    -
    - -
    -
    -
    - -
    -
    -

    {{ item.name }}

    - {% if item.title %} -

    {{ item.title }}

    - {% endif %} - {% if item.created %} -

    Since {{ item.created }}

    - {% endif %} -
    +
    +
    + +
    +
    +
    - -
    -
    -
    -

    Datasets {{result.count}}

    +
    +
    + +
    +
    +
    + +
    +
    +
      +
    • +
    • + +
    • +
    +
    +
    +
    +
    +

    {{ result.results|length }} dataset{{ "s" if result.results|length != 1 else ""}} found

    +
    +
    +
      + {% for dataset in result.results %} +
    • +
      +
      +
      +

      + {{ dataset.title }} + +

      +
      {{ dataset.description|truncate(180) }}
      +
      + +
      +
      +
    • + {% endfor %} +
    -
    - -
    - - {% if result.count > 0 %} -
    -
    - {{ snippets.package_list_show(result.results) }} -
    -
    - - {% if result.count > 10 %} - {% set path = 'collections/' + item.name %} - {{ snippets.pagination(query.q, pages, result, path) }} - {% endif %} - + {% if totalPages > 1 %} +
    +
      + {% for page in pages %} +
    • {{ page }}
    • + {% endfor %} +
    • »
    • +
    +
    {% endif %} -
    +

    diff --git a/themes/eds/views/collections-home.html b/themes/eds/views/collections-home.html index d2e9c81b..f71ca676 100644 --- a/themes/eds/views/collections-home.html +++ b/themes/eds/views/collections-home.html @@ -7,78 +7,78 @@ {% block content %} -
    -
    -
    -
    - +
    +
    +
    + +
    +
    +
    +
    +
    -
    -
    -
    +
    +
    + +
    +
    +
    +

    {{ title }}

    + +
    +
    +
      +
    • +
    • + +
    • +
    -
    -
    -

    {{ collections|length }} {{ "organization" if slug=="organization" else "collection" }}{{ "s" if collections|length != 1 else ""}} found

    -
    +
    +
    +
    +

    {{ collections|length }} {{ "organization" if slug=="organization" else "collection" }}{{ "s" if collections|length != 1 else ""}} found

    - -
      - {% for collection in collections %} -
    • - {{ collection.name }} -

      {{ collection.title }}

      +
    + +
      + {% for collection in collections %} +
    • + {{ collection.name }} +

      {{ collection.title }}

      + {% if slug=="organization" %} {{ collection.count }} Dataset{{ 's' if collection.count != 1 else '' }} - - View {{ collection.title }} - -
    • - {% endfor %} -
    • -
    -
    -
    -
    + {% endif %} + + View {{ collection.title }} + + + {% endfor %} +
  • + +
    +
    -
    + {% endblock %} diff --git a/themes/eds/views/owner.html b/themes/eds/views/owner.html new file mode 100644 index 00000000..22c7ff3e --- /dev/null +++ b/themes/eds/views/owner.html @@ -0,0 +1,216 @@ +{% extends "base.html" %} +{% import '_snippets.html' as snippets %} + +{% block title %} +{{ item.title }} +{% endblock %} + +{% block bodyclass %}search{% endblock %} + +{% block content %} + +
    +
    + +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
      +
    • +
    • + +
    • +
    +
    +
    +
    +
    +

    {{ result.count }} dataset{{ "s" if result.count != 1 else ""}} found

    +
    +
    +
    +
      + {% for dataset in result.results %} +
    • +
      +
      +
      +

      + {{ dataset.title }} + +

      +
      {{ dataset.description|truncate(180) }}
      +
      + +
      +
      +
    • + {% endfor %} +
    +
    + {% if totalPages > 1 %} +
    +
      + {% for page in pages %} +
    • {{ page }}
    • + {% endfor %} +
    • »
    • +
    +
    + {% endif %} +
    +
    +
    +
    +
    +{% endblock %} diff --git a/themes/eds/views/search.html b/themes/eds/views/search.html index d3d3ceff..d3ea3d8e 100644 --- a/themes/eds/views/search.html +++ b/themes/eds/views/search.html @@ -14,7 +14,7 @@
    @@ -34,21 +34,13 @@

    @@ -131,37 +77,13 @@

    @@ -172,16 +94,17 @@

    - - Formats + {{__('Formats')}}

    @@ -192,16 +115,18 @@

    - Licenses + {{__('Licenses')}}

    -
    +
      -
    • +
    • - + + + +
    -
    @@ -269,8 +190,7 @@

    {% endfor %}

    - - + {% if totalPages > 1 %}
      {% for page in pages %} @@ -279,15 +199,10 @@

    • »
    - + {% endif %}

    - -
    - - - From b2c45d5f5e5234eb64c56c469066de77d10c6f05 Mon Sep 17 00:00:00 2001 From: anuveyatsu Date: Thu, 11 Jul 2019 11:35:32 +0600 Subject: [PATCH 4/7] [search][xl]: search page divided into partials and bugs are fixed all over --- themes/eds/i18n/en.json | 5 +- .../eds/views/partials/data-search-form.njk | 23 +++ .../views/partials/data-search-pagination.njk | 18 ++ .../views/partials/data-search-results.njk | 43 +++++ themes/eds/views/partials/search-filter.njk | 104 +++++++++++ themes/eds/views/search.html | 168 +----------------- 6 files changed, 196 insertions(+), 165 deletions(-) create mode 100644 themes/eds/views/partials/data-search-form.njk create mode 100644 themes/eds/views/partials/data-search-pagination.njk create mode 100644 themes/eds/views/partials/data-search-results.njk create mode 100644 themes/eds/views/partials/search-filter.njk diff --git a/themes/eds/i18n/en.json b/themes/eds/i18n/en.json index 4244e6ae..d37b8240 100644 --- a/themes/eds/i18n/en.json +++ b/themes/eds/i18n/en.json @@ -38,5 +38,8 @@ "What are Organizations?": "What are Organizations?", "Order by": "Order by", "Dataset Collections": "Dataset Collections", - "What are Dataset Collections?": "What are Dataset Collections?" + "What are Dataset Collections?": "What are Dataset Collections?", + "Show More Groups": "Show More Groups", + "Relevance": "Relevance", + "Last Modified": "Last Modified" } \ No newline at end of file diff --git a/themes/eds/views/partials/data-search-form.njk b/themes/eds/views/partials/data-search-form.njk new file mode 100644 index 00000000..ecc69620 --- /dev/null +++ b/themes/eds/views/partials/data-search-form.njk @@ -0,0 +1,23 @@ + + +
    +
    +
      +
    • +
    • + +
    • +
    +
    +
    +
    +
    +

    {{ result.count }} dataset{{ "s" if result.count != 1 else ""}} found

    +
    +
    + diff --git a/themes/eds/views/partials/data-search-pagination.njk b/themes/eds/views/partials/data-search-pagination.njk new file mode 100644 index 00000000..6fa1d1c8 --- /dev/null +++ b/themes/eds/views/partials/data-search-pagination.njk @@ -0,0 +1,18 @@ +{% if totalPages > 1 %} +
    +
      + {% for page in pages %} + {% if page == '...' %} +
    • + {{page}} +
    • + {% else %} +
    • + {{page}} +
    • + {% endif %} + {% endfor %} +
    • »
    • +
    +
    +{% endif %} diff --git a/themes/eds/views/partials/data-search-results.njk b/themes/eds/views/partials/data-search-results.njk new file mode 100644 index 00000000..905d73d6 --- /dev/null +++ b/themes/eds/views/partials/data-search-results.njk @@ -0,0 +1,43 @@ +
      + {% for dataset in result.results %} +
    • +
      +
      +
      +

      + {{ dataset.title or dataset.name }} +

      +
      + {% if dataset.readmeSnippet %} +

      + {{ dataset.readmeSnippet }} +

      + {% elif dataset.readmeHtml %} +

      + {{ dataset.readmeHtml|safe }} +

      + {% elif dataset.description %} +

      + {% if dataset.description|length > 200 %} + {{ dataset.description|truncate(200) }} + {% else %} + {{ dataset.description }} + {% endif %} +

      + {% endif %} +
      +
      +
        + {% for resource in dataset.resources %} + {% if resource.format %} +
      • + {{ resource.format }} +
      • + {% endif %} + {% endfor %} +
      +
      +
      +
    • + {% endfor %} +
    diff --git a/themes/eds/views/partials/search-filter.njk b/themes/eds/views/partials/search-filter.njk new file mode 100644 index 00000000..b835dce7 --- /dev/null +++ b/themes/eds/views/partials/search-filter.njk @@ -0,0 +1,104 @@ +
    +
    +

    + + {{__('Organizations')}} +

    + + +
    +
    + +

    + + {{__('Groups')}} +

    + + +
    +
    + +

    + + {{__('Tags')}} +

    + + + +
    +
    + +

    + + {{__('Formats')}} +

    + + + +
    +
    + +

    + + {{__('Licenses')}} +

    + + +
    +
    diff --git a/themes/eds/views/search.html b/themes/eds/views/search.html index d3ea3d8e..0fdf1a50 100644 --- a/themes/eds/views/search.html +++ b/themes/eds/views/search.html @@ -26,113 +26,7 @@
    -
    -
    -
    -
      -
    • -
    • - -
    • -
    -
    -
    -
    -
    -

    {{ result.results|length }} dataset{{ "s" if result.results|length != 1 else ""}} found

    -
    -
    -
    -
      - {% for dataset in result.results %} -
    • -
      -
      -
      -

      - {{ dataset.title }} - -

      -
      {{ dataset.description|truncate(180) }}
      -
      - -
      -
      -
    • - {% endfor %} -
    + {% include "./partials/data-search-form.njk" %} + {% include "./partials/data-search-results.njk" %}
    - {% if totalPages > 1 %} -
    -
      - {% for page in pages %} -
    • {{ page }}
    • - {% endfor %} -
    • »
    • -
    -
    - {% endif %} + {% include "./partials/data-search-pagination.njk" %}
    diff --git a/themes/eds/views/owner.html b/themes/eds/views/owner.html index 22c7ff3e..04c8d992 100644 --- a/themes/eds/views/owner.html +++ b/themes/eds/views/owner.html @@ -30,7 +30,7 @@

    @@ -50,164 +50,17 @@

    -
    -
    -

    - - {{__('Organizations')}} -

    - - -
    -
    -

    - - {{__('Groups')}} -

    - - -
    -
    -

    - - {{__('Tags')}} -

    - - -
    -
    -

    - - {{__('Formats')}} -

    - - -
    -
    -

    - - {{__('Licenses')}} -

    - - -
    -
    + {% include "./partials/search-filter.njk" %} close
    -
    -
    -
    -
      -
    • -
    • - -
    • -
    -
    -
    -
    -
    -

    {{ result.count }} dataset{{ "s" if result.count != 1 else ""}} found

    -
    -
    -
    -
      - {% for dataset in result.results %} -
    • -
      -
      -
      -

      - {{ dataset.title }} - -

      -
      {{ dataset.description|truncate(180) }}
      -
      - -
      -
      -
    • - {% endfor %} -
    + {% include "./partials/data-search-form.njk" %} + {% include "./partials/data-search-results.njk" %}
    - {% if totalPages > 1 %} -
    -
      - {% for page in pages %} -
    • {{ page }}
    • - {% endfor %} -
    • »
    • -
    -
    - {% endif %} + {% include "./partials/data-search-pagination.njk" %}
    diff --git a/themes/eds/views/search.html b/themes/eds/views/search.html index 0fdf1a50..26473ee3 100644 --- a/themes/eds/views/search.html +++ b/themes/eds/views/search.html @@ -34,8 +34,6 @@
    -
    -
    {% include "./partials/data-search-form.njk" %} {% include "./partials/data-search-results.njk" %}
    From b0b9c3eef0c0c03ab12d83747a5a11004aa57fdc Mon Sep 17 00:00:00 2001 From: anuveyatsu Date: Thu, 11 Jul 2019 11:50:19 +0600 Subject: [PATCH 6/7] [static][xs]: static page template renders content correctly --- views/static.html | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/views/static.html b/views/static.html index 19f2dc48..d433e3c1 100644 --- a/views/static.html +++ b/views/static.html @@ -1,13 +1,26 @@ {% extends "base.html" %} -{% block title %} -Welcome - About -{% endblock %} +{% block title%}{{title}}{% endblock %} -{% block bodyclass %}static{% endblock %} +{% block bodyclass %}blog static{% endblock %} {% block content %} -
    - {{ title }} + +
    +
    +
    + +
    +
    + {{content | safe}} +
    +
    +
    +
    + {% endblock %} From 47705d4bc11457d0281cc9345a055101c23ae489 Mon Sep 17 00:00:00 2001 From: anuveyatsu Date: Thu, 11 Jul 2019 14:18:17 +0600 Subject: [PATCH 7/7] [showcase][l]: implementaiton of the showcase page. Missing: - filters - adding schema so that metadata section works --- themes/eds/routes.js | 150 ++++++++++++++++++++ themes/eds/views/base.html | 5 +- themes/eds/views/showcase.html | 244 +++++++++++++++++++++++++++++++++ 3 files changed, 397 insertions(+), 2 deletions(-) create mode 100644 themes/eds/routes.js create mode 100644 themes/eds/views/showcase.html diff --git a/themes/eds/routes.js b/themes/eds/routes.js new file mode 100644 index 00000000..40a60a18 --- /dev/null +++ b/themes/eds/routes.js @@ -0,0 +1,150 @@ +const fetch = require('node-fetch') +const moment = require('moment') +const config = require('../../config') +const dms = require('../../lib/dms') +const utils = require('../../utils') + + +module.exports = function (app) { + app.get('/:owner/:name', async (req, res, next) => { + const Model = new dms.DmsModel(config) + let datapackage = null + + try { + datapackage = await Model.getPackage(req.params.name) + } catch (err) { + next(err) + return + } + + // Convert timestamps into human readable format: + datapackage.resources[0].created = moment(datapackage.resources[0].created).format('MMMM Do, YYYY') + datapackage.resources[0].last_modified = moment(datapackage.resources[0].last_modified).format('MMMM Do, YYYY') + + // Prep downloads property with various formats + datapackage.downloads = [ + { + format: 'CSV', + path: datapackage.resources[0].path + }, + { + format: 'TSV', + path: datapackage.resources[0].path + '?format=tsv' + }, + { + format: 'XLSX - Excel', + path: datapackage.resources[0].path + '?bom=true' + }, + { + format: 'JSON', + path: datapackage.resources[0].path + '?format=json' + }, + { + format: 'XML', + path: datapackage.resources[0].path + '?format=xml' + } + ] + + // Prep resource e.g., make an inline datapackage and pass to renderer lib + datapackage.resources[0].path = config.get('API_URL') + `datastore_search?resource_id=${datapackage.resources[0].id}` + const response = await fetch(datapackage.resources[0].path) + if (response.ok) { + const result = await response.json() + datapackage.resources[0].rows = result.result.total + datapackage.resources[0].data = result.result.records.map(record => { + delete record._id + delete record._full_text + return record + }) + } else { + // Data is unavailable + datapackage.resources[0].unavailable = true + } + delete datapackage.resources[0].path + // Resource format should be known tabular format for data previews to work + // in EDS, all resources are in 'data' format which isn't valid for previewing + datapackage.resources[0].format = 'csv' + + const schema = { + fields: [ + { + name: 'GasDay', + title: 'Gas Day', + type: 'date', + description: 'Gas Day is a period commencing at 06:00 CET on any day and ending at 06:00 CET on the following day. The Gas Day is reduced to 23 Hours at the transition to summer time and is increased to 25 Hours at the transition to winter time.', + example: '2017-12-24', + unit: 'Days' + }, + { + name: 'KWhFromBiogas', + type: 'number' + }, + { + name: 'KWhToDenmark', + type: 'number' + }, + { + name: 'KWhFromNorthSea', + type: 'number' + }, + { + name: 'KWhToOrFromStorage', + type: 'number' + }, + { + name: 'KWhToOrFromGermany', + type: 'number' + }, + { + name: 'KWhToSweden', + type: 'number' + } + ] + } + datapackage.resources[0].schema = schema + + // Since "datapackage-views-js" library renders views according to + // descriptor's "views" property, we need to generate view objects: + datapackage.views = datapackage.views || [] + datapackage.resources.forEach((resource, index) => { + // Convert bytes into human-readable format: + resource.size = resource.size ? bytes(resource.size, {decimalPlaces: 0}) : resource.size + const view = { + id: index, + title: resource.title || resource.name, + resources: [ + resource.name + ], + specType: null + } + resource.format = resource.format.toLowerCase() + // Add 'table' views for each tabular resource: + const tabularFormats = ['csv', 'tsv', 'dsv', 'xls', 'xlsx'] + if (tabularFormats.includes(resource.format)) { + view.specType = 'table' + } else if (resource.format.includes('json')) { + // Add 'map' views for each geo resource: + view.specType = 'map' + } else if (resource.format === 'pdf') { + view.specType = 'document' + } + + datapackage.views.push(view) + }) + + const profile = await Model.getProfile(req.params.owner) + + res.render('showcase.html', { + title: req.params.owner + ' | ' + req.params.name, + dataset: datapackage, + owner: { + name: profile.name, + title: profile.title, + description: utils.processMarkdown.render(profile.description), + avatar: profile.image_display_url || profile.image_url + }, + thisPageFullUrl: req.protocol + '://' + req.get('host') + req.originalUrl, + dpId: JSON.stringify(datapackage).replace(/'/g, "'") + }) + }) +} diff --git a/themes/eds/views/base.html b/themes/eds/views/base.html index d99f9334..3b3ad2cf 100644 --- a/themes/eds/views/base.html +++ b/themes/eds/views/base.html @@ -40,11 +40,12 @@ - - {% if dataset %} + {% endif %} + + diff --git a/themes/eds/views/showcase.html b/themes/eds/views/showcase.html new file mode 100644 index 00000000..4cbe5205 --- /dev/null +++ b/themes/eds/views/showcase.html @@ -0,0 +1,244 @@ +{% extends "base.html" %} + +{% block title %} +{{dataset.title or dataset.name}} - Dataset +{% endblock %} + +{% block content %} + + + +
    +
    + + + +
    +
    +
    +
    +
    + +
      +
    • + +
    • +
    • +
      + + +
      +
    • +
    • + + Metadata + +
    • +
    • + +
    • +
    +
    +

    {{ dataset.title }}

    +
    +

    + Total number of rows: {{ dataset.resources[0].rows }} +

    +
    + + {% for view in dataset.views %} + +
    + + {% endfor %} +
    + + + + +
    +
    +
    +
    + + + +
    +
    +
    + +
    + {% for field in dataset.resources[0].schema.fields %} +
    +
    +
    +

    {{ field.title or field.name }}

    + + + {% for key, value in field %} + + + + + {% endfor %} + +
    {{key}}{{value}}
    +
    +
    +
    + {% endfor %} +
    +
    +
    +
    + +
    +
    + +
    +{% endblock %} + +{% block scripts %} + + + +{% endblock %}