diff --git a/ayanova/src/views/home-dashboard.vue b/ayanova/src/views/home-dashboard.vue index 051d74ca..35f0e1dd 100644 --- a/ayanova/src/views/home-dashboard.vue +++ b/ayanova/src/views/home-dashboard.vue @@ -129,16 +129,16 @@ export default { }, methods: { dashMoveStart: function(id) { - console.log("home-dashboard:dashMoveStart", id); + this.move("start", id); }, dashMoveBack: function(id) { - console.log("home-dashboard:dashMoveBack", id); + this.move("left", id); }, dashMoveForward: function(id) { - console.log("home-dashboard:dashMoveForward", id); + this.move("right", id); }, dashMoveEnd: function(id) { - console.log("home-dashboard:dashMoveEnd", id); + this.move("end", id); }, dashRemove: function(id) { let index = this.getEffectiveViewItemIndexById(id); @@ -148,13 +148,43 @@ export default { this.effectiveView.splice(index, 1); this.saveView(); }, - // dashRefresh: function(item) { - // v-on:dash-refresh="dashRefresh" - // console.log( - // "home-dashboard:refresh (normally handle @ typed dash control)", - // item - // ); - // }, + move: function(direction, id) { + let index = this.getEffectiveViewItemIndexById(id); + if (index == -1) { + return; + } + + let totalItems = this.effectiveView.length; + let newIndex = 0; + //calculate new index + switch (direction) { + case "start": + newIndex = 0; + break; + case "left": + newIndex = index - 1; + if (newIndex < 0) { + newIndex = 0; + } + break; + case "right": + newIndex = index + 1; + if (newIndex > totalItems - 1) { + newIndex = totalItems - 1; + } + break; + case "end": + newIndex = totalItems - 1; + break; + } + + this.effectiveView.splice( + newIndex, + 0, + this.effectiveView.splice(index, 1)[0] + ); + this.saveView(); + }, getEffectiveViewItemIndexById: function(id) { return this.effectiveView.findIndex(z => z.id == id); },