You need to sign in or sign up before continuing.
admin-equirment.component.ts 12.1 KB
Newer Older
1 2 3
import { Component, OnInit } from '@angular/core';
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
import { Equirment } from 'src/app/models/equirment.model';
4
import { ItemDetail } from 'src/app/models/itemDetail.model';
5
import { RoomDetail } from 'src/app/models/RoomDetail.model';
Your Name committed
6
import { Type } from 'src/app/models/type.model';
7
import { MyRoom, Room } from 'src/app/models/rooms.model';
8 9
import { EquirmentService } from 'src/app/service/equirment.service';
import { RoomService } from 'src/app/service/room.service';
10 11
import { RoomDetailService } from 'src/app/service/room-detail.service';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
Your Name committed
12
import { TypeService } from 'src/app/service/type.service';
13 14 15 16 17 18 19

@Component({
  selector: 'app-admin-equirment',
  templateUrl: './admin-equirment.component.html',
  styleUrls: ['./admin-equirment.component.scss']
})
export class AdminEquirmentComponent implements OnInit {
20
  myForm: FormGroup;
21
  time = { hour: 13, minute: 30 };
22

23 24 25 26 27

  closeResult = '';

  listEquirmentModel: Equirment[] = [];
  listRoomModel: Room[] = [];
28 29
  listItemDetail: ItemDetail[] = [];
  listRoomDetail: RoomDetail[] = [];
30

31 32 33 34 35 36 37 38 39 40
  listEquirmentModelEdit: Equirment | undefined;
  listRoomModelEdit: Room | undefined;

  page = 1;
  pageSize = 10;
  collectionSize = 0;

  pageListRoom = 1;
  pageSizeListRoom = 10;
  collectionSizeListRoom = 0;
41 42


43
  modelEquirment = new Equirment();
44 45 46
  modelRoom: Room
  modelItemDetail = new ItemDetail();
  modelRoomDetail = new RoomDetail();
Your Name committed
47
  modelType = new Type();
48

49 50 51 52 53 54 55 56
  RoomForm = new FormGroup({
    rId: new FormControl(''),
    rName: new FormControl(''),
    rType: new FormControl(''),
    rPic: new FormControl(''),
    roomLimit: new FormControl(''),
    rDesc: new FormControl('')
  });
57

58 59
  myFormRoom: FormGroup;
  myFormEquir: FormGroup;
Your Name committed
60
  myFormType: FormGroup;
61

62
  constructor(private modalService: NgbModal, private equirmentService: EquirmentService, private roomService: RoomService, private RoomDetailService: RoomDetailService
Your Name committed
63
    , private fb: FormBuilder,private typeService: TypeService) {
64 65 66
  }

  ngOnInit() {
Your Name committed
67 68 69 70 71 72
    this.equirmentService.getListEquirment().subscribe( result => {
      this.listEquirmentModel = result;
    });
    this.roomService.getListRoom().subscribe( result => {
      this.listRoomModel = result;
    });
73
    this.collectionSizeListRoom = this.listRoomModel.length
74
    this.collectionSize = this.listEquirmentModel.length
Chanachai committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    this.myFormRoom = new FormGroup({
      userNameForm : new FormControl('',[Validators.required]),
      rTelephone : new FormControl('',[Validators.required]),
      email : new FormControl('',[Validators.required, Validators.email]),
      rName : new FormControl('',[Validators.required]),
      rDesc : new FormControl('',[Validators.required]),
      rType : new FormControl('',[Validators.required]),
      sDate : new FormControl('',[Validators.required]),
      eDate : new FormControl('',[Validators.required]),
      sTime : new FormControl('',[Validators.required]),
      eTime : new FormControl('',[Validators.required]),
      remark : new FormControl(''),
      allDay: new FormControl('')
    });

    this.myFormEquir = new FormGroup({
      userNameForm : new FormControl('',[Validators.required]),
      eTelephone : new FormControl('',[Validators.required]),
      email : new FormControl('',[Validators.required, Validators.email]),
      eqName : new FormControl('',[Validators.required]),
      eqType : new FormControl('',[Validators.required]),
      eqDesc : new FormControl('',[Validators.required]),
      sDate : new FormControl('',[Validators.required]),
      eDate : new FormControl(''),
      sTime : new FormControl(''),
      eTime : new FormControl(''),
      Quantity : new FormControl('',[Validators.required]),
      remark : new FormControl(''),
    })
Your Name committed
104 105

    this.myFormType = new FormGroup({
106
      typeName : new FormControl('',[Validators.required]),
Your Name committed
107
    })
108
 
109 110
  }

111 112
  bookEquir(editLend, item: Equirment) {

113
    this.modelItemDetail = new ItemDetail();
Your Name committed
114
    this.modelItemDetail.equirments = item;
115
    console.log("item", this.modelItemDetail);
116 117 118 119 120 121 122 123 124 125

    this.modalService.open(editLend, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

  bookRoom(editroom, item: Room) {

126 127 128 129 130 131 132 133 134 135
    // this.modelRoom = new MyRoom({
    //   "rId": 2,
    //   "rName": "ห้องคู่",
    //   "rType": "ห้อง",
    //   "rPic": "assets/img/room.jpg",
    //   "roomLimit": 50,
    //   "rDesc": "จำนวนคน 50 คน"
    // });
    // this.modelRoom = new MyRoom(item);
    console.log("room", this.modelRoom);
136 137

    this.modalService.open(editroom, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
138
      console.log("RESUT", result)
139 140
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
141
      console.log("reason", reason)
142 143 144 145
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
  addroom(contentroom,item : Room) {
    this.modelRoom = new MyRoom;
    this.modelRoom = item;
    this.modalService.open(contentroom, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      console.log("RESUT", result)
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      console.log("reason", reason)
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

  addequirment(contentequirment,item : Equirment) {
    this.modelEquirment = new Equirment;
    this.modelEquirment = item;
161
    this.modalService.open(contentequirment, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
162
      console.log("RESUT", result)
163 164
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
165
      console.log("reason", reason)
166 167 168 169
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
  Eopen(contentequirment, index?: number) {
    this.index = index;
    let temp = {
      eqName: this.listEquirmentModel[this.index].eqName,
      eqType: this.listEquirmentModel[this.index].eqType,
      eqDesc: this.listEquirmentModel[this.index].eqDesc,
      eqId: this.listEquirmentModel[this.index].eqId,
      eqPic: this.listEquirmentModel[this.index].eqPic,
    }
    this.listEquirmentModelEdit = temp

    // this.modelEquirment = new Equirment();
    this.modalService.open(contentequirment, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }
  index = -1;
  Ropen(contentroom, index?: number) {
    this.index = index;
    let temp = {
      rName: this.listRoomModel[this.index].rName,
      rType: this.listRoomModel[this.index].rType,
      rDesc: this.listRoomModel[this.index].rDesc,
      rId: this.listRoomModel[this.index].rId,
      rPic: this.listRoomModel[this.index].rPic,
      roomLimit: this.listRoomModel[this.index].roomLimit,
    }
    this.listRoomModelEdit = temp

    // this.modelRoom = new MyRoom();
202 203 204 205 206 207 208
    this.modalService.open(contentroom, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

209 210
  openItemDetail(contentequirment) {
    this.modelEquirment = new Equirment();
211 212 213 214
    this.myFormEquir = new FormGroup({
      eqName : new FormControl(this.modelEquirment.eqName,[Validators.required]),
      eqType : new FormControl(this.modelEquirment.eqType,[Validators.required]),
      eqDesc : new FormControl(this.modelEquirment.eqDesc,[Validators.required]),
Chanachai committed
215
      eqPic : new FormControl(this.modelEquirment.eqPic,[Validators.required]),
216
    })
217
    this.modalService.open(contentequirment, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
218 219 220 221 222 223
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

224 225
  openRoomDetail(contentroom) {
    this.modelRoom = new MyRoom();
226 227 228 229
    this.myFormRoom = new FormGroup({
      rName : new FormControl(this.modelRoom.rName,[Validators.required]),
      rType : new FormControl(this.modelRoom.rType,[Validators.required]),
      rDesc : new FormControl(this.modelRoom.rDesc,[Validators.required]),
Chanachai committed
230
      rPic : new FormControl(this.modelRoom.rPic,[Validators.required]),
231
    })
232
    this.modalService.open(contentroom, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
233 234 235 236 237 238
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

Your Name committed
239 240 241 242 243 244 245 246 247 248 249 250
  openType(contenttype) {
    this.modelType = new Type ();
    this.myFormType = new FormGroup({
      typeId : new FormControl(this.modelType.typeId,[Validators.required]),
      typeName : new FormControl(this.modelType.typeName,[Validators.required]),
    })
    this.modalService.open(contenttype, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281

  private getDismissReason(reason: any): string {
    if (reason === ModalDismissReasons.ESC) {
      return 'by pressing ESC';
    } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
      return 'by clicking on a backdrop';
    } else {
      return `with: ${reason}`;
    }
  }
  refreshCountries() {
    this.listEquirmentModel = this.listEquirmentModel
    this.listRoomModel = this.listRoomModel
      .map((item, i) => ({ id: i + 1, ...item }))
      .slice((this.page - 1) * this.pageSize, (this.page - 1) * this.pageSize + this.pageSize);
  }

  NgbdTimepickerBasic() {

  }

  saveEquirment() {

    this.equirmentService.addEquirment(this.modelEquirment);
    this.modalService.dismissAll();
    this.ngOnInit();

  }

  saveRoom() {

282 283 284
    this.roomService.addRoom(this.modelRoom);
    this.modalService.dismissAll();
    this.ngOnInit();
285 286

  }
287

Your Name committed
288
  saveType(){
289
    this.typeService.addType(this.modelType);
Your Name committed
290 291 292 293
    this.modalService.dismissAll();
    this.ngOnInit();
  }

294 295 296 297 298
  editRoom() {
    this.roomService.editroom(this.modelRoom);
    this.modalService.dismissAll();
    this.ngOnInit();
  }
299 300 301 302 303

  onSubmit() {
    // TODO: Use EventEmitter with form value
    console.warn(this.RoomForm.value);
  }
304
  
305
  updateRoomProfile() {
306 307 308
    this.listRoomModel[this.index].rName = this.myFormRoom.value.rName
    this.listRoomModel[this.index].rDesc = this.myFormRoom.value.rDesc
    this.listRoomModel[this.index].rType = this.myFormRoom.value.rType
Your Name committed
309
    this.roomService.updateRoom(this.listRoomModel[this.index])
310 311
    this.modalService.dismissAll();
    this.ngOnInit();
312 313 314
  }

  updateItemProfile() {
315 316 317
    this.listEquirmentModel[this.index].eqName = this.myFormEquir.value.eqName
    this.listEquirmentModel[this.index].eqDesc = this.myFormEquir.value.eqDesc
    this.listEquirmentModel[this.index].eqType = this.myFormEquir.value.eqType
Your Name committed
318
    this.equirmentService.updateEquirment(this.listEquirmentModel[this.index])
319 320 321 322
    this.modalService.dismissAll();
    this.ngOnInit();
  }

323
  deleteRoomProfile() {
Your Name committed
324
    this.roomService.deleteRoom(this.modelRoom)
325 326 327
    this.modalService.dismissAll();
    this.ngOnInit();
  }
328 329
  
  deleteEquirProfile() {
Your Name committed
330
    this.equirmentService.deleteEquirment(this.modelEquirment)
331 332 333
    this.modalService.dismissAll();
    this.ngOnInit();
  }
334

335
  openDeleteRoom(deleteRoom , item) {
336 337
    this.modelRoom = item ;
    this.modalService.open(deleteRoom, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
338 339 340 341
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
342 343
  }

344 345 346 347 348 349 350 351 352
  openDeleteEquirment(deleteEquirment , item) {
    this.modelEquirment = item ;
    this.modalService.open(deleteEquirment, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

353
}