admin-pending.component.ts 10.7 KB
Newer Older
1
import { Component, OnInit } from '@angular/core';
2
import { NgbDate, NgbCalendar, NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap';
3
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
4
import { Equirment } from 'src/app/models/equirment.model';
Chanachai committed
5 6 7 8 9
import { ItemDetail } from 'src/app/models/itemDetail.model';
import { ItemDetailService } from 'src/app/service/item-detail.service';
import { RoomDetail } from 'src/app/models/roomDetail.model';
import { RoomDetailService } from 'src/app/service/room-detail.service';
import { MyRoom, Room } from 'src/app/models/rooms.model';
10 11
import { EquirmentService } from 'src/app/service/equirment.service';
import { RoomService } from 'src/app/service/room.service';
12
import { FormControl, FormGroup, Validators } from '@angular/forms';
13 14 15 16

@Component({
  selector: 'app-admin-pending',
  templateUrl: './admin-pending.component.html',
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  styleUrls: ['./admin-pending.component.scss'],
  styles: [`
  .form-group.hidden {
    width: 0;
    margin: 0;
    border: none;
    padding: 0;
  }
  .custom-day {
    text-align: center;
    padding: 0.185rem 0.25rem;
    display: inline-block;
    height: 2rem;
    width: 2rem;
  }
  .custom-day.focused {
    background-color: #e6e6e6;
  }
  .custom-day.range, .custom-day:hover {
    background-color: rgb(2, 117, 216);
    color: white;
  }
  .custom-day.faded {
    background-color: rgba(2, 117, 216, 0.5);
  }
`]

44
})
45

46
export class AdminPendingComponent implements OnInit {
47 48
  time = { hour: 13, minute: 30 };

49 50
  page = 1;
  pageSize = 10;
51 52 53 54 55
  collectionSize = 0;

  pageListRoom = 1;
  pageSizeListRoom = 10;
  collectionSizeListRoom = 0;
56

57 58
  closeResult = '';

59 60
  listItemDetail: ItemDetail[] = [];
  listRoomDetail: RoomDetail[] = [];
61

62
  modelEquirment = new Equirment();
Chanachai committed
63
  modelRoom = new MyRoom();
64 65
  modelItemDetail = new ItemDetail();
  modelRoomDetail = new RoomDetail();
66

67
  hoveredDate: NgbDate | null = null;
68

69 70 71
  fromDate: NgbDate | null;
  toDate: NgbDate | null;

72 73
  constructor(private calendar: NgbCalendar, public formatter: NgbDateParserFormatter, private modalService: NgbModal, private ItemDetailService: ItemDetailService, private RoomDetailService: RoomDetailService
    , private equirmentService: EquirmentService, private roomService: RoomService) {
74 75
    this.fromDate = calendar.getToday();
    this.toDate = calendar.getNext(calendar.getToday(), 'd', 10);
76
    this.refreshitemDetail();
77 78
  }

79
  refreshitemDetail() {
80
    this.listItemDetail = this.listItemDetail
81 82 83 84
      .map((country, i) => ({ id: i + 1, ...country }))
      .slice((this.page - 1) * this.pageSize, (this.page - 1) * this.pageSize + this.pageSize);
  }

85 86 87 88 89 90 91 92 93 94 95
  onDateSelection(date: NgbDate) {
    if (!this.fromDate && !this.toDate) {
      this.fromDate = date;
    } else if (this.fromDate && !this.toDate && date && date.after(this.fromDate)) {
      this.toDate = date;
    } else {
      this.toDate = null;
      this.fromDate = date;
    }
  }

96 97 98 99 100 101 102
  open(content) {
    this.modalService.open(content, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }
103 104
  date = '10-12-2561'

105 106
  sDate = ""
  eDate = ""
107 108
  openItemDetail(content: string, item: ItemDetail) {
    this.modelItemDetail = item;
109

110 111 112 113
    let sDate = this.modelItemDetail.sDate.split('/')
    this.sDate = sDate[0] + "-" + sDate[1] + "-" + sDate[2]
    let eDate = this.modelItemDetail.eDate.split('/')
    this.eDate = eDate[0] + "-" + eDate[1] + "-" + eDate[2]
114 115 116 117 118 119 120 121 122 123 124 125 126

    this.myFormEquir = new FormGroup({
      userNameForm: new FormControl(this.modelItemDetail.userName, [Validators.required]),
      eTelephone: new FormControl(this.modelItemDetail.eTelephone, [Validators.required]),
      email: new FormControl(this.modelItemDetail.email, [Validators.required, Validators.email]),
      eqName: new FormControl(this.modelItemDetail.equirment.eqName, [Validators.required]),
      eqDesc: new FormControl(this.modelItemDetail.equirment.eqDesc, [Validators.required]),
      eqType: new FormControl(this.modelItemDetail.equirment.eqType, [Validators.required]),
      sDate: new FormControl(this.modelItemDetail.sDate, [Validators.required]),
      eDate: new FormControl(this.modelItemDetail.eDate, [Validators.required]),
      sTime: new FormControl(this.modelItemDetail.sTime, [Validators.required]),
      eTime: new FormControl(this.modelItemDetail.eTime, [Validators.required]),
      Quantity: new FormControl(this.modelItemDetail.Quantity, [Validators.required]),
127
      Remark: new FormControl(this.modelItemDetail.remark),
128
      eStatus: new FormControl(this.modelItemDetail.eStatus),
129 130
      allDay: new FormControl(this.modelItemDetail.allDay),
      returnItem: new FormControl(this.modelItemDetail.returnItem)
131
    })
132 133 134 135 136 137 138
    this.modalService.open(content, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

139
  rDate(item: string, item2: string) {
140 141
    let Dates = item.split("/")
    let dates = Dates[0] + "-" + Dates[1] + "-" + Dates[2]
142 143

    if (item2 == "sdate") {
144
      this.modelRoomDetail.sDate = dates
145
    }
146
    if (item2 == "edate") {
147
      this.modelRoomDetail.eDate = dates
148
    }
149
  }
150

151 152
  openRoomDetail(content: string, item: RoomDetail) {
    this.modelRoomDetail = item;
153

154 155 156 157 158
    let sDate = this.modelRoomDetail.sDate.split('/')
    this.sDate = sDate[0] + "-" + sDate[1] + "-" + sDate[2]
    let eDate = this.modelRoomDetail.eDate.split('/')
    this.eDate = eDate[0] + "-" + eDate[1] + "-" + eDate[2]
    console.log(this.modelRoomDetail)
159 160 161 162 163 164 165 166 167

    this.myFormRoom = new FormGroup({
      userNameForm: new FormControl(this.modelRoomDetail.userName, [Validators.required]),
      rTelephone: new FormControl(this.modelRoomDetail.rTelephone, [Validators.required]),
      email: new FormControl(this.modelRoomDetail.email, [Validators.required, Validators.email]),
      rName: new FormControl(this.modelRoomDetail.room.rName, [Validators.required]),
      rDesc: new FormControl(this.modelRoomDetail.room.rDesc, [Validators.required]),
      rType: new FormControl(this.modelRoomDetail.room.rType, [Validators.required]),
      sDate: new FormControl(this.modelRoomDetail.sDate, [Validators.required]),
168 169
      eDate: new FormControl(this.modelRoomDetail.eDate, [Validators.required]),
      sTime: new FormControl(this.modelRoomDetail.sTime, [Validators.required]),
170
      eTime: new FormControl(this.modelRoomDetail.eTime, [Validators.required]),
171
      remark: new FormControl(this.modelRoomDetail.remark),
172 173
      rStatus: new FormControl(this.modelRoomDetail.rStatus),
      allDay: new FormControl(this.modelRoomDetail.allDay)
174
    });
175 176 177 178 179 180 181
    this.modalService.open(content, { ariaLabelledBy: 'modal-basic-title' }).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }

182 183 184 185 186 187 188 189 190 191
  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}`;
    }
  }

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
  isHovered(date: NgbDate) {
    return this.fromDate && !this.toDate && this.hoveredDate && date.after(this.fromDate) && date.before(this.hoveredDate);
  }

  isInside(date: NgbDate) {
    return this.toDate && date.after(this.fromDate) && date.before(this.toDate);
  }

  isRange(date: NgbDate) {
    return date.equals(this.fromDate) || (this.toDate && date.equals(this.toDate)) || this.isInside(date) || this.isHovered(date);
  }

  validateInput(currentValue: NgbDate | null, input: string): NgbDate | null {
    const parsed = this.formatter.parse(input);
    return parsed && this.calendar.isValid(NgbDate.from(parsed)) ? NgbDate.from(parsed) : currentValue;
  }

209 210 211
  myFormRoom: FormGroup;
  myFormEquir: FormGroup;

212
  ngOnInit(): void {
213 214 215 216
    this.listItemDetail = this.ItemDetailService.getListItemDetail();
    this.listRoomDetail = this.RoomDetailService.getListRoomDetail();
    this.collectionSizeListRoom = this.listItemDetail.length;

217 218
  }

219 220 221 222 223
  saveEquirment() {
    this.equirmentService.addEquirment(this.modelEquirment);
    this.modalService.dismissAll();
    this.ngOnInit();
  }
224

225 226 227 228 229
  saveRoom() {
    this.roomService.addRoom(this.modelRoom);
    this.modalService.dismissAll();
    this.ngOnInit();
  }
230

231 232 233 234 235 236 237 238 239 240 241 242 243 244
  saveStatusRoom() {

    console.log("this.modelRoomDetail", this.modelRoomDetail)
    console.log("form", this.myFormRoom)
    this.modelRoomDetail.userName = this.myFormRoom.value.userNameForm;
    this.modelRoomDetail.rTelephone  = this.myFormRoom.value.rTelephone
    this.modelRoomDetail.email  = this.myFormRoom.value.email
    this.modelRoomDetail.room.rName  = this.myFormRoom.value.rName
    this.modelRoomDetail.room.rDesc  = this.myFormRoom.value.rDesc
    this.modelRoomDetail.room.rType  = this.myFormRoom.value.rType
    this.modelRoomDetail.sDate  = this.myFormRoom.value.sDate
    this.modelRoomDetail.eDate  = this.myFormRoom.value.eDate
    this.modelRoomDetail.sTime  = this.myFormRoom.value.sTime
    this.modelRoomDetail.eTime  = this.myFormRoom.value.eTime
245
    this.modelRoomDetail.remark  = this.myFormRoom.value.remark
246
    this.modelRoomDetail.rStatus  = this.myFormRoom.value.rStatus
247
    this.modelRoomDetail.allDay = this.myFormRoom.value.allDay
248
    console.log("this.modelRoomDetail", this.modelRoomDetail)
DESKTOP-HF0LVOG\myhr committed
249
    this.RoomDetailService.updateRoomDetail(this.modelRoomDetail)
250 251 252
    this.modalService.dismissAll();
    this.ngOnInit();
  }
253

254 255 256 257 258 259 260 261 262 263 264 265 266 267
  saveStatusEquirment() {

    console.log("this.modelItemDetail", this.modelItemDetail)
    console.log("form", this.myFormEquir)
    this.modelItemDetail.userName = this.myFormEquir.value.userNameForm;
    this.modelItemDetail.eTelephone  = this.myFormEquir.value.eTelephone
    this.modelItemDetail.email  = this.myFormEquir.value.email
    this.modelItemDetail.equirment.eqName  = this.myFormEquir.value.eqName
    this.modelItemDetail.equirment.eqDesc  = this.myFormEquir.value.eqDesc
    this.modelItemDetail.equirment.eqType  = this.myFormEquir.value.eqType
    this.modelItemDetail.sDate  = this.myFormEquir.value.sDate
    this.modelItemDetail.eDate  = this.myFormEquir.value.eDate
    this.modelItemDetail.sTime  = this.myFormEquir.value.sTime
    this.modelItemDetail.eTime  = this.myFormEquir.value.eTime
268
    this.modelItemDetail.remark  = this.myFormEquir.value.remark
269
    this.modelItemDetail.eStatus  = this.myFormEquir.value.eStatus
270
    this.modelItemDetail.allDay = this.myFormEquir.value.allDay
271 272 273 274 275 276
    console.log("this.modelItemDetail", this.modelItemDetail)
    this.ItemDetailService.updateItemDetail(this.modelItemDetail)
    this.modalService.dismissAll();
    this.ngOnInit();
  }
  
277

278
}
279