Răsfoiți Sursa

HUE-2033 [core] Added project move functionality

Enrico Berti 11 ani în urmă
părinte
comite
5595e06b8e

+ 62 - 32
desktop/core/src/desktop/templates/home2.mako

@@ -182,9 +182,8 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
                 <th style="width: 26px">&nbsp;</th>
                 <th style="width: 200px">${_('Name')}</th>
                 <th>${_('Description')}</th>
-                <th style="width: 150px">${_('Projects')}</th>
-                <th style="width: 100px">${_('Owner')}</th>
                 <th style="width: 150px">${_('Last Modified')}</th>
+                <th style="width: 80px; text-align: center">${_('Project')}</th>
                 <th style="width: 40px">${_('Sharing')}</th>
               </tr>
             </thead>
@@ -245,17 +244,21 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
     <td style="width: 26px"><img data-bind="attr: { src: icon }"></td>
     <td><a data-bind="attr: { href: url }, text: name"></a></td>
     <td data-bind="text: description"></td>
-    <td>
-      <div class="documentTags" data-bind="foreach: tags">
-        <span class="badge" data-bind="text: name"></span>
-      </div>
-    </td>
-    <td data-bind="text: owner"></td>
     <td data-bind="text: lastModified"></td>
+    <td style="text-align: center; white-space: nowrap">
+      <a href="javascript:void(0)" rel="tooltip" data-placement="left" data-bind="click: moveDoc, attr: {'data-original-title': '${ _("Change project for") } '+name}" style="padding-left:8px; padding-right: 8px">
+        <span data-bind="foreach: tags">
+          <!-- ko if: name != 'trash'-->
+          <span class="badge" data-bind="text: name"></span>
+          <!-- /ko -->
+        </span>
+      </a>
+    </td>
     <td style="width: 40px; text-align: center">
-      <a rel="tooltip" data-placement="left" style="padding-left:10px" data-bind="click: shareDoc, attr: {'data-original-title': '${ _("Share") } '+name}, css:{'baseShared': true, 'isShared': perms.read.users.length + perms.read.groups.length > 0}">
+      <a rel="tooltip" data-placement="left" style="padding-left:10px; padding-right: 10px" data-bind="click: shareDoc, attr: {'data-original-title': '${ _("Share") } '+name}, visible: isMine , css:{'baseShared': true, 'isShared': perms.read.users.length + perms.read.groups.length > 0}">
         <i class="fa fa-users"></i>
       </a>
+      <i class="fa fa-ban" style="padding-left:8px; padding-right: 8px" data-bind="visible: !isMine"></i>
     </td>
   </tr>
 </script>
@@ -286,7 +289,7 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
         <h3>${_('Confirm Delete')}</h3>
     </div>
     <div class="modal-body">
-        <p>${_('Are you sure you want to delete the project')} <strong><span data-bind="text: selectedForDelete().name"></span></strong>? ${_('All its documents will be moved to the default tag.')}</p>
+        <p>${_('Are you sure you want to delete the project')} <strong><span data-bind="text: selectedTagForDelete().name"></span></strong>? ${_('All its documents will be moved to the default tag.')}</p>
     </div>
     <div class="modal-footer">
         <a class="btn" data-dismiss="modal">${_('No')}</a>
@@ -294,6 +297,30 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
     </div>
 </div>
 
+<div id="documentMoveModal" class="modal hide fade">
+    <div class="modal-header">
+        <a href="#" class="close" data-dismiss="modal">&times;</a>
+        <h3>${_('Move to a project')}</h3>
+    </div>
+    <div class="modal-body">
+        <p>
+          ${_('Select the project you want to move this document to')}
+          <ul class="unstyled">
+            <!-- ko foreach: myTags -->
+              <li>
+                <a href="javascript:void(0)" style="padding-left: 4px" data-bind="click: moveDocFinal">
+                  <i class="fa fa-tag"></i> <span data-bind="text: name"></span>
+                </a>
+              </li>
+            <!-- /ko -->
+          </ul>
+        </p>
+    </div>
+    <div class="modal-footer">
+        <a class="btn" data-dismiss="modal">${_('Cancel')}</a>
+    </div>
+</div>
+
 
 <div id="documentShareModal" class="modal hide fade">
   <div class="modal-header">
@@ -332,25 +359,6 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
   </div>
 </div>
 
-
-<script type="text/html" id="tag-sharer-template">
-  <div style="margin-right:10px;margin-bottom: 6px;float:left;">
-    <span class="tags-modal-checkbox badge">
-       <i class="fa fa-trash-o"></i> <span data-bind="text: name"></span>
-    </span>
-    <div data-bind="template: { name: 'tag-template', foreach: projects }"></div>
-  </div>
-</script>
-
-
-<script type="text/html" id="tag-edit-template">
-  <div style="margin-right:10px;margin-bottom: 6px;float:left;">
-    <span class="tags-modal-checkbox badge">
-       <i class="fa fa-trash-o"></i> <span data-bind="text: name"></span>
-    </span>
-  </div>
-</script>
-
 <script src="/static/ext/js/datatables-paging-0.1.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/js/knockout-min.js" type="text/javascript" charset="utf-8"></script>
 <script src="/static/ext/js/knockout.mapping-2.3.2.js" type="text/javascript" charset="utf-8"></script>
@@ -496,12 +504,12 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
   }
 
   function removeTag() {
-    viewModel.selectedForDelete(viewModel.selectedTag());
+    viewModel.selectedTagForDelete(viewModel.selectedTag());
     $("#removeTagModal").modal("show");
   }
 
   function removeTagFinal() {
-    var tag = viewModel.selectedForDelete();
+    var tag = viewModel.selectedTagForDelete();
     $.post("/desktop/api/tag/remove_tag", {
       tag_id: tag.id()
     }, function (response) {
@@ -519,6 +527,26 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
     });
   }
 
+  function moveDoc(doc) {
+    viewModel.selectedDoc(doc);
+    $("#documentMoveModal").modal("show");
+  }
+
+  function moveDocFinal(tag) {
+    $.post("/desktop/api/doc/update_tags", {
+      data: JSON.stringify({
+        doc_id: viewModel.selectedDoc().id,
+        tag_ids: [tag.id()]
+      })
+    }, function (response) {
+      if (response.doc != null) {
+        $(document).trigger("info", "${ _("Project updated successfully.") }");
+        viewModel.updateDoc(response.doc);
+      }
+      $("#documentMoveModal").modal("hide");
+    })
+  }
+
   function shareDoc(doc) {
     viewModel.selectedDoc(doc);
     $("#documentShareModal").modal("show");
@@ -568,7 +596,9 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
         if (response.status != 0) {
           $(document).trigger("error", "${_("There was an error processing your action: ")}" + response.message);
         }
-        viewModel.documents.valueHasMutated();
+        else {
+          viewModel.updateDoc(response.doc);
+        }
       }
     });
   }

+ 21 - 49
desktop/core/static/js/home.vm.js

@@ -18,53 +18,6 @@
 function HomeViewModel(json_tags, json_docs) {
   var self = this;
 
-  var MOCK_TAGS = {
-    'history': {'name': 'History', 'id': 1, 'docs': [1], 'type': 'history'},
-    'trash': {'name': 'Trash', 'id': 3, 'docs': [2]},
-    'mine': [
-      {'name': 'default', 'id': 2, 'docs': [3]},
-      {'name': 'web', 'id': 3, 'docs': [3]}
-    ],
-    'notmine': [
-      {'name': 'romain', 'projects': [
-        {'name': 'example', 'id': 20, 'docs': [10]},
-        {'name': 'ex2', 'id': 30, 'docs': [10, 11]}
-      ]},
-      {'name': 'pai', 'projects': [
-        {'name': 'example2', 'id': 20, 'docs': [10]}
-      ]}
-    ]
-  };
-
-  var MOCK_DOCUMENTS = {
-    '1': {
-      'id': 1,
-      'name': 'my query history', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
-      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
-    },
-    '2': {
-      'id': 2,
-      'name': 'my query 2 trashed', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
-      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
-    },
-    '3': {
-      'id': 3,
-      'name': 'my query 3 tagged twice', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
-      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
-    },
-    '10': {
-      'id': 10,
-      'name': 'my query 3 shared', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
-      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
-    },
-    '11': {
-      'id': 11,
-      'name': 'my query 4 shared', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
-      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
-    }
-  };
-
-
   var ALL_DOCUMENTS = json_docs;
   self.tags = ko.mapping.fromJS(json_tags);
   self.documents = ko.observableArray([]);
@@ -81,7 +34,7 @@ function HomeViewModel(json_tags, json_docs) {
   }));
 
   self.selectedTag = ko.observable({});
-  self.selectedForDelete = ko.observable({
+  self.selectedTagForDelete = ko.observable({
     name: ''
   });
 
@@ -169,7 +122,26 @@ function HomeViewModel(json_tags, json_docs) {
       }
     });
     return _tag;
-  };
+  }
+
+  self.getDocById = function (docId) {
+    var _doc = null;
+    $.each(ALL_DOCUMENTS, function (id, doc) {
+      if (doc.id == docId) {
+        _doc = doc;
+      }
+    });
+    return _doc;
+  }
+
+  self.updateDoc = function (doc) {
+    $.each(ALL_DOCUMENTS, function (id, iDoc) {
+      if (iDoc.id == doc.id) {
+        ALL_DOCUMENTS[id] = doc;
+      }
+    });
+    self.filterDocs(self.selectedTag());
+  }
 
   self.filterDocs = function (tag) {
     self.documents.removeAll();