view src/app/progress-spinner/progress-spinner.component.ts @ 224:1c1cc4ec183c

Setup analysis-item to display determinate spinner if progress prop provided when declared.
author Lucas Thompson <dev@lucas.im>
date Fri, 21 Apr 2017 12:55:24 +0100
parents 7224d9f990cf
children 53ea6406d601
line wrap: on
line source
/**
 * Created by lucast on 14/03/2017.
 */


import {Component, Input} from "@angular/core";
@Component({
  selector: 'ugly-progress-spinner',
  template: `
    <div class="container" [hidden]="!isVisible">
      <md-spinner
        class="spinner"
        [attr.color]="'primary'"
        [mode]="isDeterminate ? 'determinate' : 'indeterminate'"
        [value]="currentProcess"
      ></md-spinner>
    </div>
  `,
  styles: [`
    .container {
      height: 40px;
      width: 40px;
      position: absolute;
      top: calc(50% - 20px);
      left: calc(50% - 20px);
    }

    .spinner {
      width: 100%;
      height: 100%;
    }
  `]
})
export class ProgressSpinnerComponent {
  private currentProcess: number = 0;

  @Input() isVisible: boolean = true;
  @Input() isDeterminate: boolean = false;
  @Input()
  set progress(value: number) {
    if (value < 0) {
      this.currentProcess = 0;
    } else if (value > 100) {
      this.currentProcess = 100;
    } else {
      this.currentProcess = value;
    }
  }
}