2021-08-02 19:06:41 +02:00
|
|
|
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
2021-07-12 18:32:17 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
2021-07-26 16:12:23 +02:00
|
|
|
<label for="searchText" class="form-label fw-bold">{{ label }}</label>
|
|
|
|
<div class="row mb-2">
|
2021-07-12 18:32:17 +02:00
|
|
|
<div class="col">
|
|
|
|
<input
|
|
|
|
autocomplete="off"
|
|
|
|
type="text"
|
|
|
|
class="form-control"
|
|
|
|
id="searchText"
|
|
|
|
v-model="searchText"
|
|
|
|
@keyup="search()"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="col">
|
2021-07-26 16:12:23 +02:00
|
|
|
<div v-if="selectedResult">
|
2021-08-12 17:13:04 +02:00
|
|
|
<div v-if="type === 'contacttype'">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control"
|
|
|
|
id="contactContent"
|
|
|
|
v-model="contactContent"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div v-if="type === 'language'">
|
2021-07-12 18:32:17 +02:00
|
|
|
<select
|
|
|
|
class="form-select"
|
|
|
|
aria-label="Selektiere dein Level"
|
|
|
|
v-model="level"
|
|
|
|
>
|
2021-08-12 17:13:04 +02:00
|
|
|
<option v-for="(value, key) in languagesSelection" :value="key" :key="key">{{value}}</option>
|
2021-07-12 18:32:17 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
2021-08-12 17:13:04 +02:00
|
|
|
<select
|
|
|
|
class="form-select"
|
|
|
|
aria-label="Selektiere dein Level"
|
|
|
|
v-model="level"
|
|
|
|
>
|
|
|
|
<option v-for="(value, key) in levelSelection" :value="key" :key="key">{{value}}</option>
|
|
|
|
</select>
|
2021-07-12 18:32:17 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="col">
|
|
|
|
<button
|
2021-07-26 16:12:23 +02:00
|
|
|
v-if="selectedResult && !selectedResult.edit"
|
2021-07-12 18:32:17 +02:00
|
|
|
type="button"
|
2021-07-26 16:12:23 +02:00
|
|
|
class="btn btn-outline-success"
|
|
|
|
aria-label="Hinzufügen"
|
2021-07-12 18:32:17 +02:00
|
|
|
@click="addSelectedResult()"
|
|
|
|
>
|
2021-07-26 16:12:23 +02:00
|
|
|
<img
|
|
|
|
src="/img/bootstrap-icons-1.5.0/plus-lg.svg"
|
|
|
|
alt="Hinzufügen Icon"
|
|
|
|
/>
|
2021-07-12 18:32:17 +02:00
|
|
|
Hinzufügen
|
|
|
|
</button>
|
2021-07-26 16:12:23 +02:00
|
|
|
<button
|
|
|
|
v-if="selectedResult && selectedResult.edit"
|
|
|
|
type="button"
|
|
|
|
class="btn btn-outline-success"
|
|
|
|
aria-label="Hinzufügen"
|
|
|
|
@click="editSelectedResult()"
|
|
|
|
>
|
2021-08-15 20:35:15 +02:00
|
|
|
Änderung speichern
|
2021-07-26 16:12:23 +02:00
|
|
|
</button>
|
2021-07-12 18:32:17 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="" v-if="searchResults">
|
|
|
|
<ul class="list-group">
|
|
|
|
<li
|
|
|
|
class="list-group-item"
|
|
|
|
v-for="result in searchResults"
|
|
|
|
:key="result.id"
|
|
|
|
:class="{
|
2021-07-26 16:12:23 +02:00
|
|
|
'bg-info':
|
|
|
|
selectedResult &&
|
|
|
|
selectedResult.id &&
|
|
|
|
result.id === selectedResult.id,
|
2021-07-12 18:32:17 +02:00
|
|
|
}"
|
|
|
|
@click="selectedResult = result"
|
|
|
|
>
|
|
|
|
{{ result.name }}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2021-07-26 17:10:28 +02:00
|
|
|
<profile-list
|
|
|
|
:values="values"
|
|
|
|
:type="type"
|
|
|
|
:editable="true"
|
|
|
|
@edit-value="editValue($event)"
|
|
|
|
@remove-value="removeValue($event)"
|
|
|
|
></profile-list>
|
2021-07-12 18:32:17 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2021-07-26 17:10:28 +02:00
|
|
|
import ProfileList from "@/components/ProfileList";
|
|
|
|
|
2021-08-12 17:13:04 +02:00
|
|
|
import levelJson from "@/assets/skill_level.json"
|
|
|
|
import languagesJson from "@/assets/language_level.json"
|
|
|
|
|
2021-07-12 18:32:17 +02:00
|
|
|
export default {
|
|
|
|
name: "AutoComplete",
|
2021-07-26 17:10:28 +02:00
|
|
|
components: {
|
|
|
|
ProfileList,
|
|
|
|
},
|
2021-07-12 18:32:17 +02:00
|
|
|
props: {
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
values: {
|
|
|
|
type: Array,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-07-28 21:52:12 +02:00
|
|
|
iconUrl: this.apiUrl,
|
2021-07-12 18:32:17 +02:00
|
|
|
searchText: "",
|
|
|
|
contactContent: "",
|
|
|
|
searchResults: [],
|
|
|
|
showErrorMessage: false,
|
2021-08-12 17:13:04 +02:00
|
|
|
level: "1",
|
2021-07-26 16:12:23 +02:00
|
|
|
selectedResult: null,
|
2021-08-12 17:13:04 +02:00
|
|
|
levelSelection: levelJson,
|
|
|
|
languagesSelection: languagesJson,
|
2021-07-12 18:32:17 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async search() {
|
|
|
|
try {
|
|
|
|
const request = await this.axios.get(
|
2021-07-28 21:52:12 +02:00
|
|
|
`${this.apiUrl}/${this.type}s?search=${this.searchText}`,
|
2021-07-12 18:32:17 +02:00
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (request.status === 200) {
|
|
|
|
this.searchResults = request.data[`${this.type}s`];
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error();
|
|
|
|
this.showErrorMessage = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addSelectedResult() {
|
2021-07-26 16:12:23 +02:00
|
|
|
if (
|
|
|
|
this.values
|
|
|
|
.map((item) => item[this.type].id)
|
|
|
|
.includes(this.selectedResult.id)
|
|
|
|
) {
|
2021-07-12 18:32:17 +02:00
|
|
|
return false;
|
2021-07-26 16:12:23 +02:00
|
|
|
}
|
|
|
|
|
2021-07-12 18:32:17 +02:00
|
|
|
let changeValues = Object.assign(this.values);
|
|
|
|
let newValue = {
|
2021-07-26 16:12:23 +02:00
|
|
|
profile_id: localStorage.getItem("user_id"),
|
|
|
|
};
|
|
|
|
if (this.type != "contacttype") {
|
|
|
|
newValue.level = this.level;
|
|
|
|
} else {
|
|
|
|
newValue.content = this.contactContent;
|
2021-07-12 18:32:17 +02:00
|
|
|
}
|
2021-07-26 16:12:23 +02:00
|
|
|
newValue[this.type] = this.selectedResult;
|
2021-07-12 18:32:17 +02:00
|
|
|
changeValues.push(newValue);
|
|
|
|
this.searchText = "";
|
|
|
|
this.searchResults = [];
|
2021-07-26 16:12:23 +02:00
|
|
|
this.selectedResult = null;
|
2021-07-12 18:32:17 +02:00
|
|
|
this.level = 1;
|
|
|
|
this.$emit("update-values", changeValues);
|
|
|
|
},
|
2021-07-26 16:12:23 +02:00
|
|
|
editSelectedResult() {
|
|
|
|
this.values.map((item) => {
|
2021-07-26 17:10:28 +02:00
|
|
|
if (item[this.type].name == this.selectedResult.name) {
|
2021-07-26 16:12:23 +02:00
|
|
|
if (this.type != "contacttype") {
|
2021-07-26 17:10:28 +02:00
|
|
|
item.level = this.level;
|
2021-07-26 16:12:23 +02:00
|
|
|
} else {
|
2021-07-26 17:10:28 +02:00
|
|
|
item.content = this.contactContent;
|
2021-07-26 16:12:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
2021-07-26 17:10:28 +02:00
|
|
|
|
2021-07-26 16:12:23 +02:00
|
|
|
this.$emit("update-values", this.values);
|
|
|
|
},
|
2021-07-12 18:32:17 +02:00
|
|
|
removeValue(valueId) {
|
|
|
|
const newValues = this.values.filter((value) => {
|
|
|
|
if (valueId === value[this.type].id) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.$emit("update-values", newValues);
|
|
|
|
},
|
2021-07-26 16:12:23 +02:00
|
|
|
editValue(value) {
|
|
|
|
this.searchResults = [value[this.type]];
|
|
|
|
this.selectedResult = {
|
|
|
|
...value[this.type],
|
|
|
|
level: value.level,
|
|
|
|
edit: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.type != "contacttype") {
|
|
|
|
this.level = value.level;
|
|
|
|
} else {
|
|
|
|
this.contactContent = value.content;
|
|
|
|
}
|
|
|
|
this.level = value.level;
|
|
|
|
},
|
2021-07-12 18:32:17 +02:00
|
|
|
},
|
|
|
|
};
|
2021-07-28 21:52:12 +02:00
|
|
|
</script>
|