Skip to content

Commit 0b0b80d

Browse files
committed
Add search box to server pages
1 parent b1b6a7e commit 0b0b80d

File tree

4 files changed

+111
-10
lines changed

4 files changed

+111
-10
lines changed

resources/assets/scripts/components/core/Navigation.vue

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
<template>
2-
<div class="nav">
3-
<div class="logo">
2+
<div class="nav flex">
3+
<div class="logo flex-1">
44
<router-link :to="{ name: 'dashboard' }">
55
Pterodactyl
66
</router-link>
77
</div>
8-
<div class="menu">
8+
<div class="search-box flex-none" v-if="$route.name !== 'dashboard'">
9+
<input type="text" class="search-input" id="searchInput" placeholder="Search..."
10+
:class="{ 'has-search-results': servers.length > 0 && searchActive }"
11+
v-on:focus="searchActive = true"
12+
v-on:blur="searchActive = false"
13+
v-on:input="search"
14+
v-model="searchTerm"
15+
/>
16+
<div class="search-results select-none" :class="{ 'hidden': servers.length === 0 || !searchActive }">
17+
<router-link
18+
v-for="server in servers"
19+
:key="server.identifier"
20+
:to="{ name: 'server', params: { id: server.identifier } }"
21+
>
22+
<div class="flex items-center">
23+
<div class="flex-1">
24+
<span class="font-bold text-grey-darkest">{{ server.name }}</span><br />
25+
<span class="font-light text-grey-dark text-sm" v-if="server.description.length > 0">{{ server.description }}</span>
26+
</div>
27+
<div class="flex-none">
28+
<span class="pillbox bg-indigo">{{ server.node }}</span>
29+
</div>
30+
</div>
31+
</router-link>
32+
</div>
33+
</div>
34+
<div class="menu flex-none">
935
<ul>
1036
<li>
1137
<router-link :to="{ name: 'dashboard' }">
@@ -33,12 +59,56 @@
3359
</template>
3460

3561
<script>
62+
import debounce from 'lodash/debounce';
63+
import { mapState } from 'vuex';
3664
import { LogOutIcon, ServerIcon, SettingsIcon, UserIcon } from 'vue-feather-icons'
3765
3866
export default {
3967
name: 'navigation',
4068
components: { LogOutIcon, ServerIcon, SettingsIcon, UserIcon },
69+
70+
data: function () {
71+
return {
72+
searchActive: false,
73+
};
74+
},
75+
76+
computed: {
77+
...mapState('dashboard', ['servers']),
78+
searchTerm: {
79+
get: function () {
80+
return this.$store.getters['dashboard/getSearchTerm'];
81+
},
82+
set: function (value) {
83+
this.$store.dispatch('dashboard/setSearchTerm', value);
84+
}
85+
}
86+
},
87+
4188
methods: {
89+
search: debounce(function () {
90+
if (this.searchTerm.length > 3) {
91+
this.gatherSearchResults(this.searchTerm);
92+
}
93+
}, 500),
94+
95+
gatherSearchResults: function () {
96+
this.$store.dispatch('dashboard/loadServers')
97+
.then(() => {
98+
if (this.servers.length === 0) {
99+
}
100+
})
101+
.catch(err => {
102+
console.error(err);
103+
const response = err.response;
104+
if (response.data && isObject(response.data.errors)) {
105+
response.data.errors.forEach(error => {
106+
this.error(error.detail);
107+
});
108+
}
109+
});
110+
},
111+
42112
doLogout: function () {
43113
this.$store.commit('auth/logout');
44114
return window.location = this.route('auth.logout');

resources/assets/scripts/components/dashboard/ServerBox.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
* Poll the API for changes every 10 seconds when the component is mounted.
9999
*/
100100
mounted: function () {
101-
console.log(this.server);
102101
this.$options.dataGetTimeout = window.setInterval(() => {
103102
this.getResourceUse();
104103
}, 10000);

resources/assets/styles/components/miscellaneous.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ code {
7171
@apply .inline-block .rounded-full .text-white .text-center .leading-none .justify-center .w-8 .h-8 .mr-2 .flex .flex-row .items-center;
7272
}
7373

74-
& .pillbox {
75-
@apply .rounded-full .px-2 .py-1 .text-white .font-medium .leading-none .text-xs;
76-
}
77-
7874
& a, & a:visited {
7975
@apply .no-underline .text-grey-darkest;
8076
}
@@ -89,6 +85,10 @@ code {
8985
}
9086
}
9187

88+
.pillbox {
89+
@apply .rounded-full .px-2 .py-1 .text-white .font-medium .leading-none .text-xs;
90+
}
91+
9292
.server-search {
9393
@apply .w-full .my-4;
9494

resources/assets/styles/components/navigation.css

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,39 @@
1111
}
1212

1313
@screen xsx {
14-
@apply .hidden
14+
@apply .hidden;
15+
}
16+
}
17+
18+
& > .search-box {
19+
& > .search-input {
20+
@apply .text-sm .p-2 .mt-3 .mx-3 .rounded .border .border-blue-darker .bg-grey-lightest .text-grey-darkest;
21+
width: 26rem;
22+
opacity: 0.7;
23+
transition: ease-in-out opacity 150ms;
24+
25+
&:focus {
26+
@apply .border-blue-darkest;
27+
opacity: 1;
28+
}
29+
30+
&.has-search-results {
31+
@apply .border-b-0 .rounded-b-none;
32+
opacity: 1 !important;
33+
}
34+
}
35+
36+
& .search-results {
37+
@apply .absolute .bg-grey-lightest .border .border-blue-darkest .border-t-0 .rounded .rounded-t-none .p-2 .mx-3 .z-50;
38+
width: 26rem;
39+
40+
& > a {
41+
@apply .block .no-underline .p-2 .rounded;
42+
43+
&:hover {
44+
@apply .bg-grey-lighter;
45+
}
46+
}
1547
}
1648
}
1749

@@ -35,7 +67,7 @@
3567
}
3668

3769
@screen sm {
38-
@apply .float-right .mx-8 .inline-block;
70+
@apply .float-right .mr-8 .inline-block;
3971
}
4072
}
4173
}

0 commit comments

Comments
 (0)