Commit 7aad22af38cee227f09d3eeac1748592b7ad217d
- Diff rendering mode:
- inline
- side by side
sugar_network_webui/app.py
(20 / 14)
  | |||
35 | 35 | import tempfile | |
36 | 36 | ||
37 | 37 | from sugar_network import client | |
38 | from sugar_network.toolkit.http import NotFound | ||
38 | 39 | from client import Client | |
39 | 40 | ||
40 | 41 | _BUFFER_SIZE = 1024 * 10 | |
… | … | ||
105 | 105 | conf = gconf.client_get_default() | |
106 | 106 | return conf.get_string('/desktop/sugar/user/color').split(',') | |
107 | 107 | ||
108 | def get_user(): | ||
109 | import gconf | ||
110 | conf = gconf.client_get_default() | ||
111 | return conf.get_string('/desktop/sugar/user/nick') | ||
108 | 112 | ||
113 | |||
109 | 114 | def get_documents_path(): | |
110 | 115 | """Gets the path of the DOCUMENTS folder | |
111 | 116 | ||
… | … | ||
141 | 141 | stroke, fill = get_colors() | |
142 | 142 | kwvar = { | |
143 | 143 | 'userid': client.sugar_uid(), | |
144 | 'sugar_nick' : get_user() | ||
144 | 145 | } | |
145 | 146 | return dict(stroke=stroke, fill=fill, **kwvar) | |
146 | 147 | ||
… | … | ||
150 | 150 | def before_request(): | |
151 | 151 | g.home_mount = home_mount | |
152 | 152 | g.network_mount = network_mount | |
153 | if 'connected' not in session: | ||
154 | session['connected'] = network_mount.client.inline | ||
155 | if session['connected'] and not network_mount.client.inline: | ||
156 | session['connected'] = False | ||
153 | session['connected'] = network_mount.client.inline | ||
157 | 154 | if not session['connected']: | |
158 | 155 | g.client = home_mount.client | |
159 | 156 | g.Contexts = home_mount.Contexts | |
… | … | ||
184 | 184 | def incoming(event): | |
185 | 185 | global _pull_events | |
186 | 186 | _pull_events.append(event) | |
187 | #if event['event']=='inline' and event.get('state')=='offline': | ||
188 | # session['connected'] = False | ||
189 | #if event['event']=='inline' and event.get('state')=='online': | ||
190 | # session['connected'] = True | ||
187 | 191 | return None | |
188 | 192 | _pull_listener = Client.connect(incoming) | |
189 | 193 | ||
… | … | ||
485 | 485 | ||
486 | 486 | @app.errorhandler(404) | |
487 | 487 | def page_not_found(error): | |
488 | template = 'browser-view.html' | ||
489 | return render_template(template, total=0, info=_('Error'), | ||
490 | resource_type='context', query='', total_pages=0, | ||
491 | browser_view='true', result=[], type='context', | ||
492 | meta=_('Object not found.'), page=1), 404 | ||
488 | title = _('Object not found.') | ||
489 | body = _('The resource you are looking for '\ | ||
490 | + 'is not available at the moment.\n\n'\ | ||
491 | + 'If you are offline try connecting.'); | ||
492 | return render_template('dialog.html', title=title, body=body) | ||
493 | 493 | ||
494 | 494 | ||
495 | 495 | @app.errorhandler(500) | |
… | … | ||
518 | 518 | else: | |
519 | 519 | session['page'] = int(request.args['_preload']) | |
520 | 520 | session.modified = True | |
521 | logging.debug("page " + str(page) + " preload " + str(preload)) | ||
522 | logging.debug("session-page " + str(session['page'])) | ||
523 | 521 | except KeyError: | |
524 | 522 | return redirect(url_for('context_grid', | |
525 | 523 | type=request.args.get('type'), | |
… | … | ||
609 | 609 | 'summary', 'favorite', 'clone', 'type']) | |
610 | 610 | try: | |
611 | 611 | session['last_context_title'] = context['title'] | |
612 | except RuntimeError: | ||
612 | except NotFound: | ||
613 | 613 | abort(404) | |
614 | 614 | session['last_context'] = context['guid'] | |
615 | 615 | session.modified = True | |
… | … | ||
653 | 653 | 'summary', 'favorite', 'clone', 'type']) | |
654 | 654 | try: | |
655 | 655 | session['last_context_title'] = context['title'] | |
656 | except RuntimeError: | ||
656 | except NotFound: | ||
657 | 657 | abort(404) | |
658 | 658 | session['last_context'] = context['guid'] | |
659 | 659 | session.modified = True | |
… | … | ||
761 | 761 | session['last_context'] = context['guid'] | |
762 | 762 | session['last_context_title'] = context['title'] | |
763 | 763 | session.modified = True | |
764 | except RuntimeError: | ||
764 | except NotFound: | ||
765 | 765 | abort(404) | |
766 | 766 | ||
767 | 767 | stroke, fill = get_colors() |
  | |||
36 | 36 | </a> | |
37 | 37 | </div> | |
38 | 38 | <div class="mtime"> | |
39 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
39 | {% if (session['connected'] or False) %} | ||
40 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
41 | {% else %} | ||
42 | {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} | ||
43 | {% endif %} | ||
40 | 44 | </div> | |
41 | 45 | <div class="resource-meta"> | |
42 | 46 | {%- for tag in item['tags'] %} |
  | |||
6 | 6 | <img class="comment-icon" src="/static/icons/comments.png" /> | |
7 | 7 | <div class="comment-content">{{item['message']}}</div> | |
8 | 8 | </div> | |
9 | <div class='mtime mtime-comment'>{{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
9 | <div class='mtime mtime-comment'> | ||
10 | {% if (session['connected'] or False) %} | ||
11 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
12 | {% else %} | ||
13 | {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} | ||
14 | {% endif %} | ||
15 | |||
10 | 16 | {%- if item.is_author -%} | |
11 | 17 | <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> | |
12 | 18 | {%- endif -%} |
  | |||
36 | 36 | </a> | |
37 | 37 | </div> | |
38 | 38 | <div class="mtime"> | |
39 | {% if (session['connected'] or False) %} | ||
39 | 40 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | |
41 | {% else %} | ||
42 | {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} | ||
43 | {% endif %} | ||
40 | 44 | </div> | |
41 | 45 | <div class="resource-meta"> | |
42 | 46 | {%- for tag in item['tags'] %} |
  | |||
31 | 31 | {{item['content']}} | |
32 | 32 | </div> | |
33 | 33 | <div class='mtime'> | |
34 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
34 | {% if (session['connected'] or False) %} | ||
35 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
36 | {% else %} | ||
37 | {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} | ||
38 | {% endif %} | ||
35 | 39 | </div> | |
36 | 40 | <div class="resource-meta"> | |
37 | 41 | {%- for tag in item['tags'] %} |
  | |||
11 | 11 | <div class="resource-content"> | |
12 | 12 | <pre>{{resource['content']|safe}}</pre> | |
13 | 13 | </div> | |
14 | <div class='mtime'>{{_('by %(author)s on %(date)s', author=resource['author'][0]['name'], date=resource['mtime']|timedelta)}} | ||
14 | <div class='mtime'> | ||
15 | {% if (session['connected'] or False) %} | ||
16 | {{_('by %(author)s on %(date)s', author=resource['author'][0]['name'], date=resource['mtime']|timedelta)}} | ||
17 | {% else %} | ||
18 | {{_('by %(author)s on %(date)s', author=sugar_nick, date=resource['mtime']|timedelta)}} | ||
19 | {% endif %} | ||
15 | 20 | </div> | |
16 | 21 | <div class="resource-meta"> | |
17 | 22 | {%- for tag in resource['tags'] %} | |
… | … | ||
66 | 66 | {{item['content']|safe}} | |
67 | 67 | </div> | |
68 | 68 | <div class='mtime'> | |
69 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
69 | {% if (session['connected'] or False) %} | ||
70 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
71 | {% else %} | ||
72 | {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} | ||
73 | {% endif %} | ||
70 | 74 | </div> | |
71 | 75 | <div class="resource-meta"> | |
72 | 76 | {%- for tag in item['tags'] %} |
  | |||
29 | 29 | {{item['content']}}</a> | |
30 | 30 | </div> | |
31 | 31 | <div class="resource-meta"> | |
32 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
32 | {% if (session['connected'] or False) %} | ||
33 | {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}} | ||
34 | {% else %} | ||
35 | {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}} | ||
36 | {% endif %} | ||
37 | |||
33 | 38 | {%- for tag in item['tags'] %} | |
34 | 39 | <span class="tag">{{tag}}</span> | |
35 | 40 | {%- endfor %} |
  | |||
9 | 9 | <script src="/static/js/jquery.history.js"></script> | |
10 | 10 | <script src="/static/js/jquery-ui-1.8.16.sugar.min.js" type="text/javascript"></script> | |
11 | 11 | <script src="/static/js/jquery.livequery.min.js" type="text/javascript" charset="utf-8"></script> | |
12 | <!--script src="/static/js/toastr.js"></script--> | ||
13 | <!--link href="/static/css/toastr.css" rel="stylesheet"/--> | ||
12 | <script src="/static/js/toastr.js"></script> | ||
13 | <link href="/static/css/toastr.css" rel="stylesheet"/> | ||
14 | 14 | <!--script src="/static/js/sticky.full.js" type="text/javascript"></script--> | |
15 | 15 | <!--link rel="stylesheet" href="/static/css/sticky.full.css" type="text/css" /--> | |
16 | 16 | <style> | |
… | … | ||
398 | 398 | }; | |
399 | 399 | ||
400 | 400 | $(document).ready( function() { | |
401 | /* | ||
402 | sse = new EventSource('/my_event_source'); | ||
401 | sse = new EventSource('/my_event_source'); | ||
403 | 402 | ||
404 | 403 | sse.onmessage = function(message) { | |
405 | 404 | data = $.parseJSON(message.data); | |
406 | 405 | if (data.event=="inline" && data.state=="offline") { | |
407 | 406 | toastr.info('Your are now in offline mode.'); | |
408 | 407 | $('#sn-button-img').removeClass('sugar-network-online'); | |
408 | location.reload(); | ||
409 | // TODO: proper ajaxy reload | ||
409 | 410 | } | |
410 | 411 | if (data.event=="inline" && data.state=="online") { | |
411 | 412 | toastr.info('Your are now in online mode.'); | |
412 | 413 | $('#sn-button-img').addClass('sugar-network-online'); | |
414 | location.reload(); | ||
415 | // TODO: proper ajaxy reload | ||
413 | 416 | } | |
417 | /* TODO: Handle these | ||
414 | 418 | if (data.event=="push") { | |
415 | 419 | toastr.info('Sugar Network is synchronized.'); | |
416 | 420 | } | |
417 | 421 | if (data.event=="create") { | |
418 | 422 | toastr.warning('New ' + data.props.type[0]); | |
419 | 423 | } | |
420 | console.log('A message has arrived!'); | ||
424 | console.log('A message has arrived!');*/ | ||
421 | 425 | } | |
422 | */ | ||
423 | 426 | ||
424 | 427 | $( "#sn-button" ).tooltip({position:"bottom right", offset:[-3,-60], predelay:500}); | |
425 | 428 | $( "#browser-button" ).tooltip({position:"bottom right", offset:[-3,-60], predelay:500}); | |
… | … | ||
486 | 486 | var term = $('#query').val(); | |
487 | 487 | if(e.keyCode == 13 && _selected==false) { | |
488 | 488 | location='/context/search/'+term; | |
489 | /* For adding tag filters */ | ||
490 | /** if (term[0]=='#') { | ||
491 | /* Send the data using post * | ||
492 | $('#query').val('{{query or ''}}'); | ||
493 | $.post( '/_tags', { tag:term }, | ||
494 | function( data ) { | ||
495 | $( "#tags-section" ).empty().append( data ); | ||
496 | /* bind_del(); * | ||
497 | location.reload(); | ||
498 | } | ||
499 | ); | ||
500 | } | ||
501 | else { | ||
502 | /* location='/resource/{{resource_type}}s/'+term; * | ||
503 | location='/context/search/'+term; | ||
504 | }*/ | ||
505 | 489 | return false; //prevents form from being submitted. | |
506 | 490 | } | |
507 | 491 | } |
  | |||
89 | 89 | <img class="toolbar-icon" src="/static/icons/list-add.png" /> | |
90 | 90 | </div> | |
91 | 91 | </li--> | |
92 | <!-- TODO: useful until properly updating cursor on events --> | ||
93 | <li class="toolbar-items" onclick="location.href='/reload'+location.pathname;"> | ||
94 | <div class="toolbar-button has_tooltip" title="{{_('reload')}}"> | ||
95 | <img class="toolbar-icon" src="/static/icons/reload.png" /> | ||
96 | </div> | ||
97 | </li> | ||
92 | 98 | <li class="toolbar-items" onclick="location='/project/new?returnto=' + location.href"> | |
93 | 99 | <div class="toolbar-button has_tooltip" title="{{_('create new context')}}"> | |
94 | 100 | <img class="toolbar-icon" src="/static/icons/go-up.png" /> | |
… | … | ||
105 | 105 | <img class="toolbar-icon" src="/static/icons/activity-about.png" /> | |
106 | 106 | </div> | |
107 | 107 | </li> | |
108 | |||
109 | <!--li class="toolbar-items" onclick="location.href='/reload'+location.pathname;"> | ||
110 | <div class="toolbar-button has_tooltip" title="{{_('reload')}}"> | ||
111 | <img class="toolbar-icon" src="/static/icons/reload.png" /> | ||
112 | </div> | ||
113 | </li--> | ||
114 | 108 | </ul> | |
115 | 109 | </div> |