Skip to content

Commit

Permalink
feat: paper base setting dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangChiTW committed Apr 11, 2023
1 parent 6a7d3ad commit 9c8befa
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 23 deletions.
67 changes: 50 additions & 17 deletions src/components/editor/dialogs/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<p>
Substrate Type:
<span :key="key">
<select v-model="substrate">
<select v-model="substrateType" @change="onSwitchSubstrate">
<option value="glass"> Glass </option>
<option value="paper"> Paper </option>
</select>
</span>
</p>
<p v-if="substrate == 'glass'">
<p v-if="substrateType == 'glass'">
Canvas Grid:
<span :key="keyInput">
<input
Expand All @@ -26,7 +26,7 @@
min="500"
max="5000"
step="500"
:value="gridUnit.current"
:value="grid"
@change="autoAdjust"
@blur="onGridBlur"
title="grid scale"
Expand All @@ -42,22 +42,27 @@
</span>
</p>
<p v-else>
Canvas Grid:
<span :key="key">
<select :value=1300>
<option value=1300> 1300 </option>
</select>
</span>
<span>
Currently not supported
um
</span>
</p>
</div>
<div class="confirm-dialog__actions">
<mdc-button v-if="substrate == 'glass'" @click="onConfirm" class="confirm-dialog__delete-btn" unelevated>Apply</mdc-button>
<mdc-button v-else disabled unelevated>Apply</mdc-button>
<mdc-button @click="closeDialog" v-if="parseInt(gridUnit.current) > 0">Cancel</mdc-button>
<mdc-button @click="onConfirm" class="confirm-dialog__delete-btn" unelevated>Apply</mdc-button>
<mdc-button @click="closeDialog">Cancel</mdc-button>
</div>
</dialog>
</template>

<script>
import { mapState, mapActions, mapMutations } from 'vuex'
import { newProject, _updateGridUnit } from '@/store/types'
import { mapState, mapActions } from 'vuex'
import { newProject } from '@/store/types'
import dialogPolyfill from 'dialog-polyfill/dialog-polyfill'
import { mapFields } from 'vuex-map-fields'
Expand All @@ -73,11 +78,25 @@ export default {
return {
key: 0,
keyInput: 0,
substrate: 'glass',
invalidInput: false
substrateType: 'glass',
invalidInput: false,
grid: 0
}
},
computed: {
parameterTable() {
return {
'glass': {
'cornerSize': 5,
'gapSize': 0.5
},
'paper': {
'cornerSize': 0,
'gapSize': 30
}
}
},
...mapFields([
'app.gridUnit',
'app.chip'
Expand All @@ -89,19 +108,25 @@ export default {
},
methods: {
openDialog () {
this.substrateType = this.project.substrate
this.grid = this.gridUnit.current
if (!this.$el.showModal) {
dialogPolyfill.registerDialog(this.$el)
}
this.$el.showModal()
},
onConfirm () {
if (this.invalidInput) {
return
}
this.newProject({
substrate: this.substrateType,
height: this.chip.height,
width: this.chip.width,
gridUnit: this.gridUnit.current,
cornerSize: 5,
gapSize: 0.5
gridUnit: this.grid,
cornerSize: this.parameterTable[this.substrateType].cornerSize,
gapSize: this.parameterTable[this.substrateType].gapSize
})
this.closeDialog()
},
Expand Down Expand Up @@ -134,13 +159,21 @@ export default {
newVal = 500
this.invalidInput = true
}
this._updateGridUnit(newVal)
this.grid = newVal
if (this.invalidInput) {
this.keyInput++
}
},
...mapActions([newProject]),
...mapMutations([_updateGridUnit])
onSwitchSubstrate (e) {
if (e.target.value === 'paper') {
this.grid = 1300
} else {
this.grid = 2000
}
},
...mapActions([newProject])
}
}
</script>
Expand Down
3 changes: 2 additions & 1 deletion src/factories/projectFactory.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import shortid from 'shortid'
import newPage from './pageFactory'

function newProject (title, gridUnit, cornerSize, gapSize, height, width) {
function newProject (title, substrate, gridUnit, cornerSize, gapSize, height, width) {
return {
id: shortid.generate(),
title: title,
substrate: substrate,
gridUnit: gridUnit,
cornerSize: cornerSize,
gapSize: gapSize,
Expand Down
5 changes: 3 additions & 2 deletions src/factories/stateFactory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import newProject from './projectFactory'

function newState (height, width, gridUnit, cornerSize, gapSize, project) {
function newState (substrate, height, width, gridUnit, cornerSize, gapSize, project) {
const h = height / gridUnit
const w = width / gridUnit
const _matrix = []
Expand All @@ -18,6 +18,7 @@ function newState (height, width, gridUnit, cornerSize, gapSize, project) {
}
return {
app: {
substrate: substrate,
svgContent: '',
apiStatus: false,
isLoading: false,
Expand Down Expand Up @@ -59,7 +60,7 @@ function newState (height, width, gridUnit, cornerSize, gapSize, project) {
isAuthorized: false,
authenticatedUser: null
},
project: project || newProject('My Project', gridUnit, cornerSize, gapSize, height, width)
project: project || newProject('My Project', substrate, gridUnit, cornerSize, gapSize, height, width)
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/store/actions/projectAct.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ const projectActions = {
const _project = JSON.parse(atob(project))
if (!_project.gridUnit || !_project.chip) {
store.replaceState(newState(
state.app.substrate,
parseInt(state.app.chip.height),
parseInt(state.app.chip.width),
parseInt(2000),
Expand All @@ -297,12 +298,13 @@ const projectActions = {
))
commit(types.addProject)
} else {
store.replaceState(newState(parseInt(_project.chip.height), parseInt(_project.chip.width), parseInt(_project.gridUnit), _project.cornerSize, _project.gapSize, _project))
store.replaceState(newState(state.app.substrate, parseInt(_project.chip.height), parseInt(_project.chip.width), parseInt(_project.gridUnit), _project.cornerSize, _project.gapSize, _project))
commit(types.addProject)
await dispatch(types.checkAuth)
}
} else {
store.replaceState(newState(
state.app.substrate,
parseInt(state.app.chip.height),
parseInt(state.app.chip.width),
parseInt(2000),
Expand All @@ -322,6 +324,7 @@ const projectActions = {
*/
[types.resetProject]: async function ({ state, dispatch }) {
await dispatch(types.newProject, {
substrate: state.app.substrate,
height: state.app.chip.height,
width: state.app.chip.width,
gridUnit: state.app.gridUnit ? state.app.gridUnit.origin : 2000,
Expand All @@ -335,10 +338,10 @@ const projectActions = {
* (or better to say, resets vuegg to initial state)
*/
[types.newProject]: async function ({ dispatch, commit }, payload) {
const { height, width, gridUnit, cornerSize, gapSize } = payload
const { substrate, height, width, gridUnit, cornerSize, gapSize } = payload
commit(types._toggleBlockLoadingStatus, true)

store.replaceState(newState(height, width, gridUnit, cornerSize, gapSize))
store.replaceState(newState(substrate, height, width, gridUnit, cornerSize, gapSize))
commit(types.deleteProject)

await dispatch(types.checkAuth)
Expand Down

0 comments on commit 9c8befa

Please sign in to comment.