diff options
author | Sebastian Silva <sebastian@somosazucar.org> | 2013-04-22 09:06:16 (GMT) |
---|---|---|
committer | Sebastian Silva <sebastian@somosazucar.org> | 2013-04-22 09:06:16 (GMT) |
commit | 7aad22af38cee227f09d3eeac1748592b7ad217d (patch) | |
tree | d116145645ff696d08e6ce5b72e029abb1dff010 | |
parent | 0397378439094057821ff5efd18550a9c6d16fde (diff) |
fix offline nickname & enable offline notifications
-rw-r--r-- | sugar_network_webui/app.py | 34 | ||||
-rw-r--r-- | sugar_network_webui/templates/_context-artifact-list.html | 6 | ||||
-rw-r--r-- | sugar_network_webui/templates/_context-comment-list.html | 8 | ||||
-rw-r--r-- | sugar_network_webui/templates/_context-resource-list.html | 4 | ||||
-rw-r--r-- | sugar_network_webui/templates/_context-review-list.html | 6 | ||||
-rw-r--r-- | sugar_network_webui/templates/_context-solution-list.html | 13 | ||||
-rw-r--r-- | sugar_network_webui/templates/_resource-list.html | 7 | ||||
-rw-r--r-- | sugar_network_webui/templates/base.html | 31 | ||||
-rw-r--r-- | sugar_network_webui/templates/toolbar.html | 12 |
9 files changed, 73 insertions, 48 deletions
diff --git a/sugar_network_webui/app.py b/sugar_network_webui/app.py index 7b742bd..8d9e147 100644 --- a/sugar_network_webui/app.py +++ b/sugar_network_webui/app.py @@ -35,6 +35,7 @@ import simplejson import tempfile from sugar_network import client +from sugar_network.toolkit.http import NotFound from client import Client _BUFFER_SIZE = 1024 * 10 @@ -104,6 +105,11 @@ def get_colors(): conf = gconf.client_get_default() return conf.get_string('/desktop/sugar/user/color').split(',') +def get_user(): + import gconf + conf = gconf.client_get_default() + return conf.get_string('/desktop/sugar/user/nick') + def get_documents_path(): """Gets the path of the DOCUMENTS folder @@ -135,6 +141,7 @@ def inject_vars(): stroke, fill = get_colors() kwvar = { 'userid': client.sugar_uid(), + 'sugar_nick' : get_user() } return dict(stroke=stroke, fill=fill, **kwvar) @@ -143,10 +150,7 @@ def inject_vars(): def before_request(): g.home_mount = home_mount g.network_mount = network_mount - if 'connected' not in session: - session['connected'] = network_mount.client.inline - if session['connected'] and not network_mount.client.inline: - session['connected'] = False + session['connected'] = network_mount.client.inline if not session['connected']: g.client = home_mount.client g.Contexts = home_mount.Contexts @@ -180,6 +184,10 @@ def before_request(): def incoming(event): global _pull_events _pull_events.append(event) + #if event['event']=='inline' and event.get('state')=='offline': + # session['connected'] = False + #if event['event']=='inline' and event.get('state')=='online': + # session['connected'] = True return None _pull_listener = Client.connect(incoming) @@ -477,11 +485,11 @@ def resource_list(query=None): @app.errorhandler(404) def page_not_found(error): - template = 'browser-view.html' - return render_template(template, total=0, info=_('Error'), - resource_type='context', query='', total_pages=0, - browser_view='true', result=[], type='context', - meta=_('Object not found.'), page=1), 404 + title = _('Object not found.') + body = _('The resource you are looking for '\ + + 'is not available at the moment.\n\n'\ + + 'If you are offline try connecting.'); + return render_template('dialog.html', title=title, body=body) @app.errorhandler(500) @@ -510,8 +518,6 @@ def context_grid(query=None, page=None): else: session['page'] = int(request.args['_preload']) session.modified = True - logging.debug("page " + str(page) + " preload " + str(preload)) - logging.debug("session-page " + str(session['page'])) except KeyError: return redirect(url_for('context_grid', type=request.args.get('type'), @@ -603,7 +609,7 @@ def project_browser(context_guid=None): 'summary', 'favorite', 'clone', 'type']) try: session['last_context_title'] = context['title'] - except RuntimeError: + except NotFound: abort(404) session['last_context'] = context['guid'] session.modified = True @@ -647,7 +653,7 @@ def reviews_browser(resource_guid=None, review_guid=None): 'summary', 'favorite', 'clone', 'type']) try: session['last_context_title'] = context['title'] - except RuntimeError: + except NotFound: abort(404) session['last_context'] = context['guid'] session.modified = True @@ -755,7 +761,7 @@ def context_resource_browser(context_guid=None, query=None): session['last_context'] = context['guid'] session['last_context_title'] = context['title'] session.modified = True - except RuntimeError: + except NotFound: abort(404) stroke, fill = get_colors() diff --git a/sugar_network_webui/templates/_context-artifact-list.html b/sugar_network_webui/templates/_context-artifact-list.html index 1d42359..c6ea51c 100644 --- a/sugar_network_webui/templates/_context-artifact-list.html +++ b/sugar_network_webui/templates/_context-artifact-list.html @@ -36,7 +36,11 @@ </a> </div> <div class="mtime"> - {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% if (session['connected'] or False) %} + {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% else %} + {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} + {% endif %} </div> <div class="resource-meta"> {%- for tag in item['tags'] %} diff --git a/sugar_network_webui/templates/_context-comment-list.html b/sugar_network_webui/templates/_context-comment-list.html index 36175ce..5772363 100644 --- a/sugar_network_webui/templates/_context-comment-list.html +++ b/sugar_network_webui/templates/_context-comment-list.html @@ -6,7 +6,13 @@ <img class="comment-icon" src="/static/icons/comments.png" /> <div class="comment-content">{{item['message']}}</div> </div> - <div class='mtime mtime-comment'>{{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + <div class='mtime mtime-comment'> + {% if (session['connected'] or False) %} + {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% else %} + {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} + {% endif %} + {%- if item.is_author -%} <span class="delete-comment-button has_tooltip" title="{{_('delete')}}" data-guid="{{item['guid']}}"><img class="action-button" src="/static/icons/edit-delete.png"></img></span> {%- endif -%} diff --git a/sugar_network_webui/templates/_context-resource-list.html b/sugar_network_webui/templates/_context-resource-list.html index 08a9b1b..72ba7bb 100644 --- a/sugar_network_webui/templates/_context-resource-list.html +++ b/sugar_network_webui/templates/_context-resource-list.html @@ -36,7 +36,11 @@ </a> </div> <div class="mtime"> + {% if (session['connected'] or False) %} {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% else %} + {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} + {% endif %} </div> <div class="resource-meta"> {%- for tag in item['tags'] %} diff --git a/sugar_network_webui/templates/_context-review-list.html b/sugar_network_webui/templates/_context-review-list.html index 2e20efe..4fc0fe2 100644 --- a/sugar_network_webui/templates/_context-review-list.html +++ b/sugar_network_webui/templates/_context-review-list.html @@ -31,7 +31,11 @@ {{item['content']}} </div> <div class='mtime'> - {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% if (session['connected'] or False) %} + {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% else %} + {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} + {% endif %} </div> <div class="resource-meta"> {%- for tag in item['tags'] %} diff --git a/sugar_network_webui/templates/_context-solution-list.html b/sugar_network_webui/templates/_context-solution-list.html index 4177222..7703c20 100644 --- a/sugar_network_webui/templates/_context-solution-list.html +++ b/sugar_network_webui/templates/_context-solution-list.html @@ -11,7 +11,12 @@ <div class="resource-content"> <pre>{{resource['content']|safe}}</pre> </div> - <div class='mtime'>{{_('by %(author)s on %(date)s', author=resource['author'][0]['name'], date=resource['mtime']|timedelta)}} + <div class='mtime'> + {% if (session['connected'] or False) %} + {{_('by %(author)s on %(date)s', author=resource['author'][0]['name'], date=resource['mtime']|timedelta)}} + {% else %} + {{_('by %(author)s on %(date)s', author=sugar_nick, date=resource['mtime']|timedelta)}} + {% endif %} </div> <div class="resource-meta"> {%- for tag in resource['tags'] %} @@ -61,7 +66,11 @@ {{item['content']|safe}} </div> <div class='mtime'> - {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% if (session['connected'] or False) %} + {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% else %} + {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} + {% endif %} </div> <div class="resource-meta"> {%- for tag in item['tags'] %} diff --git a/sugar_network_webui/templates/_resource-list.html b/sugar_network_webui/templates/_resource-list.html index 246a125..3877ce3 100644 --- a/sugar_network_webui/templates/_resource-list.html +++ b/sugar_network_webui/templates/_resource-list.html @@ -29,7 +29,12 @@ {{item['content']}}</a> </div> <div class="resource-meta"> - {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% if (session['connected'] or False) %} + {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} + {% else %} + {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} + {% endif %} + {%- for tag in item['tags'] %} <span class="tag">{{tag}}</span> {%- endfor %} diff --git a/sugar_network_webui/templates/base.html b/sugar_network_webui/templates/base.html index bdd1d5d..8063d6d 100644 --- a/sugar_network_webui/templates/base.html +++ b/sugar_network_webui/templates/base.html @@ -9,8 +9,8 @@ <script src="/static/js/jquery.history.js"></script> <script src="/static/js/jquery-ui-1.8.16.sugar.min.js" type="text/javascript"></script> <script src="/static/js/jquery.livequery.min.js" type="text/javascript" charset="utf-8"></script> - <!--script src="/static/js/toastr.js"></script--> - <!--link href="/static/css/toastr.css" rel="stylesheet"/--> + <script src="/static/js/toastr.js"></script> + <link href="/static/css/toastr.css" rel="stylesheet"/> <!--script src="/static/js/sticky.full.js" type="text/javascript"></script--> <!--link rel="stylesheet" href="/static/css/sticky.full.css" type="text/css" /--> <style> @@ -398,28 +398,31 @@ }; $(document).ready( function() { - /* - sse = new EventSource('/my_event_source'); + sse = new EventSource('/my_event_source'); sse.onmessage = function(message) { data = $.parseJSON(message.data); if (data.event=="inline" && data.state=="offline") { toastr.info('Your are now in offline mode.'); $('#sn-button-img').removeClass('sugar-network-online'); + location.reload(); + // TODO: proper ajaxy reload } if (data.event=="inline" && data.state=="online") { toastr.info('Your are now in online mode.'); $('#sn-button-img').addClass('sugar-network-online'); + location.reload(); + // TODO: proper ajaxy reload } + /* TODO: Handle these if (data.event=="push") { toastr.info('Sugar Network is synchronized.'); } if (data.event=="create") { toastr.warning('New ' + data.props.type[0]); } - console.log('A message has arrived!'); + console.log('A message has arrived!');*/ } - */ $( "#sn-button" ).tooltip({position:"bottom right", offset:[-3,-60], predelay:500}); $( "#browser-button" ).tooltip({position:"bottom right", offset:[-3,-60], predelay:500}); @@ -483,22 +486,6 @@ var term = $('#query').val(); if(e.keyCode == 13 && _selected==false) { location='/context/search/'+term; - /* For adding tag filters */ - /** if (term[0]=='#') { - /* Send the data using post * - $('#query').val('{{query or ''}}'); - $.post( '/_tags', { tag:term }, - function( data ) { - $( "#tags-section" ).empty().append( data ); - /* bind_del(); * - location.reload(); - } - ); - } - else { - /* location='/resource/{{resource_type}}s/'+term; * - location='/context/search/'+term; - }*/ return false; //prevents form from being submitted. } } diff --git a/sugar_network_webui/templates/toolbar.html b/sugar_network_webui/templates/toolbar.html index eae5fa8..0e3bf10 100644 --- a/sugar_network_webui/templates/toolbar.html +++ b/sugar_network_webui/templates/toolbar.html @@ -89,6 +89,12 @@ <img class="toolbar-icon" src="/static/icons/list-add.png" /> </div> </li--> + <!-- TODO: useful until properly updating cursor on events --> + <li class="toolbar-items" onclick="location.href='/reload'+location.pathname;"> + <div class="toolbar-button has_tooltip" title="{{_('reload')}}"> + <img class="toolbar-icon" src="/static/icons/reload.png" /> + </div> + </li> <li class="toolbar-items" onclick="location='/project/new?returnto=' + location.href"> <div class="toolbar-button has_tooltip" title="{{_('create new context')}}"> <img class="toolbar-icon" src="/static/icons/go-up.png" /> @@ -99,11 +105,5 @@ <img class="toolbar-icon" src="/static/icons/activity-about.png" /> </div> </li> - - <!--li class="toolbar-items" onclick="location.href='/reload'+location.pathname;"> - <div class="toolbar-button has_tooltip" title="{{_('reload')}}"> - <img class="toolbar-icon" src="/static/icons/reload.png" /> - </div> - </li--> </ul> </div> |