started working on autocomplete addEmployee

This commit is contained in:
Sockenklaus
2021-10-07 00:23:19 +02:00
parent 2057de63dd
commit 5ad0ca7e2e
8 changed files with 119 additions and 140 deletions

View File

@@ -1,35 +1,70 @@
<template lang="pug">
h1(v-if="isValid(startDate)") {{format(startDate, "MMMM y", {locale: de})}}
//- div {{employees}}
table(class='table table-sm' v-for="(row, rIndex) in dates" :key="rIndex")
div.modal.fade#addEmployeeModal(
tabindex="-1"
aria-labelledby="addEmployeeModalLabel"
aria-hidden="true"
data-bs-focus="true"
)
.modal-dialog
.modal-content
.modal-header
h5.modal-title#addEmployeeModalLabel Mitarbeiter hinzufügen
button.btn-close(type="button" data-bs-dismiss="modal" aria-label="Close")
.modal-body
o-autocomplete(
ref="autocomplete"
inputClass="form-control"
id="addEmployeeInput"
:keep-first="true"
:open-on-focus="true"
placeholder="Nach Vorname / Name suchen..."
v-model="addEmployeeInput"
:data="addEmployeeSuggestions"
ariaAutocomplete="list"
field="name"
menuPosition="bottom"
menuClass="list-group"
itemClass="list-group-item text-start"
itemHoverClass="bg-secondary bg-opacity-10"
@select="addEmployee"
)
//- TODO: #2 Can't highlight list-group-item when hovering
<!-- Schedule Table -->
table(class='table table-bordered table-sm' v-for="(row, rIndex) in dates" :key="rIndex")
thead
tr
td(style="width: 200px")
td(v-for="(day, index) in weekdays" :key="index" :class="{'text-body text-opacity-25' : row[index] === null}") {{ day }}
td(style="width: 100px") {{ format(startDate, "MMMM", {locale: de}) }}
td(v-for="(day, index) in weekdays" :key="index" :class="{'text-body text-opacity-50 bg-secondary bg-opacity-10' : row[index] === null}") {{ day }}
tr
td
td(v-for="(date, dIndex) in row" :key="dIndex")
td {{ format(startDate, "y") }}
td(v-for="(date, dIndex) in row" :key="dIndex" :class="{'bg-secondary bg-opacity-10' : row[dIndex] === null}")
template(v-if="date !== null") {{ format(date, "dd.MM.")}}
tbody
tr()
td {{}}
td(v-for="(date, dIndex) in row" :key="dIndex") &nbsp;
td(v-for="(date, dIndex) in row" :key="dIndex" :class="{'bg-secondary bg-opacity-10' : row[dIndex] === null}") &nbsp;
tr()
td(style="width: 250px")
o-autocomplete(
:keep-first="true"
:open-on-focus="true"
inputClass="form-control form-control-sm"
)
td(v-for="(date, dIndex) in row" :key="dIndex") &nbsp;
button(
class="btn btn-outline-secondary btn-sm"
data-bs-toggle="modal"
data-bs-target="#addEmployeeModal"
@click="openModal(rIndex)"
)
i(class="bi bi-plus-lg")
td(v-for="(date, dIndex) in row" :key="dIndex" :class="{'bg-secondary bg-opacity-10' : row[dIndex] === null}") &nbsp;
</template>
<script setup lang="ts">
import { toRef, computed, ref } from 'vue'
import { toRef, watch, computed, ref } from 'vue'
import { storeToRefs } from 'pinia'
import { useEmployees } from '/src/stores/employees.js'
import { addMonths, subDays, addDays, format, getISODay, isValid, eachDayOfInterval } from 'date-fns'
@@ -42,6 +77,9 @@ table(class='table table-sm' v-for="(row, rIndex) in dates" :key="rIndex")
startDate: Date,
initialOffset: number
}>()
const addEmployeeRow = ref()
const addEmployeeInput = ref('')
const autocomplete = ref(null)
const startDate = toRef(props, 'startDate')
const endDate = computed(():Date => subDays(addMonths(startDate.value, 1), 1))
@@ -50,7 +88,8 @@ table(class='table table-sm' v-for="(row, rIndex) in dates" :key="rIndex")
* Local variables
*/
const weekdays : string[] = doubleWeekdays()
const { employees } = storeToRefs(useEmployees())
const store = useEmployees()
const { employees } = storeToRefs(store)
const daysInMonth : Date[] = eachDayOfInterval({
start: startDate.value,
@@ -93,12 +132,36 @@ table(class='table table-sm' v-for="(row, rIndex) in dates" :key="rIndex")
return arr.concat(arr)
}
const addEmployeeSuggestions = computed(() => {
return employees.value.filter((el: { name: string }) => {
return el.name.toLowerCase().search(addEmployeeInput.value.toLowerCase()) > 0
})
})
/**
* TODO: #1 Can't focus the autocomplete input
*/
function openModal(index: number) {
let temp : HTMLElement = autocomplete.value ?? new HTMLElement()
temp.focus()
addEmployeeRow.value = index
}
function addEmployee(){
console.log("hi")
console.log(dates.value)
}
</script>
<style scoped>
table {
table-layout: fixed
}
.o-acp__item.list-group-item:hover {
background-color: aliceblue !important;
}
</style>