From 9f7e625d5ee4fc2340222c4c34ce377e6734b0bb Mon Sep 17 00:00:00 2001 From: Matteo Biasi Date: Sat, 4 Feb 2023 23:31:59 +0100 Subject: [PATCH] feat: refactored QuickView in minor components to support setup through config file --- .../quickview/QuickViewCardOverview.vue | 2 +- .../quickview/QuickViewContactsCard.vue | 103 ++++ .../components/quickview/QuickViewMapView.vue | 70 +++ .../quickview/QuickViewOpeningHoursView.vue | 124 +++++ .../quickview/QuickViewRecordInfoView.vue | 88 ++++ .../quickview/QuickViewTextInfoCard.vue | 50 ++ .../components/quickview/QuickViewUtils.ts | 11 + .../quickview/QuickViewWebcamsView.vue | 52 ++ .../odhActivityPoi.quickView.ts | 53 +- databrowser/src/domain/datasetConfig/types.ts | 24 +- .../domain/datasets/quickView/QuickView.vue | 466 +++++------------- 11 files changed, 668 insertions(+), 375 deletions(-) create mode 100644 databrowser/src/components/quickview/QuickViewContactsCard.vue create mode 100644 databrowser/src/components/quickview/QuickViewMapView.vue create mode 100644 databrowser/src/components/quickview/QuickViewOpeningHoursView.vue create mode 100644 databrowser/src/components/quickview/QuickViewRecordInfoView.vue create mode 100644 databrowser/src/components/quickview/QuickViewTextInfoCard.vue create mode 100644 databrowser/src/components/quickview/QuickViewUtils.ts create mode 100644 databrowser/src/components/quickview/QuickViewWebcamsView.vue diff --git a/databrowser/src/components/quickview/QuickViewCardOverview.vue b/databrowser/src/components/quickview/QuickViewCardOverview.vue index 6fda4c2de..9abd00ca9 100644 --- a/databrowser/src/components/quickview/QuickViewCardOverview.vue +++ b/databrowser/src/components/quickview/QuickViewCardOverview.vue @@ -84,7 +84,7 @@ import TagCustom from '../tag/TagCustom.vue'; defineProps<{ title?: string; - sections: Array; + sections: Array; contentHasNoPadding?: Boolean; ctaIcon?: string; }>(); diff --git a/databrowser/src/components/quickview/QuickViewContactsCard.vue b/databrowser/src/components/quickview/QuickViewContactsCard.vue new file mode 100644 index 000000000..c71cf81a4 --- /dev/null +++ b/databrowser/src/components/quickview/QuickViewContactsCard.vue @@ -0,0 +1,103 @@ + + diff --git a/databrowser/src/components/quickview/QuickViewMapView.vue b/databrowser/src/components/quickview/QuickViewMapView.vue new file mode 100644 index 000000000..3dbdba129 --- /dev/null +++ b/databrowser/src/components/quickview/QuickViewMapView.vue @@ -0,0 +1,70 @@ + + diff --git a/databrowser/src/components/quickview/QuickViewOpeningHoursView.vue b/databrowser/src/components/quickview/QuickViewOpeningHoursView.vue new file mode 100644 index 000000000..131cc8c22 --- /dev/null +++ b/databrowser/src/components/quickview/QuickViewOpeningHoursView.vue @@ -0,0 +1,124 @@ + + diff --git a/databrowser/src/components/quickview/QuickViewRecordInfoView.vue b/databrowser/src/components/quickview/QuickViewRecordInfoView.vue new file mode 100644 index 000000000..93c7ccd2c --- /dev/null +++ b/databrowser/src/components/quickview/QuickViewRecordInfoView.vue @@ -0,0 +1,88 @@ + + diff --git a/databrowser/src/components/quickview/QuickViewTextInfoCard.vue b/databrowser/src/components/quickview/QuickViewTextInfoCard.vue new file mode 100644 index 000000000..6a1b9bd11 --- /dev/null +++ b/databrowser/src/components/quickview/QuickViewTextInfoCard.vue @@ -0,0 +1,50 @@ + + diff --git a/databrowser/src/components/quickview/QuickViewUtils.ts b/databrowser/src/components/quickview/QuickViewUtils.ts new file mode 100644 index 000000000..84541721d --- /dev/null +++ b/databrowser/src/components/quickview/QuickViewUtils.ts @@ -0,0 +1,11 @@ +export const getValueOfLocale = (currentLocale: string, obj: any) => { + // Note: function can be moved as utils + const fallbackLocale = 'en'; + + return obj?.[currentLocale] || obj?.[fallbackLocale]; +}; + +export const getTextValue = (value?: String) => { + // Note: function can be moved as utils + return value ?? '/'; +}; diff --git a/databrowser/src/components/quickview/QuickViewWebcamsView.vue b/databrowser/src/components/quickview/QuickViewWebcamsView.vue new file mode 100644 index 000000000..d1b0c7079 --- /dev/null +++ b/databrowser/src/components/quickview/QuickViewWebcamsView.vue @@ -0,0 +1,52 @@ + + diff --git a/databrowser/src/config/tourism/odhActivityPoi/odhActivityPoi.quickView.ts b/databrowser/src/config/tourism/odhActivityPoi/odhActivityPoi.quickView.ts index b87d538c7..e7e7cf952 100644 --- a/databrowser/src/config/tourism/odhActivityPoi/odhActivityPoi.quickView.ts +++ b/databrowser/src/config/tourism/odhActivityPoi/odhActivityPoi.quickView.ts @@ -1,29 +1,64 @@ import { QuickViewConfig, - QuickViewSectionType, + QuickViewSectionComponent, } from '../../../domain/datasetConfig/types'; export const odhActivityPoiQuickView: QuickViewConfig = { - showTopGallery: true, + topGallery: { + isVisible: true, + fields: { + gallery: 'ImageGallery', + }, + }, elements: [ { - sectionType: QuickViewSectionType.INFO, + component: QuickViewSectionComponent.INFO, + fields: { + header: 'Detail.{language}.Header', + subHeader: 'Detail.{language}.SubHeader', + introText: 'Detail.{language}.IntroText', + }, }, { - sectionType: QuickViewSectionType.CONTACTS, + component: QuickViewSectionComponent.CONTACTS, + fields: { + companyName: 'ContactInfos.{language}.CompanyName', + givenName: 'ContactInfos.{language}.Givenname', + surname: 'ContactInfos.{language}.Surname', + address: 'ContactInfos.{language}.Address', + city: 'ContactInfos.{language}.City', + zipCode: 'ContactInfos.{language}.ZipCode', + countryName: 'ContactInfos.{language}.CountryName', + email: 'ContactInfos.{language}.Email', + phoneNumber: 'ContactInfos.{language}.Phonenumber', + url: 'ContactInfos.{language}.Url', + }, }, { - sectionType: QuickViewSectionType.WEBCAMS, + component: QuickViewSectionComponent.WEBCAMS, + fields: { + webcamsMediaItems: 'Webcam', + }, }, { - sectionType: QuickViewSectionType.MAP, - // NOTE: here can be added eg. custom default zoom etc. + component: QuickViewSectionComponent.MAP, + fields: { + gpsInfo: 'GpsInfo', + }, }, { - sectionType: QuickViewSectionType.OPENING_HORUS, + component: QuickViewSectionComponent.OPENING_HORUS, + fields: { + scheduleData: 'OperationSchedule', + }, }, { - sectionType: QuickViewSectionType.RECORD_INFO, + component: QuickViewSectionComponent.RECORD_INFO, + fields: { + lastUpdate: '_Meta.LastUpdate', + active: 'Active', + odhActive: 'OdhActive', + }, }, ], }; diff --git a/databrowser/src/domain/datasetConfig/types.ts b/databrowser/src/domain/datasetConfig/types.ts index aa82321e7..d21d518a3 100644 --- a/databrowser/src/domain/datasetConfig/types.ts +++ b/databrowser/src/domain/datasetConfig/types.ts @@ -31,16 +31,17 @@ export interface DetailElements { } export interface QuickViewElements { - sectionType: QuickViewSectionType; + component: QuickViewSectionComponent; + fields: Record; } -export enum QuickViewSectionType { - INFO, - CONTACTS, - WEBCAMS, - MAP, - OPENING_HORUS, - RECORD_INFO, +export enum QuickViewSectionComponent { + INFO = 'QuickViewTextInfoCard', + CONTACTS = 'QuickViewContactsCard', + WEBCAMS = 'QuickViewWebcamsView', + MAP = 'QuickViewMapView', + OPENING_HORUS = 'QuickViewOpeningHoursView', + RECORD_INFO = 'QuickViewRecordInfoView', } export interface EditElements { @@ -86,9 +87,14 @@ export interface DetailViewElements { elements: DetailElements[]; } export interface QuickViewPageConfig { - showTopGallery: Boolean; + topGallery: QuickViewTopGallery; elements: QuickViewElements[]; } + +export interface QuickViewTopGallery { + isVisible: boolean; + fields: Record; +} export interface EditViewElements { elements: EditElements[]; } diff --git a/databrowser/src/domain/datasets/quickView/QuickView.vue b/databrowser/src/domain/datasets/quickView/QuickView.vue index eaf854e09..e821c4392 100644 --- a/databrowser/src/domain/datasets/quickView/QuickView.vue +++ b/databrowser/src/domain/datasets/quickView/QuickView.vue @@ -19,7 +19,7 @@
-
+
+
- + - - - - - - - - - + -
+
@@ -120,28 +136,33 @@ import { useI18n } from 'vue-i18n'; import { useApiReadForCurrentDataset } from '../../api'; import { odhActivityPoiConfig } from '../../../config/tourism/odhActivityPoi/odhActivityPoi.config'; // TODO: check if it's the right way to import the file -import { QuickViewSectionType } from '../../../domain/datasetConfig/types'; +import { QuickViewSectionComponent } from '../../../domain/datasetConfig/types'; import PageContent from '../../../components/content/PageContent.vue'; import TagCustom from '../../../components/tag/TagCustom.vue'; -import MapBase from '../../../components/map/MapBase.vue'; -import QuickViewCardOverview from '../../../components/quickview/QuickViewCardOverview.vue'; -import QuickViewCardOverviewGallery from '../../../components/quickview/QuickViewCardOverviewGallery.vue'; import QuickViewFullscreenGallery from '../../../components/quickview/QuickViewFullscreenGallery.vue'; +import { getValueOfLocale } from '../../../components/quickview/QuickViewUtils'; + import ShowApiError from '../../api/components/ShowApiError.vue'; +import QuickViewTextInfoCard from '../../../components/quickview/QuickViewTextInfoCard.vue'; +import QuickViewContactsCard from '../../../components/quickview/QuickViewContactsCard.vue'; +import QuickViewWebcamsView from '../../../components/quickview/QuickViewWebcamsView.vue'; +import QuickViewMapView from '../../../components/quickview/QuickViewMapView.vue'; +import QuickViewOpeningHoursView from '../../../components/quickview/QuickViewOpeningHoursView.vue'; +import QuickViewRecordInfoView from '../../../components/quickview/QuickViewRecordInfoView.vue'; + +// import ComponentRenderer from '../../../components/componentRenderer/ComponentRenderer.vue'; const { isError, isSuccess, error, data } = useApiReadForCurrentDataset(); let forcePlaceholderImage = ref(false); -const mapComponent = ref(null); - const { t, locale } = useI18n(); const currentLocale = locale.value; const title = computed(() => { - return getValueOfLocale(data.value.Detail)?.Title || '/'; + return getValueOfLocale(currentLocale, data.value.Detail)?.Title || '/'; }); const id = computed(() => { @@ -149,20 +170,20 @@ const id = computed(() => { }); const hasImage = computed(() => { - return data.value.ImageGallery?.[0]?.ImageUrl?.length > 0; + return imageGallery.value?.ImageUrl?.length > 0; }); const mainImage = computed(() => { - if (!data.value.ImageGallery) { + if (!imageGallery.value) { return null; } - const firstImage = data.value.ImageGallery?.[0]; + const firstImage = imageGallery.value?.[0]; return firstImage?.ImageUrl && !forcePlaceholderImage.value ? { url: firstImage.ImageUrl, - desc: getValueOfLocale(firstImage.ImageDesc), + desc: getValueOfLocale(currentLocale, firstImage.ImageDesc), } : { url: 'https://via.placeholder.com/700x350?text=Missing+image', @@ -171,318 +192,51 @@ const mainImage = computed(() => { }); const imageGallery = computed(() => { - return data.value.ImageGallery || []; -}); - -const mediaItems = computed(() => { - // FIXME: check Webcam returning values - return data.value?.Webcam || getPlaceholderMediaItems(); + return ( + data.value[odhActivityPoiConfig.views?.quick?.topGallery?.fields.gallery] || + [] + ); }); const logoUrl = computed(() => { - return getValueOfLocale(data.value.ContactInfos)?.LogoUrl; + return getValueOfLocale(currentLocale, data.value.ContactInfos)?.LogoUrl; }); -const getPlaceholderMediaItems = () => { - const items = []; - - for (let index = 0; index < 5; index++) { - items.push({ - type: 'IMAGE', - url: `https://picsum.photos/1280/720`, - name: `Immagine di test ${index}`, - }); - } - items.push({ - type: 'VIDEO', - url: `http://techslides.com/demos/sample-videos/small.mp4`, - name: `Video di test`, - }); - - return items; +const onMainImageError = () => { + forcePlaceholderImage.value = true; }; + -const textInformationSections = computed(() => { - const details = getValueOfLocale(data.value.Detail); - return [ - { - content: [ - { - title: 'Header', - text: getTextValue(details?.Header), - }, - { - title: 'Subheader', - text: getTextValue(details?.SubHeader), - }, - { - title: 'Introtext', - text: getTextValue(details?.IntroText), - }, - ], - }, - ]; -}); - -const contactSections = computed(() => { - const details = getValueOfLocale(data.value.ContactInfos); - return [ - { - icon: 'IconDocument', - content: [ - { - title: t('datasets.quickView.nameCompanyName'), - text: getTextValue(details?.CompanyName), - }, - { - title: t('datasets.quickView.firstName'), - text: getTextValue(details?.Givenname), - }, - { - title: t('datasets.quickView.surname'), - text: getTextValue(details?.Surname), - }, - ], - }, - { - icon: 'IconBuilding', - content: [ - { - title: t('datasets.quickView.streetAndNumber'), - text: getTextValue(details?.Address), - }, - { - title: t('datasets.quickView.city'), - text: getTextValue(details?.City), - }, - { - title: t('datasets.quickView.zip'), - text: getTextValue(details?.ZipCode), - }, - { - title: t('datasets.quickView.country'), - text: getTextValue(details?.CountryName), - }, - ], - }, - { - icon: 'IconPhonebook', - content: [ - { - title: t('datasets.quickView.email'), - text: getTextValue(details?.Email), - }, - { - title: t('datasets.quickView.phoneNumber'), - text: getTextValue(details?.Phonenumber), - }, - { - title: t('datasets.quickView.webUrl'), - text: getTextValue(details?.Url), - }, - ], - }, - ]; -}); - -const recordInformationSections = computed(() => { - const lastUpdate = data?.value?._Meta?.LastUpdate; - - if (!lastUpdate) { - return []; - } - - const lastUpdateDate = new Date(lastUpdate).toISOString(); - const [year, month, day] = lastUpdateDate.split('T')[0].split('-'); - - const isSourceActive = data.value.Active; - const isODHActive = data.value.OdhActive; +