--- /dev/null
+
+.eg-progress-dialog progress {
+ width: 100%;
+ height: 25px;
+}
--- /dev/null
+<ng-template #dialogContent>
+ <div class="modal-header bg-info">
+ <button type="button" class="close"
+ i18n-aria-label aria-label="Close"
+ (click)="dismiss('cross_click')">
+ <span aria-hidden="true">×</span>
+ </button>
+ </div>
+
+ <div class="modal-body eg-progress-dialog">
+
+ <div *ngIf="hasValue() && hasMax()">
+ <!-- determinate progress bar. shows max/value progress -->
+ <div class="col-lg-10">
+ <progress max="{{max}}" value="{{value}}"></progress>
+ </div>
+ <div class="col-lg-2">{{percent()}}%</div>
+ </div>
+
+ <div *ngIf="hasValue() && !hasMax()">
+ <!-- semi-determinate progress bar. shows value -->
+ <div class="col-lg-10"><progress max="1"></progress></div>
+ <div class="col-lg-2">{{value}}...</div>
+ </div>
+
+ <div *ngIf="!hasValue()">
+ <!-- indeterminate -->
+ <div class="col-lg-12"><progress max="1"></progress></div>
+ </div>
+
+ </div>
+</ng-template>
--- /dev/null
+import {Component, Input, ViewChild, TemplateRef} from '@angular/core';
+import {EgDialogComponent} from '@eg/share/dialog/dialog.component';
+
+@Component({
+ selector: 'eg-progress-dialog',
+ templateUrl: './progress.component.html',
+ styleUrls: ['progress.component.css']
+})
+
+/**
+ * Progress Dialog.
+ *
+ * // assuming a template reference...
+ * @ViewChild('progressDialog')
+ * private dialog: EgProgressDialogComponent;
+ *
+ * dialog.open();
+ * dialog.update({value : 0, max : 123});
+ * dialog.increment();
+ * dialog.increment();
+ * dialog.close();
+ *
+ * Each dialog has 2 numbers, 'max' and 'value'.
+ * The content of these values determines how the dialog displays.
+ *
+ * There are 3 flavors:
+ *
+ * -- value is set, max is set
+ * determinate: shows a progression with a percent complete.
+ *
+ * -- value is set, max is unset
+ * semi-determinate, with a value report. Shows a value-less
+ * <progress/>, but shows the value as a number in the dialog.
+ *
+ * This is useful in cases where the total number of items to retrieve
+ * from the server is unknown, but we know how many items we've
+ * retrieved thus far. It helps to reinforce that something specific
+ * is happening, but we don't know when it will end.
+ *
+ * -- value is unset
+ * indeterminate: shows a generic value-less <progress/> with no
+ * clear indication of progress.
+ */
+export class EgProgressDialogComponent extends EgDialogComponent {
+
+ max: number;
+ value: number;
+
+ reset() {
+ delete this.max;
+ delete this.value;
+ }
+
+ hasValue(): boolean {
+ return Number.isInteger(this.value);
+ }
+
+ hasMax(): boolean {
+ return Number.isInteger(this.max);
+ }
+
+ percent(): number {
+ if (this.hasValue() &&
+ this.hasMax() &&
+ this.max > 0 &&
+ this.value <= this.max)
+ return Math.floor((this.value / this.max) * 100);
+ return 100;
+ }
+
+ // Set the current state of the progress bar.
+ update(args: {[key:string] : number}) {
+ if (args.max != undefined)
+ this.max = args.max;
+ if (args.value != undefined)
+ this.value = args.value;
+ }
+
+ // Increment the current value. If no amount is specified,
+ // it increments by 1. Calling increment() on an indetermite
+ // progress bar will force it to be a (semi-)determinate bar.
+ increment(amt: number) {
+ if (!Number.isInteger(amt)) amt = 1;
+
+ if (!this.hasValue())
+ this.value = 0;
+
+ this.value += amt;
+ }
+}
+
+
import {EgDialogComponent} from '@eg/share/dialog/dialog.component';
import {EgConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
import {EgPromptDialogComponent} from '@eg/share/dialog/prompt.component';
+import {EgProgressDialogComponent} from '@eg/share/dialog/progress.component';
import {EgAccessKeyDirective} from '@eg/share/accesskey/accesskey.directive';
import {EgAccessKeyService} from '@eg/share/accesskey/accesskey.service';
import {EgAccessKeyInfoComponent} from '@eg/share/accesskey/accesskey-info.component';
EgDialogComponent,
EgConfirmDialogComponent,
EgPromptDialogComponent,
+ EgProgressDialogComponent,
EgAccessKeyDirective,
EgAccessKeyInfoComponent
],
EgDialogComponent,
EgConfirmDialogComponent,
EgPromptDialogComponent,
+ EgProgressDialogComponent,
EgAccessKeyDirective,
EgAccessKeyInfoComponent
]
</fm-record-editor>
<button (click)="fmRecordEditor.open({size:'lg'})">Fm Record Editor</button>
+<br/><br/>
+
+<eg-progress-dialog #progressDialog>
+</eg-progress-dialog>
+<button (click)="showProgress()">Test Progress Dialog</button>
-import {Component, OnInit} from '@angular/core';
+import {Component, OnInit, ViewChild} from '@angular/core';
+import {EgProgressDialogComponent} from '@eg/share/dialog/progress.component';
@Component({
templateUrl: 'sandbox.component.html'
})
export class EgSandboxComponent implements OnInit {
+ @ViewChild('progressDialog')
+ private progressDialog: EgProgressDialogComponent;
+
constructor() {}
ngOnInit() {
}
+
+ showProgress() {
+ this.progressDialog.open();
+ this.progressDialog.update({value: 1, max: 100})
+ setTimeout(() => this.progressDialog.update({value: 5}), 1000);
+ setTimeout(() => this.progressDialog.update({value: 10}), 2000);
+ setTimeout(() => this.progressDialog.update({value: 50}), 3000);
+ setTimeout(() => this.progressDialog.update({value: 95}), 4000);
+ setTimeout(() => this.progressDialog.close(), 5000);
+ }
}