Skip to content

Commit

Permalink
fix(ui): correctly get/set buffer values (#795)
Browse files Browse the repository at this point in the history
fix(ui): correctly get/set buffer values
  • Loading branch information
robertsLando authored Mar 2, 2021
1 parent 8a4a958 commit 4f5a91f
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/components/ValueId.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:suffix="value.unit"
:hint="help"
persistent-hint
v-model="value.value"
v-model="parsedValue"
></v-text-field>
</div>

Expand Down Expand Up @@ -38,14 +38,14 @@
></v-text-field>

<v-text-field
v-if="!value.list && value.type === 'any'"
v-if="!value.list && (value.type === 'any' || value.type === 'buffer')"
:append-outer-icon="!disable_send ? 'send' : null"
:suffix="value.unit"
persistent-hint
:error="!!error"
:error-messages="error"
:hint="help"
v-model="parsedAny"
v-model="parsedValue"
@click:append-outer="updateValue(value)"
></v-text-field>

Expand Down Expand Up @@ -221,7 +221,7 @@ export default {
return {
durations: ['seconds', 'minutes'],
menu: false,
error: false
error: null
}
},
computed: {
Expand Down Expand Up @@ -260,27 +260,28 @@ export default {
this.value.newValue = v ? v.substr(1, 7) : null
}
},
parsedAny: {
parsedValue: {
get: function () {
if (this.value.type === 'any') {
if (typeof this.value.newValue === 'object') {
return JSON.stringify(this.value.newValue)
}
return JSON.stringify(this.value.newValue)
} else if (this.value.type === 'buffer') {
return this.value.newValue && this.value.newValue.toString('hex')
}
return this.value.newValue
},
set: function (v) {
if (this.value.type === 'any') {
if (typeof this.value.value === 'object') {
try {
this.value.newValue = JSON.parse(v)
this.error = false
} catch (error) {
this.error = 'Value not valid'
}
try {
if (this.value.type === 'any') {
this.value.newValue = JSON.parse(v)
} else if (this.value.type === 'buffer') {
this.value.newValue = Buffer.from(v, 'hex')
} else {
this.value.newValue = v
}
} else {
this.value.newValue = v
this.error = null
} catch (error) {
this.error = 'Value not valid'
}
}
},
Expand Down

0 comments on commit 4f5a91f

Please sign in to comment.