Skip to content

Instantly share code, notes, and snippets.

@CharlesGrimont
Last active June 22, 2018 08:39
Show Gist options
  • Save CharlesGrimont/19c158cf9ce08b84fb0467d0d48e5033 to your computer and use it in GitHub Desktop.
Save CharlesGrimont/19c158cf9ce08b84fb0467d0d48e5033 to your computer and use it in GitHub Desktop.
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Button,
Alert,
DeviceEventEmitter,
NativeEventEmitter,
NativeModules
} from 'react-native';
import {C8oSettings, C8o, C8oLogLevel} from "react-native-c8osdk";
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
state = {
data:""
}
constructor(props) {
super(props);
/*c8oSettings.init();
c8oSettings.setTimeout(3000);
c8oSettings.setTrustAllCertificates(true);
console.log("ABABABBABBA2");
console.log(c8oSettings.value());
console.log(c8oSettings.getConstants);*/
let settings = new C8oSettings();
settings.setTimeout(3000).setDefaultDatabaseName("edailycheck").setTrustAllCertificates(true).setLogLevelLocal(C8oLogLevel.TRACE).addCookie("certname", "pass").setLogRemote(true);
this.c8o = new C8o();
this.c8o.init("https://mb.convertigo.net/cems/projects/FlightShare", settings);
}
/* componentDidMount() {
DeviceEventEmitter.addListener("Progress", (status)=> {
this.setState({data: status.description});
});
}*/
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Text style={styles.instructions}>
{this.state.data}
</Text>
<Button title="Login and Sync" onPress={async ()=> {
this.c8o.progress.notifications((progress)=>{
console.log("here");
console.log(progress);
});
var data = await this.c8o.callJson(".login", {
"email": "olivierp@convertigo.com"
});
this.setState({data : JSON.stringify(data)}) ;
var data = await this.c8o.callJson("fs://flightshare_fullsync.sync", {
});
this.setState({data : JSON.stringify(data)}) ;
}
}/>
<Button title="Query" onPress={async ()=> {
var data = await c8o.callJson("fs://flightshare_fullsync.view", {
"ddoc": "Design_document",
"view": "AirportsByCity"
});
this.setState({data : JSON.stringify(data)}) ;
}}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Button,
Alert,
DeviceEventEmitter,
NativeEventEmitter,
NativeModules
} from 'react-native';
import {C8oSettings, C8o, C8oLogLevel} from "react-native-c8osdk";
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
state = {
data:""
}
constructor(props) {
super(props);
/*c8oSettings.init();
c8oSettings.setTimeout(3000);
c8oSettings.setTrustAllCertificates(true);
console.log("ABABABBABBA2");
console.log(c8oSettings.value());
console.log(c8oSettings.getConstants);*/
let settings = new C8oSettings();
settings.setTimeout(3000).setDefaultDatabaseName("edailycheck").setTrustAllCertificates(true).setLogLevelLocal(C8oLogLevel.TRACE).addCookie("certname", "pass").setLogRemote(true);
this.c8o = new C8o();
this.c8o.init("https://mb.convertigo.net/cems/projects/FlightShare", settings);
}
/* componentDidMount() {
DeviceEventEmitter.addListener("Progress", (status)=> {
this.setState({data: status.description});
});
}*/
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Text style={styles.instructions}>
{this.state.data}
</Text>
<Button title="Login and Sync" onPress={async ()=> {
this.c8o.callJson(".login", {
"email": "olivierp@convertigo.com"
})
.then((resp)=>{
this.setState({data : JSON.stringify(resp)})
if(resp.DatabaseVersion == "1.0"){
this.c8o.callJson("fs://flightshare_fullsync.replicate_pull", {})
.progress((progress)=>{
let progress_str = "progress: " + progress.current + " / " + progress.total + " || status: " + progress.status;
if(progress_str != {}){
this.setState({data : JSON.stringify(progress_str)})
this.c8o.log.debug(progress_str);
}
})
.then((resp2, id)=>{
this.setState({data : JSON.stringify(resp2)})
this.c8o.log.debug(JSON.stringify(resp2));
this.c8o.log.debug(JSON.stringify(id));
})
}
});
}
}/>
<Button title="Query" onPress={async ()=> {
this.c8o.callJson("fs://flightshare_fullsync.view", {
"ddoc": "Design_document",
"view": "AirportsByCity",
"__live": "customers"
})
.then((resp)=>{
alert('Then of view live triggered');
this.c8o.log.debug(JSON.stringify("resp call "));
this.c8o.log.debug(JSON.stringify(resp));
});
}}/>
<Button title="POST NEW NAME" onPress={async ()=> {
this.c8o.callJson("fs://flightshare_fullsync.post", {
"_use_policy": "merge",
"docid": "LFCF",
"name": "NEW NAME"
})
.then((resp)=>{
this.c8o.log.debug(JSON.stringify("resp post "));
this.c8o.log.debug(JSON.stringify(resp));
});
}}/>
<Button title="Promise normale" onPress={async ()=> {
this.c8o.callJson(".logissn", {
"email": "qs@convertigo.com"
})
.async()
.then((resp)=>{
alert("resp" + JSON.stringify(resp));
this.setState({data : JSON.stringify(resp)})
this.c8o.log.debug(JSON.stringify(resp));
})
.catch((err)=>{
alert("resp" + JSON.stringify(err));
this.setState({data : JSON.stringify(err)})
this.c8o.log.debug(err);
})
}
}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Button,
Alert,
DeviceEventEmitter,
NativeEventEmitter,
NativeModules
} from 'react-native';
//import * as DeviceInfo from 'react-native-device-info';
import {C8oSettings, C8o, C8oLogLevel} from "react-native-c8osdk";
/*
var C8o = NativeModules.C8o;
var c8o = require("react-native-c8o-sdk/c8oSettings");
var c8oSettings = require("react-native-c8o-sdk/c8oSettings");
var C8oSettings = NativeModules.C8oSettings;
var C8oLogLevel = NativeModules.C8oLogLevel;
*/
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
const { C8oReact } = NativeModules;
const C8oManagerEmitter = new NativeEventEmitter(C8oReact);
const subscription = C8oManagerEmitter.addListener(
'progress',
(progress)=> console.log("Event emiter react Native: " + JSON.stringify(progress))
);
type Props = {};
export default class App extends Component<Props> {
state = {
data:""
};
c8o;
constructor(props) {
super(props);
let settings = new C8oSettings();
settings.setTimeout(3000).setDefaultDatabaseName("edailycheck").setTrustAllCertificates(true).setLogLevelLocal(C8oLogLevel.TRACE);
console.log("PRINT OF SETTINGS");
console.log(settings);
this.c8o = new C8o();
// Calling init method
this.c8o.init("https://poc.convertigo.net:443/cems/projects/eDailyCheck", settings);
}
componentDidMount() {
DeviceEventEmitter.addListener("Progress", (status)=> {
this.setState({data: status})
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Text style={styles.instructions}>
{this.state.data}
</Text>
<Button title="Login and Sync" onPress={async ()=> {
var callReset = await this.c8o.callJson('fs://.reset');
var result = await this.c8o.callJson('.login', {
login: "barnett.christine",
password: "barnett.christine"
});
this.setState({data: JSON.stringify(result)});
var callReset = await this.c8o.callJson('fs://.reset');
this.setState({data: JSON.stringify(callReset)});
var resultLogin = await this.c8o.callJson("fs://.replicate_pull", {});
console.log(resultLogin);
this.setState({data: JSON.stringify(resultLogin)});
}
}/>
<Button title="Query" onPress={async ()=> {
try{
var res = await this.c8o.callJson("fs://.view", {ddoc: "views", view: "airport"});
this.setState({data: JSON.stringify(res.rows)});
console.log(res);
}
catch(e){
console.log("here");
}
}}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment