Skip to content
Snippets Groups Projects
Commit d9ff5f10 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch '21-allow-manual-passing-of-absence-reasons-to-chip-select' into 'master'

Resolve "Allow manual passing of absence reasons to chip select"

Closes #21

See merge request AlekSIS/onboarding/AlekSIS-App-Kolego!33
parents 3806fc6d 2c714054
No related branches found
No related tags found
1 merge request!33Resolve "Allow manual passing of absence reasons to chip select"
Pipeline #192009 failed
...@@ -6,11 +6,15 @@ export default { ...@@ -6,11 +6,15 @@ export default {
data() { data() {
return { return {
absenceReasons: [], absenceReasons: [],
innerValue: undefined,
}; };
}, },
apollo: { apollo: {
absenceReasons: gqlAbsenceReasons, absenceReasons: {
query: gqlAbsenceReasons,
skip() {
return this.customAbsenceReasons > 0;
},
},
}, },
props: { props: {
allowEmpty: { allowEmpty: {
...@@ -22,6 +26,20 @@ export default { ...@@ -22,6 +26,20 @@ export default {
required: false, required: false,
default: "present", default: "present",
}, },
customAbsenceReasons: {
type: Array,
required: false,
default: [],
},
},
computed: {
innerAbsenceReasons() {
if (this.customAbsenceReasons.length > 0) {
return this.customAbsenceReasons;
} else {
return this.absenceReasons;
}
},
}, },
methods: { methods: {
emit(value) { emit(value) {
...@@ -51,7 +69,7 @@ export default { ...@@ -51,7 +69,7 @@ export default {
{{ $t("kolego.absence_reason.present") }} {{ $t("kolego.absence_reason.present") }}
</v-btn> </v-btn>
<v-btn <v-btn
v-for="absenceReason in absenceReasons" v-for="absenceReason in innerAbsenceReasons"
:key="'absence-reason-' + absenceReason.id" :key="'absence-reason-' + absenceReason.id"
:color="absenceReason.colour" :color="absenceReason.colour"
outlined outlined
......
...@@ -17,12 +17,10 @@ export default { ...@@ -17,12 +17,10 @@ export default {
absenceReasons: { absenceReasons: {
query: gqlAbsenceReasons, query: gqlAbsenceReasons,
result({ data }) { result({ data }) {
if (!this.innerValue) { this.setDefaultReason(data.absenceReasons);
const defaultReason = data.absenceReasons.find((ar) => ar.default); },
if (defaultReason) { skip() {
this.updateInnerValue(defaultReason.id); return this.customAbsenceReasonsExists;
}
}
}, },
}, },
}, },
...@@ -46,6 +44,11 @@ export default { ...@@ -46,6 +44,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
customAbsenceReasons: {
type: Array,
required: false,
default: [],
},
}, },
computed: { computed: {
/** /**
...@@ -59,24 +62,51 @@ export default { ...@@ -59,24 +62,51 @@ export default {
*/ */
showChips() { showChips() {
return ( return (
!this.$apollo.queries.absenceReasons.loading || ((!this.$apollo.queries.absenceReasons.loading &&
(this.allowEmpty && this.value === this.emptyValue) this.absenceReasons.length) ||
this.customAbsenceReasonsExists ||
(this.allowEmpty && this.value === this.emptyValue)) &&
this.innerValue
); );
}, },
customAbsenceReasonsExists() {
return this.customAbsenceReasons.length > 0;
},
innerAbsenceReasons() {
if (this.customAbsenceReasonsExists) {
return this.customAbsenceReasons;
} else {
return this.absenceReasons;
}
},
}, },
mounted() { mounted() {
this.innerValue = this.value; this.innerValue = this.value;
if (this.customAbsenceReasons) {
this.setDefaultReason(this.customAbsenceReasons);
}
}, },
watch: { watch: {
value(newValue) { value(newValue) {
this.innerValue = newValue; this.innerValue = newValue;
}, },
customAbsenceReasons(newValue) {
this.setDefaultReason(newValue);
},
}, },
methods: { methods: {
updateInnerValue($event) { updateInnerValue($event) {
this.innerValue = $event; this.innerValue = $event;
this.$emit("input", $event); this.$emit("input", $event);
}, },
setDefaultReason(absenceReasons) {
if (!this.innerValue) {
const defaultReason = absenceReasons.find((ar) => ar.default);
if (defaultReason) {
this.updateInnerValue(defaultReason.id);
}
}
},
}, },
}; };
</script> </script>
...@@ -103,7 +133,7 @@ export default { ...@@ -103,7 +133,7 @@ export default {
</v-avatar> </v-avatar>
</v-chip> </v-chip>
<absence-reason-chip <absence-reason-chip
v-for="absenceReason in absenceReasons" v-for="absenceReason in innerAbsenceReasons"
:key="absenceReason.id" :key="absenceReason.id"
:absence-reason="absenceReason" :absence-reason="absenceReason"
filter filter
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment