},
insertResponse: function(response) {
- if((response.length < 1) || (response=='"donotprintme"')) {
+ if((response.length < 1) || (response=='"donotprintme"') || (response=='donotprintme')) {
this.activeLine.parent().append("<p class='response'></p>");
}
else {
this._rawCommand = "";
this._commandStack = 0;
this._tutorialPtr = 0;
- this._tutorialMax = 2;
+ this._tutorialMax = 4;
this._mongo = {};
this._mongo.test = [];
// help command
_help: function() {
return PTAG('HELP') +
- PTAG('opencloud.slices.listAll() get all slices');
+ PTAG('opencloud list opencloud API object types') +
+ PTAG('opencloud.slices list methods to can call on slices') +
+ PTAG('opencloud.slices.all() get all slices') +
+ PTAG('opencloud.slices.filter({key: "value"}) filter using dictionary') +
+ PTAG('opencloud.slices.get({key: "value"})) get using dictionary')
},
_t2: function() {
this._tutorialPtr = 2;
- return PTAG('2. List some slices') +
- PTAG('Type this:') +
- PTAG(' opencloud.slices.listAll();');
+ return PTAG('2. List some objects') +
+ PTAG('Try these:') +
+ PTAG(' opencloud.slices.all();') +
+ PTAG(' opencloud.slivers.all();') +
+ PTAG(' opencloud.sites.all();') +
+ PTAG(' opencloud.nodes.all();');
+
+ },
+
+ _t3: function() {
+ this._tutorialPtr = 3;
+ return PTAG('3. Filter some objects') +
+ PTAG('Try these:') +
+ PTAG(' opencloud.slices.get({name: "HyperCache"});');
+ PTAG(' opencloud.nodes.filter({site_id: opencloud.sites.get({name: "Princeton"})["id"]});');
+
+ },
+
+ _t4: function() {
+ this._tutorialPtr = 4;
+ return PTAG('4. Available OpenCloud objects and methods') +
+ PTAG('Try these:') +
+ PTAG(' opencloud;') +
+ PTAG(' opencloud.nodes;');
},
return this._t1;
case 't2':
return this._t2;
+ case 't3':
+ return this._t3;
+ case 't4':
+ return this._t4;
}
}
}
};
+function replaceAll(find, replace, str) {
+ return str.replace(new RegExp(find, 'g'), replace);\r
+}
+
+/* stackoverflow: http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript */
+function syntaxHighlight(json) {
+ if ( json.hasOwnProperty("__str__")) {
+ return syntaxHighlight(json.__str__());
+ }
+ if (typeof json != 'string') {\r
+ json = JSON.stringify(json, undefined, "\t");\r
+ }\r
+ json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\r
+ return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {\r
+ var cls = 'terminal_number';\r
+ if (/^"/.test(match)) {\r
+ if (/:$/.test(match)) {\r
+ cls = 'terminal_key';\r
+ } else {\r
+ cls = 'terminal_string';\r
+ }\r
+ } else if (/true|false/.test(match)) {\r
+ cls = 'terminal_boolean';\r
+ } else if (/null/.test(match)) {\r
+ cls = 'terminal_null';\r
+ }\r
+ return '<span class="' + cls + '">' + match + '</span>';\r
+ });\r
+}
+
$htmlFormat = function(obj) {
- result=tojson(obj, ' ', ' ', true);
+ //JSON.stringify(obj,undefined,2)
+ result=replaceAll("\t"," ",replaceAll("\n","<br>",syntaxHighlight(obj))); //tojson(obj, ' ', ' ', true);
return result;
}