@eeacms/volto-datahub 1.0.27 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +2 -0
- package/CHANGELOG.md +23 -0
- package/cypress.config.js +2 -2
- package/locales/en/LC_MESSAGES/volto.po +14 -0
- package/package.json +26 -2
- package/src/components/ItemView/Datasets/DatasetEsri.jsx +42 -0
- package/src/components/ItemView/Datasets/DatasetEsri.test.jsx +27 -0
- package/src/components/ItemView/Datasets/DatasetHttpLinks.jsx +65 -0
- package/src/components/ItemView/Datasets/DatasetHttpLinks.test.jsx +38 -0
- package/src/components/ItemView/Datasets/DatasetItemDownloadList.jsx +18 -155
- package/src/components/ItemView/Datasets/DatasetItemsList.jsx +2 -1
- package/src/components/ItemView/Datasets/DatasetLinks.jsx +39 -0
- package/src/components/ItemView/Datasets/DatasetLinks.test.jsx +27 -0
- package/src/components/ItemView/Datasets/DatasetUrls.jsx +33 -0
- package/src/components/ItemView/Datasets/DatasetUrls.test.jsx +25 -0
- package/src/components/ItemView/Datasets/DatasetsView.jsx +5 -56
- package/src/components/ItemView/ItemView.jsx +50 -4
- package/src/components/ItemView/index.js +3 -3
- package/src/components/ItemView/utils.js +0 -50
- package/src/components/ItemView/utils.test.js +2 -2
- package/src/constants.js +3 -0
- package/src/express-middleware.js +80 -21
- package/src/index.js +9 -4
- package/src/utils.js +114 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
### [1.0.29](https://github.com/eea/volto-datahub/compare/1.0.28...1.0.29) - 13 September 2023
|
|
8
|
+
|
|
9
|
+
#### :hammer_and_wrench: Others
|
|
10
|
+
|
|
11
|
+
- Fix snapshot [kreafox - [`3e070c5`](https://github.com/eea/volto-datahub/commit/3e070c5973e314935d674c5d41a361882317937b)]
|
|
12
|
+
- Add test [kreafox - [`5683383`](https://github.com/eea/volto-datahub/commit/568338374247690706c4b5b1b766e1663602ace9)]
|
|
13
|
+
- Fix crash in dataset view [Tiberiu Ichim - [`f3a7310`](https://github.com/eea/volto-datahub/commit/f3a7310344b760bc8b4246bf69f47912068d6d90)]
|
|
14
|
+
### [1.0.28](https://github.com/eea/volto-datahub/compare/1.0.27...1.0.28) - 8 September 2023
|
|
15
|
+
|
|
16
|
+
#### :hammer_and_wrench: Others
|
|
17
|
+
|
|
18
|
+
- Add tests [Tiberiu Ichim - [`6a8bd4d`](https://github.com/eea/volto-datahub/commit/6a8bd4d92b0fc68ef1653f412a13a38b22c2401b)]
|
|
19
|
+
- Avoid code duplicates [Tiberiu Ichim - [`3c1adb2`](https://github.com/eea/volto-datahub/commit/3c1adb2f2b38c2fbc3527dc7db89fe3c6e62caef)]
|
|
20
|
+
- Avoid code duplicates [Tiberiu Ichim - [`77d251c`](https://github.com/eea/volto-datahub/commit/77d251c1ba79d0eb8c2b1adedeedc129438cffcd)]
|
|
21
|
+
- Code cleanup [Tiberiu Ichim - [`f27e7b4`](https://github.com/eea/volto-datahub/commit/f27e7b4447d03898cf24e9ab6b24d543954c6b17)]
|
|
22
|
+
- Dont emit broken dates [Tiberiu Ichim - [`a2e9fb4`](https://github.com/eea/volto-datahub/commit/a2e9fb477b5fe3ae0bc3bffc275d3871ba52a4dd)]
|
|
23
|
+
- Directly link to accordion [Tiberiu Ichim - [`2e637bc`](https://github.com/eea/volto-datahub/commit/2e637bc39ec88eaaf3c88c93d43b3c5b2a950f1e)]
|
|
24
|
+
- Improve RSS feed for dataseries [Tiberiu Ichim - [`1a7cb1b`](https://github.com/eea/volto-datahub/commit/1a7cb1bfdce32d837f1d342744e1f94d423813a0)]
|
|
25
|
+
- Fix content type for rss feed [Tiberiu Ichim - [`65b73a7`](https://github.com/eea/volto-datahub/commit/65b73a79d73e626f652716305e80d9a2b017c85c)]
|
|
26
|
+
- test: EN locales, pre-commit fix, feature PRs checks Refs #257193 [valentinab25 - [`ead1c04`](https://github.com/eea/volto-datahub/commit/ead1c042d1358b385c19ec66ec84d7c736574b1d)]
|
|
27
|
+
- Added 'DOI' links to datahub [Zoltan Szabo - [`b33a657`](https://github.com/eea/volto-datahub/commit/b33a657096eaec4caa641379e69e941a3b2c1583)]
|
|
28
|
+
- test: Fix eslint and yarn i18n [Alin Voinea - [`39a4a69`](https://github.com/eea/volto-datahub/commit/39a4a695733514890075886753b9d7b91d853646)]
|
|
29
|
+
- i18n: Add en [Alin Voinea - [`cdb303f`](https://github.com/eea/volto-datahub/commit/cdb303f2ac5e1f9eb22eda46bb58087c62af6ba5)]
|
|
7
30
|
### [1.0.27](https://github.com/eea/volto-datahub/compare/1.0.26...1.0.27) - 25 August 2023
|
|
8
31
|
|
|
9
32
|
#### :hammer_and_wrench: Others
|
package/cypress.config.js
CHANGED
|
@@ -2,12 +2,12 @@ const { defineConfig } = require('cypress');
|
|
|
2
2
|
|
|
3
3
|
module.exports = defineConfig({
|
|
4
4
|
viewportWidth: 1280,
|
|
5
|
-
defaultCommandTimeout:
|
|
5
|
+
defaultCommandTimeout: 5000,
|
|
6
6
|
chromeWebSecurity: false,
|
|
7
7
|
reporter: 'junit',
|
|
8
8
|
video: true,
|
|
9
9
|
retries: {
|
|
10
|
-
runMode:
|
|
10
|
+
runMode: 1,
|
|
11
11
|
openMode: 0,
|
|
12
12
|
},
|
|
13
13
|
reporterOptions: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
msgid ""
|
|
2
|
+
msgstr ""
|
|
3
|
+
"Project-Id-Version: \n"
|
|
4
|
+
"Report-Msgid-Bugs-To: \n"
|
|
5
|
+
"POT-Creation-Date: \n"
|
|
6
|
+
"PO-Revision-Date: \n"
|
|
7
|
+
"Last-Translator: \n"
|
|
8
|
+
"Language: \n"
|
|
9
|
+
"Language-Team: \n"
|
|
10
|
+
"Content-Type: \n"
|
|
11
|
+
"Content-Transfer-Encoding: \n"
|
|
12
|
+
"Plural-Forms: \n"
|
|
13
|
+
|
|
14
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eeacms/volto-datahub",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"description": "@eeacms/volto-datahub: Volto add-on",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "European Environment Agency: IDM2 A-Team",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"@cypress/code-coverage": "^3.10.0",
|
|
27
27
|
"@plone/scripts": "*",
|
|
28
28
|
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
29
|
+
"husky": "*",
|
|
30
|
+
"lint-staged": "*",
|
|
29
31
|
"md5": "^2.3.0"
|
|
30
32
|
},
|
|
31
33
|
"addons": [
|
|
@@ -33,6 +35,27 @@
|
|
|
33
35
|
"@eeacms/volto-listing-block",
|
|
34
36
|
"@eeacms/volto-accordion-block"
|
|
35
37
|
],
|
|
38
|
+
"lint-staged": {
|
|
39
|
+
"src/**/*.{js,jsx,ts,tsx,json}": [
|
|
40
|
+
"make lint-fix",
|
|
41
|
+
"make prettier-fix"
|
|
42
|
+
],
|
|
43
|
+
"src/**/*.{jsx}": [
|
|
44
|
+
"make i18n"
|
|
45
|
+
],
|
|
46
|
+
"theme/**/*.{css,less}": [
|
|
47
|
+
"make stylelint-fix"
|
|
48
|
+
],
|
|
49
|
+
"src/**/*.{css,less}": [
|
|
50
|
+
"make stylelint-fix"
|
|
51
|
+
],
|
|
52
|
+
"theme/**/*.overrides": [
|
|
53
|
+
"make stylelint-fix"
|
|
54
|
+
],
|
|
55
|
+
"src/**/*.overrides": [
|
|
56
|
+
"make stylelint-fix"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
36
59
|
"scripts": {
|
|
37
60
|
"release": "release-it",
|
|
38
61
|
"release-major-beta": "release-it major --preRelease=beta",
|
|
@@ -50,6 +73,7 @@
|
|
|
50
73
|
"lint:fix": "make lint-fix",
|
|
51
74
|
"i18n": "make i18n",
|
|
52
75
|
"cypress:run": "make cypress-run",
|
|
53
|
-
"cypress:open": "make cypress-open"
|
|
76
|
+
"cypress:open": "make cypress-open",
|
|
77
|
+
"prepare": "husky install"
|
|
54
78
|
}
|
|
55
79
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { List } from 'semantic-ui-react';
|
|
2
|
+
import { SVGIcon } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
import lockSVG from 'remixicon/icons/System/lock-line.svg';
|
|
5
|
+
import { isInternalURL } from '@eeacms/volto-datahub/utils';
|
|
6
|
+
import servicesSVG from '../icons/services.svg';
|
|
7
|
+
|
|
8
|
+
const ItemLink = ({ item }) => (
|
|
9
|
+
<List.Item key={item.id}>
|
|
10
|
+
<List.Content>
|
|
11
|
+
<div>
|
|
12
|
+
<SVGIcon name={servicesSVG} size="20px" />
|
|
13
|
+
<a
|
|
14
|
+
className="item-link"
|
|
15
|
+
href={item.url}
|
|
16
|
+
target="_blank"
|
|
17
|
+
rel="noreferrer"
|
|
18
|
+
>
|
|
19
|
+
{item.protocol} {item.name || item.description}
|
|
20
|
+
</a>
|
|
21
|
+
{isInternalURL(item.url) ? (
|
|
22
|
+
<SVGIcon name={lockSVG} size="20px" />
|
|
23
|
+
) : null}
|
|
24
|
+
</div>
|
|
25
|
+
</List.Content>
|
|
26
|
+
</List.Item>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export default function DatasetEsri({ dataset }) {
|
|
30
|
+
return dataset['ESRI:REST'] || dataset['OGC:WMS'] ? (
|
|
31
|
+
<>
|
|
32
|
+
<h5>Services:</h5>
|
|
33
|
+
<List divided relaxed>
|
|
34
|
+
{[...(dataset['ESRI:REST'] || []), ...(dataset['OGC:WMS'] || [])].map(
|
|
35
|
+
(item, i) => (
|
|
36
|
+
<ItemLink item={item} key={item.id} />
|
|
37
|
+
),
|
|
38
|
+
)}
|
|
39
|
+
</List>
|
|
40
|
+
</>
|
|
41
|
+
) : null;
|
|
42
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import DatasetEsri from './DatasetEsri';
|
|
5
|
+
|
|
6
|
+
jest.mock('@eeacms/search', () => ({
|
|
7
|
+
runRequest: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const dataset = {
|
|
11
|
+
'ESRI:REST': [
|
|
12
|
+
{
|
|
13
|
+
id: 1,
|
|
14
|
+
url: 'https://example.org/1',
|
|
15
|
+
protocol: 'https',
|
|
16
|
+
name: 'First',
|
|
17
|
+
description: 'Something here',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('DatasetEsri', () => {
|
|
23
|
+
it('renders correctly', () => {
|
|
24
|
+
const tree = renderer.create(<DatasetEsri dataset={dataset} />).toJSON();
|
|
25
|
+
expect(tree).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Icon, List } from 'semantic-ui-react';
|
|
2
|
+
import { isInternalURL } from '@eeacms/volto-datahub/utils';
|
|
3
|
+
import { SVGIcon } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
import lockSVG from 'remixicon/icons/System/lock-line.svg';
|
|
6
|
+
|
|
7
|
+
export default function DatasetHttpLinks({ dataset }) {
|
|
8
|
+
return dataset['WWW:LINK-1.0-http--link'] || dataset['DOI'] ? (
|
|
9
|
+
<>
|
|
10
|
+
<h5>Links:</h5>
|
|
11
|
+
<List divided relaxed>
|
|
12
|
+
{(dataset['WWW:LINK-1.0-http--link'] || []).map((item, i) => {
|
|
13
|
+
return (
|
|
14
|
+
<List.Item key={i}>
|
|
15
|
+
<List.Content>
|
|
16
|
+
<div className="dataset-item">
|
|
17
|
+
<Icon className="linkify" />
|
|
18
|
+
<a
|
|
19
|
+
href={item.url}
|
|
20
|
+
className="item-link"
|
|
21
|
+
target="_blank"
|
|
22
|
+
rel="noreferrer"
|
|
23
|
+
>
|
|
24
|
+
<span>{item.name || item.url}</span>
|
|
25
|
+
</a>
|
|
26
|
+
{isInternalURL(item.url) ? (
|
|
27
|
+
<SVGIcon name={lockSVG} size="20px" />
|
|
28
|
+
) : null}
|
|
29
|
+
</div>
|
|
30
|
+
</List.Content>
|
|
31
|
+
{item.description ? (
|
|
32
|
+
<span className="item-description">{item.description}</span>
|
|
33
|
+
) : null}
|
|
34
|
+
</List.Item>
|
|
35
|
+
);
|
|
36
|
+
})}
|
|
37
|
+
{(dataset['DOI'] || []).map((item, i) => {
|
|
38
|
+
return (
|
|
39
|
+
<List.Item key={i}>
|
|
40
|
+
<List.Content>
|
|
41
|
+
<div className="dataset-item">
|
|
42
|
+
<Icon className="info circle" />
|
|
43
|
+
<a
|
|
44
|
+
href={item.url}
|
|
45
|
+
className="item-link"
|
|
46
|
+
target="_blank"
|
|
47
|
+
rel="noreferrer"
|
|
48
|
+
>
|
|
49
|
+
<span>{item.name || item.url}</span>
|
|
50
|
+
</a>
|
|
51
|
+
{isInternalURL(item.url) ? (
|
|
52
|
+
<SVGIcon name={lockSVG} size="20px" />
|
|
53
|
+
) : null}
|
|
54
|
+
</div>
|
|
55
|
+
</List.Content>
|
|
56
|
+
{item.description ? (
|
|
57
|
+
<span className="item-description">{item.description}</span>
|
|
58
|
+
) : null}
|
|
59
|
+
</List.Item>
|
|
60
|
+
);
|
|
61
|
+
})}
|
|
62
|
+
</List>
|
|
63
|
+
</>
|
|
64
|
+
) : null;
|
|
65
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import DatasetHttpLinks from './DatasetHttpLinks';
|
|
5
|
+
|
|
6
|
+
jest.mock('@eeacms/search', () => ({
|
|
7
|
+
runRequest: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const dataset = {
|
|
11
|
+
'WWW:LINK-1.0-http--link': [
|
|
12
|
+
{
|
|
13
|
+
id: 1,
|
|
14
|
+
url: 'https://example.org/1',
|
|
15
|
+
protocol: 'https',
|
|
16
|
+
name: 'First',
|
|
17
|
+
description: 'Something here',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
DOI: [
|
|
21
|
+
{
|
|
22
|
+
id: 1,
|
|
23
|
+
url: 'https://example.org/1',
|
|
24
|
+
protocol: 'https',
|
|
25
|
+
name: 'First',
|
|
26
|
+
description: 'Something here',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
describe('DatasetHttpLinks', () => {
|
|
32
|
+
it('renders correctly', () => {
|
|
33
|
+
const tree = renderer
|
|
34
|
+
.create(<DatasetHttpLinks dataset={dataset} />)
|
|
35
|
+
.toJSON();
|
|
36
|
+
expect(tree).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -1,173 +1,36 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { isInternalURL, groupBy, SVGIcon } from '../utils.js';
|
|
2
|
+
import { List } from 'semantic-ui-react';
|
|
4
3
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
4
|
+
import { groupBy } from '@eeacms/volto-datahub/utils';
|
|
5
|
+
import DatasetUrls from './DatasetUrls';
|
|
6
|
+
import DatasetLinks from './DatasetLinks';
|
|
7
|
+
import DatasetEsri from './DatasetEsri';
|
|
8
|
+
import DatasetHttpLinks from './DatasetHttpLinks';
|
|
7
9
|
|
|
8
10
|
const DatasetItemDownloadList = (props) => {
|
|
9
11
|
const { link } = props;
|
|
10
12
|
const dataset = groupBy(link, 'protocol');
|
|
13
|
+
const showDownload = !!(
|
|
14
|
+
dataset['WWW:URL'] ||
|
|
15
|
+
dataset['WWW:LINK'] ||
|
|
16
|
+
dataset['EEA:FILEPATH'] ||
|
|
17
|
+
dataset['EEA:FOLDERPATH']
|
|
18
|
+
);
|
|
11
19
|
|
|
12
20
|
return (
|
|
13
21
|
<div>
|
|
14
|
-
{(
|
|
15
|
-
dataset['WWW:LINK'] ||
|
|
16
|
-
dataset['EEA:FILEPATH'] ||
|
|
17
|
-
dataset['EEA:FOLDERPATH']) && (
|
|
22
|
+
{showDownload ? (
|
|
18
23
|
<>
|
|
19
24
|
<h5>Download:</h5>
|
|
20
25
|
<List divided relaxed>
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
<List.Item key={i}>
|
|
24
|
-
<List.Content>
|
|
25
|
-
<div className="dataset-item">
|
|
26
|
-
<Icon className="download" />
|
|
27
|
-
<a
|
|
28
|
-
href={item.url}
|
|
29
|
-
className="item-link"
|
|
30
|
-
target="_blank"
|
|
31
|
-
rel="noreferrer"
|
|
32
|
-
>
|
|
33
|
-
<span>{item.name}</span>
|
|
34
|
-
</a>
|
|
35
|
-
{isInternalURL(item.url) && (
|
|
36
|
-
<SVGIcon name={lockSVG} size="20px" />
|
|
37
|
-
)}
|
|
38
|
-
</div>
|
|
39
|
-
</List.Content>
|
|
40
|
-
{item.description && (
|
|
41
|
-
<span className="item-description" title={item.description}>
|
|
42
|
-
{item.description}
|
|
43
|
-
</span>
|
|
44
|
-
)}
|
|
45
|
-
</List.Item>
|
|
46
|
-
);
|
|
47
|
-
})}
|
|
48
|
-
|
|
49
|
-
{(dataset['WWW:LINK'] || []).map((item, i) => {
|
|
50
|
-
return (
|
|
51
|
-
<List.Item key={i}>
|
|
52
|
-
<List.Content>
|
|
53
|
-
<div className="dataset-item">
|
|
54
|
-
<Icon className="download" />
|
|
55
|
-
{item.name ? (
|
|
56
|
-
<a
|
|
57
|
-
href={item.url}
|
|
58
|
-
className="item-link"
|
|
59
|
-
target="_blank"
|
|
60
|
-
rel="noreferrer"
|
|
61
|
-
>
|
|
62
|
-
{item.name}
|
|
63
|
-
</a>
|
|
64
|
-
) : (
|
|
65
|
-
<a
|
|
66
|
-
href={item.url}
|
|
67
|
-
className="item-link"
|
|
68
|
-
target="_blank"
|
|
69
|
-
rel="noreferrer"
|
|
70
|
-
>
|
|
71
|
-
Download link
|
|
72
|
-
</a>
|
|
73
|
-
)}
|
|
74
|
-
{isInternalURL(item.url) && (
|
|
75
|
-
<SVGIcon name={lockSVG} size="20px" />
|
|
76
|
-
)}
|
|
77
|
-
</div>
|
|
78
|
-
</List.Content>
|
|
79
|
-
</List.Item>
|
|
80
|
-
);
|
|
81
|
-
})}
|
|
82
|
-
</List>
|
|
83
|
-
</>
|
|
84
|
-
)}
|
|
85
|
-
|
|
86
|
-
{(dataset['ESRI:REST'] || dataset['OGC:WMS']) && (
|
|
87
|
-
<>
|
|
88
|
-
<h5>Services:</h5>
|
|
89
|
-
<List divided relaxed>
|
|
90
|
-
{(dataset['ESRI:REST'] || []).map((item, i) => {
|
|
91
|
-
return (
|
|
92
|
-
<List.Item key={i}>
|
|
93
|
-
<List.Content>
|
|
94
|
-
<div>
|
|
95
|
-
<SVGIcon name={servicesSVG} size="20px" />
|
|
96
|
-
<a
|
|
97
|
-
className="item-link"
|
|
98
|
-
href={item.url}
|
|
99
|
-
target="_blank"
|
|
100
|
-
rel="noreferrer"
|
|
101
|
-
>
|
|
102
|
-
{item.protocol} {item.name || item.description}
|
|
103
|
-
</a>
|
|
104
|
-
{isInternalURL(item.url) && (
|
|
105
|
-
<SVGIcon name={lockSVG} size="20px" />
|
|
106
|
-
)}
|
|
107
|
-
</div>
|
|
108
|
-
</List.Content>
|
|
109
|
-
</List.Item>
|
|
110
|
-
);
|
|
111
|
-
})}
|
|
112
|
-
|
|
113
|
-
{(dataset['OGC:WMS'] || []).map((item, i) => {
|
|
114
|
-
return (
|
|
115
|
-
<List.Item key={i}>
|
|
116
|
-
<List.Content>
|
|
117
|
-
<div>
|
|
118
|
-
<SVGIcon name={servicesSVG} size="20px" />
|
|
119
|
-
<a
|
|
120
|
-
className="item-link"
|
|
121
|
-
href={item.url}
|
|
122
|
-
target="_blank"
|
|
123
|
-
rel="noreferrer"
|
|
124
|
-
>
|
|
125
|
-
{item.protocol} {item.name || item.description}
|
|
126
|
-
</a>
|
|
127
|
-
{isInternalURL(item.url) && (
|
|
128
|
-
<SVGIcon name={lockSVG} size="20px" />
|
|
129
|
-
)}
|
|
130
|
-
</div>
|
|
131
|
-
</List.Content>
|
|
132
|
-
</List.Item>
|
|
133
|
-
);
|
|
134
|
-
})}
|
|
26
|
+
<DatasetUrls dataset={dataset} />
|
|
27
|
+
<DatasetLinks dataset={dataset} />
|
|
135
28
|
</List>
|
|
136
29
|
</>
|
|
137
|
-
)}
|
|
30
|
+
) : null}
|
|
138
31
|
|
|
139
|
-
{dataset
|
|
140
|
-
|
|
141
|
-
<h5>Links:</h5>
|
|
142
|
-
<List divided relaxed>
|
|
143
|
-
{(dataset['WWW:LINK-1.0-http--link'] || []).map((item, i) => {
|
|
144
|
-
return (
|
|
145
|
-
<List.Item key={i}>
|
|
146
|
-
<List.Content>
|
|
147
|
-
<div className="dataset-item">
|
|
148
|
-
<Icon className="linkify" />
|
|
149
|
-
<a
|
|
150
|
-
href={item.url}
|
|
151
|
-
className="item-link"
|
|
152
|
-
target="_blank"
|
|
153
|
-
rel="noreferrer"
|
|
154
|
-
>
|
|
155
|
-
<span>{item.name || item.url}</span>
|
|
156
|
-
</a>
|
|
157
|
-
{isInternalURL(item.url) && (
|
|
158
|
-
<SVGIcon name={lockSVG} size="20px" />
|
|
159
|
-
)}
|
|
160
|
-
</div>
|
|
161
|
-
</List.Content>
|
|
162
|
-
{item.description && (
|
|
163
|
-
<span className="item-description">{item.description}</span>
|
|
164
|
-
)}
|
|
165
|
-
</List.Item>
|
|
166
|
-
);
|
|
167
|
-
})}
|
|
168
|
-
</List>
|
|
169
|
-
</>
|
|
170
|
-
)}
|
|
32
|
+
<DatasetEsri dataset={dataset} />
|
|
33
|
+
<DatasetHttpLinks dataset={dataset} />
|
|
171
34
|
</div>
|
|
172
35
|
);
|
|
173
36
|
};
|
|
@@ -6,8 +6,9 @@ import { useLocation, useHistory } from 'react-router-dom';
|
|
|
6
6
|
import { DateTime } from '@eeacms/search';
|
|
7
7
|
import { AccordionFilter } from '@eeacms/volto-accordion-block/components';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { SVGIcon } from '../utils.js';
|
|
10
10
|
import DatasetItemDownloadList from './DatasetItemDownloadList';
|
|
11
|
+
import { isInternal, isObsolete } from '@eeacms/volto-datahub/utils';
|
|
11
12
|
|
|
12
13
|
import lockSVG from 'remixicon/icons/System/lock-line.svg';
|
|
13
14
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Icon, List } from 'semantic-ui-react';
|
|
2
|
+
import { SVGIcon } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
import lockSVG from 'remixicon/icons/System/lock-line.svg';
|
|
5
|
+
import { isInternalURL } from '@eeacms/volto-datahub/utils';
|
|
6
|
+
|
|
7
|
+
export default function DatasetLinks({ dataset }) {
|
|
8
|
+
return (dataset['WWW:LINK'] || []).map((item, i) => {
|
|
9
|
+
return (
|
|
10
|
+
<List.Item key={i}>
|
|
11
|
+
<List.Content>
|
|
12
|
+
<div className="dataset-item">
|
|
13
|
+
<Icon className="download" />
|
|
14
|
+
{item.name ? (
|
|
15
|
+
<a
|
|
16
|
+
href={item.url}
|
|
17
|
+
className="item-link"
|
|
18
|
+
target="_blank"
|
|
19
|
+
rel="noreferrer"
|
|
20
|
+
>
|
|
21
|
+
{item.name}
|
|
22
|
+
</a>
|
|
23
|
+
) : (
|
|
24
|
+
<a
|
|
25
|
+
href={item.url}
|
|
26
|
+
className="item-link"
|
|
27
|
+
target="_blank"
|
|
28
|
+
rel="noreferrer"
|
|
29
|
+
>
|
|
30
|
+
Download link
|
|
31
|
+
</a>
|
|
32
|
+
)}
|
|
33
|
+
{isInternalURL(item.url) && <SVGIcon name={lockSVG} size="20px" />}
|
|
34
|
+
</div>
|
|
35
|
+
</List.Content>
|
|
36
|
+
</List.Item>
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import DatasetLinks from './DatasetLinks';
|
|
5
|
+
|
|
6
|
+
jest.mock('@eeacms/search', () => ({
|
|
7
|
+
runRequest: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const dataset = {
|
|
11
|
+
'WWW:LINK': [
|
|
12
|
+
{
|
|
13
|
+
id: 1,
|
|
14
|
+
url: 'https://example.org/1',
|
|
15
|
+
protocol: 'https',
|
|
16
|
+
name: 'First',
|
|
17
|
+
description: 'Something here',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('DatasetEsri', () => {
|
|
23
|
+
it('renders correctly', () => {
|
|
24
|
+
const tree = renderer.create(<DatasetLinks dataset={dataset} />).toJSON();
|
|
25
|
+
expect(tree).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Icon, List } from 'semantic-ui-react';
|
|
2
|
+
import { SVGIcon } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
import lockSVG from 'remixicon/icons/System/lock-line.svg';
|
|
5
|
+
import { isInternalURL } from '@eeacms/volto-datahub/utils';
|
|
6
|
+
|
|
7
|
+
export default function DatasetUrls({ dataset }) {
|
|
8
|
+
return (dataset['WWW:URL'] || []).map((item, i) => {
|
|
9
|
+
return (
|
|
10
|
+
<List.Item key={i}>
|
|
11
|
+
<List.Content>
|
|
12
|
+
<div className="dataset-item">
|
|
13
|
+
<Icon className="download" />
|
|
14
|
+
<a
|
|
15
|
+
href={item.url}
|
|
16
|
+
className="item-link"
|
|
17
|
+
target="_blank"
|
|
18
|
+
rel="noreferrer"
|
|
19
|
+
>
|
|
20
|
+
<span>{item.name}</span>
|
|
21
|
+
</a>
|
|
22
|
+
{isInternalURL(item.url) && <SVGIcon name={lockSVG} size="20px" />}
|
|
23
|
+
</div>
|
|
24
|
+
</List.Content>
|
|
25
|
+
{item.description && (
|
|
26
|
+
<span className="item-description" title={item.description}>
|
|
27
|
+
{item.description}
|
|
28
|
+
</span>
|
|
29
|
+
)}
|
|
30
|
+
</List.Item>
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import DatasetUrls from './DatasetUrls';
|
|
5
|
+
|
|
6
|
+
jest.mock('@eeacms/search', () => ({
|
|
7
|
+
runRequest: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const dataset = {
|
|
11
|
+
'WWW:URL': [
|
|
12
|
+
{
|
|
13
|
+
url: 'https://example.org/1',
|
|
14
|
+
name: 'Direct download',
|
|
15
|
+
description: 'Download link description',
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('DatasetUrl', () => {
|
|
21
|
+
it('renders correctly', () => {
|
|
22
|
+
const tree = renderer.create(<DatasetUrls dataset={dataset} />).toJSON();
|
|
23
|
+
expect(tree).toMatchSnapshot();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -1,65 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { isObsolete, isInternal, groupBy } from '../utils.js';
|
|
3
2
|
import DatasetsTab from './DatasetsTab';
|
|
3
|
+
import { parseDatasets } from '@eeacms/volto-datahub/utils';
|
|
4
4
|
|
|
5
5
|
const DatasetsView = (props) => {
|
|
6
6
|
const { item, appConfig } = props;
|
|
7
7
|
const { children } = item?.raw_value?.raw || {};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const tc = v.resourceTemporalExtentDetails[0];
|
|
13
|
-
const { start, end } = tc || {};
|
|
14
|
-
const tc_start = start?.date
|
|
15
|
-
? new Date(Date.parse(start.date)).getFullYear()
|
|
16
|
-
: '';
|
|
17
|
-
const tc_end = end?.date
|
|
18
|
-
? new Date(Date.parse(end.date)).getFullYear()
|
|
19
|
-
: '';
|
|
20
|
-
if (tc_start === tc_end) {
|
|
21
|
-
date = tc_start;
|
|
22
|
-
} else {
|
|
23
|
-
date = tc_start + '-' + tc_end;
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
date = '';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return Object.assign({ temporalDateRange: date, ...v }, e);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const datasets = all_datasets.filter((v) => {
|
|
33
|
-
return !(isObsolete(v.cl_status) || isInternal(v));
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const archivedOrRestrictedDatasets = all_datasets.filter((v) => {
|
|
37
|
-
return isObsolete(v.cl_status) || isInternal(v);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const groupDatasets = (items) => {
|
|
41
|
-
const datasetsByCoverage = groupBy(items, 'temporalDateRange');
|
|
42
|
-
|
|
43
|
-
const sortedDatasets = Object.keys(datasetsByCoverage).sort(function (
|
|
44
|
-
a,
|
|
45
|
-
b,
|
|
46
|
-
) {
|
|
47
|
-
a = Math.max(...a.split('-'));
|
|
48
|
-
b = Math.max(...b.split('-'));
|
|
49
|
-
return b - a;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const groupedDatasets = sortedDatasets.map((v, i) => {
|
|
53
|
-
return { id: i, date: v, children: datasetsByCoverage[v] };
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return groupedDatasets;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const groupedByTemporalCoverage = groupDatasets(datasets);
|
|
60
|
-
const groupedByArchivedOrRestricted = groupDatasets(
|
|
61
|
-
archivedOrRestrictedDatasets,
|
|
62
|
-
);
|
|
8
|
+
const {
|
|
9
|
+
groupedByTemporalCoverage,
|
|
10
|
+
groupedByArchivedOrRestricted,
|
|
11
|
+
} = parseDatasets(children);
|
|
63
12
|
|
|
64
13
|
return (
|
|
65
14
|
<>
|
|
@@ -8,6 +8,7 @@ import { BodyClass, asyncConnect, Helmet } from '@plone/volto/helpers';
|
|
|
8
8
|
import config from '@plone/volto/registry';
|
|
9
9
|
import { rebind, applyConfigurationSchema } from '@eeacms/search';
|
|
10
10
|
import { Callout, Banner } from '@eeacms/volto-eea-design-system/ui';
|
|
11
|
+
import { defineMessages, useIntl } from 'react-intl';
|
|
11
12
|
import {
|
|
12
13
|
MoreLikeThis,
|
|
13
14
|
MetadataSection,
|
|
@@ -16,7 +17,8 @@ import {
|
|
|
16
17
|
import { fetchResult } from '@eeacms/search/lib/hocs/useResult';
|
|
17
18
|
import { setDatahubResult } from '@eeacms/volto-datahub/store';
|
|
18
19
|
|
|
19
|
-
import {
|
|
20
|
+
import { viewRouteId } from '@eeacms/volto-datahub/constants';
|
|
21
|
+
import { isObsolete } from '@eeacms/volto-datahub/utils';
|
|
20
22
|
|
|
21
23
|
const appName = 'datahub';
|
|
22
24
|
const WORD_COUNT = 60;
|
|
@@ -46,6 +48,13 @@ function IsomorphicPortal({ children }) {
|
|
|
46
48
|
);
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
const messages = defineMessages({
|
|
52
|
+
rssFeed: {
|
|
53
|
+
id: 'rssFeed',
|
|
54
|
+
defaultMessage: 'RSS Feed',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
49
58
|
function ItemView(props) {
|
|
50
59
|
const { docid, staticContext } = props;
|
|
51
60
|
const dispatch = useDispatch();
|
|
@@ -93,6 +102,7 @@ function ItemView(props) {
|
|
|
93
102
|
WORD_COUNT,
|
|
94
103
|
);
|
|
95
104
|
const [isReadMore, setIsReadMore] = React.useState(false);
|
|
105
|
+
const currentUrl = `/en/datahub/${viewRouteId}/${docid}`;
|
|
96
106
|
|
|
97
107
|
React.useEffect(() => {
|
|
98
108
|
const handler = async () => {
|
|
@@ -107,7 +117,7 @@ function ItemView(props) {
|
|
|
107
117
|
},
|
|
108
118
|
{
|
|
109
119
|
title: rawTitle,
|
|
110
|
-
'@id':
|
|
120
|
+
'@id': currentUrl,
|
|
111
121
|
},
|
|
112
122
|
],
|
|
113
123
|
},
|
|
@@ -118,7 +128,15 @@ function ItemView(props) {
|
|
|
118
128
|
};
|
|
119
129
|
|
|
120
130
|
handler();
|
|
121
|
-
}, [item, dispatch, docid, rawTitle]);
|
|
131
|
+
}, [item, dispatch, docid, rawTitle, currentUrl]);
|
|
132
|
+
|
|
133
|
+
const intl = useIntl();
|
|
134
|
+
const rssLinks = [
|
|
135
|
+
{
|
|
136
|
+
title: 'RSS',
|
|
137
|
+
href: `${currentUrl}/datahub_rss.xml`,
|
|
138
|
+
},
|
|
139
|
+
];
|
|
122
140
|
|
|
123
141
|
return item && item._meta.found ? (
|
|
124
142
|
<div className="dataset-view">
|
|
@@ -126,7 +144,35 @@ function ItemView(props) {
|
|
|
126
144
|
<IsomorphicPortal>
|
|
127
145
|
<div className="dataset">
|
|
128
146
|
<Banner>
|
|
129
|
-
<Banner.Content
|
|
147
|
+
<Banner.Content
|
|
148
|
+
actions={rssLinks?.map((rssLink, index) => (
|
|
149
|
+
<>
|
|
150
|
+
<Helmet
|
|
151
|
+
link={[
|
|
152
|
+
{
|
|
153
|
+
rel: 'alternate',
|
|
154
|
+
title:
|
|
155
|
+
rssLink.title ?? intl.formatMessage(messages.rssFeed),
|
|
156
|
+
href: rssLink.href,
|
|
157
|
+
type:
|
|
158
|
+
rssLink.feedType === 'atom'
|
|
159
|
+
? 'application/atom+xml'
|
|
160
|
+
: 'application/rss+xml',
|
|
161
|
+
},
|
|
162
|
+
]}
|
|
163
|
+
/>
|
|
164
|
+
<Banner.Action
|
|
165
|
+
icon="ri-rss-fill"
|
|
166
|
+
title={
|
|
167
|
+
rssLink.title ?? intl.formatMessage(messages.rssFeed)
|
|
168
|
+
}
|
|
169
|
+
className="rssfeed"
|
|
170
|
+
href={rssLink.href}
|
|
171
|
+
target="_blank"
|
|
172
|
+
/>
|
|
173
|
+
</>
|
|
174
|
+
))}
|
|
175
|
+
>
|
|
130
176
|
<Banner.Subtitle>
|
|
131
177
|
<Link to={appConfig.landingPageURL}>
|
|
132
178
|
<Icon className="arrow left" />
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export DatasetsView from './Datasets/DatasetsView';
|
|
2
|
-
export MetadataSection from './MetadataSection';
|
|
3
|
-
export MoreLikeThis from './MoreLikeThis';
|
|
1
|
+
export { default as DatasetsView } from './Datasets/DatasetsView';
|
|
2
|
+
export { default as MetadataSection } from './MetadataSection';
|
|
3
|
+
export { default as MoreLikeThis } from './MoreLikeThis';
|
|
@@ -1,53 +1,3 @@
|
|
|
1
|
-
const OBSOLETE_KEYS = ['obsolete', 'superseded'];
|
|
2
|
-
|
|
3
|
-
export const isObsolete = (status) => {
|
|
4
|
-
let obsolete = false;
|
|
5
|
-
if (status) {
|
|
6
|
-
if (Array.isArray(status)) {
|
|
7
|
-
if (
|
|
8
|
-
status.filter((stat) => OBSOLETE_KEYS.includes(stat?.key)).length > 0
|
|
9
|
-
) {
|
|
10
|
-
obsolete = true;
|
|
11
|
-
}
|
|
12
|
-
} else {
|
|
13
|
-
if (OBSOLETE_KEYS.includes(status?.key)) {
|
|
14
|
-
obsolete = true;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return obsolete;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const isInternalURL = (url) => {
|
|
22
|
-
let internal = false;
|
|
23
|
-
url.split('/').forEach((part) => {
|
|
24
|
-
if (part.split('_')[6] === 'i') {
|
|
25
|
-
internal = true;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
return internal;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const isInternal = (item) => {
|
|
32
|
-
let internal = false;
|
|
33
|
-
const links = item?.link || [];
|
|
34
|
-
links.forEach((link) => {
|
|
35
|
-
if (isInternalURL(link?.url)) {
|
|
36
|
-
internal = true;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return internal;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const groupBy = (obj, key) => {
|
|
43
|
-
return obj.reduce((rv, item) => {
|
|
44
|
-
const group = rv[item[key]] || [];
|
|
45
|
-
group.push(item);
|
|
46
|
-
rv[item[key]] = group;
|
|
47
|
-
return rv;
|
|
48
|
-
}, {});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
1
|
export const SVGIcon = ({ name, size, color, className, title, onClick }) => {
|
|
52
2
|
return (
|
|
53
3
|
<svg
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { render, cleanup, fireEvent } from '@testing-library/react';
|
|
2
|
+
import { SVGIcon } from './utils';
|
|
2
3
|
import {
|
|
3
4
|
isObsolete,
|
|
4
5
|
isInternalURL,
|
|
5
6
|
isInternal,
|
|
6
7
|
groupBy,
|
|
7
|
-
|
|
8
|
-
} from './utils';
|
|
8
|
+
} from '@eeacms/volto-datahub/utils';
|
|
9
9
|
|
|
10
10
|
describe('isObsolete', () => {
|
|
11
11
|
it('should return true if status array contains obsolete keys', () => {
|
package/src/constants.js
ADDED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { registry } from '@eeacms/search';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import buildRequest from '@eeacms/search/lib/search/query';
|
|
4
3
|
import superagent from 'superagent';
|
|
5
4
|
import { Feed } from 'feed';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
import buildRequest from '@eeacms/search/lib/search/query';
|
|
7
|
+
import { fetchResult } from '@eeacms/search/lib/hocs/useResult';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
rssRouteId,
|
|
11
|
+
viewRouteId,
|
|
12
|
+
redirectRouteId,
|
|
13
|
+
} from '@eeacms/volto-datahub/constants';
|
|
8
14
|
|
|
9
15
|
const getUrlES = (appName) => {
|
|
10
16
|
return (
|
|
@@ -35,11 +41,11 @@ function handleSearchRequest(body, params) {
|
|
|
35
41
|
});
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
function toPublicURL(id) {
|
|
39
|
-
return `https://www.eea.europa.eu/en/datahub/datahubitem-view/${id}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
44
|
function generateSitemap(appConfig) {
|
|
45
|
+
const toPublicURL = (id) => {
|
|
46
|
+
return `https://eea.europa.eu/en/datahub/${viewRouteId}/${id}`;
|
|
47
|
+
};
|
|
48
|
+
|
|
43
49
|
return new Promise((resolve, reject) => {
|
|
44
50
|
const body = buildRequest({ filters: [] }, appConfig);
|
|
45
51
|
delete body['source'];
|
|
@@ -60,10 +66,6 @@ function generateSitemap(appConfig) {
|
|
|
60
66
|
'\n',
|
|
61
67
|
)}\n</urlset>`;
|
|
62
68
|
|
|
63
|
-
// zlib.gzip(Buffer.from(result, 'utf8'), (_err, buffer) => {
|
|
64
|
-
// resolve(buffer);
|
|
65
|
-
// });
|
|
66
|
-
|
|
67
69
|
resolve(result);
|
|
68
70
|
});
|
|
69
71
|
});
|
|
@@ -112,7 +114,7 @@ function datasetRedirect(req, res, next) {
|
|
|
112
114
|
});
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
function generateRSS(appConfig) {
|
|
117
|
+
function generateRSS({ appConfig, feedUrl, toPublicURL }) {
|
|
116
118
|
return new Promise((resolve, reject) => {
|
|
117
119
|
const body = buildRequest({ filters: [] }, appConfig);
|
|
118
120
|
delete body['source'];
|
|
@@ -135,6 +137,9 @@ function generateRSS(appConfig) {
|
|
|
135
137
|
id: 'https://eea.europa.eu/en/datahub',
|
|
136
138
|
generator: 'EEA Website',
|
|
137
139
|
link: 'https://eea.europa.eu/en/datahub',
|
|
140
|
+
feedLinks: {
|
|
141
|
+
rss: feedUrl,
|
|
142
|
+
},
|
|
138
143
|
});
|
|
139
144
|
|
|
140
145
|
items.forEach((item) => {
|
|
@@ -146,7 +151,7 @@ function generateRSS(appConfig) {
|
|
|
146
151
|
});
|
|
147
152
|
});
|
|
148
153
|
|
|
149
|
-
const result = feed.rss2();
|
|
154
|
+
const result = feed.rss2(); // TODO: make this pluggable
|
|
150
155
|
|
|
151
156
|
resolve(result);
|
|
152
157
|
})
|
|
@@ -154,14 +159,61 @@ function generateRSS(appConfig) {
|
|
|
154
159
|
});
|
|
155
160
|
}
|
|
156
161
|
|
|
157
|
-
function
|
|
158
|
-
|
|
162
|
+
function generateItemRSS({ appConfig, feedUrl, toPublicURL, params }) {
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
const docid = params['id'];
|
|
159
165
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
fetchResult(docid, appConfig, registry)
|
|
167
|
+
.then((body) => {
|
|
168
|
+
const result = body._result;
|
|
169
|
+
const url = toPublicURL(docid);
|
|
170
|
+
const title = result.title.raw;
|
|
171
|
+
const feed = new Feed({
|
|
172
|
+
title,
|
|
173
|
+
description: `Latest changes in ${title}`,
|
|
174
|
+
id: url,
|
|
175
|
+
generator: 'EEA Website',
|
|
176
|
+
link: url,
|
|
177
|
+
feedLinks: {
|
|
178
|
+
rss: feedUrl,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
const items = result['raw_value']['raw']['children'];
|
|
182
|
+
|
|
183
|
+
items.forEach((item) => {
|
|
184
|
+
const date = item.publicationDateForResource?.[0];
|
|
185
|
+
feed.addItem({
|
|
186
|
+
id: `${docid}/${item.id}`,
|
|
187
|
+
title: item.resourceTitleObject.default,
|
|
188
|
+
link: `${url}?activeAccordion=${item.id}`,
|
|
189
|
+
...(date ? { date: new Date(date) } : {}),
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
resolve(feed.rss2());
|
|
194
|
+
})
|
|
195
|
+
.catch(reject);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function make_rssMiddleware(config, generator) {
|
|
200
|
+
function rssMiddleware(req, res, next) {
|
|
201
|
+
const appConfig = registry.searchui['datahub'];
|
|
202
|
+
const feedUrl = `${config.settings.apiPath}${req.path}`;
|
|
203
|
+
|
|
204
|
+
const toPublicURL = (id) =>
|
|
205
|
+
`${config.settings.apiPath}/en/datahub/${viewRouteId}/${id}`;
|
|
206
|
+
|
|
207
|
+
generator({ appConfig, feedUrl, toPublicURL, params: req.params })
|
|
208
|
+
.then((body) => {
|
|
209
|
+
res.setHeader('content-type', 'application/rss+xml');
|
|
210
|
+
res.send(body);
|
|
211
|
+
})
|
|
212
|
+
.catch((body) => {
|
|
213
|
+
res.send({ error: body });
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return rssMiddleware;
|
|
165
217
|
}
|
|
166
218
|
|
|
167
219
|
export default function makeMiddlewares(config) {
|
|
@@ -170,8 +222,15 @@ export default function makeMiddlewares(config) {
|
|
|
170
222
|
middleware.use(express.urlencoded({ extended: true }));
|
|
171
223
|
|
|
172
224
|
middleware.all('**/datahub/sitemap-data.xml', sitemap);
|
|
173
|
-
middleware.all(
|
|
174
|
-
|
|
225
|
+
middleware.all(
|
|
226
|
+
'**/datahub/datahub_rss.xml',
|
|
227
|
+
make_rssMiddleware(config, generateRSS),
|
|
228
|
+
);
|
|
229
|
+
middleware.all(
|
|
230
|
+
`**/datahub/${viewRouteId}/:id/${rssRouteId}`,
|
|
231
|
+
make_rssMiddleware(config, generateItemRSS),
|
|
232
|
+
);
|
|
233
|
+
middleware.all(`**/datahub/${redirectRouteId}/:id`, datasetRedirect);
|
|
175
234
|
middleware.id = 'datahub-middlewares';
|
|
176
235
|
|
|
177
236
|
return middleware;
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import DatahubCardItem from './components/Result/DatahubCardItem';
|
|
|
3
3
|
import DatahubItemView from './components/ItemView/ItemView';
|
|
4
4
|
import { DatahubResultModel } from './config/models';
|
|
5
5
|
import { datahub_results } from './store';
|
|
6
|
+
import { viewRouteId, rssRouteId } from '@eeacms/volto-datahub/constants';
|
|
6
7
|
|
|
7
8
|
function tweakForNLPService(body, config) {
|
|
8
9
|
if (!config.enableNLP) {
|
|
@@ -35,18 +36,22 @@ const applyConfig = (config) => {
|
|
|
35
36
|
// datahub.resultViews[0].factories.item = "DatahubListingViewItem"
|
|
36
37
|
datahub.resultItemModel.factory = 'DatahubResultModel';
|
|
37
38
|
|
|
38
|
-
config.settings.nonContentRoutes.push(
|
|
39
|
-
|
|
39
|
+
config.settings.nonContentRoutes.push(new RegExp(`${viewRouteId}\\/(.*)`));
|
|
40
|
+
const rssRouteIdRegexp = rssRouteId.replace('.', '\\.');
|
|
41
|
+
config.settings.nonContentRoutes.push(
|
|
42
|
+
new RegExp(`/.+/datahub/${rssRouteIdRegexp}`),
|
|
43
|
+
);
|
|
44
|
+
|
|
40
45
|
config.settings.externalRoutes.push({
|
|
41
46
|
match: {
|
|
42
|
-
path:
|
|
47
|
+
path: new RegExp(`/.+/${rssRouteIdRegexp}`),
|
|
43
48
|
strict: true,
|
|
44
49
|
exact: true,
|
|
45
50
|
},
|
|
46
51
|
});
|
|
47
52
|
config.addonRoutes = [
|
|
48
53
|
{
|
|
49
|
-
path:
|
|
54
|
+
path: `*/${viewRouteId}/:id`,
|
|
50
55
|
component: DatahubItemView,
|
|
51
56
|
},
|
|
52
57
|
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const OBSOLETE_KEYS = ['obsolete', 'superseded'];
|
|
2
|
+
|
|
3
|
+
export const isInternalURL = (url) => {
|
|
4
|
+
let internal = false;
|
|
5
|
+
url.split('/').forEach((part) => {
|
|
6
|
+
if (part.split('_')[6] === 'i') {
|
|
7
|
+
internal = true;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return internal;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const isObsolete = (status) => {
|
|
14
|
+
let obsolete = false;
|
|
15
|
+
if (status) {
|
|
16
|
+
if (Array.isArray(status)) {
|
|
17
|
+
if (
|
|
18
|
+
status.filter((stat) => OBSOLETE_KEYS.includes(stat?.key)).length > 0
|
|
19
|
+
) {
|
|
20
|
+
obsolete = true;
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
if (OBSOLETE_KEYS.includes(status?.key)) {
|
|
24
|
+
obsolete = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return obsolete;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const isInternal = (item) => {
|
|
32
|
+
let internal = false;
|
|
33
|
+
const links = item?.link || [];
|
|
34
|
+
links.forEach((link) => {
|
|
35
|
+
if (isInternalURL(link?.url)) {
|
|
36
|
+
internal = true;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return internal;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const groupBy = (obj, key) => {
|
|
43
|
+
return obj.reduce((rv, item) => {
|
|
44
|
+
const group = rv[item[key]] || [];
|
|
45
|
+
group.push(item);
|
|
46
|
+
rv[item[key]] = group;
|
|
47
|
+
return rv;
|
|
48
|
+
}, {});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export function parseDatasets(children) {
|
|
52
|
+
const all_datasets = children.map((v, e) => {
|
|
53
|
+
let date;
|
|
54
|
+
if (v.resourceTemporalExtentDetails) {
|
|
55
|
+
const tc = v.resourceTemporalExtentDetails[0];
|
|
56
|
+
const { start, end } = tc || {};
|
|
57
|
+
const tc_start = start?.date
|
|
58
|
+
? new Date(Date.parse(start.date)).getFullYear()
|
|
59
|
+
: '';
|
|
60
|
+
const tc_end = end?.date
|
|
61
|
+
? new Date(Date.parse(end.date)).getFullYear()
|
|
62
|
+
: '';
|
|
63
|
+
if (tc_start === tc_end) {
|
|
64
|
+
date = tc_start;
|
|
65
|
+
} else {
|
|
66
|
+
date = tc_start + '-' + tc_end;
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
date = '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return Object.assign({ temporalDateRange: date, ...v }, e);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const datasets = all_datasets.filter((v) => {
|
|
76
|
+
return !(isObsolete(v.cl_status) || isInternal(v));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const archivedOrRestrictedDatasets = all_datasets.filter((v) => {
|
|
80
|
+
return isObsolete(v.cl_status) || isInternal(v);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const groupDatasets = (items) => {
|
|
84
|
+
const datasetsByCoverage = groupBy(items, 'temporalDateRange');
|
|
85
|
+
|
|
86
|
+
const sortedDatasets = Object.keys(datasetsByCoverage).sort(function (
|
|
87
|
+
a,
|
|
88
|
+
b,
|
|
89
|
+
) {
|
|
90
|
+
a = Math.max(...a.split('-'));
|
|
91
|
+
b = Math.max(...b.split('-'));
|
|
92
|
+
return b - a;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const groupedDatasets = sortedDatasets.map((v, i) => {
|
|
96
|
+
return { id: i, date: v, children: datasetsByCoverage[v] };
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return groupedDatasets;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const groupedByTemporalCoverage = groupDatasets(datasets);
|
|
103
|
+
const groupedByArchivedOrRestricted = groupDatasets(
|
|
104
|
+
archivedOrRestrictedDatasets,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
all_datasets,
|
|
109
|
+
datasets,
|
|
110
|
+
archivedOrRestrictedDatasets,
|
|
111
|
+
groupedByTemporalCoverage,
|
|
112
|
+
groupedByArchivedOrRestricted,
|
|
113
|
+
};
|
|
114
|
+
}
|