setting-base.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { Component, ChangeDetectorRef, ViewChild } from '@angular/core';
  2. import { NavController, NavParams } from 'ionic-angular';
  3. import { MeBaristaService } from '../../providers/me-barista-service';
  4. @Component({
  5. selector: 'page-setting-base',
  6. templateUrl: 'setting-base.html'
  7. })
  8. export class SettingBasePage {
  9. @ViewChild('tt42') tt42;
  10. @ViewChild('spinner') spinner;
  11. pars: any;
  12. pars_defaults: any;
  13. pars_undo: any;
  14. sub: any;
  15. temperature: any;
  16. spinner_show: boolean;
  17. header_template: any;
  18. constructor(public navCtrl: NavController, public navParams: NavParams, public cdr: ChangeDetectorRef, public abc: MeBaristaService ) {
  19. this.pars = {};
  20. this.pars_defaults = {};
  21. this.pars_undo = {};
  22. if( this.abc.connected )
  23. this.temperature = this.abc.temperature.toFixed( 2 ) + ' °C';
  24. else
  25. this.temperature = '---,-- °C';
  26. this.spinner_show = !this.abc.connected;
  27. // this.spinner.paused = !this.abc.scanning;
  28. this.header_template = '<ion-header><ion-navbar>' +
  29. '<ion-spinner #spinner [hidden]="!spinner_show" [paused]="!this.abc.scanning" (click)="this.abc.bt_discover()" style="float: right; margin-right: 1em; width: 1.5em; height: 1.5em;"></ion-spinner>' +
  30. '<span #tt42 [hidden]="spinner_show" style="float: right; margin-right: 1em;">{{temperature}}</span>' +
  31. '<button ion-button menuToggle> <ion-icon name="menu"></ion-icon> </button> <ion-title>meBarista</ion-title> </ion-navbar> </ion-header>';
  32. }
  33. processUpdate( ) {
  34. if( this.abc.connected )
  35. this.temperature = this.abc.temperature.toFixed( 2 ) + ' °C';
  36. else
  37. this.temperature = '---,-- °C';
  38. this.spinner_show = !this.abc.connected;
  39. // dit krakte niet? this.spinner.paused = !this.abc.scanning;
  40. }
  41. ionViewWillEnter() {
  42. this.sub = this.abc.temperature_s1.subscribe( data => {
  43. //console.log('sub ' + this.abc.temperature);
  44. //this.tt42 = this.abc.temperature + ' °';
  45. this.processUpdate( );
  46. this.cdr.detectChanges( );
  47. } );
  48. }
  49. ionViewWillLeave() {
  50. // this.abc.temperature_s1.unsubscribe();
  51. this.sub.unsubscribe();
  52. }
  53. init( defaults: any ) {
  54. this.pars_defaults = defaults;
  55. this.pars = this.abc.fetch( this.pars_defaults );
  56. this.doCopy( this.pars_undo, this.pars );
  57. }
  58. doCompare( o1: any, o2: any ) {
  59. for (var attr in o1)
  60. if( o1[attr] != o2[attr] ) {
  61. // console.log( 'Compare ' + attr + ' from ' + o2[ attr] + ' to ' + o1[ attr ] );
  62. return true;
  63. }
  64. return false;
  65. }
  66. doCopy( dest: any, src: any ) {
  67. for (var attr in src)
  68. if (src.hasOwnProperty(attr))
  69. dest[attr] = src[attr];
  70. }
  71. getDiff( src: any, check: any ) {
  72. var res = {};
  73. for (var attr in src)
  74. if (src.hasOwnProperty(attr) && src[attr] != check[attr] )
  75. res[ attr ] = src[ attr ];
  76. return res;
  77. }
  78. showDefaults() {
  79. return this.doCompare( this.pars, this.pars_defaults );
  80. }
  81. doDefaults() {
  82. this.doCopy( this.pars, this.pars_defaults );
  83. }
  84. showUndo() {
  85. return this.doCompare( this.pars, this.pars_undo );
  86. }
  87. doUndo() {
  88. this.doCopy( this.pars, this.pars_undo );
  89. }
  90. showUpdate() {
  91. return this.showUndo();
  92. }
  93. doUpdate() {
  94. console.log( this.getDiff( this.pars, this.pars_undo ) );
  95. this.abc.update( this.getDiff( this.pars, this.pars_undo ) );
  96. this.doCopy( this.pars_undo, this.pars );
  97. this.abc.message = 'Updated';
  98. }
  99. notify( event: any ) {
  100. // this.show_defaults = true;
  101. // TODO: do we still want this??
  102. //console.log( 'ionChange: ' + event._elementRef.nativeElement.id );
  103. //if( event.value != undefined )
  104. // console.log( 'value = ' + event.value );
  105. //if( event.checked != undefined )
  106. // console.log( 'checked = ' + event.checked );
  107. //if( event.target != undefined )
  108. // console.log( 'target = ' + event.target );
  109. //if( event.currentTarget != undefined )
  110. //console.log( 'currentraget = ' + event.currentTarget );
  111. // console.log( this.xinspect( event._elementRef.nativeElement, '' ) );
  112. }
  113. }