diff --git a/src/app/api-connector/news.service.ts b/src/app/api-connector/news.service.ts index 3f804447ff..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'; @@ -94,6 +95,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, @@ -104,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); @@ -116,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, { @@ -132,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, @@ -142,6 +161,7 @@ export class NewsService { workgroup, simple_vm, project_application_id, + consents, }; return this.http.post( diff --git a/src/app/pipe-module/pipe-module.module.ts b/src/app/pipe-module/pipe-module.module.ts index 37ae004611..7582c44040 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'; import { IsMigratedProjectPipe } from './pipes/isMigratedProject'; /** @@ -40,6 +41,7 @@ import { IsMigratedProjectPipe } from './pipes/isMigratedProject'; IsMigratedProjectIdPipe, HasStatusNotInListPipe, SignificancePipe, + SocialConsentGivenPipe, IsMigratedProjectPipe, ], exports: [ @@ -61,6 +63,7 @@ import { IsMigratedProjectPipe } from './pipes/isMigratedProject'; IsMigratedProjectIdPipe, HasStatusNotInListPipe, SignificancePipe, + SocialConsentGivenPipe, IsMigratedProjectPipe, ], imports: [CommonModule], 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..8a32f75fba --- /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 true; + } else { + return false; + } + } +} 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..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 @@ -268,6 +268,51 @@
Add testimonial draft
+
+
+ +
+
+
+
+ + +
+
+ + +
+
+
+ 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 82ddc42b5e..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 @@ -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,8 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { @Input() testimonialSent: boolean; initialLoadingSuccessful: boolean = false; image_url: string = ''; + possibleSocialConsents: SocialConsent[] = []; + selectedSocialConsents: SocialConsent[] = []; submissionSuccessful: boolean = false; autosaveTimer: ReturnType; autosaveTimeout: number = 60000; @@ -62,6 +65,9 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.setInitialData(); this.subscription = new Subscription(); this.getTestimonialData(); + this.newsService.getPossibleSocialConsents().subscribe((consents: SocialConsent[]) => { + this.possibleSocialConsents = consents; + }); } createFormGroup(): void { @@ -102,6 +108,19 @@ 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 { + const idx: number = this.selectedSocialConsents.findIndex(consent => consent.id === socialConsent.id); + + if (idx !== -1) { + this.selectedSocialConsents.splice(idx, 1); + } else { + this.selectedSocialConsents.push(socialConsent); + } + } setInitialData(): void { this.initialTitle = this.title; @@ -173,6 +192,7 @@ export class TestimonialFormComponent implements OnInit, OnDestroy { this.institution = result['institution']; this.workgroup = result['workgroup']; this.contributor = result['contributor']; + this.selectedSocialConsents = result['publication_channels']; } stopAutosaveTimer(): void { @@ -212,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 => { @@ -259,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 => {