Skip to content

Commit

Permalink
chore: improve choice of label type for KCompass
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-greffe committed Apr 30, 2024
1 parent 6d95a43 commit 707d441
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
24 changes: 22 additions & 2 deletions map/client/components/KCompass.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
color="primary"
text-color="white"
outline
:label="`${modelValue}°`"
:label="getLabel()"
/>
<q-popup-edit
v-model="direction"
Expand All @@ -51,6 +51,7 @@
>
<q-input
v-model.number="scope.value"
:prefix="getPrefix()"
suffix="°"
autofocus
dense
Expand All @@ -64,6 +65,7 @@
<script setup>
import { ref, computed } from 'vue'
import { getCssVar } from 'quasar'
import { i18n } from '../../../core/client'
// Props
const props = defineProps({
Expand All @@ -78,6 +80,13 @@ const props = defineProps({
ticks: {
type: Number,
default: 16
},
labelMode: {
type: String,
default: 'from',
validator(value) {
return ['from', 'from-to'].includes(value)
}
}
})
Expand Down Expand Up @@ -122,12 +131,23 @@ function onHandleDrag (event) {
const { x, y } = event.type.startsWith('touch') ? event.changedTouches[0] : event
computeDirection(x, y)
}
function getLabel () {
if (props.labelMode === 'from') return `${direction.value}°`
return i18n.t('KCompass.FROM_TO', {
direction: direction.value,
source: (direction.value + 180) % 360
})
}
function getPrefix () {
if (props.labelMode === 'from') return ''
return i18n.t('KCompass.FROM')
}
function onStartDrag (event) {
window.addEventListener('mousemove', onHandleDrag)
window.addEventListener('touchmove', onHandleDrag)
window.addEventListener('mouseup', onStropDrag)
window.addEventListener('touchend', onStropDrag)
};
}
function onStropDrag () {
window.removeEventListener('mousemove', onHandleDrag)
window.removeEventListener('touchmove', onHandleDrag)
Expand Down
4 changes: 4 additions & 0 deletions map/client/components/form/KDirectionField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<KCompass
v-model="model"
@update:model-value="onChanged"
:labelMode="labelMode"
class="k-compass"
/>
</template>
Expand Down Expand Up @@ -108,6 +109,9 @@ export default {
mode () {
return _.get(this.properties.field, 'mode', 'input')
},
labelMode () {
return _.get(this.properties.field, 'labelMode', 'from')
},
clearable () {
return _.get(this.properties.field, 'clearable', false)
}
Expand Down
2 changes: 2 additions & 0 deletions map/client/i18n/map_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,8 @@
"LABEL": "Legend"
},
"KCompass": {
"FROM_TO": "From {direction}° to {source}°",
"FROM": "From",
"NORTH": "N",
"EAST": "E",
"SOUTH": "S",
Expand Down
2 changes: 2 additions & 0 deletions map/client/i18n/map_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@
"LABEL": "Légende"
},
"KCompass": {
"FROM_TO": "De {direction}° vers {source}°",
"FROM": "De",
"NORTH": "N",
"EAST": "E",
"SOUTH": "S",
Expand Down

0 comments on commit 707d441

Please sign in to comment.