oxjs might be replaced get replaced right now, only use js

This commit is contained in:
j 2016-01-13 12:17:13 +05:30
parent fb51189d15
commit 47fe90329c
3 changed files with 57 additions and 89 deletions

View file

@ -242,6 +242,10 @@ actions.register(restart, cache=False)
class Update(Thread): class Update(Thread):
_status = {
'reload': False,
'status': 'Updating Open Media Library...'
}
def __init__(self): def __init__(self):
Thread.__init__(self) Thread.__init__(self)
@ -250,10 +254,11 @@ class Update(Thread):
def status(self, status, reload=False): def status(self, status, reload=False):
from websocket import trigger_event from websocket import trigger_event
trigger_event('updatestatus', { self._status = {
'reload': reload, 'reload': reload,
'status': status, 'status': status,
}) }
trigger_event('updatestatus', self._status)
def install(self): def install(self):
while update_available(): while update_available():
@ -272,7 +277,7 @@ class Update(Thread):
db_version = settings.server.get('db_version', 0) db_version = settings.server.get('db_version', 0)
if db_version < settings.DB_VERSION: if db_version < settings.DB_VERSION:
self.status('Migrating database...') self.status('Migrating database...')
time.sleep(1) time.sleep(30)
settings.server['db_version'] = settings.DB_VERSION settings.server['db_version'] = settings.DB_VERSION
def run(self): def run(self):

View file

@ -34,10 +34,13 @@ class Handler(WebSocketHandler):
self.close() self.close()
if self not in state.websockets: if self not in state.websockets:
state.websockets.append(self) state.websockets.append(self)
trigger_event('status', { if state.update:
'id': settings.USER_ID, trigger_event('updatestatus', state.tasks._status)
'online': state.online else:
}) trigger_event('status', {
'id': settings.USER_ID,
'online': state.online
})
if state.nodes: if state.nodes:
for node in state.nodes._nodes.values(): for node in state.nodes._nodes.values():
node.trigger_status() node.trigger_status()

View file

@ -4,31 +4,63 @@
var animationInterval, var animationInterval,
enableDebugMode = getLocalStorage('oml.enableDebugMode'), enableDebugMode = getLocalStorage('oml.enableDebugMode'),
omlVersion = getOMLVersion(),
oxjsPath = '/static/oxjs/' + (enableDebugMode ? 'dev' : 'min'), oxjsPath = '/static/oxjs/' + (enableDebugMode ? 'dev' : 'min'),
terminal,
theme = getLocalStorage('Ox.theme') theme = getLocalStorage('Ox.theme')
&& JSON.parse(localStorage['Ox.theme']) && JSON.parse(localStorage['Ox.theme'])
|| 'oxlight'; || 'oxlight';
loadImages(function(images) { loadImages(function(images) {
loadScreen(images); loadScreen(images);
loadOxJS(loadOML); initUpdate();
}); });
function connectSocket() {
update.socket = new WebSocket('ws://' + document.location.host + '/ws');
update.socket.onopen = function(event) {
if (update.reload) {
reload();
}
};
update.socket.onmessage = function(event) {
var name, data = JSON.parse(event.data);
name = data[0];
data = data[1];
if (name == 'updatestatus') {
update.status.innerHTML = data.status;
update.reload = data.reload;
} else {
console.log(name, data);
}
};
update.socket.onerror = function(event) {
update.socket.close();
};
update.socket.onclose = function(event) {
setTimeout(connectSocket, 1000);
};
}
function getLocalStorage(key) { function getLocalStorage(key) {
try { try {
return localStorage[key]; return localStorage[key];
} catch(e) {} } catch(e) {}
} }
function getOMLVersion() { function initUpdate(browserSupported) {
var i, path, scripts = document.getElementsByTagName('script'); window.update = {};
for (i = 0; i < scripts.length; i++) { update.status = document.createElement('div');
if(/oml.update.js/.test(scripts[i].src)) { update.status.className = 'OxElement';
return scripts[i].src.replace(/.*\?/, ''); update.status.style.left = 0;
} update.status.style.right = 0;
} update.status.style.bottom = '50px';
update.status.style.textAlign = 'center';
update.status.style.position = 'absolute';
update.status.style.paddingLeft = '16px';
update.status.style.color = '#999999';
update.status.style.fontFamily = "Lucida Grande, Segoe UI, DejaVu Sans, Lucida Sans Unicode, Helvetica, Arial, sans-serif";
update.status.style.fontSize = "11px";
document.querySelector('#loadingScreen').appendChild(update.status);
connectSocket();
} }
function loadImages(callback) { function loadImages(callback) {
@ -68,65 +100,6 @@
images.logo.src = '/static/png/oml.png'; images.logo.src = '/static/png/oml.png';
} }
function loadOML(browserSupported) {
window.oml = Ox.App({
name: 'oml',
socket: 'ws://' + document.location.host + '/ws',
url: '/api/'
}).bindEvent({
load: function(data) {
data.browserSupported = browserSupported;
oml.ui = {};
oml.ui.status = Ox.Element()
.css({
position: 'absolute',
left: 0,
right: 0,
bottom: '50px',
textAlign: 'center',
paddingLeft: '16px',
color: '#999999'
}).appendTo(Ox.$('#loadingScreen'));
oml.ui.status.html('Updating Open Media Library...');
oml.down = setTimeout(function() {
if (oml.socket.readyState != oml.socket.OPEN && Ox.isUndefined(oml.reload)) {
reload();
}
}, 5000);
},
updatestatus: function(data) {
oml.ui.status.html(data.status);
oml.reload = data.reload;
},
close: function(data) {
},
open: function(data) {
if (oml.reload) {
reload();
}
}
});
}
function loadOxJS(callback) {
var head = document.head
|| document.getElementsByTagName('head')[0]
|| document.documentElement,
script = document.createElement('script');
script.onload = function() {
Ox.load({UI: {theme: theme}}, function() {
Ox.formatUpper = function(string) {
return string.toUpperCase();
};
callback();
});
};
script.src = oxjsPath + '/Ox.js?' + omlVersion;
script.type = 'text/javascript';
head.appendChild(script);
}
function loadScreen(images) { function loadScreen(images) {
var loadingScreen = document.createElement('div'); var loadingScreen = document.createElement('div');
loadingScreen.setAttribute('id', 'loadingScreen'); loadingScreen.setAttribute('id', 'loadingScreen');
@ -153,15 +126,6 @@
document.location.href = document.location.protocol + '//' + document.location.host; document.location.href = document.location.protocol + '//' + document.location.host;
} }
function removeScreen() {
var $loadingScreen = $('#loadingScreen');
$loadingScreen.animate({
opacity: 0
}, 1000, function() {
$loadingScreen.remove();
});
}
function startAnimation() { function startAnimation() {
var css, deg = 0, loadingIcon = document.getElementById('loadingIcon'), var css, deg = 0, loadingIcon = document.getElementById('loadingIcon'),
previousTime = +new Date(); previousTime = +new Date();
@ -179,8 +143,4 @@
}, 83); }, 83);
} }
function stopAnimation() {
clearInterval(animationInterval);
}
}()); }());