Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RequestTime.vue « Checks « components « src « workflowengine « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cd702ecae826b87e176687f52a1509a4993d0db6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<template>
	<div class="timeslot">
		<Multiselect v-model="newValue.timezone" :options="timezones" @input="update" />
		<input v-model="newValue.startTime"
			type="text"
			class="timeslot--start"
			placeholder="e.g. 08:00"
			@input="update">
		<input v-model="newValue.endTime"
			type="text"
			placeholder="e.g. 18:00"
			@input="update">
		<p v-if="!valid" class="invalid-hint">{{ t('workflowengine', 'Please enter a valid time span')}}</p>
	</div>
</template>

<script>
import { Multiselect } from 'nextcloud-vue/dist/Components/Multiselect'
import moment from 'moment-timezone'
import valueMixin from '../../mixins/valueMixin'

const zones = moment.tz.names()
export default {
	name: 'RequestTime',
	components: {
		Multiselect
	},
	mixins: [
		valueMixin
	],
	props: {
		value: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			timezones: zones,
			valid: false,
			newValue: {
				startTime: null,
				endTime: null,
				timezone: moment.tz.guess()
			}
		}
	},
	methods: {
		updateInternalValue(value) {
			try {
				const data = JSON.parse(value)
				if (data.length === 2) {
					this.newValue = {
						startTime: data[0].split(' ', 2)[0],
						endTime: data[1].split(' ', 2)[0],
						timezone: data[0].split(' ', 2)[1]
					}
				}
			} catch (e) {}
		},
		validate() {
			return this.newValue.startTime && this.newValue.startTime.match(/^(0[0-9]|1[0-9]|2[0-3]|[0-9]):[0-5][0-9]$/i) !== null
				&& this.newValue.endTime && this.newValue.endTime.match(/^(0[0-9]|1[0-9]|2[0-3]|[0-9]):[0-5][0-9]$/i) !== null
				&& moment.tz.zone(this.newValue.timezone) !== null
		},
		update() {
			if (this.validate()) {
				const output = `["${this.newValue.startTime} ${this.newValue.timezone}","${this.newValue.endTime} ${this.newValue.timezone}"]`
				this.$emit('input', output)
				this.valid = true
			} else {
				this.valid = false
			}
		}
	}
}
</script>

<style scoped lang="scss">
	.timeslot {
		display: flex;
		flex-grow: 1;
		flex-wrap: wrap;
		max-width: 180px;

		.multiselect {
			width: 100%;
			margin-bottom: 5px;
		}

		input[type=text] {
			width: 50%;
			margin: 0;
			margin-bottom: 5px;

			&.timeslot--start {
				margin-right: 5px;
				width: calc(50% - 5px);
			}
		}

		.invalid-hint {
			color: var(--color-text-maxcontrast);
		}
	}
</style>