Advertisement
Guest User

Untitled

a guest
May 13th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Component, Input, OnInit} from '@angular/core';
  2. import {ActivatedRoute} from '@angular/router';
  3. import {UniversityModel} from '../../models/University.model';
  4. import {UniversityService} from '../../services/university.service';
  5. import {WishService} from '../../services/wish.service';
  6. import {WishModel} from '../../models/Wish.model';
  7. import {toNumbers} from '@angular/compiler-cli/src/diagnostics/typescript_version';
  8. import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
  9. import {User} from '../../models/User.model';
  10. import {SessionService} from '../../services/session/session.service';
  11. import {CourseModel} from '../../models/Course.model';
  12.  
  13.  
  14. @Component({
  15.   selector: 'app-agreement-host',
  16.   templateUrl: './agreement-host.component.html',
  17.   styleUrls: ['./agreement-host.component.css']
  18. })
  19. export class AgreementHostComponent implements OnInit {
  20.  
  21.   private fieldArray: Array<any> = [];
  22.   private newAttribute: any = {};
  23.   private wishList: WishModel[] = [];
  24.  
  25.   semester = ['semestre 1', 'semestre 2', 'toute l\'année'];
  26.   diploma = ['Ingenieur en science informatique', 'Ingenieur en génie électrique', 'Ingenieur en génie de l\'eau',
  27.     'Ingenieur en génie du bâtiment', 'Ingenieur en biologie'];
  28.   university: UniversityModel;
  29.   // private isNewWish = false;
  30.   user: User;
  31.  
  32.   public agreementForm: FormGroup;
  33.  
  34.   constructor(private route: ActivatedRoute, public formBuilder: FormBuilder, private universityService: UniversityService,
  35.               private wishService: WishService, private sessionService: SessionService) {
  36.     this.agreementForm = this.formBuilder.group({
  37.       semester: new FormControl(''),
  38.       diploma: new FormControl(''),
  39.       courses: this.formBuilder.array([])
  40.     });
  41.   }
  42.  
  43.   ngOnInit() {
  44.     this.getUniversity();
  45.     this.user = this.sessionService.getCurrentUserModel();
  46.   }
  47.  
  48.   getUniversity(): void {
  49.     const id = +this.route.snapshot.paramMap.get('id');
  50.     console.log(id);
  51.     this.universityService.getUniversity(id)
  52.       .subscribe(university => this.university = university);
  53.   }
  54.  
  55.   addWish() {
  56.     if (this.agreementForm.valid) {
  57.       const formValue = this.agreementForm.value;
  58.       const newWish = new WishModel(
  59.         this.user.id, this.university.id, this.university.name,
  60.         formValue.semester, formValue.diploma, this.university.agreements,
  61.         formValue.courses ? formValue.courses : []
  62.       );
  63.  
  64.  
  65.     }
  66.   }
  67.  
  68.   // editWish(isNew: boolean) {
  69.   //   //   this.isNewWish = isNew;
  70.   //   //   const bool = true;
  71.   //   //   const semesterValue = '2';
  72.   //   //   const id = +this.route.snapshot.paramMap.get('id');
  73.   //   //   this.wishService.putWish(
  74.   //   //     {
  75.   //   //       id: 1,
  76.   //   //       universityId: id,
  77.   //   //       semester: semesterValue,
  78.   //   //       agreementCompleted: bool
  79.   //   //     } as WishModel).subscribe();
  80.   //   // }
  81.  
  82.   addFieldValue() {
  83.  
  84.     const newHobbyControl = this.formBuilder.control(null, Validators.required);
  85.     this.getCourses().push(newHobbyControl);
  86.  
  87.   }
  88.  
  89.   deleteFieldValue(index) {
  90.     this.fieldArray.splice(index, 1);
  91.   }
  92.  
  93.   getCourses(): FormArray {
  94.     return this.agreementForm.get('courses') as FormArray;
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement