-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(feat): create pipe to format form title from info
Create Angular Pipe to format form title If the title doesnt contain `t-lang` tag, return the text Otherwise, use the English translation if it exists or the first translation if there's no English version of the title Refs #3735
- Loading branch information
Evans Dianga
committed
Jan 12, 2025
1 parent
fe05493
commit 5c21cba
Showing
7 changed files
with
50 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
@Pipe({ | ||
name: 'formTitleFromInfo', | ||
}) | ||
export class FormTitleFromInfoPipe implements PipeTransform { | ||
transform(formInfo) { | ||
if(formInfo.id){ | ||
if(!formInfo.title){ | ||
return formInfo.id | ||
} | ||
if(!formInfo.title.includes('t-lang')) return formInfo.title; | ||
if(formInfo.title.includes('t-lang')) { | ||
const titleDomString = new DOMParser().parseFromString(formInfo.title, 'text/html') | ||
const formTitleEnglish = titleDomString.querySelector('t-lang[en]') | ||
formInfo.title = formTitleEnglish ? formTitleEnglish.textContent : titleDomString.querySelector('t-lang').textContent | ||
return formInfo.title | ||
} | ||
} | ||
if(formInfo.formId){ | ||
if(!formInfo.formTitle){ | ||
return formInfo.formId | ||
} | ||
if(!formInfo.formTitle.includes('t-lang')) return formInfo.formTitle; | ||
if(formInfo.formTitle.includes('t-lang')) { | ||
const titleDomString = new DOMParser().parseFromString(formInfo.formTitle, 'text/html') | ||
const formTitleEnglish = titleDomString.querySelector('t-lang[en]') | ||
formInfo.formTitle = formTitleEnglish ? formTitleEnglish.textContent : titleDomString.querySelector('t-lang').textContent | ||
return formInfo.formTitle | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters