Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
<StackLayout orientation="horizontal" horizontalAlignment="center" visibility="{{ loggedIn ? 'visible' : 'collapsed' }}">
<Button tap="{{ logout }}" text="Log out" class="btn"/>
<Button tap="{{ listDevices }}" text="List devices" class="btn"/>
<Button tap="{{ startwizard }}" text="Add" width="33%" class="btn"/>
</StackLayout>

<Label text="{{ message }}" class="message" textWrap="true"/>

<Button tap="{{ onDeviceSubscribe }}" text="{{ subButtonText }}" class="btn" visibility="{{ selectedDevice && handleEvents ? 'visible' : 'collapsed' }}"/>

<ListView separatorColor="transparent" rowHeight="60" width="95%" class="m-15" items="{{ devices }}" itemTap="{{ onDeviceTap }}" horizontalAlignment="center" visibility="{{ !selectedDevice ? 'visible' : 'collapsed' }}">
<ListView.itemTemplate>
<StackLayout backgroundColor="#eee" class="p-10 m-2">
Expand Down
39 changes: 39 additions & 0 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,42 @@ import { prompt } from "tns-core-modules/ui/dialogs";
/************ SET THESE FOR QUICK LOGIN ************/
const PARTICLE_USERNAME = undefined;
const PARTICLE_PASSWORD = undefined;
/************ ALT LOGIN WITH TOKEN ************/
const PARTICLE_TOKEN = undefined;
/************ SET PARTICLE EVENT NAME ************/
const PARTICLE_EVENT_NAME = undefined;
/***************************************************/

export class HelloWorldModel extends Observable {
private static MESSAGE_KEY = "message";
private static LOGGED_IN_KEY = "loggedIn";
private static SELECTED_DEVICE_KEY = "selectedDevice";
private static SUBSCRIBE_BUTTON_KEY = "subButtonText";

loggedIn: boolean = false;
message: string = "Log in to get started";
devices: ObservableArray<TNSParticleDevice> = new ObservableArray<TNSParticleDevice>();
selectedDevice: TNSParticleDevice;
handleEvents: boolean = false;
subscribed: boolean = false;
subButtonText: string = "Subscribe to Events";

private particle: Particle;

constructor() {
super();

this.particle = new Particle();
if (PARTICLE_EVENT_NAME) this.handleEvents = true;
}

login(): void {
if (PARTICLE_USERNAME && PARTICLE_PASSWORD) {
this.doLogin(PARTICLE_USERNAME, PARTICLE_PASSWORD);
} else if (PARTICLE_TOKEN){
console.log('login tap, go for loginwithtoken option');

this.doLoginWithToken(PARTICLE_TOKEN);
} else {
prompt({
title: "Particle username",
Expand Down Expand Up @@ -58,6 +71,12 @@ export class HelloWorldModel extends Observable {
.catch(error => this.set(HelloWorldModel.MESSAGE_KEY, error));
}

private doLoginWithToken(token: string): void {
this.particle.loginWithToken(PARTICLE_TOKEN);
this.set(HelloWorldModel.LOGGED_IN_KEY, true);
this.set(HelloWorldModel.MESSAGE_KEY, "Logged in");
}

logout(): void {
this.particle.logout();
this.devices.splice(0, this.devices.length);
Expand Down Expand Up @@ -113,4 +132,24 @@ export class HelloWorldModel extends Observable {
.then(result => this.set(HelloWorldModel.MESSAGE_KEY, `${vari.name} result: ${result}`))
.catch(error => this.set(HelloWorldModel.MESSAGE_KEY, error));
}

onDeviceSubscribe(args): void {
this.subscribed = !this.subscribed;
this.set(HelloWorldModel.SUBSCRIBE_BUTTON_KEY, this.subscribed ? "Unsubscribe" : "Subscribe to Events");
if (this.subscribed) {
this.selectedDevice.subscribe(PARTICLE_EVENT_NAME, (data) => {
console.log(`selectedDevice.subscribe activity, eventdata: ${data}`);
});
} else {
this.selectedDevice.unsubscribe();
}
}

startwizard(): void {
console.log('start wizard tapped');
this.particle.startDeviceSetupWizard((result) => {
console.log('wizard callback');
});

}
}
83 changes: 41 additions & 42 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es6",
"dom"
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es6",
"dom"
],
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noEmitHelpers": true,
"noEmitOnError": false,
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/*"
],
"~/*": [
"app/*"
]
}
},
"include": [
"../src",
"**/*"
],
"sourceMap": false,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noEmitHelpers": true,
"noEmitOnError": false,
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/*"
],
"~/*": [
"app/*"
]
}
},
"include": [
"../src",
"**/*"
],
"exclude": [
"../src/node_modules",
"node_modules",
"platforms"
],
"compileOnSave": false
}
"exclude": [
"../src/node_modules",
"node_modules",
"platforms"
],
"compileOnSave": false
}
24 changes: 12 additions & 12 deletions publish/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading