Commit 4a8327cf authored by prumde's avatar prumde

Changes as per new header changes - Search


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@174387 ce508802-f39f-4f6c-b175-0d175dae99d5
parent e756b56d
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Http, Headers,RequestOptions } from '@angular/http'; import { Http, Headers,RequestOptions } from '@angular/http';
import { EcmLocation } from './ecm-location'; import { EcmLocation } from './ecm-location';
import { EmitterService } from '../ecm-search/ecm-search.component'; import { EventEmitter } from '@angular/core';
import { Store } from '@ngrx/store';
import { EcmStoreModel } from '../ecm-store/ecm-store.model';
@Injectable() @Injectable()
export class EcmLocationService { export class EcmLocationService {
pincode;
add:any; constructor( public http: Http, private store: Store<EcmStoreModel>) {}
public location: EcmLocation;
city;
loc_data;
constructor( public http: Http) {}
search(nameKey, myArray){ find(nameKey, myArray){
for (var i=0; i < myArray.length; i++) { for (var i=0; i < myArray.length; i++) {
if (myArray[i].types[0] === nameKey) { if (myArray[i].types[0] === nameKey) {
return myArray[i]; return myArray[i];
} }
}
} }
}
getCitydata() { getGeoLocation() {
let localCity = localStorage.getItem('city'); let localCity = localStorage.getItem('city');
if([null, undefined, ""].indexOf(localCity,0) != -1){ if([null, undefined, ""].indexOf(localCity,0) != -1) {
//navigator.geolocation.getCurrentPosition(this.successCallback,this.errorCallback,this.options); //navigator.geolocation.getCurrentPosition(this.successCallback,this.errorCallback,this.options);
//https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyBo62AVqqkEz5Ys9D-dQWE_VF4lVpHaFy0 //https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyBo62AVqqkEz5Ys9D-dQWE_VF4lVpHaFy0
...@@ -34,8 +32,8 @@ export class EcmLocationService { ...@@ -34,8 +32,8 @@ export class EcmLocationService {
response => { response => {
if(response.status == 200){ if(response.status == 200){
let data = response.json(); let data = response.json();
console.log('data.......'+data.location.lng); console.log('geolocate -- data.......'+ JSON.stringify(data) );
this.successCallback(data); this.displayLocation(data);
} }
}, },
error => { error => {
...@@ -46,54 +44,6 @@ export class EcmLocationService { ...@@ -46,54 +44,6 @@ export class EcmLocationService {
// do something when you already have the location // do something when you already have the location
} }
} }
getAddress() {
return this.add;
}
getCity(){
return this.city;
}
displayLocation = (latitude,longitude) => {
this.http.get('https://maps.googleapis.com/maps/api/geocode/json?latlng='+latitude+','+longitude+'&sensor=true').subscribe(
response => {
if(response.status == 200){
let data = response.json();
this.loc_data=data;
console.log(data);
if(data)
{
var resultObject = this.search("locality", data.results[0].address_components);
this.city=resultObject.long_name;
}
localStorage.setItem('mycity',this.city);
location['address'] = data.results[0].formatted_address;
this.add=data.results[0].formatted_address;
// console.log(data.results[0].formatted_address);
//console.log(this.add);
}
localStorage.setItem('location', JSON.stringify(location));
EmitterService.get("selectedCity").emit(location['city']);
},
error => {
alert(error.text());
}
);
}
successCallback = (position)=> {
//let latitude = position.coords.latitude;
//let longitude = position.coords.longitude;
let latitude = position.location.lat;
let longitude = position.location.lng;
location['latitude'] = latitude;
location['longitude'] = longitude;
console.log(latitude+' '+longitude)
this.displayLocation(latitude,longitude);
}
errorCallback = (error) => { errorCallback = (error) => {
let errorMessage = 'Unknown error'; let errorMessage = 'Unknown error';
...@@ -116,4 +66,58 @@ export class EcmLocationService { ...@@ -116,4 +66,58 @@ export class EcmLocationService {
timeout: 1000, timeout: 1000,
maximumAge: 0 maximumAge: 0
}; };
displayLocation = (position) => {
let ecmLocation : EcmLocation = new EcmLocation();
ecmLocation.latitude = position.location.lat;
ecmLocation.longitude = position.location.lng;
this.http.get('https://maps.googleapis.com/maps/api/geocode/json?latlng='+position.location.lat+','+position.location.lng+'&sensor=true').subscribe(
response => {
if(response.status == 200){
let data = response.json();
//this.loc_data=data;
console.log('geocode -- data.......'+JSON.stringify(data));
console.log('geocode -- data keys.......'+Object.keys(data));
if(data)
{
var resultObject = this.find("locality", data.results[0].address_components);
//this.city = resultObject.long_name;
ecmLocation.city = resultObject.long_name;
//this.add = data.results[0].formatted_address;
ecmLocation.address = data.results[0].formatted_address;
}
this.store.dispatch({type: 'CLEAR_LOCATION'});
this.store.dispatch({type: 'ECMLOCATION', payload: ecmLocation});
//EmitterService.get("selectedLocation").emit(ecmLocation);
//localStorage.setItem('mycity',this.city);
// console.log(data.results[0].formatted_address);
//console.log(this.add);
}
//localStorage.setItem('location', JSON.stringify(location));
//EmitterService.get("selectedCity").emit(location['city']);
},
error => {
alert(error.text());
}
);
}
} }
/*
@Injectable()
export class EmitterService {
private static _emitters: { [channel: string]: EventEmitter<any> } = {};
static get(channel: string): EventEmitter<any> {
if (!this._emitters[channel])
this._emitters[channel] = new EventEmitter();
return this._emitters[channel];
}
}
*/
\ No newline at end of file
export interface EcmLocation { export class EcmLocation {
latitude : string; public latitude : string;
longitude : string; public longitude : string;
address: string; public address: string;
pincode: number; public pincode: number;
city: string; public city: string;
public toString(){
return "[" + this.latitude + "][" + this.longitude + "][" + this.address + "][" + this.pincode + "][" + this.city + "]";
}
} }
...@@ -127,7 +127,9 @@ ...@@ -127,7 +127,9 @@
} }
.location{ .location{
width: calc( 25% - 20px ); line-height: 60px;
height: 60px;
width: calc( 25% - 20px );
position: relative; position: relative;
display: inline-block; display: inline-block;
padding: 0; padding: 0;
...@@ -141,7 +143,8 @@ ...@@ -141,7 +143,8 @@
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
width: calc( 100% - 50px ); max-width: calc( 100% - 50px );
width: auto;
vertical-align: middle; vertical-align: middle;
font-size: 12px; font-size: 12px;
color: #fff; color: #fff;
...@@ -149,6 +152,7 @@ ...@@ -149,6 +152,7 @@
margin: 0; margin: 0;
margin-left: -5px; margin-left: -5px;
} }
.location-arrow{ .location-arrow{
vertical-align: middle; vertical-align: middle;
color: #fff; color: #fff;
......
...@@ -2,15 +2,9 @@ ...@@ -2,15 +2,9 @@
<span class="search-page-border"> <span class="search-page-border">
<input #myInput type="text" placeholder="Search Food, Tour, Events and More..." class="search-terms" name="search-terms" /> <input #myInput type="text" placeholder="Search Food, Tour, Events and More..." class="search-terms" name="search-terms" />
<span class="search-which-border"> <span class="search-which-border">
<div #locateMeButton class="locate-me">Locate Me</div> <div class="locate-me">{{ userLocation ? userLocation.city : 'Locate Me' }}</div>
<div class="locate-handle" (click)="getAddress();" ></div> <div class="locate-handle" (click)="loacteMe();" ></div>
<img class="img-locate" title="Locate Me" /> <img class="img-locate" title="Locate Me" />
<select name="search-which" class="search-which">
<option value="members">Mumbai</option>
<option value="groups">Pune</option>
<option value="forums">Nashik</option>
<option value="posts">Nagpur</option>
</select>
</span> </span>
</span> </span>
<button md-raised-button class="search-submit" (click)="search(myInput.value)">Search</button> <button md-raised-button class="search-submit" (click)="search(myInput.value)">Search</button>
...@@ -18,9 +12,9 @@ ...@@ -18,9 +12,9 @@
<div *ngIf="headerState === 'fixed'" class="sb-search"> <div *ngIf="headerState === 'fixed'" class="sb-search">
<form> <form>
<input #myInput type="text" placeholder="Search Food, Tour, Events and More..." class="search-terms-fixed" value="" name="search" id="search" /> <input #myInput type="text" placeholder="Search Food, Tour, Events and More..." class="search-terms-fixed" value="" name="search" id="search" />
<div md-ripple class="location"> <div md-ripple class="location" (click)="loacteMe();">
<img class="location-img-32"/> <img class="location-img-32"/>
<span class="location-text">Neelkanth Business Park, Vidyavihar (W)</span> <span class="location-text">{{ userLocation ? userLocation.address : 'Locate Me' }}</span>
<i class="material-icons location-arrow">keyboard_arrow_down</i> <i class="material-icons location-arrow">keyboard_arrow_down</i>
</div> </div>
<input class="sb-search-submit" type="submit" (click)="search(myInput.value)"> <input class="sb-search-submit" type="submit" (click)="search(myInput.value)">
......
...@@ -4,6 +4,10 @@ import { EcmLocation } from './ecm-location'; ...@@ -4,6 +4,10 @@ import { EcmLocation } from './ecm-location';
import { EcmLocationService } from './ecm-location.service'; import { EcmLocationService } from './ecm-location.service';
import { SearchService } from './ecm-search-result/search.service'; import { SearchService } from './ecm-search-result/search.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { Store } from '@ngrx/store';
import { EcmStoreModel } from '../ecm-store/ecm-store.model';
@Component({ @Component({
selector: 'ecm-search', selector: 'ecm-search',
...@@ -29,52 +33,54 @@ import { Router } from '@angular/router'; ...@@ -29,52 +33,54 @@ import { Router } from '@angular/router';
providers: [EcmLocationService] providers: [EcmLocationService]
}) })
export class ECMSearchComponent implements OnInit { export class ECMSearchComponent implements OnInit {
@Input('compFadeState') compFadeState: string = 'false'; @Input('compFadeState') compFadeState: string = 'false';
@Input('headerState') headerState: string = 'relative'; @Input('headerState') headerState: string = 'relative';
@ViewChild('locateMeButton') locateMeButton;
@ViewChild('myInput') searchBar; @ViewChild('myInput') searchBar;
public selectedCity: string;
public pincode; public storeUserLocation : Observable<EcmLocation>;
public form_add; public userLocation : EcmLocation;
search_key; search_key;
selectedPlace = 'Mumbai'; selectedPlace = 'Mumbai';
constructor(private _ngLocation: EcmLocationService, private search_service: SearchService, private router: Router) {} constructor(private locationService: EcmLocationService, private search_service: SearchService, private router: Router, private store: Store<EcmStoreModel>) {}
ngOnInit() { ngOnInit() {
this.selectedCity = localStorage.getItem('city'); //this.selectedCity = localStorage.getItem('city');
this.search_key=this.search_service.getSearch(); this.search_key = this.search_service.getSearch();
this.storeUserLocation = this.store.select('location');
this.storeUserLocation.subscribe( userLocation => {
//console.log( 'ngOnInit >' + userLocation );
this.userLocation = userLocation;
});
} }
ngAfterViewChecked() { ngAfterViewChecked() {
if(this.form_add) if(this.search_key)
this.searchBar.nativeElement.value=this.form_add; this.searchBar.nativeElement.value=this.search_key;
this.storeUserLocation = this.store.select('location');
this.storeUserLocation.subscribe( userLocation => {
//console.log( 'ngAfterViewChecked >' + userLocation );
this.userLocation = userLocation;
});
} }
ngAfterViewInit() { ngAfterViewInit() {
if(this.search_key && this.searchBar) if(this.search_key && this.searchBar)
this.searchBar.nativeElement.value=this.search_key; this.searchBar.nativeElement.value=this.search_key;
if(localStorage.getItem('mycity'))
if(this.locateMeButton)
this.locateMeButton.nativeElement.textContent=localStorage.getItem('mycity');
} }
getAddress() { loacteMe() {
this._ngLocation.getCitydata(); this.locationService.getGeoLocation();
EmitterService.get("selectedCity").subscribe( data =>{
//this.form_add=this._ngLocation.getAddress();
let myLocation=this._ngLocation.getAddress();
localStorage.setItem('myLocation',myLocation);
this.locateMeButton.nativeElement.textContent=this._ngLocation.getCity();
});
} }
search(value) { search(value) {
if(value.trim()) if(value.trim())
{ {
this.search_service.setSearch(value.trim()); this.search_service.setSearch(value.trim());
this.router.navigate(['/search',value.trim()]); this.router.navigate(['/search',value.trim()]);
} }
} }
...@@ -83,14 +89,4 @@ export class ECMSearchComponent implements OnInit { ...@@ -83,14 +89,4 @@ export class ECMSearchComponent implements OnInit {
} }
} }
@Injectable() \ No newline at end of file
export class EmitterService {
private static _emitters: { [channel: string]: EventEmitter<any> } = {};
static get(channel: string): EventEmitter<any> {
if (!this._emitters[channel])
this._emitters[channel] = new EventEmitter();
return this._emitters[channel];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment