Explorar o código

HUE-1884 [core] Split tag view in shared and not shared ones

Split into My Projects and Shared with me on the UI
Added 'Shared by' on shared tags
Enrico Berti %!s(int64=11) %!d(string=hai) anos
pai
achega
e3c095a

+ 10 - 7
desktop/core/src/desktop/api.py

@@ -33,7 +33,7 @@ LOG = logging.getLogger(__name__)
 
 def list_docs(request):
   docs = Document.objects.get_docs(request.user).order_by('-last_modified')[:1000]
-  return HttpResponse(json.dumps(massaged_documents_for_json(docs)), mimetype="application/json")
+  return HttpResponse(json.dumps(massaged_documents_for_json(docs, request.user)), mimetype="application/json")
 
 
 def list_tags(request):
@@ -41,11 +41,11 @@ def list_tags(request):
   return HttpResponse(json.dumps(massaged_tags_for_json(tags, request.user)), mimetype="application/json")
 
 
-def massaged_documents_for_json(documents):
-  return [massage_doc_for_json(doc) for doc in documents]
+def massaged_documents_for_json(documents, user):
+  return [massage_doc_for_json(doc, user) for doc in documents]
 
 
-def massage_doc_for_json(doc):
+def massage_doc_for_json(doc, user):
   perms = doc.list_permissions()
   return {
       'id': doc.id,
@@ -62,6 +62,7 @@ def massage_doc_for_json(doc):
         }
       },
       'owner': doc.owner.username,
+      'isMine': doc.owner.username == user.username,
       'lastModified': doc.last_modified.strftime("%x %X"),
       'lastModifiedInMillis': time.mktime(doc.last_modified.timetuple())
     }
@@ -75,9 +76,11 @@ def massaged_tags_for_json(tags, user):
     massaged_tag = {
       'id': tag.id,
       'name': tag.tag,
+      'owner': tag.owner.username,
       'isTrash': tag.id == trash.id,
       'isHistory': tag.id == history.id,
-      'isExample': tag.tag == DocumentTag.EXAMPLE
+      'isExample': tag.tag == DocumentTag.EXAMPLE,
+      'isMine': tag.owner.username == user.username
     }
     ts.append(massaged_tag)
 
@@ -123,7 +126,7 @@ def update_tags(request):
     request_json = json.loads(request.POST['data'])
     try:
       doc = DocumentTag.objects.update_tags(request.user, request_json['doc_id'], request_json['tag_ids'])
-      response['doc'] = massage_doc_for_json(doc)
+      response['doc'] = massage_doc_for_json(doc, request.user)
       response['status'] = 0
     except Exception, e:
       response['message'] = force_unicode(e)
@@ -162,7 +165,7 @@ def update_permissions(request):
       doc.sync_permissions(data)
       response['message'] = _('Permissions updated!')
       response['status'] = 0
-      response['doc'] = massage_doc_for_json(doc)
+      response['doc'] = massage_doc_for_json(doc, request.user)
     except Exception, e:
       response['message'] = force_unicode(e)
   else:

+ 34 - 9
desktop/core/src/desktop/templates/home.mako

@@ -123,19 +123,34 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
            <li class="viewHistory toggable-section">
              <a href="javascript:void(0)"><i class="fa fa-clock-o"></i> ${_('History')} <span id="historyCounter" class="badge pull-right">0</span></a>
            </li>
-          <li class="nav-header tag-header">${_('Projects')} <div class="edit-tags" style="display: inline;cursor: pointer;margin-left: 6px" title="${ _('Edit projects') }"><i class="fa fa-tags"></i></div> </li>
+          <li class="nav-header tag-mine-header">${_('My Projects')} <div class="edit-tags" style="display: inline;cursor: pointer;margin-left: 6px" title="${ _('Edit projects') }"><i class="fa fa-pencil"></i></div> </li>
+          <% has_tag = False %>
           % if len(tags) > 2:
             % for tag in tags:
-              % if tag.tag not in ('trash', 'history'):
-              <li class="toggle-tag" data-tag="${ tag.tag }"><a href="javascript:void(0)">${ tag.tag } <span class="tag-counter badge pull-right">0</span></a></li>
+              % if tag.tag not in ('trash', 'history') and tag.is_mine:
+              <% has_tag = True %>
+              <li class="toggle-tag" data-tag="${ tag.tag }"><a href="javascript:void(0)"><i class="fa fa-tag"></i> ${ tag.tag }<span class="tag-counter badge pull-right">0</span></a></li>
               % endif
             % endfor
-          % else:
-            <li><a href="javascript:void(0)" class="edit-tags" style="line-height:24px"><i class="fa fa-plus-circle"></i> ${_('There are currently no projects. Click here to add one now!')}</a></li>
           % endif
-          <li class="nav-header tag-header">
-            ${_('Shared with me')} <div class="edit-tags" style="display: inline;margin-left: 6px" ><i class="fa fa-tags"></i></div>
+          % if not has_tag:
+            <li><a href="javascript:void(0)" class="edit-tags" style="line-height:24px"><i class="fa fa-plus-circle"></i> ${_('You currently own no projects. Click here to add one now!')}</a></li>
+          % endif
+          <li class="nav-header tag-shared-header">
+            ${_('Shared with me')}
           </li>
+           <% has_tag = False %>
+           % if len(tags) > 2:
+            % for tag in tags:
+              % if tag.tag not in ('trash', 'history') and not tag.is_mine:
+              <% has_tag = True %>
+              <li class="toggle-tag" data-tag="${ tag.tag }" rel="tooltip" title="${_('Shared by %s' % tag.owner)}" data-placement="right"><a href="javascript:void(0)"><i class="fa fa-tag"></i> ${ tag.tag }<span class="tag-counter badge pull-right">0</span></a></li>
+              % endif
+            % endfor
+          % endif
+          % if not has_tag:
+            <li><a href="javascript:void(0)" style="line-height:24px"><i class="fa fa-plus-circle"></i> ${_('There are currently no projects shared with you.')}</a></li>
+          % endif
         </ul>
       </div>
 
@@ -425,14 +440,24 @@ $(document).ready(function () {
       if (!JSON_TAGS[i].isTrash && !JSON_TAGS[i].isHistory) {
         var _t = $("<li>").addClass("toggle-tag");
         _t.attr("data-tag", JSON_TAGS[i].name);
-        _t.html('<a href="javascript:void(0)">' + JSON_TAGS[i].name + '<span class="tag-counter badge pull-right">0</span></a>');
-        _t.insertAfter(".tag-header");
+        _t.html('<a href="javascript:void(0)"><i class="fa fa-tag"></i> ' + JSON_TAGS[i].name + '<span class="tag-counter badge pull-right">0</span></a>');
+        if (JSON_TAGS[i].isMine){
+          _t.insertAfter(".tag-mine-header");
+        }
+        else {
+          _t.tooltip({
+            placement: "right",
+            title: "${_('Shared by')} " + JSON_TAGS[i].owner
+          });
+          _t.insertAfter(".tag-shared-header");
+        }
       }
     }
     if (_selected != ""){
       $(".toggle-tag[data-tag='"+_selected+"']").click();
     }
     updateTagCounters();
+    $("a[rel='tooltip']").tooltip();
   }
 
   function renderTagsModal() {

+ 14 - 3
desktop/core/src/desktop/views.py

@@ -55,18 +55,29 @@ def home(request):
       Document.objects.get_docs(request.user).order_by('-last_modified').exclude(tags__tag__in=['history'])[:500],
       Document.objects.get_docs(request.user).order_by('-last_modified').filter(tags__tag__in=['history'])[:100]
   )
+  docs = list(docs)
   tags = DocumentTag.objects.get_tags(user=request.user)
 
   apps = appmanager.get_apps_dict(request.user)
 
   return render('home.mako', request, {
     'apps': apps,
-    'documents': docs,
-    'json_documents': json.dumps(massaged_documents_for_json(docs)),
-    'tags': tags,
+    'documents': augment_docs(docs, request.user),
+    'json_documents': json.dumps(massaged_documents_for_json(docs, request.user)),
+    'tags': augment_tags(tags, request.user),
     'json_tags': json.dumps(massaged_tags_for_json(tags, request.user))
   })
 
+def augment_docs(docs, user):
+  for doc in docs:
+    doc.is_mine = doc.owner.username == user.username
+  return docs
+
+def augment_tags(tags, user):
+  for tag in tags:
+    tag.is_mine = tag.owner.username == user.username
+  return tags
+
 
 @access_log_level(logging.WARN)
 def log_view(request):