1 import {Component, Input, ViewChild, TemplateRef} from '@angular/core';
2 import {DialogComponent} from '@eg/share/dialog/dialog.component';
5 selector: 'eg-progress-dialog',
6 templateUrl: './progress.component.html',
7 styleUrls: ['progress.component.css']
11 * TODO: This duplicates the code from ProgressInlineComponent.
12 * This component should insert to <eg-progress-inline/> into
13 * its template instead of duplicating the code. However, until
14 * Angular bug https://github.com/angular/angular/issues/14842
15 * is fixed, it's not possible to get a reference to the embedded
16 * inline progress, which is needed for access the update/increment
18 * Also consider moving the progress traking logic to a service
19 * to reduce code duplication.
25 * // assuming a template reference...
26 * @ViewChild('progressDialog')
27 * private dialog: ProgressDialogComponent;
30 * dialog.update({value : 0, max : 123});
35 * Each dialog has 2 numbers, 'max' and 'value'.
36 * The content of these values determines how the dialog displays.
38 * There are 3 flavors:
40 * -- value is set, max is set
41 * determinate: shows a progression with a percent complete.
43 * -- value is set, max is unset
44 * semi-determinate, with a value report. Shows a value-less
45 * <progress/>, but shows the value as a number in the dialog.
47 * This is useful in cases where the total number of items to retrieve
48 * from the server is unknown, but we know how many items we've
49 * retrieved thus far. It helps to reinforce that something specific
50 * is happening, but we don't know when it will end.
53 * indeterminate: shows a generic value-less <progress/> with no
54 * clear indication of progress.
56 export class ProgressDialogComponent extends DialogComponent {
67 return Number.isInteger(this.value);
71 return Number.isInteger(this.max);
75 if (this.hasValue() &&
78 this.value <= this.max) {
79 return Math.floor((this.value / this.max) * 100);
84 // Set the current state of the progress bar.
85 update(args: {[key: string]: number}) {
86 if (args.max !== undefined) {
89 if (args.value !== undefined) {
90 this.value = args.value;
94 // Increment the current value. If no amount is specified,
95 // it increments by 1. Calling increment() on an indetermite
96 // progress bar will force it to be a (semi-)determinate bar.
97 increment(amt?: number) {
98 if (!Number.isInteger(amt)) { amt = 1; }
100 if (!this.hasValue()) {