import { Component, ViewChild } from '@angular/core';
import { BackandService } from '@backand/angular2-sdk';
import { NavController, Slides } from 'ionic-angular';
import { Facebook, NativeStorage } from 'ionic-native';
import { HomeComponent } from '../home/home.component';
@Component({
selector: 'start-slides',
templateUrl: 'slides.component.html',
})
export class SlidesComponent {
@ViewChild(Slides) slides: Slides;
FB_APP_ID: number = 1720580138271771;
slideindex:number = 0;
isRegistrationCompleted:boolean = false;
items:any[] = [];
error;
constructor(public navCtrl: NavController, private backand: BackandService) {
Facebook.browserInit(this.FB_APP_ID, "v2.8");
this.backand.on("items_updated",
(data: any) => {
console.log("items_updated event triggered");
console.log(data);
}
);
}
goToSlide(index) {
this.slides.slideTo(index, 500);
this.slideindex = this.slides.getActiveIndex();
}
goToNext() {
this.slides.slideNext();
this.slideindex = this.slides.getActiveIndex();
}
slideChanged() {
this.slideindex = this.slides.getActiveIndex();
}
_postDetailsToDB(response) {
let nav = this.navCtrl;
let details = {
accessToken: response.authResponse.accessToken,
expiresIn: response.authResponse.expiresIn,
modifiedAt: new Date().getTime(),
session_key: response.authResponse.session_key,
sig: response.authResponse.sig,
userID: response.authResponse.userID,
status: response.status
};
this.backand.object.create('fbsignups', details)
.then((data: any) => {
console.log('Data posted to DB');
NativeStorage.setItem('user', details)
.then(function(){
nav.setRoot(HomeComponent);
}, function (error) {
console.log(error);
})
},
(err: any) => {
console.log(err);
}
);
}
loginWithFacebook(){
let ref = this;
let permissions = new Array();
//the permissions your facebook app needs from the user
permissions = ["public_profile"];
Facebook.login(permissions)
.then(function(response){
ref._postDetailsToDB(response);
}, function(error){
console.log(error);
});
}
}