SHARE
TWEET

Untitled

a guest Oct 21st, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit, Input, OnDestroy } from '@angular/core';
  2. import { FormGroup } from '@angular/forms';
  3. import { NotificationsService } from 'angular2-notifications';
  4. import { map } from 'rxjs/operators';
  5. import { Subscription } from 'rxjs';
  6. import { FoSharedDataService } from '../../core/fo-shared-data.service';
  7. import { FoSequenceSubscribeDataService } from './data/fo-sequence-subscribe-data.service';
  8. import { SequenceItem } from './data/model/fo-sequence.model';
  9. import { FoSequenceSubscribeApiService } from './data/fo-sequence-subscribe-api.service';
  10.  
  11. @Component({
  12.   selector: 'fo-sequence-subscribe-modal',
  13.   templateUrl: './fo-sequence-subscribe-modal.component.html',
  14.   styleUrls: ['./fo-sequence-subscribe-modal.component.scss'],
  15.   providers: [FoSequenceSubscribeApiService]
  16. })
  17. export class FoSequenceSubscribeModalComponent implements OnInit, OnDestroy {
  18.   _subscription = new Subscription();
  19.  
  20.   FORM_CONTROL_LOCATION = 'FORM_CONTROL_LOCATION';
  21.  
  22.   @Input() close: Function;
  23.  
  24.   isSubmitting = false;
  25.  
  26.   isReviewSequenceEnabled = false;
  27.  
  28.   sequenceUiItems$ = this.dataService.sequences$.pipe(
  29.     map(sequences =>
  30.       sequences.map(sequence => {
  31.         return {
  32.           ...sequence,
  33.           is_selected: false
  34.         };
  35.       })
  36.     )
  37.   );
  38.  
  39.   form = new FormGroup({});
  40.  
  41.   sequenceUiItems: SequenceUiItem[] = [];
  42.  
  43.   isDataNotAvailable$ = this.dataService.isDataNotAvailable$;
  44.  
  45.  
  46.   constructor(
  47.     private notification: NotificationsService,
  48.     private sharedDataService: FoSharedDataService,
  49.     private dataService: FoSequenceSubscribeDataService,
  50.   ) {}
  51.  
  52.   ngOnInit() {
  53.     this._subscription.add(
  54.       this.sequenceUiItems$.subscribe(seq => (this.sequenceUiItems = seq))
  55.     );
  56.     this.dataService.fetch();
  57.   }
  58.  
  59.   toggleSelectSequence(item: SequenceUiItem) {
  60.     item.is_selected = !item.is_selected;
  61.     this.sequenceUiItems = this.sequenceUiItems.map(sequence => {
  62.       if (sequence.sequence_id === item.sequence_id) {
  63.         return {
  64.           ...sequence,
  65.           ...item
  66.         };
  67.       }
  68.       return sequence;
  69.     });
  70.   }
  71.  
  72.   onSubmit() {
  73.     // if (this.isSubmitting) {
  74.     //   return;
  75.     // }
  76.     // if (this.form.valid) {
  77.     //   const payload: CheckInPayload = {
  78.     //     unirson_id: this.unirsonInfo.unirson_id,
  79.     //     location_id: this.form.value[this.FORM_CONTROL_LOCATION],
  80.     //     seq_ids: this.sequenceUiItems
  81.     //       .filter(sequence => sequence.is_selected)
  82.     //       .map(sequence => sequence.sequence_id),
  83.     //     review_seq: this.isReviewSequenceEnabled ? 1 : 0
  84.     //   };
  85.     //   this.isSubmitting = true;
  86.     //   this.apiService.checkIn(payload).subscribe(
  87.     //     res => {
  88.     //       this.isSubmitting = false;
  89.     //       this.close();
  90.     //     },
  91.     //     error => {
  92.     //       this.isSubmitting = false;
  93.     //       foShowErrorNotification(error, this.notification);
  94.     //     }
  95.     //   );
  96.     // } else {
  97.     //   this.notification.error('Not allowed', 'One or more invalid inputs');
  98.     // }
  99.   }
  100.  
  101.   ngOnDestroy() {
  102.     this._subscription.unsubscribe();
  103.   }
  104. }
  105.  
  106. export interface SequenceUiItem extends SequenceItem {
  107.   is_selected: boolean;
  108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top