Web: Sleep schedule UX updates

This commit is contained in:
Francesco Siddi 2022-07-26 16:20:08 +02:00 committed by Francesco Siddi
parent 85eb17e434
commit 35591b174b
3 changed files with 124 additions and 31 deletions

View File

@ -223,7 +223,7 @@ h2.column-title {
color: var(--color-text-hint); color: var(--color-text-hint);
font-size: var(--font-size-base); font-size: var(--font-size-base);
margin: 0; margin: 0;
padding-bottom: var(--spacer-xs); padding-bottom: var(--spacer-sm);
} }
h3.sub-title { h3.sub-title {

View File

@ -0,0 +1,84 @@
<template>
<label>
<span class="switch">
<input type="checkbox" :checked="isChecked" @change="$emit('switchToggle')">
<span class="slider round"></span>
</span>
<span class="switch-label">{{ label }}</span>
</label>
</template>
<script setup>
const props = defineProps(['isChecked', 'label']);
</script>
<style scoped>
label {
display: inline-block;
}
.switch {
position: relative;
display: inline-block;
width: 32px;
height: 14px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: var(--color-text-muted);
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 10px;
width: 10px;
left: 4px;
bottom: 2px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: var(--color-accent);
}
input:focus + .slider {
box-shadow: 0 0 1px var(--color-accent);
}
input:checked + .slider:before {
-webkit-transform: translateX(14px);
-ms-transform: translateX(14px);
transform: translateX(14px);
}
/* Rounded sliders */
.slider.round {
border-radius: 10px;
}
.slider.round:before {
border-radius: 50%;
}
.switch-label {
margin-left: 0.5rem;
cursor: pointer;
}
</style>

View File

@ -35,35 +35,18 @@
</dl> </dl>
<section class="sleep-schedule" :class="{'is-schedule-active': workerSleepSchedule.is_active}"> <section class="sleep-schedule" :class="{'is-schedule-active': workerSleepSchedule.is_active}">
<h3 class="sub-title">Sleep Schedule</h3> <h3 class="sub-title">
<div class="btn-bar-group"> <switch-checkbox
<div class="btn-bar"> :isChecked="workerSleepSchedule.is_active"
<label for="toggle-sleep-schedule" v-if="!isScheduleEditing"> @switch-toggle="toggleWorkerSleepSchedule" >
<input </switch-checkbox>
v-model="workerSleepSchedule.is_active" Sleep Schedule
@change="toggleWorkerSleepSchedule" <div v-if="!isScheduleEditing" class="sub-title-buttons">
class="toggle-sleep-schedule" <button @click="isScheduleEditing = true">Edit</button>
id="toggle-sleep-schedule"
type="checkbox">
<span class="btn btn-primary" v-if="workerSleepSchedule.is_active">
Turn Schedule Off
</span>
<span class="btn" v-else>
Turn Schedule On
</span>
</label>
<button v-if="isScheduleEditing" @click="cancelEditWorkerSleepSchedule" class="btn">Cancel</button>
<button v-if="isScheduleEditing" @click="saveWorkerSleepSchedule" class="btn btn-primary">Save Schedule</button>
<button v-else @click="isScheduleEditing = true" class="btn btn-secondary">Edit</button>
</div> </div>
</div> </h3>
<p>Time of the day (and on which days) this worker should go to sleep. </p>
<div v-if="isScheduleEditing">
<p>
Adjust at which time of the day (and on which days) this worker should go to sleep.
</p>
</div>
<div class="sleep-schedule-edit" v-if="isScheduleEditing"> <div class="sleep-schedule-edit" v-if="isScheduleEditing">
<div> <div>
<label>Days of the week</label> <label>Days of the week</label>
@ -86,13 +69,18 @@
<span class="input-help-text"> <span class="input-help-text">
Use 24-hour format. Use 24-hour format.
</span> </span>
<div class="btn-bar-group">
<div class="btn-bar">
<button v-if="isScheduleEditing" @click="cancelEditWorkerSleepSchedule" class="btn">Cancel</button>
<button v-if="isScheduleEditing" @click="saveWorkerSleepSchedule" class="btn btn-primary">Save Schedule</button>
</div>
</div>
</div> </div>
<dl v-if="!isScheduleEditing"> <dl v-if="!isScheduleEditing">
<dt>Status</dt> <dt>Status</dt>
<dd> <dd>
<span v-if="workerSleepSchedule.is_active">enabled</span> {{ workerSleepScheduleStatusLabel }}
<span v-else>disabled</span>
</dd> </dd>
<dt>Days of Week</dt> <dt>Days of Week</dt>
<dd> <dd>
@ -123,6 +111,7 @@ import { WorkerMgtApi, WorkerSleepSchedule } from '@/manager-api';
import { apiClient } from '@/stores/api-query-count'; import { apiClient } from '@/stores/api-query-count';
import { workerStatus } from "../../statusindicator"; import { workerStatus } from "../../statusindicator";
import LinkWorkerTask from '@/components/LinkWorkerTask.vue'; import LinkWorkerTask from '@/components/LinkWorkerTask.vue';
import SwitchCheckbox from '@/components/SwitchCheckbox.vue';
export default { export default {
props: [ props: [
@ -130,6 +119,7 @@ export default {
], ],
components: { components: {
LinkWorkerTask, LinkWorkerTask,
SwitchCheckbox,
}, },
data() { data() {
return { return {
@ -172,6 +162,9 @@ export default {
'end_time': this.workerSleepSchedule.end_time === '' ? '24:00' : this.workerSleepSchedule.end_time, 'end_time': this.workerSleepSchedule.end_time === '' ? '24:00' : this.workerSleepSchedule.end_time,
} }
}, },
workerSleepScheduleStatusLabel() {
return this.workerSleepSchedule.is_active ? 'Enabled' : 'Disabled';
},
}, },
methods: { methods: {
fetchWorkerSleepSchedule() { fetchWorkerSleepSchedule() {
@ -195,7 +188,8 @@ export default {
this.notifs.add(notifMessage)); this.notifs.add(notifMessage));
}, },
toggleWorkerSleepSchedule() { toggleWorkerSleepSchedule() {
let verb = this.workerSleepSchedule.is_active ? 'Enabled' : 'Disabled'; this.workerSleepSchedule.is_active = !this.workerSleepSchedule.is_active;
let verb = this.workerSleepScheduleStatusLabel;
this.setWorkerSleepSchedule(`${verb} schedule for worker ${this.workerData.name}`); this.setWorkerSleepSchedule(`${verb} schedule for worker ${this.workerData.name}`);
}, },
saveWorkerSleepSchedule() { saveWorkerSleepSchedule() {
@ -214,6 +208,21 @@ export default {
</script> </script>
<style scoped> <style scoped>
.sub-title {
position: relative;
}
.switch {
top: 1px;
}
.sub-title-buttons {
position: absolute;
right: var(--spacer);
bottom: var(--spacer-xs);
}
.sleep-schedule .btn-bar label+.btn { .sleep-schedule .btn-bar label+.btn {
margin-left: var(--spacer-sm); margin-left: var(--spacer-sm);
} }