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

94.2% Statements 65/69
100% Branches 8/8
87.5% Functions 7/8
94.2% Lines 65/69

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 701x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 7x 7x 6x 6x     6x 6x 1x 1x 6x 6x 1x 1x 6x 6x 1x 1x 6x 6x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x   1x 1x 6x 6x 2x 2x 6x  
import { NgOptimizedImage, NgStyle } from '@angular/common';
import { Component, Input, OnInit, inject, input, output } from '@angular/core';
import { FlagService } from '@services/flag.service';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { CityClass } from '@classes/city.class';
import { PreviewDestinationModalComponent } from '../preview-destination-modal/preview-destination-modal.component';
 
@Component({
	selector: 'grt-citybox',
	templateUrl: './citybox.component.html',
	styleUrls: ['./citybox.component.scss'],
	imports: [NgStyle, NgOptimizedImage],
	providers: [BsModalService],
})
export class CityboxComponent implements OnInit {
	private modalService = inject(BsModalService);
	flagService = inject(FlagService);
 
	@Input() city!: CityClass;
	readonly mainPage = input.required<boolean>();
	readonly index = input.required<number>();
	readonly deselect = output<CityClass>();
	readonly selected = output<CityClass>();
	readonly showdetails = output<CityClass>();
	selectedCity!: CityClass;
	countryName!: string;
	modalRef!: BsModalRef;
	hover = false;
 
	ngOnInit() {
		this.countryName = this.city && this.city.countryName.replace(/\s+/g, '-');
	}
 
	replaceUrl(url: string) {
		return url.replace(/https:\/\/res-(?:[1-5]\.|)\bcloudinary.com\/gorealtravel\/image\/upload\//g, '');
	}
 
	add() {
		this.selected.emit(this.city);
	}
 
	remove() {
		this.deselect.emit(this.city);
	}
 
	details() {
		this.showdetails.emit(this.city);
	}
 
	openModal(data: any) {
		const initialState = {
			city: data, // Pass data to the modal
		};
		this.modalRef = this.modalService.show(PreviewDestinationModalComponent, {
			initialState,
		});
 
		this.modalRef.content.addCityToTrip.subscribe(() => {
			this.add(); // Call the function in the parent component
		});
		this.modalRef.content.removeCityFromTrip.subscribe(() => {
			this.remove(); // Call the function in the parent component
		});
	}
 
	setHover(bool: boolean) {
		this.hover = bool;
	}
}