-
+
{{ resultTitle(pushResult) }}
{{ resultDescription(pushResult) }}
-
+
{{
t('components.pushData.result.pushResultId', {
- id: pushResult.pushResult.id,
+ id: pushResult.pushResponse.id,
})
}}
@@ -38,19 +38,19 @@ SPDX-License-Identifier: AGPL-3.0-or-later
import { useI18n } from 'vue-i18n';
import IconCheckCircle from '../../../../../components/svg/IconCheckCircle.vue';
import IconExclamationMark from '../../../../../components/svg/IconExclamationMark.vue';
-import { PublisherWithPushResult } from './types';
+import { PublisherWithPushResponse } from './types';
const { t } = useI18n();
-defineProps<{ pushResults: PublisherWithPushResult[] }>();
+defineProps<{ pushResults: PublisherWithPushResponse[] }>();
-const resultTitle = (pushResult: PublisherWithPushResult) =>
- pushResult.pushResult.success
- ? t('components.pushData.result.successTitle', { name: pushResult.name })
- : t('components.pushData.result.errorTitle', { name: pushResult.name });
+const resultTitle = ({ name, pushResponse }: PublisherWithPushResponse) =>
+ pushResponse.success
+ ? t('components.pushData.result.successTitle', { name })
+ : t('components.pushData.result.errorTitle', { name });
-const resultDescription = (pushResult: PublisherWithPushResult) =>
- pushResult.pushResult.success
+const resultDescription = ({ pushResponse }: PublisherWithPushResponse) =>
+ pushResponse.success
? t('components.pushData.result.successDescription')
- : pushResult.pushResult.error;
+ : pushResponse.error;
diff --git a/databrowser/src/domain/cellComponents/components/cells/pushDataCell/lastPush.ts b/databrowser/src/domain/cellComponents/components/cells/pushDataCell/lastPush.ts
new file mode 100644
index 00000000..80724932
--- /dev/null
+++ b/databrowser/src/domain/cellComponents/components/cells/pushDataCell/lastPush.ts
@@ -0,0 +1,77 @@
+// SPDX-FileCopyrightText: NOI Techpark
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import { formatDistanceToNow, format as formatFn } from 'date-fns';
+import { MaybeRef, computed, toValue } from 'vue';
+import {
+ DEFAULT_DATE_TIME_FORMAT,
+ withOdhBaseUrl,
+} from '../../../../../config/utils';
+import { useApiRead } from '../../../../api/useApi';
+import { WithTourismPagination } from '../../../../datasets/pagination/types';
+import { OdhPushResponse, PushResponseData } from './types';
+
+// Send push notifications to publishers
+export const useLastPushResponse = (id: MaybeRef) => {
+ const url = computed(() => {
+ const idValue = toValue(id);
+ return idValue == null
+ ? undefined
+ : // Fetch last push info for the given id
+ withOdhBaseUrl(
+ `/v1/PushResponse?pagesize=1&pagenumber=1&rawsort=-Date&rawfilter=and(eq(PushObject.Id,'${idValue}'))`
+ );
+ });
+
+ const { data, error, isLoading, isError, refetch } =
+ useApiRead>(url);
+
+ const pushResponse = computed(() => {
+ if (data.value == null) {
+ return { state: 'empty' };
+ }
+
+ if (data.value.TotalResults === 0) {
+ return {
+ state: 'info',
+ message: 'No data available',
+ };
+ }
+
+ const odhPushResponse = data.value.Items[0];
+
+ return {
+ state: 'ok',
+ id: odhPushResponse.Id,
+ ...buildDateInfo(odhPushResponse.Date),
+ };
+ });
+
+ return { pushResponse, error, isLoading, isError, refetch };
+};
+
+const buildDateInfo = (dateAsString: string | undefined) => {
+ if (dateAsString == null) {
+ return {
+ date: undefined,
+ dateAgo: undefined,
+ dateFormatted: 'unknown',
+ };
+ }
+
+ const date = new Date(dateAsString);
+
+ const pushResponseDate = formatFn(date, DEFAULT_DATE_TIME_FORMAT);
+
+ const pushResponseDateAgo = formatDistanceToNow(date, {
+ addSuffix: true,
+ includeSeconds: true,
+ });
+
+ return {
+ date: pushResponseDate,
+ dateAgo: pushResponseDateAgo,
+ dateFormatted: `${pushResponseDate} (${pushResponseDateAgo})`,
+ };
+};
diff --git a/databrowser/src/domain/cellComponents/components/cells/pushDataCell/pushNotification.ts b/databrowser/src/domain/cellComponents/components/cells/pushDataCell/pushNotification.ts
index 0fa32d55..96d30340 100644
--- a/databrowser/src/domain/cellComponents/components/cells/pushDataCell/pushNotification.ts
+++ b/databrowser/src/domain/cellComponents/components/cells/pushDataCell/pushNotification.ts
@@ -7,11 +7,42 @@ import { axiosWithMaybeAuth } from '../../../../api/apiAuth';
import {
OdhPushResponseMany,
Publisher,
- PublisherWithPushResult,
+ PublisherWithPushResponse,
} from './types';
+import { MaybeRef, ref, toValue } from 'vue';
type PushNotificationResponse = AxiosResponse;
+export const useSendPushNotifications = (
+ selectedPublishers: MaybeRef
+) => {
+ // It is not possible to send push notifications when they are already sent, until the popup is closed
+ const isPushed = ref(false);
+
+ // Array of push results that is updated when the push notifications are sent
+ const publishersWithPushResponse = ref([]);
+
+ // Send push notifications to publishers
+ const sendPushes = async () => {
+ try {
+ publishersWithPushResponse.value = await sendPushNotifications(
+ toValue(selectedPublishers)
+ );
+ } catch (err) {
+ console.error(err);
+ publishersWithPushResponse.value = [];
+ }
+
+ isPushed.value = true;
+ };
+
+ return {
+ isPushed,
+ publishersWithPushResponse,
+ sendPushes,
+ };
+};
+
// Send push notifications to publishers
export const sendPushNotifications = async (publishers: Publisher[]) => {
// Get the axios instance with authentication
@@ -30,7 +61,7 @@ export const sendPushNotifications = async (publishers: Publisher[]) => {
// Wait for all push notifications to be sent and build the result
return Promise.allSettled(mutatePromises).then((response) =>
- publishers.map((publisher, index) =>
+ publishers.map((publisher, index) =>
buildPushResult(publisher, response[index])
)
);
@@ -39,13 +70,13 @@ export const sendPushNotifications = async (publishers: Publisher[]) => {
const buildPushResult = (
publisher: Publisher,
promiseResult: PromiseSettledResult
-): PublisherWithPushResult => {
+): PublisherWithPushResponse => {
// Handle request errors
if (promiseResult.status === 'rejected') {
const error = getErrorMessage(promiseResult.reason);
return {
...publisher,
- pushResult: {
+ pushResponse: {
success: false,
error,
},
@@ -56,7 +87,7 @@ const buildPushResult = (
const result = promiseResult.value.data[publisher.id];
return {
...publisher,
- pushResult: {
+ pushResponse: {
id: result.Id,
date: result.Date,
success: result.Result.Success,
diff --git a/databrowser/src/domain/cellComponents/components/cells/pushDataCell/types.ts b/databrowser/src/domain/cellComponents/components/cells/pushDataCell/types.ts
index bcac4ed8..31a70644 100644
--- a/databrowser/src/domain/cellComponents/components/cells/pushDataCell/types.ts
+++ b/databrowser/src/domain/cellComponents/components/cells/pushDataCell/types.ts
@@ -9,13 +9,15 @@ export interface Publisher {
url: string;
}
-export interface PublisherWithPushResult extends Publisher {
- pushResult: {
- success: boolean;
- id?: string;
- date?: string;
- error?: string;
- };
+export interface PushResponse {
+ success: boolean;
+ id?: string;
+ date?: string;
+ error?: string;
+}
+
+export interface PublisherWithPushResponse extends Publisher {
+ pushResponse: PushResponse;
}
export interface OdhPushResponse {
@@ -35,3 +37,12 @@ export interface OdhPushResponse {
}
export type OdhPushResponseMany = Record;
+
+export interface PushResponseData {
+ state: 'empty' | 'info' | 'ok' | 'error';
+ id?: string;
+ date?: string;
+ dateAgo?: string;
+ dateFormatted?: string;
+ message?: string;
+}
diff --git a/databrowser/src/locales/en.json b/databrowser/src/locales/en.json
index f0cb3731..7e223b82 100644
--- a/databrowser/src/locales/en.json
+++ b/databrowser/src/locales/en.json
@@ -323,8 +323,7 @@
"title": "Information on last push.",
"sentAt": "Last Push: {date}",
"pushResponseId": "ID: {id}",
- "error": "Error: {error}",
- "sentAtUnknown": "unknown"
+ "error": "Error: {error}"
},
"popup": {
"buttonAfterSend": "Push-Notifications sent",