Skip to content

Commit

Permalink
Merge pull request #8 from gisktzh/feature/gb3-1674-metadata-nullable…
Browse files Browse the repository at this point in the history
…-handling

fix breaking changes from api v2 update
  • Loading branch information
TIL-EBP authored Oct 16, 2024
2 parents 841e484 + 4b7988a commit e6e730d
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span class="data-display__item__value">
@switch (element.type) {
@case ('text') {
<span [innerHTML]="element.value ?? '-'"></span>
<span [innerHTML]="element.value | textOrPlaceholder"></span>
}
@case ('url') {
@if (element.value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Component, Input} from '@angular/core';
import {DataDisplayElement} from '../../types/data-display-element.type';
import {NgForOf} from '@angular/common';
import {TextOrPlaceholderPipe} from '../../../shared/pipes/text-or-placeholder.pipe';

@Component({
selector: 'data-display',
standalone: true,
imports: [NgForOf],
imports: [NgForOf, TextOrPlaceholderPipe],
templateUrl: './data-display.component.html',
styleUrls: ['./data-display.component.scss'],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
</tr>
@for (attribute of attributes; track attribute.name) {
<tr class="dataset-element-table__table__row">
<td class="dataset-element-table__table__row__column">{{ attribute.name }}</td>
<td class="dataset-element-table__table__row__column" [innerHTML]="attribute.description | formatLineBreaks"></td>
<td class="dataset-element-table__table__row__column">{{ attribute.type }}</td>
<td class="dataset-element-table__table__row__column">{{ attribute.unit }}</td>
<td class="dataset-element-table__table__row__column">{{ attribute.name | textOrPlaceholder }}</td>
<td
class="dataset-element-table__table__row__column"
[innerHTML]="attribute.description | textOrPlaceholder | formatLineBreaks"
></td>
<td class="dataset-element-table__table__row__column">{{ attribute.type | textOrPlaceholder }}</td>
<td class="dataset-element-table__table__row__column">{{ attribute.unit | textOrPlaceholder }}</td>
</tr>
}
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import {Component, Input} from '@angular/core';
import {LayerAttributes} from '../../../../shared/interfaces/layer-attributes.interface';
import {NgForOf} from '@angular/common';
import {FormatLineBreaksPipe} from '../../../../shared/pipes/format-line-breaks.pipe';
import {TextOrPlaceholderPipe} from '../../../../shared/pipes/text-or-placeholder.pipe';

@Component({
selector: 'dataset-element-table',
standalone: true,
imports: [NgForOf, FormatLineBreaksPipe],
imports: [NgForOf, FormatLineBreaksPipe, TextOrPlaceholderPipe],
templateUrl: './dataset-element-table.component.html',
styleUrl: './dataset-element-table.component.scss',
})
Expand Down
4 changes: 2 additions & 2 deletions src/app/data-catalogue/utils/data-extraction.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('DataExtractionUtils', () => {
zipCode: 2222,
poBox: null,
section: null,
url: 'https://www.example.com',
url: {href: 'https://www.example.com'},
};

const result = DataExtractionUtils.extractContactElements(mockContact);
Expand All @@ -36,7 +36,7 @@ describe('DataExtractionUtils', () => {
{title: 'Tel', value: mockContact.phone, type: 'text'},
{title: 'Tel direkt', value: mockContact.phoneDirect, type: 'text'},
{title: 'E-Mail', value: mockContact.email, type: 'url'},
{title: 'www', value: {href: mockContact.url}, type: 'url'},
{title: 'www', value: mockContact.url, type: 'url'},
];
expect(result).toEqual(expected);
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/data-catalogue/utils/data-extraction.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class DataExtractionUtils {
{title: 'Tel', value: contact.phone, type: 'text'},
{title: 'Tel direkt', value: contact.phoneDirect, type: 'text'},
{title: 'E-Mail', value: contact.email, type: 'url'},
{title: 'www', value: {href: contact.url}, type: 'url'},
{title: 'www', value: contact.url, type: 'url'},
];
}
}
4 changes: 2 additions & 2 deletions src/app/shared/interfaces/gb3-metadata.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export interface DepartmentalContact {
village: string;
phone: string;
phoneDirect: string;
email: LinkObject;
url: string;
email: LinkObject | null;
url: LinkObject | null;
}

interface BaseMetadataInterface {
Expand Down
6 changes: 3 additions & 3 deletions src/app/shared/interfaces/layer-attributes.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface LayerAttributes {
name: string;
description: string;
type: string;
name: string | null;
description: string | null;
type: string | null;
unit: string | null;
}
82 changes: 42 additions & 40 deletions src/app/shared/models/gb3-api-generated.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ export interface MetadataDatasets {
datasets: Dataset[];
}

export interface MetadataGeoshopProducts {
geoshop_products?: {
/** Geoshop product ID */
giszhnr: number;
/** Link auf Geodatashop bei NOGD-Daten */
url_shop: string | null;
}[];
}

export interface MetadataMap {
map: Map;
}
Expand Down Expand Up @@ -421,6 +430,11 @@ export interface PrintNew {
};
}

export interface PrintReport {
/** Link to report file */
report_url: string;
}

export interface ProductsList {
/** Timestamp of product list in ISO8601 format */
timestamp: string;
Expand Down Expand Up @@ -656,9 +670,9 @@ export interface Contact {
/** Telephon direkt */
telephon_direkt: string;
/** E-Mail */
email: LinkObject;
email: LinkObject | null;
/** URL */
weburl: LinkObject;
weburl: LinkObject | null;
}

export interface Dataset {
Expand Down Expand Up @@ -751,13 +765,13 @@ export interface Dataset {
datenbezugart: string;
attribute: {
/** Attributname */
name: string;
name: string | null;
/** Attributtyp */
typ: string;
typ: string | null;
/** Einheit des Attributwerts */
einheit: string | null;
/** Beschreibung des Attributs */
beschreibung: string;
beschreibung: string | null;
}[];
}[];
services: {
Expand Down Expand Up @@ -968,6 +982,10 @@ export interface Map {
name: string;
/** Beschreibung der Karte */
beschreibung: string;
/** Link to the internet version of the current map */
gbkarten_internet_url: LinkObject | null;
/** Link to the intranet version of the current map (only available whether this api is called from intranet) */
gbkarten_intranet_url: LinkObject | null;
/** Link auf GB2-Karte */
gb2_url: LinkObject | null;
/** Links auf weiterführende Verweise */
Expand Down Expand Up @@ -1121,6 +1139,21 @@ export interface Service {
}[];
}

export interface VectorInputGeneral {
/** GeoJSON file containing FeatureCollection or Feature, or KML file */
file: File;
}

export interface VectorInputGeojson {
/** GeoJSON file containing FeatureCollection or Feature */
file: File;
}

export interface VectorInputKml {
/** KML file */
file: File;
}

/** Vector layer */
export interface VectorLayer {
/** Vector layer type */
Expand Down Expand Up @@ -1207,27 +1240,12 @@ export interface VectorLayerWithoutStyles {

export type CantonListData = Canton;

export interface ImportGeojsonCreatePayload {
/** GeoJSON file containing FeatureCollection or Feature */
file: File;
}

export type ImportGeojsonCreateData = VectorLayer;

export type ExportGeojsonCreateData = GenericGeojsonFeatureCollection;

export interface ImportCreatePayload {
/** GeoJSON file containing FeatureCollection or Feature, or KML file */
file: File;
}

export type ImportCreateData = VectorLayer;

export interface ImportKmlCreatePayload {
/** KML file */
file: File;
}

export type ImportKmlCreateData = VectorLayer;

export type ExportKmlCreateData = any;
Expand All @@ -1242,14 +1260,7 @@ export type MetadataDatasetsListData = MetadataDatasets;

export type MetadataDatasetsDetailData = MetadataDataset;

export interface MetadataGeoshopProductsListData {
geoshop_products: {
/** Geoshop product ID */
giszhnr: number;
/** Link auf Geodatashop bei NOGD-Daten */
url_shop: string | null;
}[];
}
export type MetadataGeoshopProductsListData = MetadataGeoshopProducts;

export type MetadataMapsListData = MetadataMaps;

Expand Down Expand Up @@ -1277,20 +1288,11 @@ export type UserFavoritesDetailData = PersonalFavorite;

export type UserFavoritesDeleteData = any;

export interface PrintCreateData {
/** Link to report file */
report_url: string;
}
export type PrintCreateData = PrintReport;

export interface PrintFeatureInfoCreateData {
/** Link to report file */
report_url: string;
}
export type PrintFeatureInfoCreateData = PrintReport;

export interface PrintLegendCreateData {
/** Link to report file */
report_url: string;
}
export type PrintLegendCreateData = PrintReport;

export type PrintDetailData = any;

Expand Down
28 changes: 28 additions & 0 deletions src/app/shared/pipes/text-or-placeholder.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {TextOrPlaceholderPipe} from './text-or-placeholder.pipe';

describe('TextOrPlaceholderPipe', () => {
let pipe: TextOrPlaceholderPipe;

beforeEach(() => {
pipe = new TextOrPlaceholderPipe();
});
it('create an instance', () => {
expect(pipe).toBeTruthy();
});
it('returns the string value if present', () => {
const value: string = 'test';

const result = pipe.transform(value);

const expected = 'test';
expect(result).toEqual(expected);
});
it('returns the placeholder if the value is null', () => {
const value = null;

const result = pipe.transform(value);

const expected = '-';
expect(result).toEqual(expected);
});
});
11 changes: 11 additions & 0 deletions src/app/shared/pipes/text-or-placeholder.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
name: 'textOrPlaceholder',
standalone: true,
})
export class TextOrPlaceholderPipe implements PipeTransform {
transform(value: string | null): string {
return value ?? '-';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const mockMapDetailResponse = {
topic: 'test-topic',
verweise: [],
gb2_url: null,
gbkarten_internet_url: null,
gbkarten_intranet_url: null,
},
} as MetadataMapsDetailData;

Expand Down Expand Up @@ -153,7 +155,7 @@ const mockDatasetDetailResponse = {
} as MetadataDatasetsDetailData;

const expectedMockDepartmentalContact: DepartmentalContact = {
url: mockContact.weburl.href,
url: mockContact.weburl,
email: mockContact.email,
phoneDirect: mockContact.telephon_direkt,
phone: mockContact.telephon,
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/apis/gb3/gb3-metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export class Gb3MetadataService extends Gb3ApiService {
department: contact.amt,
division: contact.fachstelle,
section: contact.sektion,
url: contact.weburl.href,
url: contact.weburl,
street: contact.strassenname,
poBox: contact.postfach,
email: contact.email,
Expand Down

0 comments on commit e6e730d

Please sign in to comment.