mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-04-13 00:00:10 +08:00
DEMO with output
This commit is contained in:
@@ -1,7 +1,78 @@
|
||||
import {ElementRef} from 'angular2/angular2';
|
||||
|
||||
import {Page, NavParams} from 'ionic/ionic';
|
||||
|
||||
import {Camera, StatusBar, Toast, ActionSheet} from 'ionic-native';
|
||||
|
||||
function safeJSONStringify (input, maxDepth)
|
||||
{
|
||||
|
||||
var output,
|
||||
refs = [],
|
||||
refsPaths = [];
|
||||
|
||||
maxDepth = maxDepth || 5;
|
||||
|
||||
function recursion (input, path, depth)
|
||||
{
|
||||
var output = {},
|
||||
pPath,
|
||||
refIdx;
|
||||
|
||||
path = path || "";
|
||||
depth = depth || 0;
|
||||
depth++;
|
||||
|
||||
if (maxDepth && depth > maxDepth)
|
||||
{
|
||||
return "{depth over " + maxDepth + "}";
|
||||
}
|
||||
|
||||
for (var p in input)
|
||||
{
|
||||
pPath = (path ? (path+".") : "") + p;
|
||||
if (typeof input[p] === "function")
|
||||
{
|
||||
//output[p] = "{function}";
|
||||
}
|
||||
else if (typeof input[p] === "object")
|
||||
{
|
||||
/*
|
||||
refIdx = refs.indexOf(input[p]);
|
||||
|
||||
if (-1 !== refIdx)
|
||||
{
|
||||
output[p] = recursion(input[p])"{reference to " + refsPaths[refIdx] + "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
*/
|
||||
refs.push(input[p]);
|
||||
refsPaths.push(pPath);
|
||||
output[p] = recursion(input[p], pPath, depth);
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
output[p] = input[p];
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
if (typeof input === "object")
|
||||
{
|
||||
output = recursion(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
output = input;
|
||||
}
|
||||
|
||||
return JSON.stringify(output);
|
||||
}
|
||||
|
||||
// To specify arguments for any plugin calls
|
||||
var demoArgs = {};
|
||||
demoArgs[ActionSheet] = {
|
||||
@@ -28,7 +99,16 @@ demoArgs[Toast] = {
|
||||
templateUrl: 'app/plugin/plugin.html',
|
||||
})
|
||||
export class Plugin {
|
||||
constructor(params: NavParams) {
|
||||
constructor(params: NavParams, elementRef: ElementRef) {
|
||||
|
||||
let el = elementRef.nativeElement;
|
||||
|
||||
this.textArea = el.querySelector('textarea');
|
||||
|
||||
this.content = {
|
||||
items: [],
|
||||
value: ''
|
||||
};
|
||||
|
||||
this.plugin = params.get('plugin');
|
||||
console.log('Plugin', this.plugin);
|
||||
@@ -41,6 +121,22 @@ export class Plugin {
|
||||
});
|
||||
}
|
||||
|
||||
output(...args) {
|
||||
var s = args.map((v) => {
|
||||
if(typeof v === 'object') {
|
||||
console.log('Stringifying', v);
|
||||
return safeJSONStringify(v, 4);//JSON.stringify(v);
|
||||
}
|
||||
return v;
|
||||
});
|
||||
|
||||
this.content.items.push(s.join(' '));
|
||||
|
||||
this.content.value = this.content.items.join();
|
||||
|
||||
this.textArea.scrollTop = this.textArea.scrollHeight;
|
||||
}
|
||||
|
||||
doMethod(method) {
|
||||
let pluginMethodArgEntry = demoArgs[this.plugin];
|
||||
|
||||
@@ -63,18 +159,23 @@ export class Plugin {
|
||||
|
||||
if(v && v.then) {
|
||||
v.then(() => {
|
||||
console.log('Success', arguments);
|
||||
console.log('Success', arguments, this);
|
||||
this.output(arguments);
|
||||
}, (err) => {
|
||||
console.error('Error', err);
|
||||
this.output(err);
|
||||
});
|
||||
} else {
|
||||
console.log('Response: ', v);
|
||||
this.output(v);
|
||||
|
||||
if(v.subscribe) {
|
||||
console.log('Observable response, subscribing...');
|
||||
v.subscribe((val) => {
|
||||
console.log('Observable val', val);
|
||||
this.output(val);
|
||||
}, (err) => {
|
||||
this.output(err);
|
||||
console.log('ERROR: Observable', err);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user