loginss.ts 4.56 KB
Newer Older
mohan122's avatar
mohan122 committed
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
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,Platform,AlertController } from 'ionic-angular';

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Geolocation } from '@ionic-native/geolocation';

/**
 * Generated class for the LoginssPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-loginss',
  templateUrl: 'loginss.html',
})
export class LoginssPage {
  public itemsy : Array<any> = [];
  public itemsk: Array<any> = [];
  location:any;
  position:any;
  value:any;
  lappy:any;
  latitude:any;
  dats:any;
  
  public ionicNamedColor: string = 'primary';
  longitude:any;
  private baseURI : string  = "http://localhost/vamsi/tesss.php";
  private baseURIp : string  = "http://localhost/vamsi/productdis.php";
  constructor(public navCtrl: NavController,private alertctrl:AlertController,private geolocation: Geolocation,public platform:Platform, public navParams: NavParams,public http   : HttpClient) {
    
  }


  loads() : void
  {
     this.http
     .get('http://localhost/vamsi/corda.php')
     .subscribe((data : any) =>
     {
        console.dir(data);
       
        this.itemsy = data;
        this.initializeItems();
     },
     (error : any) =>
     {
        console.dir(error);
     });
  }
  initializeItems() {
    this.itemsk = this.itemsy;
    
  }
  alert(message:string){
    this.alertctrl.create({
      title: 'Location Alert',
      subTitle: message,
      buttons: ['OK']
    }).present();
  }
  

  mapUse(){
    this.platform.ready().then(()=>{
      let options={timeout:3000,enableHighAccuracy:true,maximumAge:0}
  this.geolocation.getCurrentPosition(options).then((location) => {
    console.log('Fetched the location successfully',location);
    this.location=location;
    this.latitude=location.coords.latitude;
    this.longitude=location.coords.longitude;
    console.log(location.coords.latitude);
      this.saveEntry();
  }).catch((error) => {
    console.log('Error getting location', error);
  
    this.alert('No Location Traced');
  });
  });
    }
    getItems(ev: any) {
      // Reset items back itemsto all of the 
      
      this.initializeItems();
      // set val to the value of the searchbar
      let val = ev.target.value;
  
      // if the value is an empty string don't filter the items
      if (val && val.trim() != '') {
        this.itemsk = this.itemsk.filter((itemy) => {
          return (itemy.item.toLowerCase().indexOf(val.toLowerCase()) > -1);
        })
      }
    }
  
  
    saveEntry() : void
    {
       let latitude:number=this.latitude,
          longitude:number=this.longitude;
  
      
          this.createEntry(latitude,longitude);
    }
    createEntry(latitude:number,longitude:number) : void
  {
     let headers 	: any		= new HttpHeaders({ 'Content-Type': 'application/json' }),
         options 	: any		= {"key":"create", "latitude":latitude,"longitude":longitude },
         url       : any      	= this.baseURI ;

     this.http.post(url, JSON.stringify(options), headers)
     .subscribe((data : any) =>
     {
        // If the request was successful notify the user
     
        console.log(`Congratulations the ${latitude} was successfully added`);
        this.loads();
     },
     (error : any) =>
     {
        console.log({error});
     });
  }


  help():void{
    this.http
    .get('http://localhost/vamsi/productdis.php')
    .subscribe((datak : any) =>
    {
       console.dir(datak);
      
       
    },
    (error : any) =>
    {
       console.dir(error);
    });



  }
  
  hello(itemy,i){
    this.ionicNamedColor = 'secondary';
    
    let index = this.itemsk.indexOf(itemy);
    if(index > -1){
      this.dats=this.itemsk[index];
      let dat:string=this.dats.item;
      this.registeritem(dat);
    }
    
    }
    registeritem(dat:string) : void
    {
      console.log(dat);
       let headers 	: any		= new HttpHeaders({ 'Content-Type': 'application/json' }),
           options 	: any		= {"key":"create", "piece":dat},
           url       : any      	= this.baseURIp ;
  
       this.http.post(url, JSON.stringify(options), headers)
       .subscribe((data : any) =>
       {
          // If the request was successful notify the user
       
          console.log(`Congratulations the ${dat} was successfully added`);
          this.help();
         
       },
       (error : any) =>
       {
          console.log({error});
       });
    }
  ionViewDidLoad() {
    this.mapUse();
    
    console.log('ionViewDidLoad LoginssPage');
  }

}