Transition Group: Add enable disable functionallity. User component: Add condition to avoid double message for login.
This commit is contained in:
parent
013ce7d5f4
commit
e3f082b802
|
@ -52,7 +52,7 @@
|
||||||
<button (click)="login()" class=" uk-button uk-button-primary">Login</button>
|
<button (click)="login()" class=" uk-button uk-button-primary">Login</button>
|
||||||
</div>
|
</div>
|
||||||
</form-->
|
</form-->
|
||||||
<div *ngIf="errorCode == '1' || !loggedIn" class="uk-alert uk-alert-warning">
|
<div *ngIf="errorCode == '1' || (!loggedIn && errorCode != '3')" class="uk-alert uk-alert-warning">
|
||||||
The requested page requires authentication.
|
The requested page requires authentication.
|
||||||
<span *ngIf="!loggedIn">Please <a class="uk-link" (click)="logIn()"> sign in</a> to continue.
|
<span *ngIf="!loggedIn">Please <a class="uk-link" (click)="logIn()"> sign in</a> to continue.
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
import {TransitionGroupItemDirective} from "./transition-group-item.directive";
|
import {TransitionGroupItemDirective} from "./transition-group-item.directive";
|
||||||
import {AfterViewInit, Component, ContentChildren, OnDestroy, QueryList, ViewEncapsulation} from "@angular/core";
|
import {AfterViewInit, Component, ContentChildren, OnDestroy, QueryList, ViewEncapsulation} from "@angular/core";
|
||||||
import {Subscription} from "rxjs";
|
import {Subscription} from "rxjs";
|
||||||
|
import {THREE} from "@angular/cdk/keycodes";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transition Component for array changes
|
||||||
|
*
|
||||||
|
* Call init() method if array is changed. e.g. (different array, insert, delete) and before swap action
|
||||||
|
*
|
||||||
|
* If a change is triggered, but you want to avoid transition use disable() - (Your changes) - init() - enable()
|
||||||
|
*
|
||||||
|
* */
|
||||||
@Component({
|
@Component({
|
||||||
selector: '[transition-group]',
|
selector: '[transition-group]',
|
||||||
template: '<ng-content></ng-content>',
|
template: '<ng-content></ng-content>',
|
||||||
|
@ -10,35 +19,38 @@ import {Subscription} from "rxjs";
|
||||||
})
|
})
|
||||||
export class TransitionGroupComponent implements AfterViewInit, OnDestroy {
|
export class TransitionGroupComponent implements AfterViewInit, OnDestroy {
|
||||||
@ContentChildren(TransitionGroupItemDirective) items: QueryList<TransitionGroupItemDirective>;
|
@ContentChildren(TransitionGroupItemDirective) items: QueryList<TransitionGroupItemDirective>;
|
||||||
|
private disabled: boolean = false;
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
this.init();
|
this.init();
|
||||||
this.subscription = this.items.changes.subscribe(items => {
|
this.subscription = this.items.changes.subscribe(items => {
|
||||||
items.forEach(item => item.prevPos = item.newPos || item.prevPos);
|
if(!this.disabled) {
|
||||||
items.forEach(this.runCallback);
|
items.forEach(item => item.prevPos = item.newPos || item.prevPos);
|
||||||
this.refreshPosition('newPos');
|
items.forEach(this.runCallback);
|
||||||
items.forEach(item => item.prevPos = item.prevPos || item.newPos); // for new items
|
this.refreshPosition('newPos');
|
||||||
|
items.forEach(item => item.prevPos = item.prevPos || item.newPos); // for new items
|
||||||
const animate = () => {
|
|
||||||
items.forEach(this.applyTranslation);
|
const animate = () => {
|
||||||
this['_forceReflow'] = document.body.offsetHeight; // force reflow to put everything in position
|
items.forEach(this.applyTranslation);
|
||||||
this.items.forEach(this.runTransition.bind(this));
|
this['_forceReflow'] = document.body.offsetHeight; // force reflow to put everything in position
|
||||||
}
|
this.items.forEach(this.runTransition.bind(this));
|
||||||
|
}
|
||||||
const willMoveSome = items.some((item) => {
|
|
||||||
const dx = item.prevPos.left - item.newPos.left;
|
const willMoveSome = items.some((item) => {
|
||||||
const dy = item.prevPos.top - item.newPos.top;
|
const dx = item.prevPos.left - item.newPos.left;
|
||||||
return dx || dy;
|
const dy = item.prevPos.top - item.newPos.top;
|
||||||
});
|
return dx || dy;
|
||||||
|
});
|
||||||
if (willMoveSome) {
|
|
||||||
animate();
|
if (willMoveSome) {
|
||||||
} else {
|
|
||||||
setTimeout(() => { // for removed items
|
|
||||||
this.refreshPosition('newPos');
|
|
||||||
animate();
|
animate();
|
||||||
}, 0);
|
} else {
|
||||||
|
setTimeout(() => { // for removed items
|
||||||
|
this.refreshPosition('newPos');
|
||||||
|
animate();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -49,6 +61,10 @@ export class TransitionGroupComponent implements AfterViewInit, OnDestroy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be used in every array change e.g. (different array, insert, delete)
|
||||||
|
* and before swap action
|
||||||
|
* */
|
||||||
init() {
|
init() {
|
||||||
this.refreshPosition('prevPos');
|
this.refreshPosition('prevPos');
|
||||||
this.refreshPosition('newPos');
|
this.refreshPosition('newPos');
|
||||||
|
@ -95,4 +111,20 @@ export class TransitionGroupComponent implements AfterViewInit, OnDestroy {
|
||||||
style.transitionDuration = '0s';
|
style.transitionDuration = '0s';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable transition
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
enable() {
|
||||||
|
this.disabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable transition
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
disable() {
|
||||||
|
this.disabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue