Skip to content

Commit

Permalink
Merge pull request #6263 from deNBI/fix/testimonials
Browse files Browse the repository at this point in the history
Fix/testimonials
  • Loading branch information
dweinholz authored Nov 13, 2024
2 parents 7ec3437 + 9566a28 commit ab3e64e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 25 deletions.
19 changes: 10 additions & 9 deletions src/app/api-connector/news.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ export class NewsService {
contributor: string,
institution: string,
workgroup: string,
simple_vm: boolean,
image_url: string,
project_application_id: string,
soc_consents: SocialConsent[],
soc_photo_consents: SocialConsent[],
file: File
): Observable<any> {
const consents_list = soc_consents.map(soc => soc.id)
const photo_consents_list = soc_photo_consents.map(soc => soc.id)
const consents = JSON.stringify(consents_list)

const photo_consents = JSON.stringify(photo_consents_list)
const formData: FormData = new FormData()
formData.append('file', file)
formData.append('title', title)
Expand All @@ -132,10 +132,9 @@ export class NewsService {
formData.append('contributor', contributor)
formData.append('institution', institution)
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)
formData.append('photo_consents', photo_consents)

return this.http.post<any>(`${ApiSettings.getApiBaseURL()}wagtail-management/testimonial/`, formData, {
withCredentials: true
Expand All @@ -149,12 +148,14 @@ export class NewsService {
contributor: string,
institution: string,
workgroup: string,
simple_vm: boolean,
project_application_id: string,
soc_consents: SocialConsent[]
soc_consents: SocialConsent[],
pho_consents: SocialConsent[]
): Observable<any> {
const consents_list = soc_consents.map(soc => soc.id)
const consents = JSON.stringify(consents_list)
const photo_consents_list = pho_consents.map(soc => soc.id)
const photo_consents = JSON.stringify(photo_consents_list)

const testimonialData: any = {
title,
Expand All @@ -163,9 +164,9 @@ export class NewsService {
contributor,
institution,
workgroup,
simple_vm,
project_application_id,
consents
consents,
photo_consents
}

return this.http.post<any>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h5 class="card-title">Add testimonial draft</h5>
type="text"
[ngClass]="{
'is-invalid': testimonialFormGroup.controls.testimonial_title?.invalid,
'is-valid': testimonialFormGroup.controls.testimonial_title?.valid
'is-valid': testimonialFormGroup.controls.testimonial_title?.valid,
}"
/>
</div>
Expand All @@ -81,7 +81,7 @@ <h5 class="card-title">Add testimonial draft</h5>
rows="20"
[ngClass]="{
'is-invalid': testimonialFormGroup.controls.testimonial_text?.invalid,
'is-valid': testimonialFormGroup.controls.testimonial_text?.valid
'is-valid': testimonialFormGroup.controls.testimonial_text?.valid,
}"
class="form-control"
name="testimonial_text"
Expand Down Expand Up @@ -119,7 +119,7 @@ <h5 class="card-title">Add testimonial draft</h5>
rows="4"
[ngClass]="{
'is-invalid': testimonialFormGroup.controls.testimonial_excerpt?.invalid,
'is-valid': testimonialFormGroup.controls.testimonial_excerpt?.valid
'is-valid': testimonialFormGroup.controls.testimonial_excerpt?.valid,
}"
></textarea>
</div>
Expand Down Expand Up @@ -157,7 +157,7 @@ <h5 class="card-title">Add testimonial draft</h5>
required
[ngClass]="{
'is-invalid': testimonialFormGroup.controls.testimonial_contributor?.invalid,
'is-valid': testimonialFormGroup.controls.testimonial_contributor?.valid
'is-valid': testimonialFormGroup.controls.testimonial_contributor?.valid,
}"
/>
</div>
Expand Down Expand Up @@ -195,7 +195,7 @@ <h5 class="card-title">Add testimonial draft</h5>
required
[ngClass]="{
'is-invalid': testimonialFormGroup.controls.testimonial_instituton?.invalid,
'is-valid': testimonialFormGroup.controls.testimonial_institution?.valid
'is-valid': testimonialFormGroup.controls.testimonial_institution?.valid,
}"
/>
</div>
Expand Down Expand Up @@ -225,7 +225,7 @@ <h5 class="card-title">Add testimonial draft</h5>
required
[ngClass]="{
'is-invalid': testimonialFormGroup.controls.testimonial_workgroup?.invalid,
'is-valid': testimonialFormGroup.controls.testimonial_workgroup?.valid
'is-valid': testimonialFormGroup.controls.testimonial_workgroup?.valid,
}"
/>
</div>
Expand Down Expand Up @@ -272,7 +272,7 @@ <h5 class="card-title">Add testimonial draft</h5>
<div class="col-md-3">
<label class="form-control-label">
<strong>
Publication Consent*
Testimonial Publication Consent*
<i
class="icon-question"
data-toggle="tooltip"
Expand Down Expand Up @@ -309,7 +309,54 @@ <h5 class="card-title">Add testimonial draft</h5>
</div>
<div class="form-text">
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.
testimonial. Please consider allowing the testimonial and testimonial information to be published on channels
where you do not authorize the use of the photo. The websites channel is selected by default and cannot be
deselected as a channel.
</div>
</div>
</div>
<div class="form-group row">
<div class="col-md-3">
<label class="form-control-label">
<strong>
Photography Publication Consent*
<i
class="icon-question"
data-toggle="tooltip"
title="Specifies which channels we can use to publish the submitted testimonial."
>
</i>
</strong>
</label>
</div>
<div class="col-md-9">
<div class="input-group">
<div class="form-check mx-2">
<input class="form-check-input" type="checkbox" disabled checked id="website_checkbox" />
<label class="form-check-label" for="website_checkbox"
>Website
<i class="icon-question" data-toggle="tooltip" title="Any content on the de.NBI and de.NBI Cloud Website">
</i
></label>
</div>
<div class="form-check mx-2" *ngFor="let socialPhotoConsent of possibleSocialConsents">
<input
class="form-check-input"
type="checkbox"
[value]="socialPhotoConsent.id"
[checked]="selectedSocialPhotoConsents | socialConsentGiven: socialPhotoConsent"
[id]="'photo_checkbox_' + socialPhotoConsent.id"
(change)="updateSelectedPhotoOptions(socialPhotoConsent)"
/>
<label class="form-check-label" for="checkbox_{{ socialPhotoConsent.id }}"
>{{ socialPhotoConsent.name }}
<i class="icon-question" data-toggle="tooltip" title="{{ socialPhotoConsent.description }}"> </i
></label>
</div>
</div>
<div class="form-text">
Please indicate here on which channels/platforms we may publish the photography uploaded for the testimonial.
The websites channel is selected by default and cannot be deselected as a channel.
</div>
</div>
</div>
Expand Down Expand Up @@ -359,6 +406,18 @@ <h5 class="card-title">Add testimonial draft</h5>
</ul>
</div>
<div class="card-footer">
<div class="row my-2">
<div class="col-auto">
<div class="alert alert-info mx-auto">
<strong>Please consider:</strong>
<p>
By submitting the testimonial, the e-mail-adress that is stated as <i>prefered</i> in your account will be
stored on our servers to enable us to contact you directly if we have any questions. By submitting the
testimonial, you explicitly consent to this storage!
</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-auto">
<div class="btn-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class TestimonialFormComponent implements OnInit, OnDestroy {
image_url: string = ''
possibleSocialConsents: SocialConsent[] = []
selectedSocialConsents: SocialConsent[] = []
selectedSocialPhotoConsents: SocialConsent[] = []
submissionSuccessful: boolean = false
autosaveTimer: ReturnType<typeof setTimeout>
autosaveTimeout: number = 60000
Expand All @@ -54,15 +55,13 @@ export class TestimonialFormComponent implements OnInit, OnDestroy {
file: File = null
hideTestimonialForm: boolean = false


constructor(private newsService: NewsService) {

}
constructor(private newsService: NewsService) {}

ngOnInit(): void {
this.setInitialData()
this.subscription = new Subscription()
this.getTestimonialData()

this.newsService.getPossibleSocialConsents().subscribe((consents: SocialConsent[]) => {
this.possibleSocialConsents = consents
})
Expand Down Expand Up @@ -120,6 +119,15 @@ export class TestimonialFormComponent implements OnInit, OnDestroy {
}
}

updateSelectedPhotoOptions(socialPhotoConsent: SocialConsent): void {
const idx: number = this.selectedSocialPhotoConsents.findIndex(consent => consent.id === socialPhotoConsent.id)
if (idx !== -1) {
this.selectedSocialPhotoConsents.splice(idx, 1)
} else {
this.selectedSocialPhotoConsents.push(socialPhotoConsent)
}
}

setInitialData(): void {
this.initialTitle = this.title
this.initialText = this.text
Expand Down Expand Up @@ -191,6 +199,7 @@ export class TestimonialFormComponent implements OnInit, OnDestroy {
this.workgroup = result['workgroup']
this.contributor = result['contributor']
this.selectedSocialConsents = result['publication_channels']
this.selectedSocialPhotoConsents = result['photo_publication_channels']
}

stopAutosaveTimer(): void {
Expand Down Expand Up @@ -228,9 +237,9 @@ export class TestimonialFormComponent implements OnInit, OnDestroy {
this.contributor,
this.institution,
this.workgroup,
this.simple_vm,
this.project_application.project_application_id.toString(),
this.selectedSocialConsents
this.selectedSocialConsents,
this.selectedSocialPhotoConsents
)
.subscribe(
(): void => {
Expand Down Expand Up @@ -275,10 +284,9 @@ export class TestimonialFormComponent implements OnInit, OnDestroy {
this.contributor,
this.institution,
this.workgroup,
this.simple_vm,
this.image_url,
this.project_application.project_application_id.toString(),
this.selectedSocialConsents,
this.selectedSocialPhotoConsents,
this.file
)
.subscribe((result: any): any => {
Expand Down

0 comments on commit ab3e64e

Please sign in to comment.