admin-pending.component.ts 2.98 KB
Newer Older
1
import { Component, OnInit } from '@angular/core';
2
import { NgbDate, NgbCalendar, NgbDateParserFormatter } from '@ng-bootstrap/ng-bootstrap';
3 4 5

interface Country {
  id?: number;
6
  catagory: string;
7
  type: string;
8
  detail: string;
9 10 11
  name: string;
  sdate: string;
  edate: string;
12
  status: string;
13 14 15 16 17 18
}


@Component({
  selector: 'app-admin-pending',
  templateUrl: './admin-pending.component.html',
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 44 45
  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);
  }
`]

46
})
47

48 49 50 51
export class AdminPendingComponent implements OnInit {
  page = 1;
  pageSize = 10;

52
  countries: Country[] = [
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
      {
        catagory: 'string',
        type: 'string',
        detail: 'Moniter',
        name: 'a',
        sdate: '2021-11-25',
        edate: '2021-11-25',
        status: 'waiting',
      },
      {
        catagory: 'string',
        type: 'string',
        detail: 'Mouse',
        name: 'b',
        sdate: '2021-11-25',
        edate: '2021-11-25',
        status: 'waiting',
      }
71
  ];
72

73 74 75 76 77 78 79 80
  collectionSize = this.countries.length;
  hoveredDate: NgbDate | null = null;
  fromDate: NgbDate | null;
  toDate: NgbDate | null;

  constructor(private calendar: NgbCalendar, public formatter: NgbDateParserFormatter) {
    this.fromDate = calendar.getToday();
    this.toDate = calendar.getNext(calendar.getToday(), 'd', 10);
81 82 83 84
    this.refreshCountries();
  }

  refreshCountries() {
85
    this.countries = this.countries
86 87 88 89
      .map((country, i) => ({ id: i + 1, ...country }))
      .slice((this.page - 1) * this.pageSize, (this.page - 1) * this.pageSize + this.pageSize);
  }

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  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;
    }
  }

  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;
  }

118 119 120 121
  ngOnInit(): void {
  }

}
122 123 124

export class NgbdDropdownBasic {
}