From bbb6e4ba8d0b712a2dc1ab5ba915e2229cdd6c83 Mon Sep 17 00:00:00 2001 From: Elwin Schmitz Date: Mon, 25 Nov 2024 09:46:59 +0100 Subject: [PATCH 1/6] fix: Use "name"-property to make data available in Matomo Format of contents is to be decided. Some more information is sometimes necessary, mostly nice-to-have. --- .../feedback-link/feedback-link.component.ts | 1 + .../components/q-a-set/q-a-set.component.ts | 1 + src/app/services/spreadsheet.service.ts | 35 ++++++------------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/app/components/feedback-link/feedback-link.component.ts b/src/app/components/feedback-link/feedback-link.component.ts index e0e2d6c8..7a8d68ee 100644 --- a/src/app/components/feedback-link/feedback-link.component.ts +++ b/src/app/components/feedback-link/feedback-link.component.ts @@ -115,6 +115,7 @@ export class FeedbackLinkComponent implements OnChanges, OnInit { LoggingEventCategory.ai, LoggingEvent.FeedbackAnswered, { + name: value, // Use "name"-property for Matomo answer: value, }, ); diff --git a/src/app/components/q-a-set/q-a-set.component.ts b/src/app/components/q-a-set/q-a-set.component.ts index 4fca863b..7bfb38ef 100644 --- a/src/app/components/q-a-set/q-a-set.component.ts +++ b/src/app/components/q-a-set/q-a-set.component.ts @@ -53,6 +53,7 @@ export class QASetComponent { ? LoggingEvent.QuestionOpen : LoggingEvent.QuestionClose, { + name: slug, // Use "name"-property for Matomo questionSlug: slug, question: question.substring(0, 100), }, diff --git a/src/app/services/spreadsheet.service.ts b/src/app/services/spreadsheet.service.ts index cd106ffe..1c67fde7 100644 --- a/src/app/services/spreadsheet.service.ts +++ b/src/app/services/spreadsheet.service.ts @@ -747,30 +747,17 @@ export class SpreadsheetService { const parentRow = all.find((row) => row.slug === element.parentSlug); // When defined parentRow is missing, treat as a 'normal' question - if (!parentRow) { - this.loggingService.logEvent( - LoggingEventCategory.error, - LoggingEvent.NotFoundParentQuestion, - { - row: element.id, - slug: element.slug, - parentSlug: element.parentSlug, - }, - ); - return element; - } - - // When pointing to itself, treat as a 'normal' question - if (parentRow === element) { - this.loggingService.logEvent( - LoggingEventCategory.error, - LoggingEvent.NotFoundParentQuestionIsSelf, - { - row: element.id, - slug: element.slug, - parentSlug: element.parentSlug, - }, - ); + if (!parentRow || parentRow === element) { + const errorType = + parentRow === element + ? LoggingEvent.NotFoundParentQuestionIsSelf + : LoggingEvent.NotFoundParentQuestion; + this.loggingService.logEvent(LoggingEventCategory.error, errorType, { + name: `row=${element.id};slug=${element.slug};parent=${element.parentSlug}`, + row: element.id, + slug: element.slug, + parentSlug: element.parentSlug, + }); return element; } From 35881ad652fa4a5c56b5e11d0dcf89199632d7ad Mon Sep 17 00:00:00 2001 From: Elwin Schmitz Date: Fri, 8 Nov 2024 13:02:56 +0100 Subject: [PATCH 2/6] fix: Cleanup unused imports --- src/app/components/offer/offer.component.ts | 3 +-- src/app/pages/search/search.page.ts | 3 +-- src/app/referral/referral.page.ts | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/app/components/offer/offer.component.ts b/src/app/components/offer/offer.component.ts index 17718cc9..7e19dae4 100644 --- a/src/app/components/offer/offer.component.ts +++ b/src/app/components/offer/offer.component.ts @@ -1,6 +1,5 @@ import { NgFor, NgIf } from '@angular/common'; import { Component, Input } from '@angular/core'; -import { RouterLink } from '@angular/router'; import { IonImg } from '@ionic/angular/standalone'; import { MarkdownModule } from 'ngx-markdown'; import { @@ -17,7 +16,7 @@ import { formatPhoneNumberAsUrl } from 'src/app/shared/utils'; templateUrl: './offer.component.html', styleUrls: ['./offer.component.scss'], standalone: true, - imports: [MarkdownModule, IonImg, NgIf, NgFor, RouterLink], + imports: [MarkdownModule, IonImg, NgIf, NgFor], }) export class OfferComponent { @Input() diff --git a/src/app/pages/search/search.page.ts b/src/app/pages/search/search.page.ts index 533ef66d..5624fc63 100644 --- a/src/app/pages/search/search.page.ts +++ b/src/app/pages/search/search.page.ts @@ -2,7 +2,7 @@ import { NgIf } from '@angular/common'; import type { OnInit } from '@angular/core'; import { Component } from '@angular/core'; import type { Params } from '@angular/router'; -import { ActivatedRoute, Router, RouterLink } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { ParentLinkComponent } from 'src/app/components/parent-link/parent-link.component'; import { QASetListComponent } from 'src/app/components/q-a-set-list/q-a-set-list.component'; import { SearchInputComponent } from 'src/app/components/search-input/search-input.component'; @@ -21,7 +21,6 @@ import { AppPath } from 'src/routes'; standalone: true, imports: [ NgIf, - RouterLink, QASetListComponent, SearchInputComponent, ParentLinkComponent, diff --git a/src/app/referral/referral.page.ts b/src/app/referral/referral.page.ts index d3f32184..c1e5c8ce 100644 --- a/src/app/referral/referral.page.ts +++ b/src/app/referral/referral.page.ts @@ -9,7 +9,7 @@ import { RouterLink, RouterOutlet, } from '@angular/router'; -import { IonContent, IonFooter, IonHeader } from '@ionic/angular/standalone'; +import { IonContent, IonHeader } from '@ionic/angular/standalone'; import { MarkdownComponent } from 'ngx-markdown'; import { filter } from 'rxjs'; import { AppHeaderComponent } from 'src/app/components/header/header.component'; @@ -46,7 +46,6 @@ import { AppPath } from 'src/routes'; RouterOutlet, IonHeader, IonContent, - IonFooter, ], }) export class ReferralPageComponent implements OnInit { From f681f7fc28f656f3d3a4806f7ca01e4f15347226 Mon Sep 17 00:00:00 2001 From: Elwin Schmitz Date: Fri, 8 Mar 2024 10:54:07 +0100 Subject: [PATCH 3/6] feat: Add Search-via-API feature-flag/config --- .env.example | 4 ++++ src/app/pages/search/search.page.ts | 4 ++++ src/environments/environment.prod.ts.template.js | 3 +++ src/environments/environment.test.ts | 3 +++ src/environments/environment.ts | 3 +++ 5 files changed, 17 insertions(+) diff --git a/.env.example b/.env.example index 6119cc45..e2e99029 100644 --- a/.env.example +++ b/.env.example @@ -27,6 +27,10 @@ NG_USE_Q_AND_AS=true # Enable Search-feature for 'Q & A's (Possible value: `true` or leave empty for `false`) NG_USE_Q_AND_A_SEARCH=true +# (Optional) Server-side Search-feature via API (Requires NG_USE_Q_AND_A_SEARCH to be true!) +SEARCH_API= +SEARCH_API_KEY= + # Enable Feedback-prompt on Sub-Category and Offer pages (Possible value: `true` or leave empty for `false`) NG_USE_FEEDBACK_PROMPT=true diff --git a/src/app/pages/search/search.page.ts b/src/app/pages/search/search.page.ts index 5624fc63..fdf18b0f 100644 --- a/src/app/pages/search/search.page.ts +++ b/src/app/pages/search/search.page.ts @@ -12,6 +12,7 @@ import { OffersService } from 'src/app/services/offers.service'; import { PageMetaService } from 'src/app/services/page-meta.service'; import { RegionDataService } from 'src/app/services/region-data.service'; import { SearchService } from 'src/app/services/search.service'; +import { environment } from 'src/environments/environment'; import { AppPath } from 'src/routes'; @Component({ @@ -27,9 +28,12 @@ import { AppPath } from 'src/routes'; ], }) export default class SearchPageComponent implements OnInit { + public useSearchApi = environment.useQandASearch && !!environment.searchApi; + public region: string; public regionData: RegionData; public qaSets: QASet[]; + public searchQuery: string; public searchResults: QASet[]; diff --git a/src/environments/environment.prod.ts.template.js b/src/environments/environment.prod.ts.template.js index 6db7381a..7df128bb 100644 --- a/src/environments/environment.prod.ts.template.js +++ b/src/environments/environment.prod.ts.template.js @@ -13,6 +13,9 @@ export const environment = { useRegionPerLocale: ${process.env.NG_USE_REGION_PER_LOCALE === 'true' || false}, useFeedbackPrompt: ${process.env.NG_USE_FEEDBACK_PROMPT === 'true' || false}, + searchApi: '${process.env.SEARCH_API || ''}', + searchApiKey: '${process.env.SEARCH_API_KEY || ''}', + // Configuration of content localeLanguage: '${process.env.NG_LOCALE_LANGUAGE || ''}', localeDir: '${process.env.NG_LOCALE_DIR || ''}', diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index 5f7fbf51..6fc7c532 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -12,6 +12,9 @@ export const environment = { useRegionPerLocale: false, useFeedbackPrompt: true, + searchApi: '', + searchApiKey: '', + // Configuration of content localeLanguage: 'en', localeDir: 'ltr', diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 35e66554..9c2c3c05 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -14,6 +14,9 @@ export const environment = { useRegionPerLocale: true, // Enable language-switcher to switch between Regions useFeedbackPrompt: true, // Enable Feedback-prompt on Sub-Category and Offer pages + searchApi: '', // Server-side Search-feature via API + searchApiKey: '', // Server-side Search-API-Key + // Configuration of content localeLanguage: 'en', // Default language localeDir: 'ltr', // Default language direction: 'ltr' or 'rtl' From bc663db17f7db08f2c62adccc14d24fb97338e2b Mon Sep 17 00:00:00 2001 From: Elwin Schmitz Date: Fri, 8 Mar 2024 16:54:47 +0100 Subject: [PATCH 4/6] fix: Separate the real search from the URL-update, to prevent double requests --- src/app/pages/search/search.page.html | 2 +- src/app/pages/search/search.page.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/pages/search/search.page.html b/src/app/pages/search/search.page.html index 275b6f8d..24f47c11 100644 --- a/src/app/pages/search/search.page.html +++ b/src/app/pages/search/search.page.html @@ -6,7 +6,7 @@

diff --git a/src/app/pages/search/search.page.ts b/src/app/pages/search/search.page.ts index fdf18b0f..89b475c4 100644 --- a/src/app/pages/search/search.page.ts +++ b/src/app/pages/search/search.page.ts @@ -92,13 +92,17 @@ export default class SearchPageComponent implements OnInit { } } - public performSearch(rawQuery: string): void { + public onSearchInput(rawQuery: string) { const safeQuery = this.searchService.sanitizeSearchQuery(rawQuery); this.router.navigate([], { queryParams: { q: safeQuery }, queryParamsHandling: 'merge', }); + } + + public async performSearch(query: string): Promise { + const safeQuery = this.searchService.sanitizeSearchQuery(query); this.searchResults = this.searchService.query(safeQuery); From b814ace8f2aaac373656b0dc822ef2856ecefc3e Mon Sep 17 00:00:00 2001 From: Elwin Schmitz Date: Fri, 8 Mar 2024 17:12:53 +0100 Subject: [PATCH 5/6] feat: Add server-side-search (Prototype-code) --- .../search-input/search-input.component.html | 29 +++++-- .../search-input/search-input.component.scss | 38 ++++++++-- .../search-input/search-input.component.ts | 6 +- src/app/pages/search/search.page.html | 39 +++++++++- src/app/pages/search/search.page.ts | 75 ++++++++++++++++++- 5 files changed, 164 insertions(+), 23 deletions(-) diff --git a/src/app/components/search-input/search-input.component.html b/src/app/components/search-input/search-input.component.html index 1d89082c..5e6dfb97 100644 --- a/src/app/components/search-input/search-input.component.html +++ b/src/app/components/search-input/search-input.component.html @@ -2,18 +2,31 @@ role="search" #ngForm (ngSubmit)="doSubmit()" + class="search-input" > - + + + + +