2021-06-07 17:41:25 +02:00
|
|
|
<template>
|
2021-06-25 19:28:41 +02:00
|
|
|
<div class="container">
|
2021-06-07 17:41:25 +02:00
|
|
|
<h1>Suche</h1>
|
|
|
|
<form @submit.prevent="submitSearch()">
|
2021-06-25 19:28:41 +02:00
|
|
|
<div class="row">
|
|
|
|
<div class="col">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
class="form-control"
|
|
|
|
id="searchText"
|
|
|
|
v-model="searchText"
|
|
|
|
/>
|
2021-06-07 17:41:25 +02:00
|
|
|
</div>
|
2021-06-25 19:28:41 +02:00
|
|
|
<div class="col">
|
|
|
|
<button type="submit" class="btn btn-primary mb-4">
|
|
|
|
Suche Starten
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-07 17:41:25 +02:00
|
|
|
</form>
|
2021-06-25 19:28:41 +02:00
|
|
|
<div
|
|
|
|
class="alert alert-danger mb-4 mt-4"
|
|
|
|
role="alert"
|
|
|
|
v-if="showErrorMessage"
|
|
|
|
>
|
|
|
|
Bei der Suche ist ein Fehler aufgetreten
|
2021-06-07 17:41:25 +02:00
|
|
|
</div>
|
2021-07-26 17:53:28 +02:00
|
|
|
<div v-if="!searchResults">Keine Suchergebnisse Gefunden</div>
|
|
|
|
<div v-else>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-4 p-2" v-for="result in searchResults" :key="result.user_id">
|
|
|
|
<router-link :to="{ path: `/s/profile/${result.user_id}` }">
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-body">
|
|
|
|
<h5 class="card-title">
|
|
|
|
{{ result.nickname
|
|
|
|
}}<span v-if="result.pronouns"> ({{ result.pronouns }})</span>
|
|
|
|
</h5>
|
|
|
|
<h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
|
|
|
|
<p class="card-text" v-if="result.skills">
|
|
|
|
Fähigkeiten:
|
|
|
|
<span
|
|
|
|
v-for="skill in result.skills"
|
|
|
|
:key="skill.skill.name"
|
|
|
|
>{{ skill.skill.name }} </span
|
|
|
|
>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-25 19:28:41 +02:00
|
|
|
</div>
|
2021-06-07 17:41:25 +02:00
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
|
|
|
|
export default {
|
2021-06-25 19:28:41 +02:00
|
|
|
name: "Search",
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showErrorMessage: false,
|
|
|
|
searchText: "",
|
2021-07-26 17:53:28 +02:00
|
|
|
searchResults: null,
|
2021-06-25 19:28:41 +02:00
|
|
|
};
|
2021-06-07 17:41:25 +02:00
|
|
|
},
|
|
|
|
methods: {
|
2021-06-25 19:28:41 +02:00
|
|
|
async submitSearch() {
|
|
|
|
this.showErrorMessage = false;
|
|
|
|
try {
|
2021-07-26 17:10:28 +02:00
|
|
|
const result = await this.axios.get(
|
|
|
|
`${process.env.VUE_APP_API_URL}/users/profiles`,
|
2021-06-25 19:28:41 +02:00
|
|
|
{
|
2021-07-26 17:10:28 +02:00
|
|
|
headers: {
|
|
|
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
|
|
|
},
|
2021-06-07 17:41:25 +02:00
|
|
|
}
|
2021-06-25 19:28:41 +02:00
|
|
|
);
|
2021-07-26 17:10:28 +02:00
|
|
|
console.log(result)
|
2021-07-26 17:53:28 +02:00
|
|
|
|
|
|
|
this.searchResults = [
|
|
|
|
{"nickname": "peternichtlustig","user_id": 1,"skills": [ { "level": 5, "profile_id": 1, "skill": { "icon_url": "/skills/1/icon", "id": 1, "name": "PHP" } }, { "level": 3, "profile_id": 1, "skill": { "icon_url": "/skills/3/icon", "id": 3, "name": "Python" } } ],},
|
|
|
|
{"nickname": "Petra","user_id": 3,"skills": [ { "level": 3, "profile_id": 1, "skill": { "icon_url": "/skills/3/icon", "id": 3, "name": "Python" } } ],},
|
|
|
|
{"nickname": "Paul","user_id": 4,"skills": [ { "level": 5, "profile_id": 1, "skill": { "icon_url": "/skills/1/icon", "id": 1, "name": "PHP" } } ],},
|
|
|
|
{"nickname": "Keine Skills Sebastian","user_id": 5,}
|
|
|
|
]
|
2021-07-26 17:10:28 +02:00
|
|
|
|
2021-06-25 19:28:41 +02:00
|
|
|
} catch (error) {
|
2021-07-26 17:10:28 +02:00
|
|
|
console.error(error);
|
2021-06-25 19:28:41 +02:00
|
|
|
this.showErrorMessage = true;
|
2021-06-07 17:41:25 +02:00
|
|
|
}
|
2021-06-25 19:28:41 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2021-06-07 17:41:25 +02:00
|
|
|
</script>
|