Browse Source

HUE-2033 [core] Fixed document update after project or sharing changes

Enrico Berti 11 năm trước cách đây
mục cha
commit
54ab7ec

+ 5 - 5
desktop/core/src/desktop/api.py

@@ -160,7 +160,7 @@ def massaged_documents_for_json(documents, user):
   return docs
   return docs
 
 
 
 
-def massage_doc_for_json(doc):
+def massage_doc_for_json_new(doc):
   return {
   return {
       'id': doc.id,
       'id': doc.id,
       'contentType': doc.content_type.name,
       'contentType': doc.content_type.name,
@@ -178,7 +178,7 @@ def massaged_documents_for_json_old(documents, user):
   return [massage_doc_for_json(doc, user) for doc in documents]
   return [massage_doc_for_json(doc, user) for doc in documents]
 
 
 
 
-def massage_doc_for_json_old(doc, user):
+def massage_doc_for_json(doc, user):
   perms = doc.list_permissions()
   perms = doc.list_permissions()
   return {
   return {
       'id': doc.id,
       'id': doc.id,
@@ -190,12 +190,12 @@ def massage_doc_for_json_old(doc, user):
       'tags': [{'id': tag.id, 'name': tag.tag} for tag in doc.tags.all()],
       'tags': [{'id': tag.id, 'name': tag.tag} for tag in doc.tags.all()],
       'perms': {
       'perms': {
         'read': {
         'read': {
-          'users': [{'id': user.id, 'username': user.username} for user in perms.users.all()],
-          'groups': [{'id': group.id, 'name': group.name} for group in perms.groups.all()]
+          'users': [{'id': perm_user.id, 'username': perm_user.username} for perm_user in perms.users.all()],
+          'groups': [{'id': perm_group.id, 'name': perm_group.name} for perm_group in perms.groups.all()]
         }
         }
       },
       },
       'owner': doc.owner.username,
       'owner': doc.owner.username,
-      'isMine': doc.owner.username == user.username,
+      'isMine': doc.owner.username == user.username and True or False,
       'lastModified': doc.last_modified.strftime("%x %X"),
       'lastModified': doc.last_modified.strftime("%x %X"),
       'lastModifiedInMillis': time.mktime(doc.last_modified.timetuple())
       'lastModifiedInMillis': time.mktime(doc.last_modified.timetuple())
     }
     }

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

@@ -148,7 +148,7 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
                        title="${ _('Remove selected project') }" rel="tooltip" data-placement="right"></i>
                        title="${ _('Remove selected project') }" rel="tooltip" data-placement="right"></i>
              </div>
              </div>
            </li>
            </li>
-           <!-- ko template: { name: 'tag-template', foreach: myTags } -->
+           <!-- ko template: { name: 'tag-template', foreach: nyTags } -->
            <!-- /ko -->
            <!-- /ko -->
            <li data-bind="visible: myTags().length == 0">
            <li data-bind="visible: myTags().length == 0">
              <a href="javascript:void(0)" class="edit-tags" style="line-height:24px">
              <a href="javascript:void(0)" class="edit-tags" style="line-height:24px">
@@ -539,9 +539,14 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
         tag_ids: [tag.id()]
         tag_ids: [tag.id()]
       })
       })
     }, function (response) {
     }, function (response) {
-      if (response.doc != null) {
-        $(document).trigger("info", "${ _("Project updated successfully.") }");
-        viewModel.updateDoc(response.doc);
+      if (response != null){
+        if (response.status != 0) {
+          $(document).trigger("error", "${_("There was an error processing your action: ")}" + response.message);
+        }
+        else {
+          $(document).trigger("info", "${ _("Project updated successfully.") }");
+          viewModel.updateDoc(response.doc);
+        }
       }
       }
       $("#documentMoveModal").modal("hide");
       $("#documentMoveModal").modal("hide");
     })
     })

+ 15 - 0
desktop/core/static/js/home.vm.js

@@ -138,6 +138,21 @@ function HomeViewModel(json_tags, json_docs) {
     $.each(ALL_DOCUMENTS, function (id, iDoc) {
     $.each(ALL_DOCUMENTS, function (id, iDoc) {
       if (iDoc.id == doc.id) {
       if (iDoc.id == doc.id) {
         ALL_DOCUMENTS[id] = doc;
         ALL_DOCUMENTS[id] = doc;
+
+        $(self.tags.mine()).each(function (iCnt, tag) {
+          var _removeDocFromTag = true;
+          $(doc.tags).each(function (cnt, item) {
+            if (tag.id() == item.id && tag.docs().indexOf(doc.id) == -1) {
+              tag.docs().push(doc.id);
+            }
+            if (tag.docs().indexOf(doc.id) > -1 && tag.id() == item.id) {
+              _removeDocFromTag = false;
+            }
+          });
+          if (_removeDocFromTag) {
+            tag.docs().splice(tag.docs().indexOf(doc.id), 1);
+          }
+        });
       }
       }
     });
     });
     self.filterDocs(self.selectedTag());
     self.filterDocs(self.selectedTag());