Skip to content

Commit

Permalink
Add LoadingWriter and LoadingReader
Browse files Browse the repository at this point in the history
  • Loading branch information
christianezeani committed Mar 7, 2024
1 parent 3de3f85 commit 21038fe
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<radialGradient id="a4" cx=".66" fx=".66" cy=".3125" fy=".3125" gradientTransform="scale(1.5)">
<stop offset="0" stop-color="#333333"></stop>
<stop offset=".3" stop-color="#333333" stop-opacity=".9"></stop>
<stop offset=".6" stop-color="#333333" stop-opacity=".6"></stop>
<stop offset=".8" stop-color="#333333" stop-opacity=".3"></stop>
<stop offset="1" stop-color="#333333" stop-opacity="0"></stop>
<stop offset="0" stop-color="#FFFFFF"></stop>
<stop offset=".3" stop-color="#FFFFFF" stop-opacity=".9"></stop>
<stop offset=".6" stop-color="#FFFFFF" stop-opacity=".6"></stop>
<stop offset=".8" stop-color="#FFFFFF" stop-opacity=".3"></stop>
<stop offset="1" stop-color="#FFFFFF" stop-opacity="0"></stop>
</radialGradient>
<circle transform-origin="center" fill="none" stroke="url(#a4)" stroke-width="15" stroke-linecap="round" stroke-dasharray="200 1000" stroke-dashoffset="0" cx="100" cy="100" r="70">
<animateTransform type="rotate" attributeName="transform" calcMode="spline" dur="5" values="360;0" keyTimes="0;1" keySplines="0 0 1 1" repeatCount="indefinite"></animateTransform>
</circle>
<circle transform-origin="center" fill="none" opacity=".2" stroke="#333333" stroke-width="15" stroke-linecap="round" cx="100" cy="100" r="70"></circle>
<circle transform-origin="center" fill="none" opacity=".2" stroke="#FFFFFF" stroke-width="15" stroke-linecap="round" cx="100" cy="100" r="70"></circle>
</svg>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
import { LoadingReader } from '../../../services';

@Component({
selector: 'ngs-loading-animation',
Expand All @@ -7,6 +8,8 @@ import { Component } from '@angular/core';
})
export class NGSuiteLoadingAnimationComponent {

constructor() { }
constructor(
private reader: LoadingReader
) { }

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AfterViewInit, ChangeDetectorRef, Component, ComponentRef, Inject, Injector, Input, ViewChild, ViewContainerRef } from "@angular/core";
import { NGSuiteConfig } from "../../../interfaces";
import { NGSuiteLoadingAnimationComponent } from "../animation/animation.component";
import { LoadingReader, LoadingWriter } from "../../../services";

@Component({
selector: 'ngs-loading-page',
Expand All @@ -11,6 +12,14 @@ export class NGSuiteLoadingPageComponent implements AfterViewInit {

private componentRef?: ComponentRef<any>;

private writer: LoadingWriter;

@Input('text') set text(value: string) { this.writer.text.next(value); }
get text() { return this.writer.text.value; }

@Input('counter') set counter(value: number) { this.writer.counter.next(value); }
get counter() { return this.writer.counter.value; }

@ViewChild('container', {
read: ViewContainerRef
}) viewContainerRef?: ViewContainerRef;
Expand All @@ -19,17 +28,21 @@ export class NGSuiteLoadingPageComponent implements AfterViewInit {
private injector: Injector,
private cd: ChangeDetectorRef,
@Inject('NGSuite') private config: NGSuiteConfig
) { }
) {
this.writer = new LoadingWriter();
}

ngAfterViewInit() {
const { viewContainerRef, config, cd } = this;
const { writer, viewContainerRef, config, cd } = this;

if (viewContainerRef) {
const animation = config.pageLoadingAnimation || config.loadingAnimation || NGSuiteLoadingAnimationComponent;

const newInjector = Injector.create({
parent: this.injector,
providers: []
providers: [
{ provide: LoadingReader, useValue: new LoadingReader(writer) }
]
});

this.componentRef = viewContainerRef.createComponent(animation, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<ngs-loading-page [attr.data-visible]="visible"></ngs-loading-page>
<ngs-loading-page
[text]="text"
[counter]="instances"
[attr.data-visible]="visible"
></ngs-loading-page>
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ export class NGSuiteLoadingRootComponent {
}

stop() {
if (!this.instances) return;

this.instances--;

if (!this.instances) {
//
}
this.instances = Math.max(--this.instances, 0);
if (!this.instances) this.text = '';
}

}
14 changes: 14 additions & 0 deletions projects/ngsuite/src/lib/core/services/LoadingReader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Observable } from "rxjs";
import { LoadingWriter } from "./LoadingWriter";

export class LoadingReader {

readonly text: Observable<string>;
readonly counter: Observable<number>;

constructor(writer: LoadingWriter) {
this.text = writer.text.asObservable();
this.counter = writer.counter.asObservable();
}

}
13 changes: 13 additions & 0 deletions projects/ngsuite/src/lib/core/services/LoadingWriter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BehaviorSubject } from "rxjs";

export class LoadingWriter {

readonly text: BehaviorSubject<string>;
readonly counter: BehaviorSubject<number>;

constructor() {
this.text = new BehaviorSubject('');
this.counter = new BehaviorSubject(0);
}

}
2 changes: 2 additions & 0 deletions projects/ngsuite/src/lib/core/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './Loading';
export * from './LoadingWriter';
export * from './LoadingReader';
export * from './RouteLoading';

0 comments on commit 21038fe

Please sign in to comment.