Поправил схему, добавил инфу поля в навбар если пользователь админ

This commit is contained in:
Artem VV 2023-05-19 21:15:26 +07:00
parent f721d16ace
commit a287fec381
4 changed files with 32 additions and 10 deletions

View file

@ -55,8 +55,8 @@ model timetable {
model users {
id Int @id(map: "pk_users") @default(autoincrement())
login String @unique @db.VarChar(25)
pass String? @db.VarChar(100)
is_admin Boolean? @default(false)
pass String @db.VarChar(100)
is_admin Boolean @default(false)
timetable timetable[]
user_session user_session[]
}

View file

@ -1,4 +1,10 @@
---
export interface Props {
is_user_admin: boolean;
}
const { is_user_admin } = Astro.props;
const items = [
{
href: "/",
@ -8,6 +14,14 @@ const items = [
href: "/timetable",
title: "Расписание",
},
];
if (is_user_admin) {
items.push({
href: "/users",
title: "Пользователи",
});
}
const itemsRight = [
{
href: "/logout",
title: "Выйти",
@ -28,5 +42,17 @@ const items = [
))
}
</ul>
<div class="flex-grow-1"></div>
<ul class="navbar-nav me-auto mb-2 mb-lg-0 text-white">
{
itemsRight.map((e) => (
<li class="nav-item">
<a href={e.href} class="active nav-link text-white" aria-current="page">
{e.title}
</a>
</li>
))
}
</ul>
</div>
</nav>

View file

@ -20,7 +20,7 @@ if (articleId) {
<Layout title="Создание новости">
<main data-article={article?.message} data-articleId={articleId}>
<Navbar />
<Navbar is_user_admin={user.is_admin} />
<div class="container mt-5" style="max-width: 650px;">
<div class="d-flex">
<button type="button" class="btn btn-sm btn-success flex-fill" id="saveBtn">Сохранить</button>

View file

@ -17,17 +17,13 @@ if (Astro.cookies.has("session")) {
return Astro.redirect("/login");
}
const { news, alerts } = await getNewsAndAlerts();
const items: NavbarItemType[] = [
{ text: "Новости", href: "/" },
{ text: "Расписание", href: "/timetable" },
];
const sessId = Astro.cookies.get("session").value!;
const user = (await getSessionUser(sessId))!;
---
<Layout title="Новости">
<main>
<Navbar />
<Navbar is_user_admin={user.is_admin} />
<NewsBlock />
</main>
</Layout>