|
|
@ -1,126 +1,72 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div class="duration-cell-wrapper"> |
|
|
|
<v-row class="duration-wrapper"> |
|
|
|
<input |
|
|
|
<div class="caption"> |
|
|
|
ref="durationInput" |
|
|
|
A duration of time in minutes or seconds (e.g. 1:23). |
|
|
|
v-model="localState" |
|
|
|
|
|
|
|
:placeholder="durationPlaceholder" |
|
|
|
|
|
|
|
@blur="onBlur" |
|
|
|
|
|
|
|
@keypress="checkDurationFormat($event)" |
|
|
|
|
|
|
|
@keydown.enter="isEdited && $emit('input', durationInMS)" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<div v-if="showWarningMessage == true" class="duration-warning"> |
|
|
|
|
|
|
|
<!-- TODO: i18n --> |
|
|
|
|
|
|
|
Please enter a number |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<!-- TODO: i18n --> |
|
|
|
|
|
|
|
<v-autocomplete |
|
|
|
|
|
|
|
v-model="colMeta.duration" |
|
|
|
|
|
|
|
hide-details |
|
|
|
|
|
|
|
class="caption ui-type nc-ui-dt-dropdown" |
|
|
|
|
|
|
|
label="Duration Format" |
|
|
|
|
|
|
|
dense |
|
|
|
|
|
|
|
outlined |
|
|
|
|
|
|
|
item-value="id" |
|
|
|
|
|
|
|
item-text="title" |
|
|
|
|
|
|
|
:items="durationOptionList" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<template #selection="{ item }"> |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
<span class="caption grey--text text--darken-4"> |
|
|
|
|
|
|
|
{{ item.title }} |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
<template #item="{ item }"> |
|
|
|
|
|
|
|
<div class="caption"> |
|
|
|
|
|
|
|
{{ item.title }} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
</v-autocomplete> |
|
|
|
|
|
|
|
</v-row> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
import { durationOptions, convertMS2Duration, convertDurationToSeconds } from '~/helpers/durationHelper' |
|
|
|
import { durationOptions } from '~/helpers/durationHelper' |
|
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
export default { |
|
|
|
name: 'DurationCell', |
|
|
|
name: 'DuractionOptions', |
|
|
|
props: { |
|
|
|
props: ['column', 'meta', 'value'], |
|
|
|
column: Object, |
|
|
|
|
|
|
|
value: [Number, String], |
|
|
|
|
|
|
|
readOnly: Boolean |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
data: () => ({ |
|
|
|
data: () => ({ |
|
|
|
// flag to determine to show warning message or not |
|
|
|
durationOptionList: durationOptions.map(o => ({ |
|
|
|
showWarningMessage: false, |
|
|
|
...o, |
|
|
|
// duration in milliseconds |
|
|
|
// h:mm:ss (e.g. 3:45, 1:23:40) |
|
|
|
durationInMS: null, |
|
|
|
title: `${o.title} ${o.example}` |
|
|
|
// check if the cell is edited or not |
|
|
|
})), |
|
|
|
isEdited: false |
|
|
|
colMeta: { |
|
|
|
|
|
|
|
duration: 0 |
|
|
|
|
|
|
|
} |
|
|
|
}), |
|
|
|
}), |
|
|
|
computed: { |
|
|
|
watch: { |
|
|
|
localState: { |
|
|
|
value() { |
|
|
|
get() { |
|
|
|
this.colMeta = this.value || {} |
|
|
|
return convertMS2Duration(this.value, this.durationType) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
set(val) { |
|
|
|
|
|
|
|
this.isEdited = true |
|
|
|
|
|
|
|
const res = convertDurationToSeconds(val, this.durationType) |
|
|
|
|
|
|
|
if (res._isValid) { |
|
|
|
|
|
|
|
this.durationInMS = res._sec |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
durationPlaceholder() { |
|
|
|
|
|
|
|
return durationOptions[this.durationType].title |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
durationType() { |
|
|
|
colMeta(v) { |
|
|
|
return this.column?.meta?.duration || 0 |
|
|
|
this.$emit('input', v) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
created() { |
|
|
|
window.addEventListener('keypress', (_) => { |
|
|
|
this.colMeta = this.value ? { ...this.value } : { ...this.colMeta } |
|
|
|
if (this.$refs.durationInput) { |
|
|
|
|
|
|
|
this.$refs.durationInput.focus() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
|
|
|
|
checkDurationFormat(evt) { |
|
|
|
|
|
|
|
evt = evt || window.event |
|
|
|
|
|
|
|
const charCode = (evt.which) ? evt.which : evt.keyCode |
|
|
|
|
|
|
|
// ref: http://www.columbia.edu/kermit/ascii.html |
|
|
|
|
|
|
|
const PRINTABLE_CTL_RANGE = charCode > 31 |
|
|
|
|
|
|
|
const NON_DIGIT = charCode < 48 || charCode > 57 |
|
|
|
|
|
|
|
const NON_COLON = charCode !== 58 |
|
|
|
|
|
|
|
const NON_PERIOD = charCode !== 46 |
|
|
|
|
|
|
|
if (PRINTABLE_CTL_RANGE && NON_DIGIT && NON_COLON && NON_PERIOD) { |
|
|
|
|
|
|
|
this.showWarningMessage = true |
|
|
|
|
|
|
|
evt.preventDefault() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.showWarningMessage = false |
|
|
|
|
|
|
|
// only allow digits, '.' and ':' (without quotes) |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
onBlur() { |
|
|
|
|
|
|
|
if (this.isEdited) { |
|
|
|
|
|
|
|
this.$emit('input', this.durationInMS) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.isEdited = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<style scoped> |
|
|
|
<style scoped> |
|
|
|
|
|
|
|
.duration-wrapper { |
|
|
|
.duration-cell-wrapper { |
|
|
|
margin: 0; |
|
|
|
padding: 10px; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.duration-warning { |
|
|
|
.duration-wrapper .caption:first-child { |
|
|
|
text-align: left; |
|
|
|
margin: -10px 0px 10px 5px; |
|
|
|
margin-top: 10px; |
|
|
|
|
|
|
|
color: #E65100; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
</style> |
|
|
|
</style> |
|
|
|
|
|
|
|
|
|
|
|
<!-- |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @author Wing-Kam Wong <wingkwong.code@gmail.com> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @license GNU AGPL version 3 or any later version |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
|
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
|
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
|
|
|
|
|
|
* License, or (at your option) any later version. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful, |
|
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
|
|
|
* GNU Affero General Public License for more details. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
|
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
--> |
|
|
|
|
|
|
|