Commit 73135ab9 by Jonathan Thomas

Added real file uploading via axios, and now list actual File objects, and load…

Added real file uploading via axios, and now list actual File objects, and load project details when loading the editor. Made components conditional based on when the editor loads project data.
parent f5676d14
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
<script> <script>
export default { export default {
name: "Clips.vue", name: "Clips.vue",
props: ['project'],
data() { data() {
return { return {
clips: [ clips: [
...@@ -51,7 +52,7 @@ export default { ...@@ -51,7 +52,7 @@ export default {
<style scoped> <style scoped>
.scrolling-container { .scrolling-container {
height: 300px; max-height: 300px;
overflow: scroll; overflow: scroll;
} }
.img-parent { .img-parent {
......
<template> <template>
<div class="row mb-3 gy-2 gx-2 p-2 scrolling-container"> <div class="row mb-3 gy-2 gx-2 p-2 scrolling-container">
<h3>Files <button type="button" class="btn btn-primary upload-btn">Upload</button></h3> <h3>Files <button type="button" class="btn btn-primary upload-btn" @click="chooseFiles">Upload</button></h3>
<div class="col-sm-12"> <div class="col-sm-12">
<div class="form-floating mb-3"> <div class="form-floating mb-3">
<input type="text" class="form-control" id="floatingInput" placeholder="Search"> <input type="text" class="form-control" id="floatingInput" placeholder="Search">
...@@ -10,26 +10,34 @@ ...@@ -10,26 +10,34 @@
<div v-for="file in files" :key="file.id" class="col-4" style="overflow: scroll;"> <div v-for="file in files" :key="file.id" class="col-4" style="overflow: scroll;">
<img @click="toggleSelection(file)" :class="getSelectedClass(file)" class="file-thumbnail img-fluid img-thumbnail" :title="file.name" src="../assets/logo.png"/> <img @click="toggleSelection(file)" :class="getSelectedClass(file)" class="file-thumbnail img-fluid img-thumbnail" :title="file.name" src="../assets/logo.png"/>
</div> </div>
<input ref="fileUpload" type="file" @change="fileChanged" hidden>
</div> </div>
</template> </template>
<script> <script>
import { mapActions, mapState } from "vuex";
export default { export default {
name: "Files.vue", name: "Files.vue",
props: ['project'],
data() { data() {
return { return {}
files: [
{ 'id': 1, 'name': 'filename1.mp4', 'selected': false },
{ 'id': 2, 'name': 'filename1.mp4', 'selected': false },
{ 'id': 3, 'name': 'filename1.mp4', 'selected': false },
{ 'id': 4, 'name': 'filename1.mp4', 'selected': false },
{ 'id': 5, 'name': 'filename1.mp4', 'selected': false },
{ 'id': 6, 'name': 'filename1.mp4', 'selected': false },
{ 'id': 7, 'name': 'filename1.mp4', 'selected': false },
]
}
}, },
methods: { methods: {
chooseFiles() {
this.$refs.fileUpload.click()
},
fileChanged(event) {
let data = new FormData();
data.append('media', event.target.files[0]);
data.append('project', this.project.url);
data.append('json', "{}");
let payload = { project_id: this.project.id,
project_url: this.project.url,
data}
this.createFile(payload)
},
toggleSelection(fileObject) { toggleSelection(fileObject) {
fileObject.selected = !fileObject.selected fileObject.selected = !fileObject.selected
}, },
...@@ -39,14 +47,21 @@ export default { ...@@ -39,14 +47,21 @@ export default {
} else { } else {
return '' return ''
} }
} },
...mapActions(['loadFiles', 'createFile'])
},
computed: {
...mapState(['files'])
},
mounted() {
this.loadFiles(this.project.id)
} }
} }
</script> </script>
<style scoped> <style scoped>
.scrolling-container { .scrolling-container {
height: 300px; max-height: 300px;
overflow: scroll; overflow: scroll;
} }
.upload-btn { .upload-btn {
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
<script> <script>
export default { export default {
name: "Preview.vue" name: "Preview.vue",
props: ['project']
} }
</script> </script>
......
...@@ -6,7 +6,8 @@ import { instance } from "./axios" ...@@ -6,7 +6,8 @@ import { instance } from "./axios"
export default createStore({ export default createStore({
state: { state: {
counter: 1, counter: 1,
projects: {}, projects: [],
files: [],
user: null, user: null,
errors: [] errors: []
}, },
...@@ -22,17 +23,14 @@ export default createStore({ ...@@ -22,17 +23,14 @@ export default createStore({
clearErrors(state) { clearErrors(state) {
state.errors = [] state.errors = []
}, },
increment(state, amount) { setUser(state, user) {
state.counter += amount state.user = user
},
decrement(state, amount) {
state.counter -= amount
}, },
setProjects(state, projects) { setProjects(state, projects) {
state.projects = projects state.projects = projects
}, },
setUser(state, user) { setFiles(state, files) {
state.user = user state.files = files
} }
}, },
getters: { getters: {
...@@ -51,7 +49,6 @@ export default createStore({ ...@@ -51,7 +49,6 @@ export default createStore({
} }
}, },
async loadProjects({commit}) { async loadProjects({commit}) {
// Send response
try { try {
const response = await instance.get('/projects/') const response = await instance.get('/projects/')
commit('setProjects', response.data.results) commit('setProjects', response.data.results)
...@@ -59,6 +56,13 @@ export default createStore({ ...@@ -59,6 +56,13 @@ export default createStore({
commit('addError', JSON.stringify(err.response.data)) commit('addError', JSON.stringify(err.response.data))
} }
}, },
async getProject({commit}, project_id) {
try {
return instance.get(`projects/${project_id}/`)
} catch(err) {
commit('addError', JSON.stringify(err.response.data))
}
},
async createProject({dispatch, commit}, payload) { async createProject({dispatch, commit}, payload) {
try { try {
await instance.post('/projects/', payload) await instance.post('/projects/', payload)
...@@ -67,14 +71,29 @@ export default createStore({ ...@@ -67,14 +71,29 @@ export default createStore({
commit('addError', JSON.stringify(err.response.data)) commit('addError', JSON.stringify(err.response.data))
} }
}, },
async deleteProject({commit, dispatch}, id) { async deleteProject({commit, dispatch}, project_id) {
// Send response
try { try {
await instance.delete(`projects/${id}/`) await instance.delete(`projects/${project_id}/`)
dispatch('loadProjects') dispatch('loadProjects')
} catch(err) { } catch(err) {
commit('addError', JSON.stringify(err.response.data)) commit('addError', JSON.stringify(err.response.data))
} }
},
async loadFiles({commit}, project_id) {
try {
const response = await instance.get(`projects/${project_id}/files/`)
commit('setFiles', response.data.results)
} catch(err) {
commit('addError', JSON.stringify(err.response.data))
}
},
async createFile({dispatch, commit}, payload) {
try {
await instance.post(`${payload.project_url}files/`, payload.data)
dispatch('loadFiles', payload.project_id)
} catch(err) {
commit('addError', JSON.stringify(err.response.data))
}
} }
}, },
modules: { modules: {
......
<template> <template>
<div class="row"> <div class="row">
<div class="col-sm-12 col-md-4"> <div class="col-sm-12 col-md-4">
<Files/> <Files v-if="hasData" :project="project"/>
<Clips/> <Clips v-if="hasData" :project="project"/>
</div> </div>
<div class="col-sm-12 col-md-8"> <div class="col-sm-12 col-md-8">
<Preview/> <Preview v-if="hasData" :project="project"/>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { mapActions } from "vuex";
import Files from "../components/Files"; import Files from "../components/Files";
import Clips from "../components/Clips"; import Clips from "../components/Clips";
import Preview from "../components/Preview"; import Preview from "../components/Preview";
export default { export default {
name: "Editor.vue", name: "Editor.vue",
data() {
return {
hasData: false,
project: {}
}
},
methods: {
...mapActions(['getProject'])
},
computed: { computed: {
id() { id() {
return this.$route.params.id return this.$route.params.id
...@@ -24,6 +34,11 @@ export default { ...@@ -24,6 +34,11 @@ export default {
}, },
components: { components: {
Files, Clips, Preview Files, Clips, Preview
},
async mounted() {
let results = await this.getProject(this.$route.params.id)
this.project = results.data
this.hasData = true
} }
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment