equirment.service.ts 3.32 KB
Newer Older
1 2 3
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Equirment, SearchEquirmentModel } from '../models/equirment.model';
4
import { ItemDetail } from '../models/itemDetail.model';
Your Name committed
5
import { Observable } from 'rxjs';
6 7 8 9

@Injectable({ providedIn: 'root' })
export class EquirmentService {

10
  constructor(private http: HttpClient) { }
Your Name committed
11 12
  url: string = "http://11f3-49-0-64-28.ngrok.io";
  listEquirment: Equirment[] = []
13

14
  addEquirment(model: Equirment) {
Your Name committed
15 16
    // this.listEquirment.push(model);
    console.log("model", model)
Your Name committed
17
    this.http.post(this.url + "/eqment/", model).subscribe(response => {
Your Name committed
18 19
      console.log(response);
    })
20 21
  }

22 23 24 25
  // bookEquirment(models: ItemDetail){
  //   this.listEquirment.push(models);
  // }

Your Name committed
26 27 28 29 30 31 32 33 34 35 36
  // getListEquirment() {
  //   this.http.get(this.url + "/eqment/lists").subscribe((response: Equirment[]) => {
  //     // this.listEquirment = response;
  //     console.log("...",response);
  //     return response;

  //   })
  // }

  getListEquirment(): Observable<Equirment[]> {
    return this.http.get<Equirment[]>(this.url + "/eqment/lists");
37 38 39 40 41 42 43 44 45 46 47 48 49
  }

  getListRoom() {
    this.http.get(this.url).subscribe((response: any) => {
      console.log(response);
      this.listEquirment = response.content;
    }, error => {
      console.log(error)
      // alert("ไม่สามารถดึงข้อมูลห้องประชุมได้ เนื่องจาก :\n" + error.message)
    })
  }

  searchListEquirment(searchModel: SearchEquirmentModel) {
50
    this.http.get(this.url + '&startDate=' + searchModel.sDate.split("-")[2] + '-' + searchModel.sDate.split("-")[1] + '-' + searchModel.sDate.split("-")[0] + '&endDate=' + searchModel.eDate.split("-")[2] + '-' + searchModel.eDate.split("-")[1] + '-' + searchModel.eDate.split("-")[0] + '&startTime=' + searchModel.sTime + ':00' + '&endTime=' + searchModel.eTime + ':00').subscribe((response: any) => {
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
      console.log(response);
      this.listEquirment = response;
    }, error => {
      console.log(error)
      alert("ไม่สามารถค้นหาอุปกรณ์ที่ว่างได้ เนื่องจาก :\n" + error.message)
    })
  }

  // addEquirment(EquirmentModel: Equirment) {
  //   this.http.post(this.url, EquirmentModel).subscribe(response => {
  //     console.log(response);

  //   })


  // }
  deleteEquirment(EquirmentModel: Equirment) {
Your Name committed
68
    this.http.delete(this.url + "/eqment/" + EquirmentModel.eqId).subscribe(response => {
69 70 71 72 73 74 75 76 77 78 79 80 81
      console.log(response);
      this.getListRoom()
      alert("ลบข้อมูลอุปกรณ์สำเร็จ")
    })
  }

  updateEquirment(EquirmentModel: Equirment) {
    this.http.put(this.url + "/" + EquirmentModel.eqId, EquirmentModel).subscribe(response => {
      console.log(response);
      alert("อัพเดทข้อมูลอุปกรณ์สำเร็จ")
    })
  }

Your Name committed
82
  updateEquirProfile(model: Equirment) {
DESKTOP-HF0LVOG\myhr committed
83 84
    this.listEquirment = this.listEquirment.filter((value, key) => {
      if (value.eqId === model.eqId) {
Your Name committed
85
        value = model;
DESKTOP-HF0LVOG\myhr committed
86 87
      }
      return true;
Your Name committed
88
    });
DESKTOP-HF0LVOG\myhr committed
89 90
  }

91 92 93 94 95 96
  deleteEquirProfile(row_obj: Equirment) {
    this.listEquirment = this.listEquirment.filter((value, key) => {
      return value.eqId !== row_obj.eqId;
    });
  }

97 98 99
  EquirmentModel(eqId: string) {

  }
100 101

}