diff --git a/cateditor/src/components/CatalogContents.vue b/cateditor/src/components/CatalogContents.vue index 96cbaf4..39ae8ec 100644 --- a/cateditor/src/components/CatalogContents.vue +++ b/cateditor/src/components/CatalogContents.vue @@ -1,25 +1,28 @@ diff --git a/cateditor/src/components/FancyList.vue b/cateditor/src/components/FancyList.vue deleted file mode 100644 index 0cb7463..0000000 --- a/cateditor/src/components/FancyList.vue +++ /dev/null @@ -1,141 +0,0 @@ - - - - - diff --git a/cateditor/src/components/MaterialList.vue b/cateditor/src/components/MaterialList.vue new file mode 100644 index 0000000..a3575be --- /dev/null +++ b/cateditor/src/components/MaterialList.vue @@ -0,0 +1,114 @@ + + + + + diff --git a/cateditor/src/components/ProductFamilyList.vue b/cateditor/src/components/ProductFamilyList.vue new file mode 100644 index 0000000..63ed3a8 --- /dev/null +++ b/cateditor/src/components/ProductFamilyList.vue @@ -0,0 +1,113 @@ + + + + + diff --git a/cateditor/src/components/CategoryDeleteDialog.vue b/cateditor/src/components/SectionDeleteDialog.vue similarity index 80% rename from cateditor/src/components/CategoryDeleteDialog.vue rename to cateditor/src/components/SectionDeleteDialog.vue index cf5f7e6..17dd3b0 100644 --- a/cateditor/src/components/CategoryDeleteDialog.vue +++ b/cateditor/src/components/SectionDeleteDialog.vue @@ -2,10 +2,10 @@ - Delete Category + Delete Section - Really delete category: + Really delete section: @@ -26,7 +26,7 @@ export default { }), props: { value: Boolean, - category: { + section: { type: Number, required: false } @@ -42,7 +42,8 @@ export default { }, name: { get () { - var section = this.$store.getters.CAT_SECTION(this.category) + var sectionID = this.$store.getters.SELECTED_SECTION_ID + var section = this.$store.getters.CAT_SECTION(sectionID) return section ? section.name : '(none)' } } diff --git a/cateditor/src/components/CategoryInfoDialog.vue b/cateditor/src/components/SectionInfoDialog.vue similarity index 80% rename from cateditor/src/components/CategoryInfoDialog.vue rename to cateditor/src/components/SectionInfoDialog.vue index 821d2d1..72d7c08 100644 --- a/cateditor/src/components/CategoryInfoDialog.vue +++ b/cateditor/src/components/SectionInfoDialog.vue @@ -3,14 +3,13 @@ - Category Info + Section Info close - @@ -30,16 +29,11 @@ // https://stackoverflow.com/questions/48035310/open-a-vuetify-dialog-from-a-component-template-in-vuejs export default { data: () => ({ - /* name: 'Trailhead (Men)', */ models: '5 models', materials: '12 materials' }), props: { value: Boolean, - category: { - type: Number, - required: false - } }, computed: { show: { @@ -52,15 +46,18 @@ export default { }, name: { get () { - var section = this.$store.getters.CAT_SECTION(this.category) + var sectionID = this.$store.getters.SELECTED_SECTION_ID + var section = this.$store.getters.CAT_SECTION(sectionID) return section ? section.name : '(none)' }, set (value) { + var sectionID = this.$store.getters.SELECTED_SECTION_ID this.$store.dispatch('SET_CAT_SECTION_NAME', - { id: this.category, name: value }) + { id: sectionID, name: value }) } }, families () { + // TODO return this.$store.getters.CAT_FAMILIES } } diff --git a/cateditor/src/components/SectionList.vue b/cateditor/src/components/SectionList.vue new file mode 100644 index 0000000..155d0e1 --- /dev/null +++ b/cateditor/src/components/SectionList.vue @@ -0,0 +1,120 @@ + + + + + diff --git a/cateditor/src/components/SelectionMixin.js b/cateditor/src/components/SelectionMixin.js new file mode 100644 index 0000000..dd6bf5c --- /dev/null +++ b/cateditor/src/components/SelectionMixin.js @@ -0,0 +1,111 @@ +const SelectionMixin = { // eslint-disable-line no-unused-vars + computed: { + selectedSectionID: { + get () { + return this.$store.getters.SELECTED_SECTION_ID + }, + set (value) { + this.$store.dispatch('SET_SELECTED_SECTION_ID', value) + } + }, + selectedFamilyID: { + get () { + return this.$store.getters.SELECTED_FAMILY_ID + }, + set (value) { + this.$store.dispatch('SET_SELECTED_FAMILY_ID', value) + } + }, + selectedModelID: { + get () { + return this.$store.getters.SELECTED_MODEL_ID + }, + set (value) { + this.$store.dispatch('SET_SELECTED_MODEL_ID', value) + } + }, + selectedMaterial: { + get () { + return this.$store.getters.SELECTED_MATERIAL_ID + }, + set (value) { + this.$store.dispatch('SET_SELECTED_MATERIAL_ID', value) + } + }, + }, + methods: { + selectSection: function (id) { + this.selectedSectionID = id + // this.selectedFamilyID = null + // this.selectedModelID = null + // this.selectedMaterial = null + }, + selectFamily: function (id) { + this.selectedFamilyID = id + // this.selectedModelID = null + // this.selectedMaterial = null + }, + selectModel: function (id) { + this.selectedModelID = id + // this.selectedFamilyID = null + // this.selectedMaterial = null + }, + selectMaterial: function (id) { + this.selectedMaterial = id + }, + selectedFamilies: function () { + let section = this.$store.getters.CAT_SECTION(this.selectedSectionID) + let ids = this.sectionIDs(section) + let materials = this.findMaterials(ids) + return this.makeFamilies(materials) + }, + selectedFamily: function () { + let families = this.selectedFamilies() + return families.find(s => s.id === this.selectedFamilyID) + }, + sectionIDs: function (section) { + let ids = [] + + if (section !== undefined) { + for (let page of section.pages) { + for (let block of page) { + ids.push(...block.ids) + } + } + } + + return ids + }, + findMaterials: function (ids) { + return ids.map(id => this.$store.getters.MATERIAL(id)) + }, + makeFamilies: function (materials) { + let families = [] + + for (let mat of materials) { + let family = families.length > 0 ? families[families.length - 1] : null + + if (family === null || family.id !== mat.family) { + // new family + family = { id: mat.family, + name: mat.name, // TODO where does this come from? + models: [mat.model], + materials: [mat.id] } + families.push(family) + } else { + // add to existing + family.materials.push(mat.id) + family.models.push(mat.model) + family.models = this.uniquify(family.models) + } + } + + return families + }, + uniquify: function (arr) { + return [...new Set(arr)] + }, + } +} + +export default SelectionMixin diff --git a/cateditor/src/store/index.js b/cateditor/src/store/index.js index a313223..d58cdb1 100644 --- a/cateditor/src/store/index.js +++ b/cateditor/src/store/index.js @@ -7,16 +7,61 @@ export const store = new Vuex.Store({ state: { catalog: { name: 'my catalog', - sections: [{ id: 1, name: 'trailhead (men)' }, - { id: 2, name: 'trailhead (women)' }, - { id: 3, name: 'waterfront (men)' }, - { id: 4, name: 'waterfront (women)' }], - families: 5, - models: 12, - materials: 27 - } + owner: 12, + created: '2019-04-04T22:00:14Z', + sections: [ + { id: 1, + name: 'Trailhead (Men)', + pages: [ + [{ name: 'model name override', size: 2, ids: ['1001001', '1001002'] }, + { size: 1, ids: ['1001011', '1001012'] }], // one page, two blocks + [{ size: 1, ids: ['1001021'] }], + ], + }, + { id: 2, + name: 'Waterfront (Men)', + pages: [ + [{ size: 1, ids: ['1001021'] }], + ], + }, + ], + }, + materials: { + '1001001': { id: '1001001', // call them sap maybe? + model: 'AW123', + family: 'MF123', + name: 'Targhee WP', + color: 'Green / Blue' }, + '1001002': { id: '1001002', + model: 'AW123', + family: 'MF123', + name: 'Targhee WP', + color: 'Red / Purple' }, + '1001011': { id: '1001011', + model: 'WA999', + family: 'MF123', + name: 'Targhee WP FA', + color: 'Green / Blue' }, + '1001012': { id: '1001012', + model: 'WA999', + family: 'MF123', + name: 'Targhee WP FA', + color: 'Green / Blue' }, + '1001021': { id: '1001021', + model: 'BBB22', + family: 'BBBMF', + name: 'Slither', + color: 'Green / Blue' }, + }, + selectedSectionID: null, + selectedFamilyID: null, + selectedModelID: null, + selectedMaterial: null, }, getters: { + // + // catalog info + // CAT_NAME: state => { return state.catalog.name }, @@ -26,9 +71,30 @@ export const store = new Vuex.Store({ CAT_SECTION: (state) => (id) => { return state.catalog.sections.find(s => s.id === id) }, - CAT_FAMILIES: state => { - return state.catalog.families + ' product families' - } + // + // selection info + // + SELECTED_SECTION_ID: state => { + return state.selectedSectionID + }, + // SELECTED_SECTION: state => { + // return store.getters.CAT_SECTION(state.selectedSectionID) + // }, + SELECTED_FAMILY_ID: state => { + return state.selectedFamilyID + }, + SELECTED_MODEL_ID: state => { + return state.selectedModelID + }, + SELECTED_MATERIAL_ID: state => { + return state.selectedMaterial + }, + // + // material info + // + MATERIAL: (state) => (id) => { + return state.materials[id] + }, }, mutations: { SET_CAT_SECTIONS: (state, payload) => { @@ -37,7 +103,26 @@ export const store = new Vuex.Store({ SET_CAT_SECTION_NAME: (state, payload) => { var section = state.catalog.sections.find(s => s.id === payload.id) section.name = payload.name - } + }, + SET_SELECTED_SECTION_ID: (state, payload) => { + state.selectedSectionID = payload + state.selectedFamilyID = null + state.selectedModelID = null + state.selectedMaterial = null + }, + SET_SELECTED_FAMILY_ID: (state, payload) => { + state.selectedFamilyID = payload + state.selectedModelID = null + state.selectedMaterial = null + }, + SET_SELECTED_MODEL_ID: (state, payload) => { + state.selectedModelID = payload + state.selectedFamilyID = null + state.selectedMaterial = null + }, + SET_SELECTED_MATERIAL_ID: (state, payload) => { + state.selectedMaterial = payload + }, }, actions: { SET_CAT_SECTIONS: (context, payload) => { @@ -45,10 +130,22 @@ export const store = new Vuex.Store({ }, SET_CAT_SECTION_NAME: (context, payload) => { context.commit('SET_CAT_SECTION_NAME', payload) - } - // SAVE_TODO : async (context,payload) => { - // let { data } = await Axios.post('http://yourwebsite.com/api/todo') - // context.commit('ADD_TODO',payload) - // }, + }, + SET_SELECTED_SECTION_ID: (context, payload) => { + context.commit('SET_SELECTED_SECTION_ID', payload) + }, + SET_SELECTED_FAMILY_ID: (context, payload) => { + context.commit('SET_SELECTED_FAMILY_ID', payload) + }, + SET_SELECTED_MODEL_ID: (context, payload) => { + context.commit('SET_SELECTED_MODEL_ID', payload) + }, + SET_SELECTED_MATERIAL_ID: (context, payload) => { + context.commit('SET_SELECTED_MATERIAL_ID', payload) + }, + // SAVE_TODO : async (context,payload) => { + // let { data } = await Axios.post('http://yourwebsite.com/api/todo') + // context.commit('ADD_TODO',payload) + // }, } })