Skip to content

Commit

Permalink
Adding move modal. Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashwat986 committed Sep 18, 2017
1 parent 24d618d commit 13dc515
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 27 deletions.
45 changes: 43 additions & 2 deletions src/js/folder_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,50 @@ class FolderModel {
}).map((node) => node.model.uuid);
}

getNodeFromPath (folderPath) {
let node = this.root;
let path = folderPath;

if (path == null) {
return node;
}

if (typeof path === "string") {
path = path.split('/');
}

for (let key of path) {
const child = this.getChild(node, key);
if (child) {
node = child;
} else {
return null;
}
}

return node;
}

getPathFolders (node) {
return node.getPath().map((e) => e.model.name);
}

getPathBreadcrumb (node) {
let path = '';
let folders = this.getPathFolders(node);
folders.shift(); // Removing root element
return folders.map((elem) => {
path += '/' + elem;
return {
name: elem,
path
};
})
}

objectEqual (node1, node2) {
const path1 = node1.getPath().map((e) => e.model.name);
const path2 = node2.getPath().map((e) => e.model.name);
const path1 = this.getPathFolders(node1);
const path2 = this.getPathFolders(node2);
return (objectEqual(path1, path2) && objectEqual(node1.model, node2.model));
}

Expand Down
14 changes: 12 additions & 2 deletions src/js/views/file_item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<span v-if="showFiles">Hide Files</span>
<span v-else>Show Files</span>
</a>
<a class="pull-right" @click="toggleMove">
Move
</a>
</div>
<div class="panel-footer" v-if="showMove">
<move-modal :fileNode="node"></move-modal>
</div>
</div>
<div v-else-if="errored" class="panel panel-default">
Expand All @@ -56,10 +62,13 @@

<script>
import Spinner from './spinner.vue';
import MoveModal from './move_modal.vue';
module.exports = {
props: ['fileId'],
props: ['node'],
data () {
return {
fileId: this.node.model.uuid,
loading: false,
errored: false,
showFiles: false,
Expand Down Expand Up @@ -108,7 +117,8 @@ module.exports = {
}
},
components: {
'spinner': Spinner
'spinner': Spinner,
'move-modal': MoveModal
}
};
</script>
Expand Down
27 changes: 4 additions & 23 deletions src/js/views/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<template v-for="(item, index) in folderJSON.getFiles(currentPath)">
<div class="col-xs-12 visible-xs-block visible-sm-block clearfix" v-if="index % 2 == 0"></div>
<div class="col-md-12 visible-md-block visible-lg-block clearfix" v-if="index % 3 == 0"></div>
<file-item :key="item.model.uuid" :fileId="item.model.uuid"></file-item>
<file-item :key="item.model.uuid" :node="item"></file-item>
</template>
</div>
</div>
Expand Down Expand Up @@ -78,30 +78,11 @@ module.exports = {
},
methods: {
updateDisplayData () {
this.route = [];
this.currentPath = null;
const folderPath = this.$route.params.path;
let root = this.folderJSON.root;
let path = '';
// TODO: Move to folder_model
if (folderPath) {
for (let key of folderPath.split('/')) {
const child = this.folderJSON.getChild(root, key);
if (child) {
root = child;
path += '/' + key;
this.route.push({
name: key,
path
});
} else {
return;
}
}
this.currentPath = this.folderJSON.getNodeFromPath(folderPath);
if (this.currentPath != null) {
this.route = this.folderJSON.getPathBreadcrumb(this.currentPath);
}
this.currentPath = root;
}
},
watch: {
Expand Down
66 changes: 66 additions & 0 deletions src/js/views/move_modal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<div class="list-group move-list-group">
<a class="list-group-item active">
{{folderPath}}
<span class="badge" @click="moveItem">Move Here</span>
</a>
<a v-for="folder in folders" @click="updatePath(folder)" class="list-group-item">
{{folder}}
</a>
<div class="list-group-item">
<a @click="removePath">Back</a>
<a class="pull-right" @click="createFolder">New Folder</a>
</div>
</div>
</template>

<script>
module.exports = {
props: ['fileNode'],
data () {
return {
currentPath: []
};
},
computed: {
currentFolder () {
return window.folderJSON.getNodeFromPath(this.currentPath);
},
folders () {
return window.folderJSON.getFolders(this.currentFolder).map((e) => e.model.name);
},
folderPath () {
if (this.currentPath.length > 0) {
return `GistUX / ${this.currentPath.join(' / ')}`;
}
return 'GistUX';
}
},
methods: {
updatePath (val) {
this.currentPath.push(val);
},
removePath () {
this.currentPath.pop();
},
createFolder () {
this.$store.commit('addFolderToFolderJSON', {
folderName: null,
node: this.currentFolder
});
this.$store.dispatch('updateGistUXConfig');
},
moveItem () {
window.folderJSON.move(this.fileNode, this.currentFolder);
this.$store.dispatch('updateGistUXConfig');
}
}
};
</script>

<style>
.move-list-group {
margin-bottom: 0;
}
</style>

0 comments on commit 13dc515

Please sign in to comment.