1 import {Component, Input, ViewChild, TemplateRef} from '@angular/core';
6 * // assuming a template reference...
7 * @ViewChild('progress')
8 * private progress: progressInlineComponent;
10 * progress.update({value : 0, max : 123});
11 * progress.increment();
12 * progress.increment();
14 * Each progress has 2 numbers, 'max' and 'value'.
15 * The content of these values determines how the progress displays.
17 * There are 3 flavors:
19 * -- value is set, max is set
20 * determinate: shows a progression with a percent complete.
22 * -- value is set, max is unset
23 * semi-determinate, with a value report. Shows a value-less
24 * <progress/>, but shows the value as a number in the progress.
26 * This is useful in cases where the total number of items to retrieve
27 * from the server is unknown, but we know how many items we've
28 * retrieved thus far. It helps to reinforce that something specific
29 * is happening, but we don't know when it will end.
32 * indeterminate: shows a generic value-less <progress/> with no
33 * clear indication of progress.
36 selector: 'eg-progress-inline',
37 templateUrl: './progress-inline.component.html',
38 styleUrls: ['progress-inline.component.css']
40 export class ProgressInlineComponent {
43 @Input() value: number;
51 return Number.isInteger(this.value);
55 return Number.isInteger(this.max);
59 if (this.hasValue() &&
62 this.value <= this.max) {
63 return Math.floor((this.value / this.max) * 100);
68 // Set the current state of the progress bar.
69 update(args: {[key: string]: number}) {
70 if (args.max !== undefined) {
73 if (args.value !== undefined) {
74 this.value = args.value;
78 // Increment the current value. If no amount is specified,
79 // it increments by 1. Calling increment() on an indetermite
80 // progress bar will force it to be a (semi-)determinate bar.
81 increment(amt?: number) {
82 if (!Number.isInteger(amt)) { amt = 1; }
84 if (!this.hasValue()) {