Skip to content

Commit

Permalink
#109: changed set on blur to enable typing of commas without problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mulholland committed May 8, 2018
1 parent 750b6cd commit 6a603d9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 37 deletions.
106 changes: 86 additions & 20 deletions src/renderer/partials/ColumnProperties.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@
<template v-else-if="formprop.key === 'booleanTypes'">
<div class="boolean-types input-group" v-show="typeProperty === 'boolean'">
<label class="inline control-label col-sm-3" for="trueValues">True Values</label>
<input :value="getTrueValues" @input="setTrueValues($event.target.value)" type="text" class="form-control label-sm col-sm-9" id="trueValues" />
<!-- <input :value="getTrueValues()" @input="setTrueValues($event.target.value)" type="text" class="form-control label-sm col-sm-9" id="trueValues" /> -->
<input :value="getTrueValues()" @blur="setTrueValues($event.target.value)" type="text" class="form-control label-sm col-sm-9" id="trueValues" />
</div>
<div class="boolean-types input-group" v-show="typeProperty === 'boolean'">
<label class="inline control-label col-sm-3" for="falseValues">False Values</label>
<input :value="getFalseValues" @input="setFalseValues($event.target.value)" type="text" class="form-control label-sm col-sm-9" id="falseValues" />
<!-- <input :value="getFalseValues()" @input="setFalseValues($event.target.value)" type="text" class="form-control label-sm col-sm-9" id="falseValues" /> -->
<input :value="getFalseValues()" @blur="setFalseValues($event.target.value)" type="text" class="form-control label-sm col-sm-9" id="falseValues" />
</div>
</template>
<input v-else :disabled="formprop.isDisabled" :value="getProperty(formprop.key)" @input="setProperty(formprop.key, $event.target.value)" type="text" class="form-control label-sm col-sm-9" :id="formprop.key" />
Expand Down Expand Up @@ -194,7 +196,9 @@ export default {
'geojson': ['required', 'unique', 'minLength', 'maxLength', 'enum'],
'any': ['required', 'unique', 'enum']
},
constraintBooleanBindings: ['required', 'unique']
constraintBooleanBindings: ['required', 'unique'],
trueValues: ['true', 'True', 'TRUE', '1'],
falseValues: ['false', 'False', 'FALSE', '0']
}
},
subscriptions() {
Expand Down Expand Up @@ -247,26 +251,12 @@ export default {
// ensure format also updates after setting type
let temp3 = this.typeProperty
}
},
getBooleanTypes: {
async get() {
},
watch() {
}
}
},
methods: {
...mapMutations([
'pushColumnProperty', 'pushTrueValues', 'pushFalseValues'
'pushColumnProperty'
]),
setTrueValues: function(values) {
},
setFalseValues: function(values) {
},
isBooleanConstraint: function(option) {
return this.constraintBooleanBindings.indexOf(option) > -1
},
Expand Down Expand Up @@ -400,9 +390,85 @@ export default {
formatPropertyValueWrapper: function() {
return this.formatPropertyValue
},
setTrueValues: function(values) {
console.log('setting true values')
let withoutEmpties = this.removeStringEmpties(values)
let array = this.getNoDuplicatesArrayFromString(withoutEmpties)
this.setProperty('trueValues', values)
},
setFalseValues: function(values) {
console.log('setting true values')
let withoutEmpties = this.removeStringEmpties(values)
let array = this.getNoDuplicatesArrayFromString(withoutEmpties)
this.setProperty('falseValues', values)
},
// setTrueRawValues: function(values) {
// // let withoutEmpties = this.removeStringEmpties(values)
// // let array = this.getNoDuplicatesArrayFromString(withoutEmpties)
// this.setProperty('trueRawValues', values)
// },
// setFalseRawValues: function(values) {
// // let withoutEmpties = this.removeStringEmpties(values)
// // let array = this.getNoDuplicatesArrayFromString(withoutEmpties)
// this.setProperty('falseRawValues', values)
// },
getNoDuplicatesArrayFromString: function(values) {
return Array.from(new Set(values.split(',')))
},
getTrueValues: function() {
return this.getBooleanValuesOrDefaultAsString('trueValues')
},
getFalseValues: function() {
return this.getBooleanValuesOrDefaultAsString('falseValues')
},
getBooleanValuesOrDefaultAsString: function(booleanType) {
let values = this.getBooleanValuesOrDefault(booleanType)
console.log(values instanceof Array)
if (values instanceof Array) {
return values.join()
}
return values
},
getBooleanValuesOrDefault: function(booleanType) {
let values
if (booleanType === 'trueValues') {
values = this.getProperty('trueValues')
if (!values) {
// values = this.getProperty('trueRawValues')
// if (!values) {
values = this.setAndGetDefaultTrueValues()
// }
}
} else {
values = this.getProperty('falseValues')
if (!values) {
// values = this.getProperty('falseRawValues')
// if (!values) {
values = this.setAndGetDefaultFalseValues()
// }
}
}
return values
},
setAndGetDefaultTrueValues: function() {
let values = [...this.trueValues]
this.setProperty('trueValues', values)
return values
},
setAndGetDefaultFalseValues: function() {
let values = [...this.falseValues]
this.setProperty('falseValues', values)
return values
},
removeStringEmpties: function(string) {
let withoutInternalEmpties = string.replace(/[,]+/g, ',')
// also remove 'empty' if at start or end
let trimmed = _.trim(withoutInternalEmpties, ',')
return trimmed
},
// we cannot access frictionless' boolean types directly, so at least offer error message if not correct
validateBooleans: function() {
for (const booleanValues of [this.getTrueValues, this.getFalseValues]) {
for (const booleanValues of [this.trueValues, this.falseValues]) {
for (const value of booleanValues) {
const result = castBoolean('default', value)
if (typeof result !== 'boolean') {
Expand All @@ -414,7 +480,7 @@ export default {
},
computed: {
...mapGetters([
'getActiveTab', 'getHotColumnProperty', 'getConstraint', 'getAllHotTablesColumnNames', 'getTrueValues', 'getFalseValues'
'getActiveTab', 'getHotColumnProperty', 'getConstraint', 'getAllHotTablesColumnNames'
]),
getNameProperty() {
let allColumns = this.allTablesAllColumnsNames[this.activeCurrentHotId] || []
Expand Down
18 changes: 1 addition & 17 deletions src/renderer/store/modules/hots.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ const state = {
hotTabs: {},
packageProperties: {},
provenanceProperties: { markdown: '', errors: [] },
fkPackageComponents: {},
trueValues: ['true', 'True', 'TRUE', '1'],
falseValues: ['false', 'False', 'FALSE', '0']
fkPackageComponents: {}
}

export function getHotColumnPropertiesFromPropertyObject(property) {
Expand All @@ -28,12 +26,6 @@ export function getHotIdFromTabIdFunction() {
}

const getters = {
getTrueValues: state => {
return state.trueValues
},
getFalseValues: state => {
return state.falseValues
},
getFkPackageComponents: (state, getters) => (url) => {
return state.fkPackageComponents[url]
},
Expand Down Expand Up @@ -150,14 +142,6 @@ const getters = {
}

const mutations = {
pushTrueValues(state, values) {
state.trueValues.length = 0
state.trueValues.push(...values)
},
pushFalseValues(state, values) {
state.falseValues.length = 0
state.falseValues.push(...values)
},
pushFkPackageComponents(state, property) {
_.set(state.fkPackageComponents[property.url], property.tableName, property.fields)
},
Expand Down

0 comments on commit 6a603d9

Please sign in to comment.