Skip to content

Commit

Permalink
wip optimize source and metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
RudiThoeni committed Feb 28, 2024
1 parent 198bc83 commit a073d81
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 29 deletions.
19 changes: 19 additions & 0 deletions databrowser/src/config/builder/tourism/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PropertyConfig,
SubCategoryElement,
} from '../../../domain/datasets/config/types';
import { withOdhBaseUrl } from '../../utils';

export const sourceSubCategory = (): SubCategoryElement => ({
name: 'Source',
Expand All @@ -19,6 +20,24 @@ export const sourceSubCategory = (): SubCategoryElement => ({
],
});

export const sourceSubCategoryWithDistinct = (
mainentity?: string
): SubCategoryElement => ({
name: 'Source',
properties: [
{
title: 'Source (from api)',
component: CellComponent.InputReferenceCell,
objectMapping: { value: 'Source' },
params: {
url: withOdhBaseUrl('/v1/Source?typelist=' + mainentity),
labelSelector: 'Name.{language}',
keySelector: 'Key',
},
},
],
});

export const sourceTableCell = (): PropertyConfig => ({
title: 'Source',
component: CellComponent.StringCell,
Expand Down
93 changes: 65 additions & 28 deletions databrowser/src/config/tourism/metaData/metaData.sharedView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
idReadOnlyCell,
shortnameCell,
imageGalleryCategory,
licenseInfoCategory,
} from '../../builder/tourism';
import { withOdhBaseUrl } from '../../utils';

Expand Down Expand Up @@ -44,19 +45,6 @@ export const metaDataSharedView = (): DetailViewConfig | EditViewConfig => ({
),
},
},
{
title: 'Category',
component: CellComponent.CustomDataArrayCell,
arrayMapping: {
targetPropertyName: 'listItems',
pathToParent: 'Category',
},
params: {
url: withOdhBaseUrl(
'/v1/Distinct?odhtype=odhmetadata&fields=Category.[*]&rawsort=Category.[*]&getasarray=true'
),
},
},
{
title: 'Data Provider',
component: CellComponent.CustomDataArrayCell,
Expand All @@ -75,6 +63,33 @@ export const metaDataSharedView = (): DetailViewConfig | EditViewConfig => ({
component: CellComponent.ToggleCell,
objectMapping: { enabled: 'Deprecated' },
},
],
},
{
name: 'IDs',
properties: [idReadOnlyCell()],
},
{
name: 'Count',
properties: [
{
title: 'Count',
component: CellComponent.JsonCell,
objectMapping: { data: 'RecordCount' },
params: { usePreformatted: 'true' },
},
],
},
],
},
{
name: 'Api data',
slug: 'api-data',
subcategories: [
{
name: '',
properties: [
shortnameCell({ required: true }),
{
title: 'Base URL',
component: CellComponent.SelectWithOptionsCell,
Expand Down Expand Up @@ -110,11 +125,47 @@ export const metaDataSharedView = (): DetailViewConfig | EditViewConfig => ({
objectMapping: { text: 'ApiUrl' },
params: { readonly: 'true' },
},
{
title: 'Output',
component: CellComponent.DictionaryCell,
objectMapping: {
dictitems: 'Output',
},
},
{
title: 'Swagger URL',
component: CellComponent.UrlCell,
objectMapping: { text: 'SwaggerUrl' },
},
{
title: 'Type',
component: CellComponent.StringCell,
objectMapping: { text: 'Type' },
},
],
},
],
},
{
name: 'Additional data',
slug: 'additional-data',
subcategories: [
{
name: 'General data',
properties: [
{
title: 'Category',
component: CellComponent.CustomDataArrayCell,
arrayMapping: {
targetPropertyName: 'listItems',
pathToParent: 'Category',
},
params: {
url: withOdhBaseUrl(
'/v1/Distinct?odhtype=odhmetadata&fields=Category.[*]&rawsort=Category.[*]&getasarray=true'
),
},
},
{
title: 'Tags',
component: CellComponent.TagReferenceCell,
Expand All @@ -130,23 +181,9 @@ export const metaDataSharedView = (): DetailViewConfig | EditViewConfig => ({
},
],
},
{
name: 'IDs',
properties: [idReadOnlyCell()],
},
{
name: 'Count',
properties: [
{
title: 'Count',
component: CellComponent.JsonCell,
objectMapping: { data: 'RecordCount' },
params: { usePreformatted: 'true' },
},
],
},
],
},
imageGalleryCategory(),
licenseInfoCategory(),
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
seasonCategory,
shortnameCell,
sourceWithInsertsSubCategory,
sourceSubCategoryWithDistinct,
textInfoCategory,
} from '../../builder/tourism';
import { mappingCategory } from '../../builder/tourism/mapping';
Expand Down Expand Up @@ -70,6 +71,7 @@ export const odhActivityPoiSharedView = ():
],
},
]),
sourceSubCategoryWithDistinct('odhactivitypoi'),
],
},
textInfoCategory(),
Expand Down
27 changes: 26 additions & 1 deletion databrowser/src/config/tourism/source/source.sharedView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
lastChangesCell,
licenseInfoCategory,
} from '../../builder/tourism';
import { withOdhBaseUrl } from '../../utils';

export const sourceSharedView = (): DetailViewConfig | EditViewConfig => ({
elements: [
Expand Down Expand Up @@ -44,6 +45,18 @@ export const sourceSharedView = (): DetailViewConfig | EditViewConfig => ({
component: CellComponent.UrlCell,
objectMapping: { text: 'Url' },
},
lastChangesCell(),
],
},
],
},
{
name: 'Details',
slug: 'details',
subcategories: [
{
name: '',
properties: [
{
title: 'Interfaces',
component: CellComponent.ArrayEditableCell,
Expand All @@ -53,7 +66,19 @@ export const sourceSharedView = (): DetailViewConfig | EditViewConfig => ({
},
required: false,
},
lastChangesCell(),
{
title: 'valid for Types',
component: CellComponent.CustomDataArrayCell,
arrayMapping: {
targetPropertyName: 'listItems',
pathToParent: 'Types',
},
params: {
url: withOdhBaseUrl(
'/v1/Distinct?odhtype=odhmetadata&fields=OdhType&getasarray=true&excludenulloremptyvalues=true'
),
},
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
SPDX-FileCopyrightText: NOI Techpark <digital@noi.bz.it>
SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
<EditListCell :items="recordAsItems" @update="update">
<template #table="{ items }">
<DictionaryTable :dictitems="items" />
</template>
</EditListCell>
</template>

<script setup lang="ts">
import { toRefs } from 'vue';
import EditListCell from '../../utils/editList/EditListCell.vue';
import { useRecordSupportForCell } from '../../utils/editList/support/useRecordSupport';
import DictionaryTable from './DictionaryTable.vue';
import { DictionaryEntry } from './types';
const emit = defineEmits(['update']);
const props = defineProps<{ dictitems?: Record<string, string> | null }>();
const { dictitems } = toRefs(props);
const { recordAsItems, update } = useRecordSupportForCell<
string,
DictionaryEntry
>({
record: dictitems,
prop: 'dictitems',
mapRecordToItems: (record) =>
Object.entries(record).map(([key, value]) => ({ key, value })),
mapUpdateToRecord: (items) =>
items.reduce((prev, curr) => ({ ...prev, [curr.key]: curr.value }), {}),
emit,
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!--
SPDX-FileCopyrightText: NOI Techpark <digital@noi.bz.it>
SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
<EditListTable :items="dictitems" :hide-tab-link="true" :hide-sortable="true">
<template #colGroup>
<col class="w-32 md:w-40" />
<col class="w-32 md:w-60" />
</template>

<template #tableHeader>
<TableHeaderCell>Key</TableHeaderCell>
<TableHeaderCell>Value</TableHeaderCell>
</template>

<template #tableCols="{ item, index }">
<TableCell>
<StringCell
:text="item.key"
:editable="editable"
@update="updateItem(index, { key: $event.value, value: item.value })"
/>
</TableCell>
<TableCell>
<StringCell
:text="item.value"
:editable="editable"
@update="updateItem(index, { key: item.key, value: $event.value })"
/>
</TableCell>
</template>
<template #noItems>No items have been defined yet</template>
<template #addItems>
<EditListAddButton
:text="'Add new item'"
@click="addItems([{ key: '' }])"
/>
</template>
</EditListTable>
</template>

<script setup lang="ts">
import { toRefs } from 'vue';
import TableHeaderCell from '../../../../../components/table/TableHeaderCell.vue';
import TableCell from '../../../../../components/table/TableCell.vue';
import EditListTable from '../../utils/editList/table/EditListTable.vue';
import EditListAddButton from '../../utils/editList/EditListAddButton.vue';
import { useInjectActionTriggers } from '../../utils/editList/actions/useActions';
import StringCell from '../stringCell/StringCell.vue';
import { DictionaryEntry } from './types';
import { useRecordSupportForTable } from '../../utils/editList/support/useRecordSupport';
import { useInjectEditMode } from '../../utils/editList/actions/useEditMode';
const props = defineProps<{ dictitems: DictionaryEntry[] }>();
const { dictitems } = toRefs(props);
const { editable } = useInjectEditMode();
const { addItems, updateItem } = useInjectActionTriggers();
useRecordSupportForTable<DictionaryEntry>({
items: dictitems,
duplication: (items, index) => ({ ...items[index], key: '' }),
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: NOI Techpark <digital@noi.bz.it>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

export interface DictionaryEntry {
key: string;
value: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ArticleLinkInfoCell from '../components/cells/articleLinkInfoCell/Article
import ArticleTypeCell from '../components/cells/articleTypeCell/ArticleTypeCell.vue';
import CustomDataArrayCell from '../components/cells/customDataArrayCell/CustomDataArrayCell.vue';
import DateCell from '../components/cells/dateCell/DateCell.vue';
import DictionaryCell from '../components/cells/dictionaryCell/DictionaryCell.vue';
import EditedDateCell from '../components/cells/editedDateCell/EditedDateCell.vue';
import EditImageGalleryCell from '../components/cells/editImageGalleryCell/EditImageGalleryCell.vue';
import EditGpsInfoCell from '../components/cells/editGpsInfoCell/EditGpsInfoCell.vue';
Expand Down Expand Up @@ -69,6 +70,7 @@ export default {
app.component(CellComponent.ArticleTypeCell, ArticleTypeCell);
app.component(CellComponent.DateCell, DateCell);
app.component(CellComponent.CustomDataArrayCell, CustomDataArrayCell);
app.component(CellComponent.DictionaryCell, DictionaryCell);
app.component(CellComponent.EditedDateCell, EditedDateCell);
app.component(CellComponent.EditImageGalleryCell, EditImageGalleryCell);
app.component(CellComponent.EditGpsInfoCell, EditGpsInfoCell);
Expand Down
1 change: 1 addition & 0 deletions databrowser/src/domain/cellComponents/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum CellComponent {
ArticleTypeCell = 'ArticleTypeCell',
CustomDataArrayCell = 'CustomDataArrayCell',
DateCell = 'DateCell',
DictionaryCell = 'DictionaryCell',
EditedDateCell = 'EditedDateCell',
EditImageGalleryCell = 'EditImageGalleryCell',
EditGpsInfoCell = 'EditGpsInfoCell',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const isShowAlwaysComponent = (component: string) => {
component === CellComponent.ToggleCell ||
component === CellComponent.ArticleAdditionalInfoCell ||
component === CellComponent.ArticleLinkInfoCell ||
component === CellComponent.DictionaryCell ||
component === CellComponent.LoadingCell
);
};

0 comments on commit a073d81

Please sign in to comment.