Преглед изворни кода

[home2] Add support for the 'path' URL parameter

Johan Ahlen пре 9 година
родитељ
комит
62c9087b93

+ 30 - 1
desktop/core/src/desktop/static/desktop/js/home2.vm.js

@@ -56,7 +56,36 @@
   }
   }
 
 
   HomeViewModel.prototype.openPath = function (path) {
   HomeViewModel.prototype.openPath = function (path) {
-    console.log(path);
+    var self = this;
+    var parts = path.split('/');
+    parts.shift(); // Remove root
+    self.activeEntry(null);
+    var lastChild = new HueFileEntry({
+      activeEntry: self.activeEntry,
+      assistHelper: self.assistHelper,
+      app: 'documents',
+      definition: {
+        name: '/',
+        type: 'directory'
+      }
+    });
+    $.each(parts, function (idx, part) {
+      if (part === '') {
+        return false;
+      }
+      lastChild = new HueFileEntry({
+        activeEntry: self.activeEntry,
+        assistHelper: self.assistHelper,
+        parent: lastChild,
+        app: 'documents',
+        definition: {
+          name: lastChild.isRoot ? '/' + part : lastChild.definition.name + '/' + part,
+          type: 'directory'
+        }
+      })
+    });
+    self.activeEntry(lastChild);
+    self.activeEntry().load();
   };
   };
 
 
   return HomeViewModel;
   return HomeViewModel;

+ 12 - 3
desktop/core/src/desktop/templates/home2.mako

@@ -263,9 +263,18 @@ ${ fileBrowser.fileBrowser() }
       };
       };
 
 
       var viewModel = new HomeViewModel(options);
       var viewModel = new HomeViewModel(options);
-      if (location.getParameter('path')) {
-        viewModel.openPath(location.getParameter('path'));
-      }
+
+      viewModel.activeEntry.subscribe(function (newEntry) {
+        hueUtils.changeURL('/home2?path=' + newEntry.path);
+      });
+      var loadUrlParam = function () {
+        if (location.getParameter('path')) {
+          viewModel.openPath(location.getParameter('path'));
+        }
+      };
+      window.onpopstate = loadUrlParam;
+      loadUrlParam();
+
       ko.applyBindings(viewModel, $('#documentList')[0]);
       ko.applyBindings(viewModel, $('#documentList')[0]);
 
 
 ##       ShareViewModel.initSharing("#documentShareModal");
 ##       ShareViewModel.initSharing("#documentShareModal");