All files / app/elements/accomodation accomodation.component.ts

79.5% Statements 159/200
82.5% Branches 33/40
94.44% Functions 17/18
79.5% Lines 159/200

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 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 2011x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 12x 12x 1x 1x 13x 13x 13x 2x 2x 2x 2x 13x 13x 1x 13x 12x 12x 13x 13x 1x     1x         1x 13x 13x 1x 1x 13x 13x 13x 2x 2x 13x 2x 2x 13x 13x 13x 1x 1x 2x 2x 2x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                 1x 1x 1x 1x 1x                 1x 1x 1x 1x 1x 1x                 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { Component, Input, OnInit } from '@angular/core';
import { RoomClass } from '@classes/room.class';
import { WizardClass } from '@classes/wizard.class';
import { LineElementComponent } from '../line-element/line-element.component';
import * as Sentry from '@sentry/angular';
import Swal from 'sweetalert2';
 
@Component({
	selector: 'grt-accomodation',
	templateUrl: './accomodation.component.html',
	styleUrls: ['./accomodation.component.scss'],
	imports: [LineElementComponent],
})
export class AccomodationComponent implements OnInit {
	public rooms_count: number = 1;
	public bedsize: string = 'indifferent';
	public kids_age: number = 12;
	public rating: number = 4;
	daysOfTrip: string = '';
	public breakfast: boolean = true;
	public refund: boolean = true;
	@Input() wizardLocal: WizardClass | any;
	public rooms: RoomClass[] | any[] = [];
 
	Toast = Swal.mixin({
			toast: true,
			position: 'top-end',
			showCloseButton: true,
			showConfirmButton: false,
			timerProgressBar: true,
			didOpen: (toast) => {
				toast.onmouseenter = Swal.stopTimer;
				toast.onmouseleave = Swal.resumeTimer;
			},
		});
 
	constructor() {}
 
	ngOnInit() {
		this.refreshPage();
	}
 
	refreshPage() {
		this.daysOfTrip = '';
 
		if (this.wizardLocal) {
			if (this.wizardLocal.id === null || this.wizardLocal.id === undefined) {
				Sentry.captureMessage('[TransportationAComponent] wizardLocal.id is null or undefined', 'warning');
			}
		}
 
		if (this.wizardLocal && this.wizardLocal.hotel_occupancy_rooms) {
			this.rooms = this.wizardLocal.hotel_occupancy_rooms;
		} else {
			this.rooms = [];
		}
 
		if (this.rooms.length > 0 && this.rooms[0] && this.rooms[0].children > 0) {
			if (!this.rooms[0].children_ages) {
				this.rooms[0].children_ages = [];
			}
			if (this.rooms[0].children_ages.length === 0) {
				for (let i = 0; i < this.rooms[0].children; i++) {
					this.rooms[0].children_ages.push(8);
				}
			}
		}
 
		if (this.wizardLocal && this.wizardLocal.hotel_requested_bed_preference) {
			this.bedsize = this.wizardLocal.hotel_requested_bed_preference;
		}
 
		this.rating = this.wizardLocal && this.wizardLocal.hotel_requested_stars;
		if (this.wizardLocal && this.wizardLocal.hotel_include_breakfast !== null) {
			this.breakfast = this.wizardLocal.hotel_include_breakfast;
		}
		if (this.wizardLocal && this.wizardLocal.hotel_include_non_refundable !== null) {
			this.refund = this.wizardLocal.hotel_include_non_refundable;
		}
 
		this.daysOfTrip = this.wizardLocal && this.wizardLocal.getDaysString();
	}
 
	setRating(newRating: number) {
		if (newRating < 3) newRating = 3;
		this.rating = newRating;
	}
 
	roomsDec(): void {
		if (this.rooms?.length !== 1) {
			this.rooms.splice(-1, 1);
		} else {
			this.Toast.fire({
				icon: 'error',
				text: 'At least 1 room is required.',
				background: '#bd362f',
				color: '#fff',
				timer: 5000,
			});
		}
	}
 
	roomsInc(): void {
		if (this.rooms?.length < 8) {
			const newRoom = {
				adults: 2,
				children: 0,
				'children-ages': [],
			};
			this.rooms.push(new RoomClass(newRoom));
		} else {
			this.Toast.fire({
				icon: 'error',
				text: 'Max capacity is 8 rooms.',
				background: '#bd362f',
				color: '#fff',
				timer: 5000,
			});
		}
	}
	adultDecApi(index: any): void {
		if (this.rooms[index].adults !== 1) {
			this.rooms[index].adults--;
		} else {
			this.Toast.fire({
				icon: 'error',
				text: 'Min capacity is 1 person. Each room must have at least one person.',
				background: '#bd362f',
				color: '#fff',
				timer: 5000,
			});
		}
	}
 
	adultIncApi(index: any): void {
		if (this.rooms[index].children + this.rooms[index].adults < 4) {
			this.rooms[index].adults++;
		} else {
			this.Toast.fire({
				icon: 'error',
				text: 'Max capacity is 4 persons. After creating your itinerary, higher occupancy options may be available.',
				background: '#bd362f',
				color: '#fff',
				timer: 5000,
			});
		}
	}
 
	kidsDecApi(index: any): void {
		if (this.rooms[index].children !== 0) {
			this.rooms[index].children--;
			this.rooms[index].children_ages.splice(-1, 1);
		}
	}
 
	kidsIncApi(index: any): void {
		if (this.rooms[index].children + this.rooms[index].adults < 4) {
			this.rooms[index].children++;
			this.rooms[index].children_ages.push(12);
		} else {
			this.Toast.fire({
				icon: 'error',
				text: 'Max capacity is 4 persons. After creating your itinerary, higher occupancy options may be available.',
				background: '#bd362f',
				color: '#fff',
				timer: 5000,
			});
		}
	}
	ageDecApi(index: any, k: any): void {
		if (this.rooms[index].children_ages[k] !== 0) {
			this.rooms[index].children_ages[k]--;
		}
	}
 
	ageIncApi(index: any, k: any): void {
		if (this.rooms[index].children_ages[k] !== 17) {
			this.rooms[index].children_ages[k]++;
		}
	}
 
	ageDec(): void {
		this.kids_age--;
	}
 
	ageInc(): void {
		this.kids_age++;
	}
 
	setBreakfast(value: any): void {
		this.breakfast = value;
	}
	setRefund(value: any): void {
		this.refund = value;
	}
 
	setBedSize(bedSize: any) {
		this.bedsize = bedSize;
	}
}