Created
August 4, 2017 14:02
-
-
Save NikhilRadadiya/856040b19671a91941a64410a0018ad0 to your computer and use it in GitHub Desktop.
home.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, ElementRef, ViewChild,Input, Output, EventEmitter } from '@angular/core'; | |
import { Http,Response,Headers } from '@angular/http'; | |
import {NgForm, FormBuilder,ReactiveFormsModule,FormGroup} from '@angular/forms'; | |
import { Observable,Subscription } from 'rxjs/Rx'; | |
import { Router, NavigationStart, ActivatedRoute,Params } from '@angular/router'; | |
import {QuoteService} from 'app/services/quote.service'; | |
import { LoadpageService } from 'app/services/loadpage.service'; | |
import { asEnumerable } from 'linq-es2015'; | |
import { Inclusion } from './inclusions'; | |
import { Optional } from './optionals'; | |
import { Options } from './options'; | |
import { Itinerary } from './itinerary'; | |
import { Suppliment } from './supplement'; | |
import { Term } from './term'; | |
declare let jsPDF; | |
declare var $: any; | |
@Component({ | |
selector: 'home', | |
templateUrl: './home.component.html', | |
styleUrls: ['./home.component.css'] | |
}) | |
export class HomeComponent implements OnInit { | |
/*Basic Details Section*/ | |
@ViewChild('main') el: ElementRef; | |
//Event EventEmitter | |
@Input() tour; | |
isReady:boolean; | |
private eventDate: any = new Date("2017-06-28"); | |
public quotes: any; | |
public quotesRes: any; | |
public FooterText: any; | |
public Logo: any; | |
public cityBreaks: any; | |
public cityBreak = []; | |
public quoteLists:any; | |
public imgURL = "http://mydeskapi.techpure.co.uk"; | |
private diff: number; | |
private distance: number; | |
private countDownResult: number; | |
private months: number; | |
private days: number; | |
private hours: number; | |
private minutes: number; | |
private seconds: number; | |
/*Inclusions*/ | |
//@ViewChild('myCarousel') el: ElementRef; | |
public inclusions:any; | |
public inclusionList:Inclusion[]; | |
public allCat:any; | |
public disp_obj =[]; | |
public Incl = []; | |
/*Options*/ | |
public OptionsUrl: string = "http://mydeskapi.techpure.co.uk/api/QuoteWebController/Baseload"; | |
public optionsdata:Options[]; | |
public servicewiseData:Options[]; | |
public Opts:any; | |
//public SerOpts=[]; | |
public SerOpts:any; | |
public OptionsRes=[]; | |
public QuotType:any; | |
public Cities = ['Phuket','Broc','Montreux']; | |
public Ratings = ['1','2','3']; | |
/*Optionals*/ | |
public optionals:Optional[]; | |
public Opt = []; | |
public optTitle = []; | |
/*Supplement*/ | |
public supplements:any; | |
/*Itinerary*/ | |
public itinerary:Itinerary[]; | |
public Itns:any; | |
public ItnBg:any; | |
/*TravelGuide*/ | |
public travelGuides:any; | |
public categories:any; | |
public categoryImgs:any; | |
public allCategories:any; | |
public Category :any; | |
public uniqCategory =""; | |
public uniqCats:any; | |
public Optional:any; | |
public Active = 'All'; | |
/*Terms*/ | |
public terms: Term[]; | |
public notes: Term[]; | |
public exclusions: Term[]; | |
//public exclusions:any; | |
public uniqTerm= []; | |
public TermCons = []; | |
public ImpNotes = []; | |
public ExclusionList = []; | |
/*Revisions*/ | |
public url: string = "http://mydeskapi.techpure.co.uk/api/QuoteWebController/Insert"; | |
public revisions: any; | |
public resultCode: any; | |
public responeseMsg: any; | |
public name:string; | |
public email:string; | |
public phone:string; | |
public message:any; | |
public submitted:boolean; | |
public InquiryCode:any; | |
public QuoteCode:any; | |
public corporate:any; | |
constructor( | |
private http:Http, | |
private quoteService:QuoteService, | |
private loadpageService:LoadpageService, | |
private _router: Router, | |
private _activeRoute: ActivatedRoute | |
) { | |
this._activeRoute.queryParams.subscribe((params: Params) => { | |
this.corporate = params['corporate']; | |
this.QuoteCode = params['QuoteCode']; | |
this.InquiryCode = params['InquiryCode']; | |
}); | |
this.submitted = false; | |
} | |
ngOnInit() { | |
this.isReady = false; | |
this.loadpageService.setdata(this.isReady); | |
var quo = this.getQuotes(); | |
//console.log(this.getQuotes()); | |
this.getInclusion(); | |
this.getSupplemet(); | |
this.getOptionals(); | |
this.getOption(); | |
this.getItinerary(); | |
this.getTravelGuide(); | |
this.getTerms(); | |
} | |
getQuotes(){ | |
this.quoteService.getQuotes() | |
.subscribe( | |
quotes => { | |
this.loadpageService.setdata(this.isReady); | |
this.quotes = quotes.resultData; | |
this.quotesRes = quotes.resultData; | |
this.QuotType = this.quotesRes.BasicDetails[0].QuotType; | |
this.FooterText = this.quotesRes.BasicDetails[0].FooterText; | |
this.Logo = this.quotesRes.BasicDetails[0].Logo; | |
this.cityBreaks = this.quotesRes.CityBreak; | |
this.quoteLists = this.quotesRes.QuotList; | |
Observable.interval(1000).map((x) => { | |
var countDownDate = new Date(this.quotesRes.BasicDetails[0].Traveldate +' 00:00:00').getTime(); | |
var now = new Date().getTime(); | |
this.distance = countDownDate - now; | |
}).subscribe((x) => { | |
this.months = Math.floor(this.distance / (1000 * 60 * 60 * 24 * 30)); | |
var dtm = Math.floor((new Date(this.quotesRes.BasicDetails[0].Traveldate +' 00:00:00').getTime() - new Date().getTime()) / 1000); | |
this.days = Math.floor(dtm / 60 / 60 / 24 % 30); | |
this.hours = Math.floor((this.distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); | |
this.minutes = Math.floor((this.distance % (1000 * 60 * 60)) / (1000 * 60)); | |
this.seconds = Math.floor((this.distance % (1000 * 60)) / 1000); | |
}); | |
//console.log(this.quoteLists.length); | |
for(let city of this.quotesRes.CityBreak) { | |
if(city.NoOfNights > 1){ | |
this.cityBreak.push(' '+city.NoOfNights +' Nights '+ city.CityName +''); | |
}else{ | |
this.cityBreak.push(city.NoOfNights +' Night '+ city.CityName +''); | |
} | |
} | |
this.isReady = true; | |
}, | |
response => { | |
if (response.status == 404) { | |
//this.router.navigate(['NotFound']); | |
} | |
}); | |
} | |
/*Options*/ | |
getOption() { | |
this.quoteService.getQuotes().mergeMap( quotes => { | |
// Do whatever you need to do with quotes | |
//this.QuotType = 'QUOTTYP-3'; | |
if(this.quotes.BasicDetails[0].QuotType == 'QUOTTYP-3'){ | |
return this.quoteService.getServiceWiseOptions() | |
} | |
else{ | |
return this.quoteService.getOptions() | |
} | |
}) | |
.subscribe( | |
options => { | |
if(this.quotes.BasicDetails[0].QuotType == 'QUOTTYP-3'){ | |
this.servicewiseData = options.resultData.ServiceWiseOption; | |
}else{ | |
this.servicewiseData = options.resultData.Hoteloption; | |
} | |
this.SerOpts = asEnumerable(this.servicewiseData).GroupBy(x => x.OptionId, x => x, | |
(key, b) => | |
{ return { | |
OptionId: key ,SerOptionsRes: asEnumerable(b).ToArray() } | |
}) | |
.ToArray(); | |
console.log(this.SerOpts); | |
setTimeout(() => { | |
$('#myCarousel2').carousel({ | |
interval: false | |
}) | |
$('.fdi-Carousel2 .item').each(function () { | |
var next = $(this).next(); | |
if (!next.length) { | |
next = $(this).siblings(':first'); | |
} | |
next.children(':first-child').clone().appendTo($(this)); | |
}); | |
}, 5000); | |
}, | |
response => { | |
if (response.status == 404) { | |
//this.router.navigate(['NotFound']); | |
} | |
} | |
) | |
} | |
/*Inclusion*/ | |
getInclusion(){ | |
this.quoteService.getInclusion() | |
.subscribe( | |
inclusions=> { | |
//this.inclusions = inclusions.resultData; | |
this.inclusionList = inclusions.resultData.Inclusions; | |
this.Incl = asEnumerable(this.inclusionList).GroupBy(x => x.Category, x => x, | |
(key, b) => | |
{ return { | |
Category: key ,Services: asEnumerable(b).ToArray() } | |
}) | |
.ToArray(); | |
setTimeout(() => { | |
$('#myCarousel').carousel({ | |
interval: 10000 | |
}) | |
$('.fdi-Carousel .item').each(function () { | |
var next = $(this).next(); | |
if (!next.length) { | |
next = $(this).siblings(':first'); | |
} | |
next.children(':first-child').clone().appendTo($(this)); | |
if (next.next().length > 0) { | |
next.next().children(':first-child').clone().appendTo($(this)); | |
} | |
else { | |
$(this).siblings(':first').children(':first-child').clone().appendTo($(this)); | |
} | |
}); | |
$(".content").mCustomScrollbar({ | |
enable:true | |
}); | |
}, 3000); | |
}, | |
response => { | |
if (response.status == 404) { | |
//this.router.navigate(['NotFound']); | |
} | |
} | |
) | |
} | |
/*Optionals*/ | |
getOptionals(){ | |
this.quoteService.getOptionals() | |
.subscribe(optionals => { | |
this.optionals = optionals.resultData.Optionals; | |
this.Opt = asEnumerable(this.optionals).GroupBy(x => x.OptionalsFor, x => x, | |
(key, b) => | |
{ return { | |
OptionalsFor: key ,Optionals: asEnumerable(b).ToArray() } | |
}) | |
.ToArray(); | |
}, | |
response => { | |
if (response.status == 404) { | |
//this.router.navigate(['NotFound']); | |
} | |
}) | |
} | |
/*Supplemet*/ | |
getSupplemet(){ | |
this.quoteService.getSupplement() | |
.subscribe(supplements => { | |
this.supplements = supplements.resultData.Suppliment; | |
//console.log(this.supplements); | |
}, | |
response => { | |
if (response.status == 404) { | |
//this.router.navigate(['NotFound']); | |
} | |
}) | |
} | |
/*Itinerary*/ | |
getItinerary(){ | |
this.quoteService.getItinerary() | |
.subscribe(itinerary => { | |
this.itinerary = itinerary.resultData.Itinary; | |
this.Itns = asEnumerable(this.itinerary).GroupBy(x => x.CheckinDay, x => x, | |
(key, b) => | |
{ return { | |
CheckinDay: key ,itineraries: asEnumerable(b).ToArray() } | |
}) | |
.ToArray(); | |
}, | |
response => { | |
if (response.status == 404) { | |
} | |
}) | |
} | |
/*Optionals*/ | |
getTravelGuide(){ | |
this.quoteService.getTravelGuide() | |
.subscribe(travelGuides => { | |
this.travelGuides = travelGuides.resultData; | |
this.categories = travelGuides.resultData.TravelGuide; | |
this.Optional = 1; | |
var catsArr=[]; | |
//var uniqCats=[]; | |
for(let i=0;i<this.categories.length;i++) { | |
if(catsArr.indexOf(this.categories[i].Category) == -1){ | |
catsArr.push(this.categories[i].Category); | |
this.uniqCategory += "."+this.categories[i].Category+", "; | |
//console.log(this.categories[i].Category); | |
//this.uniqCats.push(this.categories[i].Category); | |
} | |
} | |
console.log(catsArr); | |
this.uniqCats = "HOTEL"; | |
this.allCategories = catsArr; | |
//this.allCategories = this.uniqCategory.substring(0, this.uniqCategory.length-2); | |
console.log(this.allCategories); | |
}, | |
response => { | |
if (response.status == 404) { | |
//this.router.navigate(['NotFound']); | |
} | |
} | |
) | |
} | |
getOnlyOptional(type,value){ | |
console.log(value); | |
this.quoteService.getTravelGuide() | |
.subscribe(travelGuides => { | |
this.travelGuides = travelGuides.resultData; | |
var categories = travelGuides.resultData.TravelGuide; | |
this.Optional = 1; | |
var arr=[]; | |
if(value != ""){ | |
for (let category of categories) { | |
if(type == "Category"){ | |
if(category.Category == value){ | |
this.Active = value; | |
arr.push(category); | |
} | |
} | |
if(type == "Optional"){ | |
this.Active = "Optional"; | |
if(category.Optional == value){ | |
arr.push(category); | |
} | |
} | |
} | |
this.categories = arr; | |
} else { | |
this.Active = "All"; | |
this.categories = categories; | |
} | |
}, | |
response => { | |
if (response.status == 404) { | |
//this.router.navigate(['NotFound']); | |
} | |
} | |
) | |
} | |
/*Terms*/ | |
getTerms(){ | |
this.quoteService.getTerms() | |
.subscribe( | |
terms => { | |
this.terms = terms.resultData.Terms; | |
this.notes = terms.resultData.ImpNotes; | |
this.exclusions = terms.resultData.Exclusions; | |
this.TermCons = asEnumerable(this.terms).GroupBy(x => x.Heading, x => x, | |
(key, b) => | |
{ return { Heading: key, TermsDesc: asEnumerable(b).ToArray() } }) | |
.ToArray(); | |
this.ImpNotes = asEnumerable(this.notes).GroupBy(x => x.Heading, x => x, | |
(key, b) => | |
{ return { Heading: key, TermsDesc: asEnumerable(b).ToArray() } }) | |
.ToArray(); | |
this.ExclusionList = asEnumerable(this.exclusions).GroupBy(x => x.heading, x => x, | |
(key, b) => | |
{ return { Heading: key, TermsDesc: asEnumerable(b).ToArray() } }) | |
.ToArray(); | |
}, | |
response => { | |
if (response.status == 404) { | |
//this.router.navigate(['NotFound']); | |
} | |
}); | |
} | |
/*Revisions*/ | |
getRevision(SendRequest: NgForm){ | |
this.submitted = true; | |
if(this.name == undefined){ | |
this.name = ""; | |
} | |
if(this.email == undefined){ | |
this.email = ""; | |
} | |
if(this.phone == undefined){ | |
this.phone = ""; | |
} | |
if(this.message == undefined){ | |
this.message = ""; | |
} | |
let headers = new Headers({ | |
'Content-Type': 'application/x-www-form-urlencoded' | |
}); | |
let params = { | |
"Srno":null, | |
"Corporate":this.corporate, | |
"Inquirycode":this.InquiryCode, | |
"QuoteCode":this.QuoteCode, | |
"Firstname":this.name, | |
"Lastname":"", | |
"Email":this.email, | |
"Phonecode":"91", | |
"Phone":this.phone, | |
"Message":this.message, | |
"Corporateby":0, | |
"Unitby":"0", | |
"Locationby":"0", | |
"Branchby":"0", | |
"Createdby":0, | |
"Createdip":null, | |
"Deletestatus":0, | |
"Customtag":"", | |
"Tasksrno":null, | |
"Eventsrno":null, | |
"Notificationsrno":null, | |
"Calendarsrno":null, | |
"Emailsrno":null | |
} | |
return this.http.post(this.url,params) | |
.map(res => res.json()) | |
.catch(this.errorHandler) | |
.subscribe( | |
data => { | |
this.revisions = data.resultData; | |
this.resultCode = data.resultCode; | |
this.responeseMsg = data.message.MessageText; | |
//SendRequest.reset(); | |
//SendRequest.resetForm({name: '', email: '', phone: '', message: ''}); | |
SendRequest.resetForm(); | |
}, | |
err => { | |
console.log(err); | |
} | |
) | |
} | |
errorHandler(error: Response){ | |
console.error(error); | |
return Observable.throw(error || "Server error"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment