From 7c9c83ecc5f9f835411e21f32df6bdb867e31d18 Mon Sep 17 00:00:00 2001 From: cjong Date: Sat, 18 Feb 2017 15:18:07 +0100 Subject: [PATCH 1/9] Added lazy loading features --- loading.svg | 1 + paper-tree-node.html | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 loading.svg diff --git a/loading.svg b/loading.svg new file mode 100644 index 0000000..460e05d --- /dev/null +++ b/loading.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/paper-tree-node.html b/paper-tree-node.html index e619117..1575c3d 100755 --- a/paper-tree-node.html +++ b/paper-tree-node.html @@ -66,6 +66,16 @@ padding: 5px; } + .node-preicon.loading:before { + content: ''; + background:url('loading.svg'); + background-size:cover; + position:absolute; + width:24px; + height:24px; + margin-left:-24px; + } + .node-preicon, .node-name { cursor: pointer; } @@ -101,7 +111,7 @@
- + {{data.name}} diff --git a/paper-tree-node.html b/paper-tree-node.html index cc5e842..3e4f0be 100755 --- a/paper-tree-node.html +++ b/paper-tree-node.html @@ -188,10 +188,10 @@ */ /** - * The `toggle-children` event is fired whenever a tree node is expanded or collapsed. + * The `toggle` event is fired whenever a tree node is expanded or collapsed. * This event can be used by the host to lazy load grandchildren. * - * @event toggle-children + * @event toggle */ /** @@ -242,7 +242,7 @@ */ toggleChildren: function() { this.set("data.open", !this.data.open && this.data.children && this.data.children.length); - this.fire("toggle-children", this); + this.fire("toggle", this); } }); From e9ad01ba68e4d59d6f9abe269b1e4867f0fe2415 Mon Sep 17 00:00:00 2001 From: cjong Date: Tue, 21 Feb 2017 17:39:58 +0100 Subject: [PATCH 5/9] Added --loading-icon-theme to paper-tree-node --- demo/lazyload-demo.html | 38 ++++++++++++++++++++++++--------- loading.svg => demo/loading.svg | 0 paper-tree-node.html | 18 ++++++---------- 3 files changed, 34 insertions(+), 22 deletions(-) rename loading.svg => demo/loading.svg (100%) diff --git a/demo/lazyload-demo.html b/demo/lazyload-demo.html index eaeaff3..50d2a67 100644 --- a/demo/lazyload-demo.html +++ b/demo/lazyload-demo.html @@ -6,6 +6,16 @@

Lazy loading paper-tree demo

@@ -23,8 +33,7 @@

Lazy loading paper-tree demo

doc:{ type: Object, value: { - name: 'Loading...', - loading: true + name: 'Loading...' } } }, @@ -33,8 +42,13 @@

Lazy loading paper-tree demo

var self = this; // Update the root doc for the tree after 1 second delay window.setTimeout(function() { - var rootDoc = {name:'Cronos', loading:true, updatePath:'doc'}; + var rootDoc = {name:'Cronos', updatePath:'doc'}; self.doc = rootDoc; + + //var rootNode = self.root; + //TODO find the span that will have the loading class + //self.toggleClass('loading', true, [rootNode]); + // Add the children to the root. self.addChildrenToNode(rootDoc); }, 1000); @@ -46,6 +60,7 @@

Lazy loading paper-tree demo

//We only have to get the grandchildren once if(nodeData.gotGrandChildren) return; nodeData.gotGrandChildren = true; + nodeData.children.forEach(function(child){ //Add grandchildren to the child. self.addChildrenToNode(child); @@ -56,16 +71,19 @@

Lazy loading paper-tree demo

var self = this; // Wait a couple of seconds to simulate async data retrieval window.setTimeout(function() { - var updatePath = treeNode.updatePath; + + var updatePath = treeNode.updatePath+'.children'; var children = [ - {name:'Zeus', loading:true, updatePath:updatePath+'.children.0'}, - {name:'Apollo', loading:true, updatePath:updatePath+'.children.1'}, - {name:'Athena', loading:true, updatePath:updatePath+'.children.2'}, - {name:'Poseidon', loading:true, updatePath:updatePath+'.children.3'} + {name:'Zeus', updatePath:updatePath+'.0'}, + {name:'Apollo', updatePath:updatePath+'.1'}, + {name:'Athena', updatePath:updatePath+'.2'}, + {name:'Poseidon', updatePath:updatePath+'.3'} ]; + // We use set(updatePath... to trigger the correct valueChange events in the tree - self.set(updatePath+'.loading', false); - self.set(updatePath+'.children', children); + // Simply setting children on the treeNode won't have any effect. + self.set(updatePath, children); + }, Math.floor(Math.random() * 2000)); } }); diff --git a/loading.svg b/demo/loading.svg similarity index 100% rename from loading.svg rename to demo/loading.svg diff --git a/paper-tree-node.html b/paper-tree-node.html index 3e4f0be..e288e0c 100755 --- a/paper-tree-node.html +++ b/paper-tree-node.html @@ -22,7 +22,8 @@ Custom property | Description | Default ----------------|-------------|---------- `--paper-tree-selected-background-color` | Highlight color for selected node | `rgba(200, 200, 200, 0.5)` -`--paper-tree-selected-color` | Text and icon color for selected node | `inherit` +`--paper-tree-selected-color` | Text and icon color for selected node | `inherit` +`--loading-icon-theme` | Theme for loading icon | `no default` @demo --> @@ -42,6 +43,10 @@ display: inline-block; } + .node-preicon.collapsed.loading:before { + @apply(--loading-icon-theme); + } + .node-row { padding-left: 4px; padding-right: 4px; @@ -70,16 +75,6 @@ padding: 5px; } - .node-preicon.loading:before { - content: ''; - background:url('loading.svg'); - background-size:cover; - position:absolute; - width:24px; - height:24px; - margin-left:-24px; - } - .node-preicon, .node-name { cursor: pointer; } @@ -201,7 +196,6 @@ * @return {string} The class name indicating whether the node is open or closed */ _computeClass: function(change) { - if(change && change.base && change.base.loading) return 'node-preicon loading'; var open = change && change.base && change.base.open; var children = change && change.base && change.base.children; return 'node-preicon ' + ((open && children && children.length) ? 'expanded' : children && children.length ? 'collapsed' : ''); From 2a10ed1272a360563573311183fe6fb35929e60b Mon Sep 17 00:00:00 2001 From: cjong Date: Tue, 21 Feb 2017 17:55:06 +0100 Subject: [PATCH 6/9] Added --loading-icon-theme to paper-tree-node --- paper-tree-node.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paper-tree-node.html b/paper-tree-node.html index e288e0c..dbe7a98 100755 --- a/paper-tree-node.html +++ b/paper-tree-node.html @@ -43,7 +43,7 @@ display: inline-block; } - .node-preicon.collapsed.loading:before { + .node-preicon.loading:before { @apply(--loading-icon-theme); } From df0f6fff576df045dc8c0167b1e885210466595c Mon Sep 17 00:00:00 2001 From: Florian Maffini Date: Fri, 24 Feb 2017 16:38:59 +0100 Subject: [PATCH 7/9] refactoring lazy loading appraoch for more genericity --- demo/index.html | 84 ++++++++++++++++++++++++++++++++++++ demo/lazyload-demo.html | 92 --------------------------------------- demo/lazyloading.html | 96 +++++++++++++++++++++++++++++++++++++++++ paper-tree-node.html | 29 ++++++++----- 4 files changed, 198 insertions(+), 103 deletions(-) delete mode 100644 demo/lazyload-demo.html create mode 100644 demo/lazyloading.html diff --git a/demo/index.html b/demo/index.html index f9bc524..76110ac 100755 --- a/demo/index.html +++ b/demo/index.html @@ -18,6 +18,7 @@

Basic demo with only one node

+ +

Lazy loading demo

+ + + +
diff --git a/demo/lazyload-demo.html b/demo/lazyload-demo.html deleted file mode 100644 index 50d2a67..0000000 --- a/demo/lazyload-demo.html +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - diff --git a/demo/lazyloading.html b/demo/lazyloading.html new file mode 100644 index 0000000..607bb37 --- /dev/null +++ b/demo/lazyloading.html @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + diff --git a/paper-tree-node.html b/paper-tree-node.html index dbe7a98..20c1df6 100755 --- a/paper-tree-node.html +++ b/paper-tree-node.html @@ -21,9 +21,10 @@ Custom property | Description | Default ----------------|-------------|---------- -`--paper-tree-selected-background-color` | Highlight color for selected node | `rgba(200, 200, 200, 0.5)` -`--paper-tree-selected-color` | Text and icon color for selected node | `inherit` -`--loading-icon-theme` | Theme for loading icon | `no default` +`--paper-tree-selected-background-color` | Highlight color for selected node | `rgba(200, 200, 200, 0.5)` +`--paper-tree-selected-color` | Text and icon color for selected node | `inherit` +`--paper-tree-preicon-theme` | Change theme for node pre-icon (+/- toggle) | +`--paper-tree-icon-theme` | Change theme for node icon | @demo --> @@ -43,8 +44,8 @@ display: inline-block; } - .node-preicon.loading:before { - @apply(--loading-icon-theme); + .node-preicon:before { + @apply(--paper-tree-preicon-theme); } .node-row { @@ -83,6 +84,7 @@ cursor: pointer; width: 24px; height: 24px; + @apply(--paper-tree-icon-theme); } #actions { @@ -110,7 +112,7 @@
- + {{data.name}} diff --git a/demo/lazyloading.html b/demo/lazyloading.html index 5830ab0..32fdbef 100644 --- a/demo/lazyloading.html +++ b/demo/lazyloading.html @@ -9,15 +9,15 @@