-
Notifications
You must be signed in to change notification settings - Fork 900
WEB-894 | Ng-busy lazy loader + no-data null record pipe #3443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anshita-21
wants to merge
2
commits into
openMF:dev
Choose a base branch
from
anshita-21:fix/WEB-894
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
| /** | ||
| * Copyright since 2025 Mifos Initiative | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| // ng-busy directive styles | ||
| .busy-loading { | ||
| position: relative; | ||
| pointer-events: none; | ||
|
|
||
| .css-spinner { | ||
| display: inline-block; | ||
| vertical-align: middle; | ||
| } | ||
| } | ||
|
|
||
| // Button specific busy styles | ||
| button.busy-loading { | ||
| cursor: not-allowed; | ||
| } | ||
|
|
||
| // Dots animation for loading indicator | ||
| @keyframes dots { | ||
| 0%, | ||
| 20% { | ||
| opacity: 0; | ||
| transform: scale(0.8); | ||
| } | ||
|
|
||
| 50% { | ||
| opacity: 1; | ||
| transform: scale(1); | ||
| } | ||
|
|
||
| 80%, | ||
| 100% { | ||
| opacity: 0; | ||
| transform: scale(0.8); | ||
| } | ||
| } |
This file contains hidden or 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,161 @@ | ||
| /** | ||
| * Copyright since 2025 Mifos Initiative | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| import { | ||
| Directive, | ||
| Input, | ||
| ElementRef, | ||
| Renderer2, | ||
| OnInit, | ||
| OnChanges, | ||
| SimpleChanges, | ||
| OnDestroy, | ||
| inject | ||
| } from '@angular/core'; | ||
|
|
||
| @Directive({ | ||
| selector: '[mifosxNgBusy]', | ||
| standalone: true | ||
| }) | ||
| export class NgBusyDirective implements OnInit, OnChanges, OnDestroy { | ||
| @Input() mifosxNgBusy = false; | ||
| @Input() busyText = ''; | ||
| @Input() busyClass = 'busy-loading'; | ||
|
|
||
| private originalContent: string | null = null; | ||
| private originalDisabled: boolean | null = null; | ||
| private spinnerElement: HTMLElement | null = null; | ||
| private styleElement: HTMLStyleElement | null = null; | ||
| private static globalStylesAdded = false; | ||
|
|
||
| private el = inject(ElementRef); | ||
| private renderer = inject(Renderer2); | ||
|
|
||
| ngOnInit() { | ||
| // Store original content and state | ||
| this.originalContent = this.el.nativeElement.innerHTML; | ||
| this.originalDisabled = this.el.nativeElement.disabled; | ||
anshita-21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Add global styles for animation | ||
| this.addGlobalStyles(); | ||
| } | ||
|
|
||
| ngOnChanges(changes: SimpleChanges) { | ||
| if (changes['mifosxNgBusy']) { | ||
| this.updateBusyState(); | ||
| } | ||
| } | ||
|
|
||
| private updateBusyState() { | ||
| if (this.mifosxNgBusy) { | ||
| this.showBusyState(); | ||
| } else { | ||
| this.hideBusyState(); | ||
| } | ||
| } | ||
|
|
||
| private showBusyState() { | ||
| // Add busy class | ||
| this.renderer.addClass(this.el.nativeElement, this.busyClass); | ||
|
|
||
| // Disable element | ||
| this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'true'); | ||
|
|
||
| // Create busy content | ||
| const busyContent = this.createBusyContent(); | ||
|
|
||
| // Clear and set busy content | ||
| this.el.nativeElement.innerHTML = ''; | ||
| this.el.nativeElement.appendChild(busyContent); | ||
| } | ||
|
|
||
| private hideBusyState() { | ||
| // Remove busy class | ||
| this.renderer.removeClass(this.el.nativeElement, this.busyClass); | ||
|
|
||
| // Restore original disabled state | ||
| if (this.originalDisabled) { | ||
| this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'true'); | ||
| } else { | ||
| this.renderer.removeAttribute(this.el.nativeElement, 'disabled'); | ||
| } | ||
|
|
||
| // Restore original content | ||
| if (this.originalContent !== null && this.originalContent !== undefined) { | ||
| this.el.nativeElement.innerHTML = this.originalContent; | ||
| } | ||
anshita-21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private createBusyContent(): HTMLElement { | ||
| const container = this.renderer.createElement('span'); | ||
| this.renderer.setStyle(container, 'display', 'inline-flex'); | ||
| this.renderer.setStyle(container, 'align-items', 'center'); | ||
| this.renderer.setStyle(container, 'gap', '8px'); | ||
|
|
||
| // Create CSS spinner with proper rotation | ||
| this.spinnerElement = this.renderer.createElement('span'); | ||
| this.renderer.addClass(this.spinnerElement, 'css-spinner'); | ||
|
|
||
| // Create spinner using CSS border technique | ||
| this.renderer.setStyle(this.spinnerElement, 'display', 'inline-block'); | ||
| this.renderer.setStyle(this.spinnerElement, 'width', '16px'); | ||
| this.renderer.setStyle(this.spinnerElement, 'height', '16px'); | ||
| this.renderer.setStyle(this.spinnerElement, 'border', '2px solid rgba(255, 255, 255, 0.3)'); | ||
| this.renderer.setStyle(this.spinnerElement, 'border-top', '2px solid #ffffff'); | ||
| this.renderer.setStyle(this.spinnerElement, 'border-radius', '50%'); | ||
| this.renderer.setStyle(this.spinnerElement, 'animation', 'spin 1s linear infinite'); | ||
| this.renderer.setStyle(this.spinnerElement, 'vertical-align', 'middle'); | ||
|
|
||
| // Create text | ||
| const text = this.busyText || 'Loading...'; | ||
| const textNode = this.renderer.createText(text); | ||
anshita-21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Assemble | ||
| container.appendChild(this.spinnerElement); | ||
| container.appendChild(textNode); | ||
|
|
||
| return container; | ||
| } | ||
|
|
||
| private addGlobalStyles() { | ||
| // Add proper rotation animation only once globally | ||
| if (!NgBusyDirective.globalStylesAdded) { | ||
| this.styleElement = this.renderer.createElement('style'); | ||
| this.renderer.setProperty( | ||
| this.styleElement, | ||
| 'innerHTML', | ||
| ` | ||
| @keyframes spin { | ||
| 0% { transform: rotate(0deg); } | ||
| 100% { transform: rotate(360deg); } | ||
| } | ||
|
|
||
| .css-spinner { | ||
| border: 2px solid rgba(255, 255, 255, 0.3) !important; | ||
| border-top: 2px solid #ffffff !important; | ||
| } | ||
|
|
||
| button .css-spinner { | ||
| border: 2px solid rgba(255, 255, 255, 0.3) !important; | ||
| border-top: 2px solid #ffffff !important; | ||
| } | ||
| ` | ||
| ); | ||
| this.renderer.appendChild(document.head, this.styleElement); | ||
| NgBusyDirective.globalStylesAdded = true; | ||
| } | ||
| } | ||
|
|
||
| ngOnDestroy() { | ||
| // Clean up style element if this is the last instance | ||
| if (this.styleElement && NgBusyDirective.globalStylesAdded) { | ||
| this.renderer.removeChild(document.head, this.styleElement); | ||
| NgBusyDirective.globalStylesAdded = false; | ||
| } | ||
| } | ||
anshita-21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.