Commit 65940eac authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis
Browse files

Support GUI control of language and sync_on_start

parent 0373ae6b
......@@ -59,6 +59,8 @@ SYNC_PREFIX = 'sync'
config.DEFAULTS = {
'global': {
'agkyra_dir': AGKYRA_DIR,
'sync_on_start': 'on',
'language': 'en'
},
CLOUD_PREFIX: {
# <cloud>: {
......
......@@ -117,10 +117,10 @@ var settings_menu = new gui.MenuItem({
$.each(globals.settings, function(key, val) {old_settings[key]=val;});
windows['settings'] = gui.Window.open("settings.html", {
toolbar: false, focus: true,
width: 860, height: 620
width: 860, height: 860
});
windows['settings'].on('closed', function() {
log_debug('Settings windows is closed');
log_debug('Settings windows is closed');
globals.settings_are_open = false;
var new_settings = import_settings();
$.each(new_settings, function(key, setting) {
......
......@@ -37,7 +37,9 @@ var globals = {
url: null,
container: null,
directory: null,
exclude: null
exclude: null,
language: 'en',
sync_on_start: true
},
status: {synced: 0, unsynced: 0, failed: 0, code: STATUS['UNINITIALIZED']},
authenticated: false,
......
......@@ -24,9 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<script type="text/javascript">
var path = require('path');
var fs = require('fs');
var COMMON = JSON.parse(
fs.readFileSync(path.join('..', 'ui_data/common_en.json')));
var SETTINGS = COMMON.SETTINGS;
var LANG = JSON.parse(fs.readFileSync(path.join('..', 'ui_data/languages.json')));
var errors = {
cloud_url_empty: 'Provide a Cloud Authentication URL',
......@@ -41,6 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var fs = require('fs');
var exclude = null;
var cur_lang = 'en';
$(document).ready(function() {
var url = get_setting('url')
if (url) {
......@@ -62,7 +61,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
$('#exclude').val(
fs.readFileSync(exclude, encoding='utf-8'));
} catch (err) {console.log(err);}
if (!get_setting('language')) set_setting('language', cur_lang);
if (get_setting('sync_on_start')) $('#start_sync_box').click();
});
cur_lang = get_setting('language');
function update_exclude(new_content) {
if (exclude) fs.writeFile(exclude, new_content);
}
......@@ -192,6 +196,42 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
return cloud && token && container && directory;
}
function check_start_sync() {
settings['sync_on_start'] = $('#start_sync_box').is(':checked');
}
function localize() {
settings['language'] = cur_lang;
var COMMON = JSON.parse(
fs.readFileSync(path.join('..', 'ui_data/common_' + cur_lang + '.json')));
var SETTINGS = COMMON.SETTINGS;
document.getElementById('title').innerHTML = SETTINGS.TITLE;
document.getElementById('appearance_label').innerHTML = SETTINGS.APPEARANCE;
document.getElementById('language_label').innerHTML = SETTINGS.LANGUAGE;
document.getElementById('cloud_label').innerHTML = SETTINGS.CLOUD;
document.getElementById('url_label').innerHTML = SETTINGS.URL;
document.getElementById('token_label').innerHTML = SETTINGS.TOKEN;
document.getElementById('get_creds').innerHTML = SETTINGS.RETRIEVE;
document.getElementById('sync_label').innerHTML = SETTINGS.SYNC;
document.getElementById('container_label').innerHTML = SETTINGS.CONTAINER;
document.getElementById('directory_label').innerHTML = SETTINGS.DIRECTORY;
document.getElementById('dirdialogue_label').innerHTML = SETTINGS.DIRDIALOGUE;
document.getElementById('sync_button').innerHTML = SETTINGS.SAVE;
var lang_code = '';
for (key in LANG) {
var lang = LANG[key];
var checked = ''
if (key === cur_lang) checked = 'checked'
lang_code += '<div class="small-1 columns">'
+ '<input type="radio" name="language" value="' + key + '" '
+ checked
+ ' onclick="cur_lang=\'' + key + '\'; localize();">'
+ lang.name + '<img src="' + lang.icon + '"/></input></div>';
}
document.getElementById('language_space').innerHTML = lang_code;
}
window.setInterval(function() {
// Refresh get_creds visibility, until refresh_endpoints
// changes are in effect
......@@ -209,12 +249,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<h2><img src="static/images/about.png"/> <span id="title">User Settings</span></h2>
</header>
<form>
<fieldset>
<legend id="appearance_label">Appearance</legend>
<div class="clearfix">
<div class="small-3 columns">
<label id="language_label" for="language_space" class="right inline">Language</label>
</div>
<div class="small-9 columns" id="language_space">
<!-- This will be filled by scripts -->
</div>
</div>
<div class="clearfix">
<div class="small-3 columns">
<label id="start_sync_label" for="start_sync" class="right inline">Sync on start up</label>
</div>
<div class="small-9 columns" id="start_sync">
<input type="checkbox" name="start_sync_box" id="start_sync_box" onchange="check_start_sync();"/>
</div>
</div>
</fieldset>
<fieldset>
<legend id="cloud_label">Cloud</legend>
<div class="clearfix">
<div class="small-3 columns">
<label id="url_label" for="cloud-url" class="right inline">Cloud URL</label>
</div>
<div class="small-9 columns" id="cloud-error">
<input type="text" id="cloud-url" placeholder="Authentication URL"
......@@ -294,16 +352,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</form>
</div>
<script type="text/javascript">
document.getElementById('title').innerHTML = SETTINGS.TITLE;
document.getElementById('cloud_label').innerHTML = SETTINGS.CLOUD;
document.getElementById('url_label').innerHTML = SETTINGS.URL;
document.getElementById('token_label').innerHTML = SETTINGS.TOKEN;
document.getElementById('get_creds').innerHTML = SETTINGS.RETRIEVE;
document.getElementById('sync_label').innerHTML = SETTINGS.SYNC;
document.getElementById('container_label').innerHTML = SETTINGS.CONTAINER;
document.getElementById('directory_label').innerHTML = SETTINGS.DIRECTORY;
document.getElementById('dirdialogue_label').innerHTML = SETTINGS.DIRDIALOGUE;
document.getElementById('sync_button').innerHTML = SETTINGS.SAVE;
localize();
</script>
</body>
</html>
......@@ -234,7 +234,9 @@ class WebSocketProtocol(WebSocket):
"url": <auth url>,
"container": <container>,
"directory": <local directory>,
"exclude": <file path>
"exclude": <file path>,
"language": <en|el>,
"sync_on_start": <true|false>
} or {<ERROR>: <ERROR CODE>}
-- PUT SETTINGS --
......@@ -244,7 +246,9 @@ class WebSocketProtocol(WebSocket):
"url": <auth url>,
"container": <container>,
"directory": <local directory>,
"exclude": <file path>
"exclude": <file path>,
"language": <en|el>,
"sync_on_start": <true|false>
}
HELPER: {"CREATED": 201, "action": "put settings",} or
{<ERROR>: <ERROR CODE>, "action": "get settings",}
......@@ -266,7 +270,7 @@ class WebSocketProtocol(WebSocket):
settings = dict(
token=None, url=None,
container=None, directory=None,
exclude=None)
exclude=None, sync_on_start=True, language="en")
cnf = AgkyraConfig()
essentials = ('url', 'token', 'container', 'directory')
......@@ -380,6 +384,10 @@ class WebSocketProtocol(WebSocket):
self.settings['url'] = None
self.set_status(code=STATUS['SETTINGS MISSING'])
self.settings['sync_on_start'] = (
self.cnf.get('global', 'sync_on_start') == 'on')
self.settings['language'] = self.cnf.get('global', 'language')
# for option in ('container', 'directory', 'exclude'):
for option in ('container', 'directory'):
try:
......@@ -425,6 +433,11 @@ class WebSocketProtocol(WebSocket):
self.cnf.set_sync(sync, option, self.settings[option] or '')
changes = True
self.cnf.set('global', 'language', self.settings.get('language', 'en'))
sync_on_start = self.settings.get('sync_on_start', False)
self.cnf.set(
'global', 'sync_on_start', 'on' if sync_on_start else 'off')
if changes:
self.cnf.write()
LOG.debug('Settings saved')
......
......@@ -34,7 +34,7 @@ FORMATTER = logging.Formatter(
"%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s")
HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.DEBUG)
LOGGER.setLevel(logging.INFO)
def main():
......
......@@ -34,7 +34,7 @@ FORMATTER = logging.Formatter(
"%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s")
HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.DEBUG)
LOGGER.setLevel(logging.INFO)
def main():
......
......@@ -26,7 +26,7 @@ FORMATTER = logging.Formatter(
"%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s")
HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.DEBUG)
LOGGER.setLevel(logging.INFO)
def main():
......
......@@ -48,6 +48,8 @@
},
"SETTINGS": {
"TITLE": "Ρυθμίσεις χρήστη",
"APPEARANCE": "Εμφάνιση",
"LANGUAGE": "Γλώσσα",
"CLOUD": "Απομακρυσμένο σύστημα (νέφος)",
"URL": "URL νέφους",
"TOKEN": "Κλειδί token",
......
......@@ -48,6 +48,8 @@
},
"SETTINGS": {
"TITLE": "User Settings",
"APPEARANCE": "Appearance",
"LANGUAGE": "Language",
"CLOUD": "Cloud",
"URL": "Cloud URL",
"TOKEN": "User Token",
......
{
"en": {
"name": "English",
"icon": "static/images/language/en.png"
},
"el": {
"name": "Ελληνικά",
"icon": "static/images/language/el.png"
}
}
\ No newline at end of file
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