Skip to content

Commit fa107ff

Browse files
committed
3208: Added colibo feed type
1 parent c01afab commit fa107ff

File tree

6 files changed

+196
-28
lines changed

6 files changed

+196
-28
lines changed

src/components/feed-sources/feed-source-form.jsx

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { React } from "react";
2-
import { Button } from "react-bootstrap";
2+
import { Alert, Button } from "react-bootstrap";
33
import { useTranslation } from "react-i18next";
44
import { useNavigate } from "react-router-dom";
55
import PropTypes from "prop-types";
@@ -13,6 +13,7 @@ import FormInput from "../util/forms/form-input";
1313
import CalendarApiFeedType from "./templates/calendar-api-feed-type";
1414
import NotifiedFeedType from "./templates/notified-feed-type";
1515
import EventDatabaseApiFeedType from "./templates/event-database-feed-type";
16+
import ColiboFeedType from "./templates/colibo-feed-type.jsx";
1617

1718
/**
1819
* The feed-source form component.
@@ -47,6 +48,10 @@ function FeedSourceForm({
4748
const { t } = useTranslation("common", { keyPrefix: "feed-source-form" });
4849
const navigate = useNavigate();
4950

51+
const typeInOptions =
52+
!feedSource?.feedType ||
53+
feedSourceTypeOptions.find((el) => el.value === feedSource.feedType);
54+
5055
return (
5156
<>
5257
<Form>
@@ -72,32 +77,62 @@ function FeedSourceForm({
7277
value={feedSource.description}
7378
onChange={handleInput}
7479
/>
75-
<FormSelect
76-
name="feedType"
77-
formGroupClasses="mb-2"
78-
label={t("feed-source-feed-type-label")}
79-
value={feedSource.feedType}
80-
onChange={onFeedTypeChange}
81-
disabled={mode === "PUT"}
82-
options={feedSourceTypeOptions}
83-
/>
80+
{typeInOptions && (
81+
<FormSelect
82+
name="feedType"
83+
formGroupClasses="mb-2"
84+
label={t("feed-source-feed-type-label")}
85+
value={feedSource.feedType}
86+
onChange={onFeedTypeChange}
87+
disabled={mode === "PUT"}
88+
options={feedSourceTypeOptions}
89+
/>
90+
)}
91+
{!typeInOptions && (
92+
<>
93+
<FormInput
94+
name="title"
95+
formGroupClasses="mb-2"
96+
type="text"
97+
disabled
98+
label={t("feed-source-feed-type-label")}
99+
value={feedSource.feedType}
100+
onChange={() => {}}
101+
/>
102+
<Alert className="mt-4" variant="warning">
103+
{t("feed-type-not-supported")}
104+
</Alert>
105+
</>
106+
)}
84107

85-
{feedSource?.feedType === "App\\Feed\\CalendarApiFeedType" && (
108+
{feedSource?.feedType ===
109+
"App\\Feed\\SourceType\\Calendar\\CalendarApiFeedType" && (
86110
<CalendarApiFeedType
87111
handleInput={handleSecretInput}
88112
formStateObject={feedSource.secrets}
89113
mode={mode}
90114
feedSourceId={feedSource["@id"]}
91115
/>
92116
)}
93-
{feedSource?.feedType === "App\\Feed\\EventDatabaseApiFeedType" && (
117+
{feedSource?.feedType ===
118+
"App\\Feed\\SourceType\\Colibo\\ColiboFeedType" && (
119+
<ColiboFeedType
120+
handleInput={handleSecretInput}
121+
formStateObject={feedSource.secrets}
122+
mode={mode}
123+
feedSourceId={feedSource["@id"]}
124+
/>
125+
)}
126+
{feedSource?.feedType ===
127+
"App\\Feed\\SourceType\\EventDatabase\\EventDatabaseApiFeedType" && (
94128
<EventDatabaseApiFeedType
95129
handleInput={handleSecretInput}
96130
formStateObject={feedSource.secrets}
97131
mode={mode}
98132
/>
99133
)}
100-
{feedSource?.feedType === "App\\Feed\\NotifiedFeedType" && (
134+
{feedSource?.feedType ===
135+
"App\\Feed\\SourceType\\Notified\\NotifiedFeedType" && (
101136
<NotifiedFeedType
102137
handleInput={handleSecretInput}
103138
formStateObject={feedSource.secrets}

src/components/feed-sources/feed-source-manager.jsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,42 @@ function FeedSourceManager({
6060

6161
const feedSourceTypeOptions = [
6262
{
63-
value: "App\\Feed\\EventDatabaseApiFeedType",
63+
value: "App\\Feed\\SourceType\\Calendar\\CalendarApiFeedType",
64+
title: t("dynamic-fields.calendar-api-feed-type.title"),
65+
key: "0",
66+
secretsDefault: {
67+
locations: [],
68+
},
69+
},
70+
{
71+
value: "App\\Feed\\SourceType\\Colibo\\ColiboFeedType",
72+
title: t("colibo-feed-type.title"),
73+
key: "5",
74+
secretsDefault: {
75+
api_base_uri: "",
76+
client_id: "",
77+
client_secret: "",
78+
recipients: [],
79+
},
80+
},
81+
{
82+
value: "App\\Feed\\SourceType\\EventDatabase\\EventDatabaseApiFeedType",
6483
title: t("dynamic-fields.event-database-api-feed-type.title"),
6584
key: "1",
6685
secretsDefault: {
6786
host: "",
6887
},
6988
},
7089
{
71-
value: "App\\Feed\\NotifiedFeedType",
90+
value: "App\\Feed\\SourceType\\Notified\\NotifiedFeedType",
7291
title: t("dynamic-fields.notified-feed-type.title"),
7392
key: "2",
7493
secretsDefault: {
7594
token: "",
7695
},
7796
},
7897
{
79-
value: "App\\Feed\\CalendarApiFeedType",
80-
title: t("dynamic-fields.calendar-api-feed-type.title"),
81-
key: "0",
82-
secretsDefault: {
83-
locations: [],
84-
},
85-
},
86-
{
87-
value: "App\\Feed\\RssFeedType",
98+
value: "App\\Feed\\SourceType\\Rss\\RssFeedType",
8899
title: t("dynamic-fields.rss-feed-type.title"),
89100
key: "4",
90101
secretsDefault: {},
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { React, useEffect, useState } from "react";
2+
import PropTypes from "prop-types";
3+
import { useTranslation } from "react-i18next";
4+
import { Alert } from "react-bootstrap";
5+
import MultiselectFromEndpoint from "../../slide/content/multiselect-from-endpoint";
6+
import ConfigLoader from "../../../config-loader";
7+
import FormInput from "../../util/forms/form-input.jsx";
8+
9+
const ColiboFeedType = ({
10+
feedSourceId,
11+
handleInput,
12+
formStateObject,
13+
mode,
14+
}) => {
15+
const { t } = useTranslation("common", {
16+
keyPrefix: "colibo-feed-type",
17+
});
18+
19+
const [optionsEndpoint, setOptionsEndpoint] = useState(null);
20+
21+
useEffect(() => {
22+
if (feedSourceId && feedSourceId !== "") {
23+
ConfigLoader.loadConfig().then((config) => {
24+
let endpoint = config.api;
25+
endpoint = endpoint.replace(/\/$/, "");
26+
endpoint += feedSourceId;
27+
endpoint += "/config/FeedEntryRecipients";
28+
29+
setOptionsEndpoint(endpoint);
30+
});
31+
}
32+
}, [feedSourceId]);
33+
34+
return (
35+
<>
36+
{!feedSourceId && (
37+
<Alert className="mt-4" variant="warning">
38+
{t("save-before-recipients-can-be-set")}
39+
</Alert>
40+
)}
41+
42+
<FormInput
43+
name="api_base_uri"
44+
type="text"
45+
label={t("api-base-uri")}
46+
className="mb-2"
47+
onChange={handleInput}
48+
placeholder={
49+
mode === "PUT" ? t("redacted-value-input-placeholder") : ""
50+
}
51+
value={formStateObject?.api_base_uri}
52+
/>
53+
54+
<FormInput
55+
name="client_id"
56+
type="text"
57+
className="mb-2"
58+
label={t("client-id")}
59+
onChange={handleInput}
60+
placeholder={
61+
mode === "PUT" ? t("redacted-value-input-placeholder") : ""
62+
}
63+
value={formStateObject?.client_id}
64+
/>
65+
66+
<FormInput
67+
name="client_secret"
68+
type="text"
69+
label={t("client-secret")}
70+
onChange={handleInput}
71+
placeholder={
72+
mode === "PUT" ? t("redacted-value-input-placeholder") : ""
73+
}
74+
value={formStateObject?.client_secret}
75+
/>
76+
77+
<Alert className="mt-4" variant="info">
78+
{t("values-info")}
79+
</Alert>
80+
81+
{optionsEndpoint && (
82+
<MultiselectFromEndpoint
83+
onChange={handleInput}
84+
name="recipients"
85+
disableSearch={false}
86+
label={t("recipients")}
87+
value={formStateObject.recipients ?? []}
88+
optionsEndpoint={optionsEndpoint}
89+
/>
90+
)}
91+
</>
92+
);
93+
};
94+
95+
ColiboFeedType.propTypes = {
96+
handleInput: PropTypes.func,
97+
formStateObject: PropTypes.shape({
98+
api_base_uri: PropTypes.string,
99+
client_id: PropTypes.string,
100+
client_secret: PropTypes.string,
101+
recipients: PropTypes.arrayOf(PropTypes.string),
102+
}),
103+
feedSourceId: PropTypes.string,
104+
mode: PropTypes.string,
105+
};
106+
107+
export default ColiboFeedType;

src/components/slide/content/content-form.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function ContentForm({
7272
}
7373

7474
returnElement = (
75-
<div key={formData.key}>
75+
<div key={formData.key} className={formData.formGroupClasses}>
7676
{formData?.label && (
7777
<label htmlFor={formData.name} className="form-label">
7878
{formData.label}

src/components/slide/content/feed-selector.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ function FeedSelector({
123123
value={getValueFromConfiguration(element.name)}
124124
label={element.label}
125125
optionsEndpoint={element.endpoint}
126-
singleSelect={formElement.singleSelect ?? false}
126+
disableSearch={element.disableSearch ?? false}
127+
singleSelect={element.singleSelect ?? false}
127128
/>
128129
);
129130
}

src/translations/da/common.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@
261261
"save-feed-source-error": "Der skete en fejl da feed source skulle gemmes:",
262262
"load-feed-source-error": "Der skete en fejl da feed source med følgende id: {{id}} skulle hentes:"
263263
},
264+
"colibo-feed-type": {
265+
"title": "Colibo"
266+
},
264267
"dynamic-fields": {
265268
"event-database-api-feed-type": {
266269
"title": "Eventdatabase API",
@@ -273,20 +276,21 @@
273276
"redacted-value-input-placeholder": "Skjult værdi"
274277
},
275278
"calendar-api-feed-type": {
276-
"title": "Kalender feed",
279+
"title": "Kalender",
277280
"locations": "Lokationer",
278281
"redacted-value-input-placeholder": "Skjult værdi",
279282
"save-before-locations-can-be-set": "Bemærk! Datakilden skal gemmes før der kan tilkobles lokationer. Gem og åbn datakilden igen."
280283
},
281284
"rss-feed-type": {
282-
"title": "RSS feed"
285+
"title": "RSS"
283286
}
284287
}
285288
},
286289
"feed-source-form": {
287290
"feed-source-name-label": "Navn",
288291
"feed-source-description-label": "Beskrivelse",
289292
"feed-source-feed-type-label": "Type",
293+
"feed-type-not-supported": "Typen understøttes ikke af administrationen.",
290294
"save-button": "Gem datakilde",
291295
"cancel-button": "Annuller"
292296
},
@@ -1075,5 +1079,15 @@
10751079
"active": "Aktiv",
10761080
"future": "Fremtidig",
10771081
"expired": "Udløbet"
1082+
},
1083+
"colibo-feed-type": {
1084+
"title": "Colibo feed",
1085+
"api-base-uri": "API Base URI",
1086+
"client-id": "Client ID",
1087+
"client-secret": "Client Secret",
1088+
"values-info": "Værdierne Client ID og Client Secret findes ved at oprette en API klient i \"Systemadministration\" -> \"API adgangshåndtering\" i Colibo intranet.",
1089+
"recipients": "Modtagergrupper",
1090+
"redacted-value-input-placeholder": "Skjult værdi",
1091+
"save-before-recipients-can-be-set": "Bemærk! Datakilden skal gemmes før der kan tilkobles modtagergrupper. Gem og åbn datakilden igen."
10781092
}
10791093
}

0 commit comments

Comments
 (0)