From 356da78ec6646d671d1555cfc1667db38983d1bb Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 23 Nov 2023 13:54:52 +0000 Subject: [PATCH 1/5] working on social consents --- src/app/api-connector/news.service.ts | 9 +++++++++ .../testimonial-forms/testimonial-form.component.ts | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/app/api-connector/news.service.ts b/src/app/api-connector/news.service.ts index 3f804447ff..98e4bb7664 100644 --- a/src/app/api-connector/news.service.ts +++ b/src/app/api-connector/news.service.ts @@ -94,6 +94,15 @@ export class NewsService { }); } + getPossibleSocialConsents(): Observable { + const params: HttpParams = new HttpParams(); + + return this.http.get(`${ApiSettings.getApiBaseURL()}wagtail-management/testimonial/social_consents/`, { + params, + withCredentials: true, + }); + } + sendTestimonialDraft( title: string, text: string, diff --git a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts index 82ddc42b5e..b1504f692e 100644 --- a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts +++ b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts @@ -62,6 +62,9 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.setInitialData(); this.subscription = new Subscription(); this.getTestimonialData(); + this.newsService.getPossibleSocialConsents().subscribe((stuff: any) => { + console.log(stuff); + }); } createFormGroup(): void { From a5c65f1a6f1f5255fbbcbe108b71050c00575216 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 30 Nov 2023 11:14:45 +0000 Subject: [PATCH 2/5] working on consent --- .../testimonial-forms/social-consent.model.ts | 12 ++++++ .../testimonial-form.component.html | 37 +++++++++++++++++++ .../testimonial-form.component.ts | 6 ++- 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/app/shared/shared_modules/testimonial-forms/social-consent.model.ts diff --git a/src/app/shared/shared_modules/testimonial-forms/social-consent.model.ts b/src/app/shared/shared_modules/testimonial-forms/social-consent.model.ts new file mode 100644 index 0000000000..b254529c18 --- /dev/null +++ b/src/app/shared/shared_modules/testimonial-forms/social-consent.model.ts @@ -0,0 +1,12 @@ +/** + * Social Consent class. + */ +export class SocialConsent { + id: number; + name: string; + description: string; + + constructor(socialConsent?: Partial) { + Object.assign(this, socialConsent); + } +} diff --git a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html index 2009ff181b..6aea7a2334 100644 --- a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html +++ b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html @@ -268,6 +268,43 @@
Add testimonial draft
+
+
+ +
+
+
+
+ + +
+
+ + +
+ +
+
+ Please indicate here on which channels/platforms we may publish your testimonial. The website channel is + selected by default and is the absolute minimum. +
+
+
diff --git a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts index b1504f692e..7af1e1f9a7 100644 --- a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts +++ b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts @@ -7,6 +7,7 @@ import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms import { TESTIMONIAL_PAGE_LINK, CLOUD_PORTAL_SUPPORT_MAIL, SINGLE_TESTIMONIAL_PAGE_LINK } from '../../../../links/links'; import { NewsService } from '../../../api-connector/news.service'; import { Application } from '../../../applications/application.model/application.model'; +import { SocialConsent } from './social-consent.model'; @Component({ selector: 'app-testimonial-form', @@ -42,6 +43,7 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { @Input() testimonialSent: boolean; initialLoadingSuccessful: boolean = false; image_url: string = ''; + possibleSocialConsents: SocialConsent[] = []; submissionSuccessful: boolean = false; autosaveTimer: ReturnType; autosaveTimeout: number = 60000; @@ -62,8 +64,8 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.setInitialData(); this.subscription = new Subscription(); this.getTestimonialData(); - this.newsService.getPossibleSocialConsents().subscribe((stuff: any) => { - console.log(stuff); + this.newsService.getPossibleSocialConsents().subscribe((consents: SocialConsent[]) => { + this.possibleSocialConsents = consents; }); } From 03d32f4ea5e550f8549c6d35700a4d1a6f5b0ae8 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 30 Nov 2023 12:30:59 +0000 Subject: [PATCH 3/5] added checkbox functionality (buggy) --- .../testimonial-form.component.html | 3 ++- .../testimonial-form.component.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html index 6aea7a2334..654e7dd8cf 100644 --- a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html +++ b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html @@ -272,7 +272,7 @@
Add testimonial draft
diff --git a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts index 7af1e1f9a7..bef7808c04 100644 --- a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts +++ b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts @@ -44,6 +44,7 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { initialLoadingSuccessful: boolean = false; image_url: string = ''; possibleSocialConsents: SocialConsent[] = []; + selectedSocialConsents: SocialConsent[] = []; submissionSuccessful: boolean = false; autosaveTimer: ReturnType; autosaveTimeout: number = 60000; @@ -107,6 +108,21 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.checkAutosaveNeed(); }); } + /** + * updateSelectedOptions does not work yet + * @param socialConsent the object that got checked/unchecked + */ + updateSelectedOptions(socialConsent: SocialConsent): void { + // needs adustment ! let idx: number = this.selectedSocialConsents.findIndex((consent: SocialConsent): boolean => {return consent.id.toString() === socialConsent.id.toString()}); + const idx: number = 0; // TODO: ADJUST + if (idx !== -1) { + this.selectedSocialConsents = this.selectedSocialConsents.splice(idx, 1); + } else { + this.selectedSocialConsents.push(socialConsent); + } + + console.log(this.selectedSocialConsents); + } setInitialData(): void { this.initialTitle = this.title; From 3d8717b254e7b7180db2434c656d25cd5277a3fb Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 1 Dec 2023 10:56:18 +0000 Subject: [PATCH 4/5] almost there --- src/app/pipe-module/pipe-module.module.ts | 3 +++ .../pipes/social-consent-given.pipe.ts | 19 +++++++++++++++++++ .../testimonial-form.component.html | 17 ++++++++++++----- .../testimonial-form.component.ts | 8 +++++--- 4 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/app/pipe-module/pipes/social-consent-given.pipe.ts diff --git a/src/app/pipe-module/pipe-module.module.ts b/src/app/pipe-module/pipe-module.module.ts index fd2eff008f..bba35f3f5b 100644 --- a/src/app/pipe-module/pipe-module.module.ts +++ b/src/app/pipe-module/pipe-module.module.ts @@ -15,6 +15,7 @@ import { IsFutureTimePipe } from './pipes/futureTime.pipe'; import { IsMigratedProjectIdPipe } from './pipes/migratedList'; import { HasStatusNotInListPipe } from './pipes/has-status-not-in-list.pipe'; import { SignificancePipe } from '../shared/shared_modules/components/maintenance-notification/significance-pipe/significance.pipe'; +import { SocialConsentGivenPipe } from './pipes/social-consent-given.pipe'; /** * Pipemodule @@ -39,6 +40,7 @@ import { SignificancePipe } from '../shared/shared_modules/components/maintenanc IsMigratedProjectIdPipe, HasStatusNotInListPipe, SignificancePipe, + SocialConsentGivenPipe, ], exports: [ FlavorCounterPipe, @@ -59,6 +61,7 @@ import { SignificancePipe } from '../shared/shared_modules/components/maintenanc IsMigratedProjectIdPipe, HasStatusNotInListPipe, SignificancePipe, + SocialConsentGivenPipe, ], imports: [CommonModule], providers: [IsMigratedProjectIdPipe], diff --git a/src/app/pipe-module/pipes/social-consent-given.pipe.ts b/src/app/pipe-module/pipes/social-consent-given.pipe.ts new file mode 100644 index 0000000000..690fc46b50 --- /dev/null +++ b/src/app/pipe-module/pipes/social-consent-given.pipe.ts @@ -0,0 +1,19 @@ +import { Pipe, PipeTransform } from '@angular/core'; +import { SocialConsent } from 'app/shared/shared_modules/testimonial-forms/social-consent.model'; + +/** + * Generic Pipe to check if element is in list. + */ +@Pipe({ + name: 'socialConsentGiven', +}) +export class SocialConsentGivenPipe implements PipeTransform { + transform(list: SocialConsent[], value: SocialConsent): boolean { + const idx: number = list.findIndex(consent => consent.id === value.id); + if (idx !== -1) { + return false; + } else { + return true; + } + } +} diff --git a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html index 654e7dd8cf..c5870e08c6 100644 --- a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html +++ b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.html @@ -286,23 +286,30 @@
Add testimonial draft
- +
- +
-
- Please indicate here on which channels/platforms we may publish your testimonial. The website channel is - selected by default and is the absolute minimum. + Please indicate here on which channels/platforms we may publish your testimonial or information about your + testimonial. The website channels are selected by default and cannot be deselected as a channel.
diff --git a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts index bef7808c04..8be11cbc0b 100644 --- a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts +++ b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts @@ -113,10 +113,10 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { * @param socialConsent the object that got checked/unchecked */ updateSelectedOptions(socialConsent: SocialConsent): void { - // needs adustment ! let idx: number = this.selectedSocialConsents.findIndex((consent: SocialConsent): boolean => {return consent.id.toString() === socialConsent.id.toString()}); - const idx: number = 0; // TODO: ADJUST + const idx: number = this.selectedSocialConsents.findIndex(consent => consent.id === socialConsent.id); + if (idx !== -1) { - this.selectedSocialConsents = this.selectedSocialConsents.splice(idx, 1); + this.selectedSocialConsents.splice(idx, 1); } else { this.selectedSocialConsents.push(socialConsent); } @@ -194,6 +194,8 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.institution = result['institution']; this.workgroup = result['workgroup']; this.contributor = result['contributor']; + this.selectedSocialConsents = result['publication_channels']; + console.log(this.selectedSocialConsents); } stopAutosaveTimer(): void { From 852e613259e0c5d6290b6791e2535df6359d2cc2 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 1 Dec 2023 11:45:38 +0000 Subject: [PATCH 5/5] feat(Testimonial): Ability to give consent on specific publication channels --- src/app/api-connector/news.service.ts | 11 +++++++++++ .../pipe-module/pipes/social-consent-given.pipe.ts | 4 ++-- .../testimonial-forms/testimonial-form.component.ts | 5 ++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/app/api-connector/news.service.ts b/src/app/api-connector/news.service.ts index 98e4bb7664..883f784644 100644 --- a/src/app/api-connector/news.service.ts +++ b/src/app/api-connector/news.service.ts @@ -2,6 +2,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, of } from 'rxjs'; import { map, catchError } from 'rxjs/operators'; +import { SocialConsent } from 'app/shared/shared_modules/testimonial-forms/social-consent.model'; import { ApiSettings } from './api-settings.service'; import { FacilityNews } from '../facility_manager/newsmanagement/facility-news'; import { News } from '../news/news.model'; @@ -113,8 +114,12 @@ export class NewsService { simple_vm: boolean, image_url: string, project_application_id: string, + soc_consents: SocialConsent[], file: File, ): Observable { + const consents_list = soc_consents.map(soc => soc.id); + const consents = JSON.stringify(consents_list); + const formData: FormData = new FormData(); formData.append('file', file); formData.append('title', title); @@ -125,6 +130,7 @@ export class NewsService { formData.append('workgroup', workgroup); formData.append('simple_vm', JSON.stringify(simple_vm)); formData.append('project_application_id', project_application_id); + formData.append('consents', consents); console.log(formData); return this.http.post(`${ApiSettings.getApiBaseURL()}wagtail-management/testimonial/`, formData, { @@ -141,7 +147,11 @@ export class NewsService { workgroup: string, simple_vm: boolean, project_application_id: string, + soc_consents: SocialConsent[], ): Observable { + const consents_list = soc_consents.map(soc => soc.id); + const consents = JSON.stringify(consents_list); + const testimonialData: any = { title, text, @@ -151,6 +161,7 @@ export class NewsService { workgroup, simple_vm, project_application_id, + consents, }; return this.http.post( diff --git a/src/app/pipe-module/pipes/social-consent-given.pipe.ts b/src/app/pipe-module/pipes/social-consent-given.pipe.ts index 690fc46b50..8a32f75fba 100644 --- a/src/app/pipe-module/pipes/social-consent-given.pipe.ts +++ b/src/app/pipe-module/pipes/social-consent-given.pipe.ts @@ -11,9 +11,9 @@ export class SocialConsentGivenPipe implements PipeTransform { transform(list: SocialConsent[], value: SocialConsent): boolean { const idx: number = list.findIndex(consent => consent.id === value.id); if (idx !== -1) { - return false; - } else { return true; + } else { + return false; } } } diff --git a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts index 8be11cbc0b..93e35a7331 100644 --- a/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts +++ b/src/app/shared/shared_modules/testimonial-forms/testimonial-form.component.ts @@ -120,8 +120,6 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { } else { this.selectedSocialConsents.push(socialConsent); } - - console.log(this.selectedSocialConsents); } setInitialData(): void { @@ -195,7 +193,6 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.workgroup = result['workgroup']; this.contributor = result['contributor']; this.selectedSocialConsents = result['publication_channels']; - console.log(this.selectedSocialConsents); } stopAutosaveTimer(): void { @@ -235,6 +232,7 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.workgroup, this.simple_vm, this.project_application.project_application_id.toString(), + this.selectedSocialConsents, ) .subscribe( (): void => { @@ -282,6 +280,7 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.simple_vm, this.image_url, this.project_application.project_application_id.toString(), + this.selectedSocialConsents, this.file, ) .subscribe((result: any): any => {