implement "new catalog" in editor

This commit is contained in:
Seth Ladygo
2019-05-04 14:44:34 -07:00
parent 7431f23b67
commit 829df7667e
4 changed files with 45 additions and 8 deletions

View File

@ -2,6 +2,8 @@
<v-stepper v-model="step"> <v-stepper v-model="step">
<v-stepper-header> <v-stepper-header>
<v-stepper-step :complete="step > 1" step="1">Catalog info</v-stepper-step> <v-stepper-step :complete="step > 1" step="1">Catalog info</v-stepper-step>
<Loading text="Loading" :show="loadingCatalog"/>
<v-divider></v-divider> <v-divider></v-divider>
<v-stepper-step :complete="step > 2" step="2">Contents</v-stepper-step> <v-stepper-step :complete="step > 2" step="2">Contents</v-stepper-step>
<v-divider></v-divider> <v-divider></v-divider>
@ -40,17 +42,32 @@
</template> </template>
<script> <script>
import Loading from './Loading'
import CatalogInfo from './CatalogInfo' import CatalogInfo from './CatalogInfo'
import CatalogContents from './CatalogContents' import CatalogContents from './CatalogContents'
export default { export default {
components: { components: {
Loading,
CatalogInfo, CatalogInfo,
CatalogContents CatalogContents
}, },
data: () => ({ data: () => ({
step: 1, step: 1,
}), }),
computed: {
loadingCatalog() {
return this.$store.getters.loadingCatalog
},
savingCatalog() {
return this.$store.getters.savingCatalog
},
},
methods: {
saveCatalog() {
this.$store.dispatch('saveCatalog')
},
},
mounted: function() { mounted: function() {
// catalogID is set by django // catalogID is set by django
// in a script block in our parent page. // in a script block in our parent page.

View File

@ -0,0 +1,21 @@
<template>
<v-dialog v-model="show" persistent width="300">
<v-card color="green" dark>
<v-card-text class="white--text">
{{ text }}
<v-progress-linear indeterminate color="white" class="mb-0" />
</v-card-text>
</v-card>
</v-dialog>
</template>
<script>
export default {
data: () => ({
}),
props: {
text: String,
show: Boolean,
},
}
</script>

View File

@ -78,7 +78,7 @@ export const store = new Vuex.Store({
selectedFamilyID: null, selectedFamilyID: null,
selectedModelID: null, selectedModelID: null,
selectedMaterial: null, selectedMaterial: null,
loadingCatalog: true, loadingCatalog: false,
savingCatalog: false, savingCatalog: false,
}, },
getters: { getters: {
@ -212,6 +212,10 @@ export const store = new Vuex.Store({
context.commit('setCatalogProperty', data) context.commit('setCatalogProperty', data)
}, },
newCatalog({ commit }) {
commit('setCatalog', {})
},
async loadCatalog({ commit }, id) { async loadCatalog({ commit }, id) {
try { try {
commit('setLoadingCatalog', true) commit('setLoadingCatalog', true)
@ -219,18 +223,15 @@ export const store = new Vuex.Store({
if (response.data) { if (response.data) {
console.log('recieved catalog:', response.data) console.log('recieved catalog:', response.data)
commit('setCatalog', response.data) commit('setCatalog', response.data)
commit('setCatalogID', id)
} else { } else {
console.log('no catalog') console.log('no catalog')
commit('setCatalog', null) commit('setCatalog', null)
commit('setCatalogID', null)
} }
commit('setLoadingCatalog', false) commit('setLoadingCatalog', false)
} catch (error) { } catch (error) {
// TODO set loading error property // TODO set loading error property
console.error('error loading catalog: ', error) console.error('error loading catalog: ', error)
commit('setCatalog', null) commit('setCatalog', null)
commit('setCatalogID', null)
commit('setLoadingCatalog', false) commit('setLoadingCatalog', false)
} }
}, },
@ -244,11 +245,9 @@ export const store = new Vuex.Store({
if (response.data) { if (response.data) {
console.log('recieved catalog:', response.data) console.log('recieved catalog:', response.data)
commit('setCatalog', response.data) commit('setCatalog', response.data)
commit('setCatalogID', response.data.id)
} else { } else {
console.error('no catalog returned from save!') console.error('no catalog returned from save!')
commit('setCatalog', null) commit('setCatalog', null)
commit('setCatalogID', null)
} }
commit('setSavingCatalog', false) commit('setSavingCatalog', false)
}) })

View File

@ -139,9 +139,9 @@ class Catalog(models.Model):
sections = 0 sections = 0
pages = 0 pages = 0
materials = 0 materials = 0
for section in data.get('sections'): for section in data.get('sections', []):
sections += 1 sections += 1
for page in section.get('pages'): for page in section.get('pages', []):
pages += 1 pages += 1
for block in page: for block in page:
materials += len(block.get('ids', [])) materials += len(block.get('ids', []))