瀏覽代碼

[home2] Drop the old file list with pagination and switch to the new HueDirectory

Johan Ahlen 10 年之前
父節點
當前提交
b1bcfdf
共有 2 個文件被更改,包括 33 次插入110 次删除
  1. 22 71
      desktop/core/src/desktop/static/desktop/js/home2.vm.js
  2. 11 39
      desktop/core/src/desktop/templates/home2.mako

+ 22 - 71
desktop/core/src/desktop/static/desktop/js/home2.vm.js

@@ -19,12 +19,13 @@
     define([
       'knockout',
       'desktop/js/assist/assistHelper',
+      'desktop/js/documents/hueDirectory',
       'knockout-mapping'
     ], factory);
   } else {
-    root.HomeViewModel = factory(ko, assistHelper);
+    root.HomeViewModel = factory(ko, assistHelper, HueDirectory);
   }
-}(this, function (ko, AssistHelper) {
+}(this, function (ko, AssistHelper, HueDirectory) {
 
   function HomeViewModel(options) {
     var self = this;
@@ -34,81 +35,29 @@
     self.assistHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
 
     self.documents = ko.observableArray([]);
-    self.path = ko.mapping.fromJS('/');
-    self.mkdirFormPath = ko.observable('');
-    self.deleteFormPath = ko.observable('');
-    self.shareFormDocId = ko.observable('');
-    self.exportFormDocIds = ko.observable('');
-
-    self.page = ko.observable(1);
-    self.documentsPerPage = ko.observable(50);
-
-    self.renderableDocuments = ko.computed(function () {
-      return self.documents().slice((self.page() * 1 - 1) * self.documentsPerPage(), (self.page() * self.documentsPerPage()) - 1);
-    });
-
-    self.totalPages = ko.computed(function () {
-      return Math.ceil(self.documents().length / self.documentsPerPage());
-    });
-
-    self.hasPrevious = ko.computed(function () {
-      return self.page() > 1;
-    });
 
-    self.hasNext = ko.computed(function () {
-      return self.page() < self.totalPages();
-    });
-
-    self.page.subscribe(function (value) {
-      if (isNaN(value * 1)) {
-        self.page(1);
-      }
-      if (value > self.totalPages()) {
-        self.page(self.totalPages());
+    self.currentDirectory = ko.observable(new HueDirectory({
+      assistHelper: self.assistHelper,
+      definition: {
+        name: '/'
       }
-      if (value < 1) {
-        self.page(1);
-      }
-    });
+    }));
 
-    self.nextPage = function () {
-      if (self.hasNext()) {
-        self.page(self.page() + 1);
-      }
-    };
+    self.currentDirectory().open();
 
-    self.previousPage = function () {
-      if (self.hasPrevious()) {
-        self.page(self.page() - 1);
-      }
-    };
-
-    self.documents.subscribe(function () {
-      self.page(1);
-    });
-
-
-    self.loadDocuments = function(path) {
-      $.get("/desktop/api2/docs2/", {
-       path: path
-      }, function(data) {
-        self.path(path);
-        self.documents(data.documents);
-      }).fail(function (xhr) {
-        $(document).trigger("error", xhr.responseText);
-      });
-    };
+    self.mkdirFormPath = ko.observable('');
+    self.deleteFormPath = ko.observable('');
+    self.shareFormDocId = ko.observable('');
+    self.exportFormDocIds = ko.observable('');
 
     self.mkdir = function() {
       $.post("/desktop/api2/doc/mkdir", {
-        parent_path: ko.mapping.toJSON(self.path),
+        parent_path: ko.mapping.toJSON(self.currentDirectory().path),
         name: ko.mapping.toJSON(self.mkdirFormPath)
       }, function (data) {
         if (data.status == 0) {
-          self.loadDocuments(self.path()); // TODO proper refresh
-          self.mkdirFormPath('');
-        }
-        else {
+          self.currentFolder.load();
+        } else {
           $(document).trigger("error", data.message);
         }
       }).fail(function (xhr) {
@@ -122,10 +71,8 @@
         skip_trash: ko.mapping.toJSON(false)
       }, function (data) {
         if (data.status == 0) {
-          self.loadDocuments(self.path()); // TODO proper refresh
-          self.mkdirFormPath('');
-        }
-        else {
+          self.currentDirectory().load();
+        } else {
           $(document).trigger("error", data.message);
         }
       }).fail(function (xhr) {
@@ -139,5 +86,9 @@
     };
   }
 
+  HomeViewModel.prototype.openPath = function (path) {
+    console.log(path);
+  };
+
   return HomeViewModel;
 }));

+ 11 - 39
desktop/core/src/desktop/templates/home2.mako

@@ -216,21 +216,20 @@ ${ assist.assistPanel() }
           </ul>
         </div>
         <h2 class="card-heading simple">${_('My Documents')}</h2>
-        <span data-bind="text: path"></span>
         <br/>
-        <input data-bind="value: mkdirFormPath" placeholder="dir name, e.g. projects"></input>
+        <input data-bind="value: mkdirFormPath" placeholder="dir name, e.g. projects" />
         <a href="javascript:void(0);" class="btn" data-bind="click: mkdir"><i class="fa fa-plus-circle"></i> ${ _('Create Directory') }</a>
 
-        <input data-bind="value: deleteFormPath" placeholder="doc id, e.g. 50491"></input>
+        <input data-bind="value: deleteFormPath" placeholder="doc id, e.g. 50491" />
         <a href="javascript:void(0);" class="btn" data-bind="click: deleteDocument"><i class="fa fa-times"></i> ${ _('Delete') }</a>
 
-        <input data-bind="value: shareFormDocId" placeholder="doc id, e.g. 50491"></input>
+        <input data-bind="value: shareFormDocId" placeholder="doc id, e.g. 50491" />
         <a class="share-link btn" rel="tooltip" data-placement="bottom" style="margin-left:20px" data-bind="click: function(e){ prepareShareModal(e) },
           attr: {'data-original-title': '${ _ko("Share") } ' + name}">
           <i class="fa fa-users"></i> ${ _('Share') }
         </a>
 
-        <input data-bind="value: exportFormDocIds" placeholder="doc id, e.g. 50491,50492"></input>
+        <input data-bind="value: exportFormDocIds" placeholder="doc id, e.g. 50491,50492" />
         <a class="share-link btn" data-bind="click: exportDocuments">
           <i class="fa fa-download"></i> ${ _('Export') }
         </a>
@@ -239,39 +238,9 @@ ${ assist.assistPanel() }
           <i class="fa fa-upload"></i> ${ _('Import') }
         </a>
 
-        <div class="card-body">
-          <p>
-          <table id="documents" class="table table-striped table-condensed" data-bind="visible: documents().length > 0">
-            <thead>
-              <tr>
-                <th style="width: 26px">&nbsp;</th>
-                <th style="width: 200px">${_('Name')}</th>
-                <th>${_('Description')}</th>
-              </tr>
-            </thead>
-            <tbody data-bind="template: { name: 'document-template', foreach: renderableDocuments}">
-            </tbody>
-            <tfoot data-bind="visible: documents().length > 0">
-              <tr>
-                <td colspan="7">
-                  <div class="pull-right" style="margin-top: 10px" data-bind="visible: hasPrevious() || hasNext()">
-                    <span>${_('Page')} <input type="number" class="input-mini" style="text-align: center" data-bind="value: page"> ${_('of')} <span data-bind="text: totalPages"></span></span>
-                  </div>
-                  <div class="pagination">
-                    <ul>
-                      <li><a data-bind="click: previousPage, visible: hasPrevious">${_('Previous')}</a></li>
-                      <li><a data-bind="click: nextPage, visible: hasNext">${_('Next')}</a></li>
-                    </ul>
-                  </div>
-                </td>
-              </tr>
-            </tfoot>
-          </table>
-          <div data-bind="visible: documents().length == 0">
-            <h4 style="color: #777; margin-bottom: 30px">${_('There are currently no documents in this project or tag.')}</h4>
-          </div>
-          </p>
-        </div>
+        <!-- ko with: currentDirectory -->
+        <div></div>
+        <!-- /ko -->
       </div>
     </div>
   </div>
@@ -316,7 +285,10 @@ ${ commonimportexport(request) | n,unicode }
       };
 
       var viewModel = new HomeViewModel(options);
-      viewModel.loadDocuments(location.getParameter('path') ? location.getParameter('path') : '/');
+      if (location.getParameter('path')) {
+        viewModel.openPath(location.getParameter('path'));
+      }
+      viewModel.currentDirectory().open(true);
       ko.applyBindings(viewModel, $('#documentList')[0]);
 
 ##       ShareViewModel.initSharing("#documentShareModal");