Skip to content

Commit

Permalink
Добавил панель админа
Browse files Browse the repository at this point in the history
  • Loading branch information
danilpavlov committed Dec 19, 2024
1 parent a7658be commit 14d3eb1
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/src/api/serverApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// frontend/src/api/serverApi.js
const BASE_URL = 'http://your-backend-url/api';
const BASE_URL = 'http://localhost:8080';

export const getServers = async () => {
const response = await fetch(`${BASE_URL}/servers`);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import RegisterView from '../views/RegisterView.vue';
import LoginView from '../views/LoginView.vue';
import UserPanelView from '../views/UserPanelView.vue';
import UserJobsView from '../views/UserJobsView.vue';
import AdminPanelView from '../views/AdminPanelView.vue';

const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
Expand All @@ -24,6 +25,7 @@ const router = createRouter({
{ path: '/register', name: 'Register', component: RegisterView },
{ path: '/login', name: 'Login', component: LoginView },
{ path: '/user-panel', name: 'UserPanel', component: UserPanelView },
{ path: '/admin-panel', name: 'AdminPanel', component: AdminPanelView },
{ path: '/user/:id/jobs', name: 'UserJobs', component: UserJobsView },
],
})
Expand Down
80 changes: 80 additions & 0 deletions frontend/src/views/AdminPanelView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<template>
<div class="admin-panel">
<h1>Admin Panel</h1>
<ServerForm />

<button @click="loadServers">Refresh Servers</button>
<h2>Servers</h2>
<ul>
<li v-for="server in servers" :key="server.id">
<h3>{{ server.hostname }}</h3>
<p>{{ server.description }}</p>
<p>Status: {{ server.status }}</p>
<p>Address: {{ server.address }}</p>
<p>CPU: {{ server.cpu_info }}</p>
<p>GPU: {{ server.gpu_info }}</p>
<p>RAM: {{ server.ram_size_gb }} GB</p>
</li>
</ul>
</div>
</template>

<script>
import { ref, onMounted } from 'vue';
import { getServers } from '../api/serverApi';
import ServerForm from '../components/ServerForm.vue';
export default {
components: { ServerForm },
setup() {
const servers = ref([]);
const loadServers = async () => {
servers.value = []
try {
const response = await getServers();
console.log('SERVERS:', response);
response.forEach((server) => {
console.log(server)
servers.value.push(server);
});
} catch (error) {
alert('Failed to load servers');
}
};
onMounted(loadServers);
return {
servers,
loadServers,
};
},
};
</script>

<style scoped>
.admin-panel {
max-width: 1000px;
margin: auto;
padding: 20px;
}
h1, h2 {
text-align: center;
}
ul {
display: flex;
flex-wrap: wrap;
list-style-type: none;
padding: 0;
gap: 10px;
}
li {
border: 1px solid #ddd;
padding: 10px;
margin-bottom: 10px;
flex: 1 1 calc(33.333% - 20px); /* Adjust the width as needed */
box-sizing: border-box;
}
</style>

0 comments on commit 14d3eb1

Please sign in to comment.