show warning if unable to conenct to lsd

This commit is contained in:
j 2013-11-03 15:35:05 +01:00
parent 6013154708
commit fd7d603934
3 changed files with 129 additions and 84 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
MANIFEST
build
db.sqlite
secret.txt

14
README Normal file
View File

@ -0,0 +1,14 @@
LSD example site
REQUIREMENTS
you have to install
Django
pip install Django
django_lsd
pip install git+https://git.0x2620.org/django_lsd.git#egg=django_lsd
CLINETS
and users will need to run lsd, more on that at
https://git.0x2620.org/?p=lsd.git

View File

@ -1,5 +1,6 @@
Ox.load('UI', function() {
var current,
var lsdURL = 'http://127.0.0.1:15550',
current,
columns = [
{
id: 'state',
@ -73,73 +74,79 @@ Ox.load('UI', function() {
url: '/api/'
}).bindEvent({
load: function(data) {
window.app.local = Ox.API({
url: 'http://127.0.0.1:15550/api/'
}, function() {
if (!data.user) {
signupDialog();
return;
}
app._seed = setInterval(function() {
app.local.seedRequests({});
}, 60000);
app.local.config({});
app.$player = $('<audio>');
app.play = function(id) {
var url = 'http://127.0.0.1:15550/get/' + id;
app.$player.attr('src', url);
app.$player[0].play();
current = id;
}
app.stop = function() {
app.$player[0].pause();
}
app.api.find({}, function(result) {
app.items = result.data.items;
app.$list = Ox.TableList({
columns: columns,
columnsMovable: true,
columnsVisible: true,
items: result.data.items,
max: 1,
pageLength: Math.min(100, result.data.items.length),
//query: getQuery(),
scrollbarVisible: true,
//sortable: true,
sort: ['+id'],
unique: 'id',
}).bindEvent({
open: function(data) {
var id = data.ids[0],
item = app.$list.value(id);
if (item.state == 'available') {
app.play(id);
} else {
app.local.addRequests({ids: [id]}, function() {
app.$list.value(id, 'state', 'downloading');
var interval = setInterval(function () {
app.local.info({id: id}, function(result) {
if (Ox.isEmpty(result.data)) {
clearInterval(interval);
app.$list.value(id, 'state', 'available');
app.$list.value(id, 'info', '');
} else {
var percent = Math.round(100
* result.data.total_done
/ result.data.total_wanted) || 0;
app.$list.value(id, 'info', '' + percent + ' % downloaded');
}
});
}, 1000);
});
}
},
}).appendTo(Ox.$body);
});
Ox.get(lsdURL + '/api/', function(result) {
!result ? warningDialog() : load(data);
});
}
});
function load(data) {
window.app.local = Ox.API({
url: lsdURL + '/api/'
}, function() {
if (!data.user) {
signupDialog();
return;
}
app._seed = setInterval(function() {
app.local.seedRequests({});
}, 60000);
app.local.config({});
app.$player = $('<audio>');
app.play = function(id) {
var url = lsdURL + '/get/' + id;
app.$player.attr('src', url);
app.$player[0].play();
current = id;
}
app.stop = function() {
app.$player[0].pause();
}
app.api.find({}, function(result) {
app.items = result.data.items;
app.$list = Ox.TableList({
columns: columns,
columnsMovable: true,
columnsVisible: true,
items: result.data.items,
max: 1,
pageLength: Math.min(100, result.data.items.length),
//query: getQuery(),
scrollbarVisible: true,
//sortable: true,
sort: ['+id'],
unique: 'id',
}).bindEvent({
open: function(data) {
var id = data.ids[0],
item = app.$list.value(id);
if (item.state == 'available') {
app.play(id);
} else {
app.local.addRequests({ids: [id]}, function() {
app.$list.value(id, 'state', 'downloading');
var interval = setInterval(function () {
app.local.info({id: id}, function(result) {
if (Ox.isEmpty(result.data)) {
clearInterval(interval);
app.$list.value(id, 'state', 'available');
app.$list.value(id, 'info', '');
} else {
var percent = Math.round(100
* result.data.total_done
/ result.data.total_wanted) || 0;
app.$list.value(id, 'info', '' + percent + ' % downloaded');
}
});
}, 1000);
});
}
},
}).appendTo(Ox.$body);
});
});
}
function signupDialog() {
var $form,
$dialog = Ox.Dialog({
@ -160,7 +167,7 @@ Ox.load('UI', function() {
username: values.username,
password: values.password,
url: document.location.origin + '/api/',
extensions: ['ogg', 'mp3']
extensions: ['ogg', 'oga', 'mp3']
}, function() {
document.location.reload();
});
@ -174,30 +181,53 @@ Ox.load('UI', function() {
],
closeButton: true,
content: Ox.Element()
.append(
$form = Ox.Form({
items: [
Ox.Input({
id: 'username',
label: Ox._('Username'),
labelWidth: 120,
width: 320
}),
Ox.Input({
autovalidate: /.+/,
id: 'password',
label: Ox._('Password'),
labelWidth: 120,
type: 'password',
width: 320
})
]
.css({
padding: '48px'
})
),
.append(
$form = Ox.Form({
items: [
Ox.Input({
id: 'username',
label: Ox._('Username'),
labelWidth: 120,
width: 320
}),
Ox.Input({
autovalidate: /.+/,
id: 'password',
label: Ox._('Password'),
labelWidth: 120,
type: 'password',
width: 320
})
]
})
),
height: 192,
removeOnClose: true,
title: 'Sign Up',
width: 432
}).open();
}
function warningDialog() {
var $dialog = Ox.Dialog({
buttons: [
],
closeButton: false,
content: Ox.Element()
.css({
padding: '48px'
})
.append(
'Could not connect to LSD on <a href="' + lsdURL + '">'+lsdURL+'</a><br>'
+ 'Please start or install <a href="https://git.0x2620.org/?p=lsd.git">LSD</a>'
),
height: 192,
removeOnClose: true,
title: 'LSD Not Running',
width: 432
}).open();
}
});