MOBILE-2949 comments: Event that notifies loading status

main
Albert Gasset 2019-04-10 13:27:44 +02:00
parent 8f1c66445f
commit 8e9af2fdda
2 changed files with 10 additions and 4 deletions

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Component, Input, OnChanges, SimpleChange } from '@angular/core'; import { Component, EventEmitter, Input, OnChanges, Output, SimpleChange } from '@angular/core';
import { NavParams, NavController } from 'ionic-angular'; import { NavController } from 'ionic-angular';
import { CoreCommentsProvider } from '../../providers/comments'; import { CoreCommentsProvider } from '../../providers/comments';
/** /**
@ -31,11 +31,15 @@ export class CoreCommentsCommentsComponent implements OnChanges {
@Input() area = ''; @Input() area = '';
@Input() page = 0; @Input() page = 0;
@Input() title?: string; @Input() title?: string;
@Input() displaySpinner = true; // Whether to display the loading spinner.
@Output() onLoading: EventEmitter<boolean>; // Eevent that indicates whether the component is loading data.
commentsLoaded = false; commentsLoaded = false;
commentsCount: number; commentsCount: number;
constructor(navParams: NavParams, private navCtrl: NavController, private commentsProvider: CoreCommentsProvider) {} constructor(private navCtrl: NavController, private commentsProvider: CoreCommentsProvider) {
this.onLoading = new EventEmitter<boolean>();
}
/** /**
* View loaded. * View loaded.
@ -56,6 +60,7 @@ export class CoreCommentsCommentsComponent implements OnChanges {
protected fetchData(): void { protected fetchData(): void {
this.commentsLoaded = false; this.commentsLoaded = false;
this.onLoading.emit(true);
this.commentsProvider.getComments(this.contextLevel, this.instanceId, this.component, this.itemId, this.area, this.page) this.commentsProvider.getComments(this.contextLevel, this.instanceId, this.component, this.itemId, this.area, this.page)
.then((comments) => { .then((comments) => {
@ -64,6 +69,7 @@ export class CoreCommentsCommentsComponent implements OnChanges {
this.commentsCount = -1; this.commentsCount = -1;
}).finally(() => { }).finally(() => {
this.commentsLoaded = true; this.commentsLoaded = true;
this.onLoading.emit(false);
}); });
} }

View File

@ -1,4 +1,4 @@
<core-loading [hideUntil]="commentsLoaded"> <core-loading [hideUntil]="commentsLoaded || !displaySpinner">
<div (click)="openComments()" *ngIf="commentsCount >= 0"> <div (click)="openComments()" *ngIf="commentsCount >= 0">
{{ 'core.commentscount' | translate : {'$a': commentsCount} }} {{ 'core.commentscount' | translate : {'$a': commentsCount} }}
</div> </div>