All files / app/pages/trip-register-page/third-step third-step.component.ts

77.77% Statements 77/99
80% Branches 4/5
50% Functions 3/6
77.77% Lines 77/99

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 1001x 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 4x 4x 4x 4x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x     4x 4x 4x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 2x 1x 1x     1x 1x     1x 1x                                 1x  
import { isPlatformBrowser } from '@angular/common';
import { Component, OnInit, PLATFORM_ID, inject } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Meta } from '@angular/platform-browser';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { HeaderElementComponent } from '@elements/header-element/header-element.component';
import { MetaTagService } from '@services/meta-tag.service';
 
@Component({
	selector: 'grt-third-step',
	imports: [HeaderElementComponent, RouterLink, ReactiveFormsModule, FormsModule],
	templateUrl: './third-step.component.html',
	styleUrl: './third-step.component.scss',
})
export class ThirdStepComponent implements OnInit {
	private router = inject(Router);
	private route = inject(ActivatedRoute);
	private platformId = inject(PLATFORM_ID);
	private meta = inject(Meta);
	private metaTag = inject(MetaTagService);
 
	isBrowser = false;
	wizardData!: any;
	slug = '';
	openedSection: string = 'default';
	purchased: string = '0';
	comment = '';
	arrival_yes: string = '1';
	depart_yes: string = '1';
 
	constructor() {
		const platformId = this.platformId;
 
		this.isBrowser = isPlatformBrowser(platformId);
	}
 
	ngOnInit(): void {
		this.metaTag.removeMetaTags();
 
		this.meta.updateTag({
			name: 'robots',
			content: 'noindex, nofollow',
		});
		if (this.isBrowser) {
			const robotsTag = document.querySelector('meta[name="robots"]');
			if (robotsTag) {
				robotsTag.setAttribute('data-seo-lock', 'true');
			}
		}
 
		this.slug = this.route.snapshot.params['slug'];
		if (this.isBrowser) {
			const id = this.route.snapshot.params['slug'];
			if (isPlatformBrowser(this.platformId)) {
				const data = localStorage.getItem(`wizard-${id}`);
				if (data) {
					this.wizardData = JSON.parse(data);
				}
			}
		}
	}
 
	toggleTickets(value: any) {
		this.openedSection = value;
		if (value === 'default') {
			this.purchased = '0';
		} else {
			this.purchased = '1';
			// this.arrival_yes = this.addedCities[0].id;
			// this.depart_yes = this.addedCities[0].id;
		}
	}
 
	goBack() {
		this.router.navigateByUrl('/trips/' + this.slug);
	}
 
	goPrev() {
		this.router.navigateByUrl('/trips/register/step-2' + this.slug);
	}
 
	continue() {
		let flights = false;
		if (this.purchased == '1') flights = true;
		if (this.comment?.length > 0) {
			this.wizardData = {
				...this.wizardData,
				'additional-comments': this.comment,
				'purchased-flights': flights,
				// 'arrive-city-id': this.arrival_yes,
				// 'depart-city-id': this.depart_yes,
			};
		}
		window.localStorage.setItem(`wizard-${this.slug}`, JSON.stringify(this.wizardData));
		window.localStorage.setItem(`wizard`, JSON.stringify(this.wizardData));
		window.localStorage.setItem('slug', this.slug);
		this.router.navigateByUrl('/trips/register/step-4');
	}
}