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

add stockage save for alldocs

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