Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added save project and delete from queue functionality #47

Merged
merged 4 commits into from Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -12,6 +12,9 @@
"postuninstall": "electron-builder install-app-deps"
},
"dependencies": {
"localforage": "^1.7.3",
"lodash": "^4.17.11",
"lodash.throttle": "^4.1.1",
"vue": "^2.6.6",
"vue-drag-resize": "^1.3.2",
"vue-js-modal": "^1.3.28",
Expand All @@ -36,4 +39,4 @@
"vue-template-compiler": "^2.5.21"
},
"main": "background.js"
}
}
26 changes: 20 additions & 6 deletions src/components/ComponentDisplay.vue
@@ -1,10 +1,14 @@
<template>
<div class="component-display">
<!-- <LoadingBar :duration="2000"/> -->
<div style="height: 500px; width: 500px; border: 1px solid red; position: relative;">
<div
style="height: 500px; width: 500px; border: 1px solid red; position: relative;"
>
<VueDraggableResizable
class-name="component-box"
v-for="([componentName, componentData]) in Object.entries(computedComponentMap)"
v-for="[componentName, componentData] in Object.entries(
computedComponentMap
)"
:key="componentName"
:w="componentData.w"
:h="componentData.h"
Expand All @@ -15,19 +19,21 @@
:parent="true"
>
<h3>{{ componentName }}</h3>
<br>
X: {{ componentData.x }} / Y: {{ componentData.y }} - Width: {{ componentData.width }} / Height: {{ componentData.height }}
<br />
X: {{ componentData.x }} / Y: {{ componentData.y }} - Width:
{{ componentData.width }} / Height: {{ componentData.height }}
</VueDraggableResizable>
<modals-container></modals-container>
<ComponentModal :modalWidth="800" :modalHeight="900"/>
<ComponentModal :modalWidth="800" :modalHeight="900" />
</div>
</div>
</template>
<script>
import { mapState } from 'vuex';
import LoadingBar from './LoadingBar.vue';
import ComponentModal from './ComponentModal.vue';
import { setComponentMap } from '../store/types';
import { setComponentMap, getPrevState } from '../store/types';
import localforage from 'localforage';
import VueDraggableResizable from 'vue-draggable-resizable';

export default {
Expand All @@ -50,6 +56,14 @@ export default {
};
},

created() {
localforage
.getItem('state')
.then(data => {
this.$store.dispatch(getPrevState, data);
})
.then(data => console.log('retrieved previous data'));
},
computed: {
...mapState(['componentMap', 'clickedComponent']),
computedComponentMap: {
Expand Down
37 changes: 31 additions & 6 deletions src/components/HomeQueue.vue
Expand Up @@ -3,24 +3,30 @@
<draggable
v-model="renderList"
group="people"
class="list-group"
ghost-class="ghost"
@start="drag = true"
@end="drag = false"
>
<div
class="white--text"
<li
class="list-group-item"
v-for="(element, index) in renderList"
:key="index + Date.now()"
>
{{ element }}
</div>
<span>{{ element }}</span>

<v-icon class="delete-icon" @click="deleteElement(index)"
>remove_circle_outline</v-icon
>
</li>
</draggable>
</div>
</template>

<script>
import draggable from 'vuedraggable';
import { mapState } from 'vuex';
import { setSelectedElementList } from '../store/types';
import { setSelectedElementList, deleteSelectedElement } from '../store/types';

export default {
name: 'HomeQueue',
Expand All @@ -44,10 +50,29 @@ export default {
}
}
},
methods: {
deleteElement(index) {
this.$store.dispatch(deleteSelectedElement, index);
}
},
components: {
draggable
}
};
</script>

<style></style>
<style scoped>
li {
list-style-type: none;
}
.list-group-item {
margin-top: 5px;
border: 1px solid black;
border-radius: 0.5cm;
background-color: palevioletred;
}

.delete-icon:hover {
cursor: pointer;
}
</style>
21 changes: 19 additions & 2 deletions src/components/NavBar.vue
Expand Up @@ -4,18 +4,31 @@
<router-link :to="{ name: 'home' }" class="prevue">
<span class="white--text">Pre</span>
<span class="green--text text--accent-2">Vue</span>
</router-link>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</router-link>
<router-link :to="{ name: 'tree' }">
<span id="tree-link" class="purple--text text--accent-2">View Component Tree</span>
</router-link>
<span>
<v-icon class="save-icon" @click="saveState">save_alt</v-icon>
<span>save</span>
</span>
</v-toolbar-title>
</v-toolbar>
</template>

<script>
import localforage from 'localforage';
export default {
name: 'NavBar',
props: ['route']
props: ['route'],
methods: {
saveState() {
const currentState = this.$store.state;
localforage
.setItem('state', currentState)
.then(data => console.log(data));
}
}
};
</script>

Expand Down Expand Up @@ -51,4 +64,8 @@ export default {
a {
text-decoration: none;
}

.save-icon:hover {
cursor: pointer;
}
</style>
4 changes: 4 additions & 0 deletions src/localStorage.js
@@ -0,0 +1,4 @@
import localforage from 'localforage';

export const saveState = state => localforage.setItem('state', state);
export const loadState = () => localforage.getItem('state');
1 change: 1 addition & 0 deletions src/main.js
Expand Up @@ -4,6 +4,7 @@ import router from './router';
import store from './store/';
import Vuetify from 'vuetify';
import VModal from 'vue-js-modal';
import { throttle } from 'lodash.throttle';
import VueDraggableResizable from 'vue-draggable-resizable';

import 'vuetify/dist/vuetify.min.css';
Expand Down
7 changes: 7 additions & 0 deletions src/store/actions.js
@@ -1,4 +1,5 @@
import * as types from './types';
import { loadState } from '../localStorage';

const actions = {
[types.registerComponent]: ({ state, commit }, payload) => {
Expand Down Expand Up @@ -27,6 +28,12 @@ const actions = {
},
[types.deleteClickedComponent]: ({ commit }) => {
commit(types.DELETE_CLICKED_COMPONENT);
},
[types.getPrevState]: ({ commit }, payload) => {
commit(types.GET_PREV_STATE, payload);
},
[types.deleteSelectedElement]: ({ commit }, payload) => {
commit(types.DELETE_SELECTED_ELEMENT, payload);
}
};

Expand Down
10 changes: 9 additions & 1 deletion src/store/mutations.js
Expand Up @@ -7,7 +7,9 @@ import {
ADD_TO_COMPONENT_HTML_LIST,
SET_CLICKED_ELEMENT_LIST,
DELETE_CLICKED_COMPONENT,
SET_COMPONENT_MAP
SET_COMPONENT_MAP,
GET_PREV_STATE,
DELETE_SELECTED_ELEMENT
} from './types';

const mutations = {
Expand Down Expand Up @@ -67,6 +69,12 @@ const mutations = {
},
[SET_COMPONENT_MAP]: (state, payload) => {
state.componentMap = payload;
},
[GET_PREV_STATE]: (state, payload) => {
Object.assign(state, payload);
},
[DELETE_SELECTED_ELEMENT]: (state, payload) => {
state.selectedElementList.splice(payload, 1);
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/store/types.js
Expand Up @@ -8,6 +8,9 @@ export const ADD_TO_COMPONENT_HTML_LIST = 'ADD_TO_COMPONENT_HTML_LIST';
export const SET_CLICKED_ELEMENT_LIST = 'SET_CLICKED_ELEMENT_LIST';
export const DELETE_CLICKED_COMPONENT = 'DELETE_CLICKED_COMPONENT';
export const SET_COMPONENT_MAP = 'SET_COMPONENT_MAP';
export const GET_PREV_STATE = 'GET_PREV_STATE';
export const DELETE_FROM_QUEUE = 'DELETE_FROM_QUEUE';
export const DELETE_SELECTED_ELEMENT = 'DELETE_SELECTED_ELEMENT';

//Actions
export const registerComponent = 'registerComponent';
Expand All @@ -18,3 +21,6 @@ export const addToComponentElementList = 'addToComponentElementList';
export const setClickedElementList = 'setClickedElementList';
export const deleteClickedComponent = 'deleteClickedComponent';
export const setComponentMap = 'setComponentMap';
export const getPrevState = 'getPrevState';
export const deleteFromQueue = 'deleteFromQueue';
export const deleteSelectedElement = 'deleteSelectedElement';
1 change: 0 additions & 1 deletion src/views/HomeView.vue
Expand Up @@ -23,7 +23,6 @@ export default {
grid-template-areas: 'component-display home-sidebar ';
grid-gap: 10px;
grid-template-columns: 8fr 2fr;
/* background-color: #2196f3; */
padding: 10px;
height: 100%;
}
Expand Down