setting-base.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. }
  23. ionViewWillEnter() {
  24. this.sub = this.abc.temperature_s1.subscribe( data => {
  25. //console.log('sub ' + this.abc.temperature);
  26. //this.tt42 = this.abc.temperature + ' °';
  27. this.cdr.detectChanges( );
  28. } );
  29. }
  30. ionViewWillLeave() {
  31. // this.abc.temperature_s1.unsubscribe();
  32. this.sub.unsubscribe();
  33. }
  34. init( defaults: any ) {
  35. this.pars_defaults = defaults;
  36. this.pars = this.abc.fetch( this.pars_defaults );
  37. this.doCopy( this.pars_undo, this.pars );
  38. }
  39. doCompare( o1: any, o2: any ) {
  40. for (var attr in o1)
  41. if( o1[attr] != o2[attr] ) {
  42. // console.log( 'Compare ' + attr + ' from ' + o2[ attr] + ' to ' + o1[ attr ] );
  43. return true;
  44. }
  45. return false;
  46. }
  47. doCopy( dest: any, src: any ) {
  48. for (var attr in src)
  49. if (src.hasOwnProperty(attr))
  50. dest[attr] = src[attr];
  51. }
  52. getDiff( src: any, check: any ) {
  53. var res = {};
  54. for (var attr in src)
  55. if (src.hasOwnProperty(attr) && src[attr] != check[attr] )
  56. res[ attr ] = src[ attr ];
  57. return res;
  58. }
  59. showDefaults() {
  60. return this.doCompare( this.pars, this.pars_defaults );
  61. }
  62. doDefaults() {
  63. this.doCopy( this.pars, this.pars_defaults );
  64. }
  65. showUndo() {
  66. return this.doCompare( this.pars, this.pars_undo );
  67. }
  68. doUndo() {
  69. this.doCopy( this.pars, this.pars_undo );
  70. }
  71. showUpdate() {
  72. return this.showUndo();
  73. }
  74. doUpdate() {
  75. console.log( this.getDiff( this.pars, this.pars_undo ) );
  76. this.abc.update( this.getDiff( this.pars, this.pars_undo ) );
  77. this.doCopy( this.pars_undo, this.pars );
  78. this.abc.message = 'Updated';
  79. }
  80. notify( event: any ) {
  81. // this.show_defaults = true;
  82. // TODO: do we still want this??
  83. //console.log( 'ionChange: ' + event._elementRef.nativeElement.id );
  84. //if( event.value != undefined )
  85. // console.log( 'value = ' + event.value );
  86. //if( event.checked != undefined )
  87. // console.log( 'checked = ' + event.checked );
  88. //if( event.target != undefined )
  89. // console.log( 'target = ' + event.target );
  90. //if( event.currentTarget != undefined )
  91. //console.log( 'currentraget = ' + event.currentTarget );
  92. // console.log( this.xinspect( event._elementRef.nativeElement, '' ) );
  93. }
  94. }