Commit 6b500761 authored by Xiaowu Zhang's avatar Xiaowu Zhang

add stockage save for alldocs

parent e7f8a34d
...@@ -8,13 +8,16 @@ ...@@ -8,13 +8,16 @@
$.mobile.pushStateEnabled = false; $.mobile.pushStateEnabled = false;
var gadget_list = { var gadget_list = {
"upload" : {"0" : "../audioplayer_upload/index.html", "upload" : {"0" : "../audioplayer_upload/index.html",
"1" : "../audioplayer_playlist/index.html"}, "1" : "../audioplayer_playlist/index.html",
"2" : "../audioplayer_playlist/index.html"},
"playlist" : {"0" : "../audioplayer_playlist/index.html", "playlist" : {"0" : "../audioplayer_playlist/index.html",
"1" : "../audioplayer_playlist/index.html"}, "1" : "../audioplayer_playlist/index.html",
"2" : "../audioplayer_playlist/index.html"},
"control" : {"0" : "../audioplayer_control/index.html", "control" : {"0" : "../audioplayer_control/index.html",
"1" : "../audioplayer_control/index.html"} "1" : "../audioplayer_control/index.html",
"2" : "../audioplayer_control/index.html"}
}, },
allStorageType = ["indexeddbStorage", "httpStorage"]; allStorageType = ["offline", "localhost", "online"];
function storageType(type) { function storageType(type) {
return allStorageType[type]; return allStorageType[type];
} }
...@@ -40,8 +43,10 @@ ...@@ -40,8 +43,10 @@
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash") .declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.allowPublicAcquisition("plEnablePage", function () { .allowPublicAcquisition("plEnablePage", function () {
var controlPanel = this.__element.getElementsByClassName('page')[0]; var controlPanel = this.__element.getElementsByClassName('page')[0];
while (controlPanel.firstChild) { if (controlPanel) {
controlPanel.removeChild(controlPanel.firstChild); while (controlPanel.firstChild) {
controlPanel.removeChild(controlPanel.firstChild);
}
} }
}) })
.allowPublicAcquisition("plDisablePage", function () { .allowPublicAcquisition("plDisablePage", function () {
...@@ -99,15 +104,24 @@ ...@@ -99,15 +104,24 @@
rJS(window) rJS(window)
.ready(function (g) { .ready(function (g) {
return g.getDeclaredGadget("httpStorage") return g.getDeclaredGadget("online")
.push(function (gadget) {
return gadget.createJio(
{ "type" : "http",
"database" : "http://192.168.242.63:8080/"}
);
})
.push(function () {
return g.getDeclaredGadget("localhost");
})
.push(function (gadget) { .push(function (gadget) {
return gadget.createJio( return gadget.createJio(
{ "type" : "http",//indexeddb { "type" : "http",
"database" : "http://localhost:8080/"} //test "database" : "http://localhost:8080/"}
); );
}) })
.push(function () { .push(function () {
return g.getDeclaredGadget("indexeddbStorage"); return g.getDeclaredGadget("offline");
}) })
.push(function (gadget) { .push(function (gadget) {
return gadget.createJio( return gadget.createJio(
...@@ -130,10 +144,12 @@ ...@@ -130,10 +144,12 @@
} }
gadget.storageType = gadget.storageType || 0; gadget.storageType = gadget.storageType || 0;
if (options.page === "playlist") { if (options.page === "playlist") {
if (options.id === "indexeddbStorage") { if (options.id === "offline") {
gadget.storageType = 0; gadget.storageType = 0;
} else if (options.id === "httpStorage") { } else if (options.id === "localhost") {
gadget.storageType = 1; gadget.storageType = 1;
} else if (options.id === "online") {
gadget.storageType = 2;
} }
} }
return gadget.declareGadget( return gadget.declareGadget(
......
...@@ -24,10 +24,13 @@ ...@@ -24,10 +24,13 @@
</div> </div>
<div class="indexeddbStorage" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="indexeddbStorage" > <div class="offline" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="offline" >
</div> </div>
<div class="httpStorage" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="httpStorage" > <div class="localhost" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="localhost" >
</div>
<div class="online" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="online" >
</div> </div>
<article class="gadget_container"></article> <article class="gadget_container"></article>
......
/*global rJS, jIO, console */ /*global rJS, jIO, console, RSVP */
/*jslint nomen: true*/
(function (rJS, jIO) { (function (rJS, jIO) {
"use strict"; "use strict";
...@@ -6,17 +7,38 @@ ...@@ -6,17 +7,38 @@
.ready(function (gadget) { .ready(function (gadget) {
// Initialize the gadget local parameters // Initialize the gadget local parameters
gadget.state_parameter_dict = {}; gadget.state_parameter_dict = {};
gadget.save = {};
}) })
.declareMethod('createJio', function (jio_options) { .declareMethod('createJio', function (jio_options) {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options); this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
}) })
.declareMethod('allDocs', function () { .declareMethod('allDocs', function () {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage,
return storage.allDocs.apply(storage, arguments); that = this;
if (that.save.data !== undefined) {
return that.save;
}
return storage.allDocs.apply(storage, arguments)
.then(function (result) {
that.save = result;
return result;
});
}) })
.declareMethod('get', function () { .declareMethod('get', function (param) {
var storage = this.state_parameter_dict.jio_storage; var storage = this.state_parameter_dict.jio_storage,
result = this.save,
length,
i;
if (result.data !== undefined) {
length = result.data.rows.length;
for (i = 0; i < length; i += 1) {
if ((result.data.rows[i].doc.title === param._id) ||
(result.data.rows[i].id === param._id)) { //xxx
return ({"data": {"title" : result.data.rows[i].doc.title}});
}
}
}
return storage.get.apply(storage, arguments); return storage.get.apply(storage, arguments);
}) })
.declareMethod('getAttachment', function () { .declareMethod('getAttachment', function () {
......
/*global window, rJS, RSVP, console, URL, Math, parseInt, document, /*global window, rJS, RSVP, console, URL, Math, parseInt, document, jIO,
Uint8Array, File, Audio, loopEventListener, jQuery, promiseEventListener*/ Uint8Array, Audio, loopEventListener, jQuery, promiseEventListener*/
/*jslint nomen: true*/ /*jslint nomen: true*/
(function (window, rJS, RSVP, loopEventListener, $, promiseEventListener) { (function (window, rJS, RSVP, loopEventListener, $, promiseEventListener) {
...@@ -122,6 +122,9 @@ ...@@ -122,6 +122,9 @@
gradient.addColorStop(0, '#f00'); gradient.addColorStop(0, '#f00');
that.audio.play(); that.audio.play();
drawFrame = function () { drawFrame = function () {
if (that.audio.duration !== 0) {
bar_context.max = that.audio.duration;
}
array = getFFTValue(that); array = getFFTValue(that);
canvasCtx.clearRect(0, 0, cwidth, cheight); canvasCtx.clearRect(0, 0, cwidth, cheight);
step = Math.round(array.length / meterNum); step = Math.round(array.length / meterNum);
...@@ -140,21 +143,7 @@ ...@@ -140,21 +143,7 @@
}; };
return promiseRequestAnimation(drawFrame); return promiseRequestAnimation(drawFrame);
} }
function nextToPlay(g) {
return new RSVP.Queue()
.push(function () {
return g.allDocs({"include_docs": true});
})
.push(function (e) {
var list = e.data.rows,
id;
do {
id = list[Math.floor(Math.random() * list.length)].id;
} while (g.currentId === id);
return g.displayThisPage({page: "control",
id : id});
});
}
gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") gk.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("plSave", "plSave") .declareAcquiredMethod("plSave", "plSave")
...@@ -176,7 +165,10 @@ ...@@ -176,7 +165,10 @@
return g.plGive("value"); return g.plGive("value");
}) })
.push(function (value) { .push(function (value) {
g.filter.frequency = value; if (value === 0) {
value = 5000;
}
g.filter.frequency.value = value;
}) })
.push(function () { .push(function () {
g.currentId = options.id; g.currentId = options.id;
...@@ -190,7 +182,16 @@ ...@@ -190,7 +182,16 @@
return g.displayThisTitle(result.data.title); return g.displayThisTitle(result.data.title);
}) })
.push(function () { .push(function () {
return nextToPlay(g); return g.allDocs({"include_docs": true});
})
.push(function (e) {
var list = e.data.rows,
id;
do {
id = list[Math.floor(Math.random() * list.length)].id;
} while (g.currentId === id);
return g.displayThisPage({page: "control",
id : id});
}) })
.push(function (url) { .push(function (url) {
g.__element.getElementsByClassName("next")[0].href = url; g.__element.getElementsByClassName("next")[0].href = url;
...@@ -224,7 +225,6 @@ ...@@ -224,7 +225,6 @@
return g.plEnablePage(); return g.plEnablePage();
}) })
.push(function () { .push(function () {
bar_context.max = g.audio.duration;
time_context.style.left = bar_context.style.left; time_context.style.left = bar_context.style.left;
$(time_context).offset().top = $(bar_context).offset().top + 3; $(time_context).offset().top = $(bar_context).offset().top + 3;
time_context.innerHTML = timeFormat(g.audio.duration); time_context.innerHTML = timeFormat(g.audio.duration);
...@@ -235,10 +235,8 @@ ...@@ -235,10 +235,8 @@
}), }),
loopEventListener(g.audio, "ended", false, function () { loopEventListener(g.audio, "ended", false, function () {
return nextToPlay(g) window.location = g.__element
.push(function (url) { .getElementsByClassName("next")[0].href;
window.location = url;
});
}), }),
loopEventListener(command_context, "click", false, function () { loopEventListener(command_context, "click", false, function () {
......
...@@ -34,8 +34,9 @@ ...@@ -34,8 +34,9 @@
<div data-role="footer" data-position="fixed" data-theme="b"> <div data-role="footer" data-position="fixed" data-theme="b">
<div data-role="navbar"> <div data-role="navbar">
<ul> <ul>
<li><a data-role="button" class="indexeddbStorage" data-icon="arrow-l">indexeddbStorage</a></li> <li><a data-role="button" class="offline" data-icon="arrow-l">offline</a></li>
<li><a data-role="button" class="httpStorage" data-icon="arrow-r">httpStorage</a></li> <li><a data-role="button" class="localhost" data-icon="arrow-r">localhost</a></li>
<li><a data-role="button" class="online" data-icon="arrow-r">online</a></li>
</ul> </ul>
</div><!-- /navbar --> </div><!-- /navbar -->
</div><!-- /footer --> </div><!-- /footer -->
......
...@@ -24,16 +24,20 @@ ...@@ -24,16 +24,20 @@
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.displayThisPage({page: "playlist", gadget.displayThisPage({page: "playlist",
id : "indexeddbStorage"}), id : "offline"}),
gadget.displayThisPage({page: "playlist", gadget.displayThisPage({page: "playlist",
id : "httpStorage"}) id : "localhost"}),
gadget.displayThisPage({page: "playlist",
id : "online"})
]); ]);
}) })
.push(function (param_list) { .push(function (param_list) {
gadget.__element.getElementsByClassName('indexeddbStorage')[0] gadget.__element.getElementsByClassName('offline')[0]
.href = param_list[0]; .href = param_list[0];
gadget.__element.getElementsByClassName('httpStorage')[0] gadget.__element.getElementsByClassName('localhost')[0]
.href = param_list[1]; .href = param_list[1];
gadget.__element.getElementsByClassName('online')[0]
.href = param_list[2];
}) })
.push(function () { .push(function () {
return gadget.allDocs({"include_docs": true}); return gadget.allDocs({"include_docs": true});
...@@ -43,8 +47,9 @@ ...@@ -43,8 +47,9 @@
i, i,
j, j,
exp; exp;
if (options.id !== undefined && options.id !== "indexeddbStorage" if (options.id !== undefined && options.id !== "offline"
&& options.id !== "httpStorage") { && options.id !== "localhost"
&& options.id !== "online") {
for (i = 0, j = 0; i < e.data.rows.length; i += 1) { for (i = 0, j = 0; i < e.data.rows.length; i += 1) {
exp = new RegExp(options.id, "i"); exp = new RegExp(options.id, "i");
if (e.data.rows[i].doc.title.search(exp) !== -1) { if (e.data.rows[i].doc.title.search(exp) !== -1) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment