Skip to content

Commit

Permalink
Fix/facility expiry (#6213)
Browse files Browse the repository at this point in the history
* further changes

* fix(Facility News): Adjusted model handling
  • Loading branch information
vktrrdk authored Sep 16, 2024
1 parent ba40431 commit f7b8c3a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ <h5>Please select the facilities to load news from:</h5>
class="form-control"
[(ngModel)]="selectedFacilityNews.title"
[ngClass]="
!isNewsTitleValid() && (news_title.dirty || news_title.touched) ? 'is-invalid' : 'is-valid'
!(selectedFacilityNews | newsTitleValid) && (news_title.dirty || news_title.touched)
? 'is-invalid'
: 'is-valid'
"
id="news_title"
name="news_title"
Expand All @@ -151,7 +153,11 @@ <h5>Please select the facilities to load news from:</h5>
class="form-control"
id="news_text"
[(ngModel)]="selectedFacilityNews.text"
[ngClass]="!isNewsTextValid() && (news_text.dirty || news_text.touched) ? 'is-invalid' : 'is-valid'"
[ngClass]="
!(selectedFacilityNews | newsTextValid) && (news_text.dirty || news_text.touched)
? 'is-invalid'
: 'is-valid'
"
name="news_text"
#news_text="ngModel"
placeholder="e.g. Dear cloud users, we are happy to inform..."
Expand All @@ -165,7 +171,11 @@ <h5>Please select the facilities to load news from:</h5>
id="news_motd"
name="news_motd"
#news_motd="ngModel"
[ngClass]="!isNewsMOTDValid() && (news_motd.dirty || news_motd.touched) ? 'is-invalid' : 'is-valid'"
[ngClass]="
!(selectedFacilityNews | newsMOTDValid) && (news_motd.dirty || news_motd.touched)
? 'is-invalid'
: 'is-valid'
"
[(ngModel)]="selectedFacilityNews.motd"
placeholder="e.g. There are important changes..."
></textarea>
Expand Down Expand Up @@ -473,7 +483,6 @@ <h4 class="modal-title">Upload News: {{ selectedFacilityNews.title }} ?</h4>
<p><strong>Consider: This news will not be send to your users via mail!</strong></p>
</div>
</div>
<!-- (click)="addNewsToWordpress(newWordpressNews, false); addModal.hide()" -->
<div class="modal-footer">
<button
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export class NewsManagerComponent implements OnInit, OnDestroy {
setCurrentNews(news?: FacilityNews): void {
this.facilityToPost = null
this.facilityToSetMOTD = null
console.log(news)
if (news) {
this.selectedFacilityNews = new FacilityNews(news)
this.facilityToPost = news.facility
Expand Down Expand Up @@ -349,13 +350,13 @@ export class NewsManagerComponent implements OnInit, OnDestroy {
isNewsTitleValid(): boolean {
if (!this.selectedFacilityNews) return false

return this.selectedFacilityNews.title?.length > 5
return this.selectedFacilityNews.title?.length >= 5
}

isNewsTextValid(): boolean {
if (!this.selectedFacilityNews) return false

return this.selectedFacilityNews.text?.length > 25
return this.selectedFacilityNews.text?.length >= 25
}

isNewsMOTDValid(): boolean {
Expand Down
17 changes: 14 additions & 3 deletions src/app/pipe-module/pipe-module.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import { SignificancePipe } from '../shared/shared_modules/components/maintenanc
import { SocialConsentGivenPipe } from './pipes/social-consent-given.pipe'
import { IsMigratedProjectPipe } from './pipes/isMigratedProject'
import { HasFlavorTypeOrIsNotCustomPipe } from './pipes/has-flavor-type.pipe'
import { NewsValidationPipe } from './pipes/news-valid.pipe'
import {
NewsValidationPipe,
NewsMOTDValidationPipe,
NewsTextValidationPipe,
NewsTitleValidationPipe
} from './pipes/news-valid.pipe'

/**
* Pipemodule
Expand Down Expand Up @@ -46,7 +51,10 @@ import { NewsValidationPipe } from './pipes/news-valid.pipe'
SocialConsentGivenPipe,
IsMigratedProjectPipe,
HasFlavorTypeOrIsNotCustomPipe,
NewsValidationPipe
NewsValidationPipe,
NewsMOTDValidationPipe,
NewsTextValidationPipe,
NewsTitleValidationPipe
],
exports: [
FlavorCounterPipe,
Expand All @@ -70,7 +78,10 @@ import { NewsValidationPipe } from './pipes/news-valid.pipe'
SocialConsentGivenPipe,
IsMigratedProjectPipe,
HasFlavorTypeOrIsNotCustomPipe,
NewsValidationPipe
NewsValidationPipe,
NewsMOTDValidationPipe,
NewsTextValidationPipe,
NewsTitleValidationPipe
],
imports: [CommonModule],
providers: []
Expand Down
41 changes: 38 additions & 3 deletions src/app/pipe-module/pipes/news-valid.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,49 @@ import { Pipe, PipeTransform } from '@angular/core'
import { FacilityNews } from 'app/facility_manager/newsmanagement/facility-news'

@Pipe({
name: 'newsValid'
name: 'newsValid',
pure: false
})
export class NewsValidationPipe implements PipeTransform {
transform(news: FacilityNews): boolean {
if (news.is_current_motd) {
if (news.motd?.length < 10) return false
if (news.motd?.length < 15) return false
}

return news.title?.length > 5 && news.text?.length > 30
return news.title?.length >= 5 && news.text?.length >= 25
}
}

@Pipe({
name: 'newsTitleValid',
pure: false
})
export class NewsTitleValidationPipe implements PipeTransform {
transform(news: FacilityNews): boolean {
return news.title?.length >= 5
}
}

@Pipe({
name: 'newsTextValid',
pure: false
})
export class NewsTextValidationPipe implements PipeTransform {
transform(news: FacilityNews): boolean {
return news.text?.length >= 25
}
}

@Pipe({
name: 'newsMOTDValid',
pure: false
})
export class NewsMOTDValidationPipe implements PipeTransform {
transform(news: FacilityNews): boolean {
if (news.is_current_motd) {
if (news.motd?.length < 15) return false
}

return true
}
}

0 comments on commit f7b8c3a

Please sign in to comment.