generated from moevm/nsql-clean-tempate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from moevm/users-client
Users client
- Loading branch information
Showing
16 changed files
with
346 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<div class="container"> | ||
<div class="card col-12 col-md-6 m-auto mt-2"> | ||
<div class="card-body m-auto"> | ||
<h1 class="text-center">Войти</h1> | ||
<FormKit v-model="login" type="text" label="Логин" /> | ||
<FormKit v-model="password" type="password" label="Пароль" /> | ||
|
||
<div class="text-end"> | ||
<button class="btn btn-primary" @click="doLogin">Войти</button> | ||
</div> | ||
|
||
<div class="text-end mt-3"> | ||
<div class="alert alert-danger"> | ||
<button class="d-block w-100 btn btn-danger me-2" @click="devLogin"> | ||
Войти dev | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref } from "vue"; | ||
import { useUserStore } from "@/store/user"; | ||
import { useToaster } from "@/store/toaster"; | ||
import { ToastTypes } from "@/config/toast"; | ||
import { useRouter } from "vue-router"; | ||
import { routeNames } from "@/router"; | ||
const router = useRouter(); | ||
const userStore = useUserStore(), | ||
toaster = useToaster(); | ||
const login = ref(""), | ||
password = ref(""); | ||
async function doLogin() { | ||
// await devLogin(); | ||
toaster.addToast({ | ||
title: "Выполнено", | ||
body: "Вы вошли в аккаунт", | ||
type: ToastTypes.primary, | ||
}); | ||
} | ||
async function devLogin() { | ||
await userStore.devLogin(); | ||
toaster.addToast({ | ||
title: "Выполнено", | ||
body: "Выполнен вход для разработчика", | ||
type: ToastTypes.primary, | ||
}); | ||
router.push({ name: routeNames.Home }); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { api } from "@/api"; | ||
import { User } from "@/types/users"; | ||
|
||
function fetchUser() { | ||
return api.get<User>("/auth/login"); | ||
} | ||
|
||
function login(login: string, password: string) { | ||
return api.post<User>("/auth/login", { login, password }); | ||
} | ||
|
||
function logout() { | ||
return api.delete("/auth/login"); | ||
} | ||
|
||
function devLogin() { | ||
return api.get<User>("/auth/login/dev"); | ||
} | ||
|
||
export const UserAPI = { fetchUser, login, logout, devLogin }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<template> | ||
<div class="container-lg mt-3"> | ||
<h3>Пользователи</h3> | ||
<AgGridVue | ||
class="ag-theme-alpine" | ||
:column-defs="columnDefs" | ||
:row-data="users" | ||
:grid-options="options" | ||
@grid-ready="fitActionsColumn" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { AgGridVue } from "ag-grid-vue3"; | ||
import { ColDef, GridOptions } from "ag-grid-community"; | ||
import { | ||
fitActionsColumn, | ||
getActionsColDef, | ||
getDefaultGridOptions, | ||
} from "@/ag-grid/factory"; | ||
import { MapInfo } from "@/types/maps"; | ||
import { onBeforeMount, ref } from "vue"; | ||
import { User } from "@/types/users"; | ||
import { UserAdminAPI } from "@/components/routes/users/api"; | ||
import { useRouter } from "vue-router"; | ||
import { useUserStore } from "@/store/user"; | ||
import { routeNames } from "@/router"; | ||
import { ToastTypes } from "@/config/toast"; | ||
import { useToaster } from "@/store/toaster"; | ||
const router = useRouter(); | ||
const userStore = useUserStore(), | ||
toaster = useToaster(); | ||
const users = ref<User[]>([]); | ||
onBeforeMount(async () => { | ||
users.value = (await UserAdminAPI.getUsers()).data; | ||
}); | ||
const columnDefs: ColDef<User>[] = [ | ||
{ headerName: "Id", field: "_id.$oid", flex: 2, minWidth: 80 }, | ||
{ headerName: "Логин", field: "login", flex: 3, minWidth: 180 }, | ||
{ headerName: "Имя", field: "name", flex: 3, minWidth: 100 }, | ||
{ headerName: "Роль", field: "role", flex: 3, minWidth: 90 }, | ||
{ | ||
...getActionsColDef([ | ||
{ | ||
tooltip: "Войти", | ||
icon: "bi bi-box-arrow-in-right", | ||
button: "btn-primary", | ||
onClicked: async (action, data) => { | ||
await userStore.login(data.login, data.password); | ||
await router.push({ name: routeNames.Home }); | ||
toaster.addToast({ | ||
title: "Выполнено", | ||
body: `Выполнен вход за пользователя ${data.name} (${data.login})`, | ||
type: ToastTypes.primary, | ||
}); | ||
}, | ||
}, | ||
{ | ||
tooltip: "Удалить", | ||
icon: "bi bi-trash", | ||
button: "btn-danger", | ||
onClicked: (action, data) => { | ||
/**/ | ||
}, | ||
}, | ||
{ | ||
tooltip: "Редактировать", | ||
icon: "bi bi-gear", | ||
button: "btn-warning", | ||
onClicked: (action, data) => { | ||
/**/ | ||
}, | ||
}, | ||
]), | ||
minWidth: 180, | ||
}, | ||
]; | ||
const options: GridOptions<MapInfo> = { | ||
...getDefaultGridOptions(), | ||
domLayout: "autoHeight", | ||
animateRows: true, | ||
}; | ||
</script> | ||
|
||
<style scoped lang="scss"></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { api } from "@/api"; | ||
import { User } from "@/types/users"; | ||
import { UserCreation } from "@/components/routes/users/types"; | ||
|
||
function getUsers() { | ||
return api.get<User[]>("/users"); | ||
} | ||
|
||
function createUser(user: UserCreation) { | ||
return api.post("/users", user); | ||
} | ||
|
||
function deleteUser(id: string) { | ||
return api.delete(`/users/user/${id}`); | ||
} | ||
|
||
function updateUser(id: string, user: UserCreation) { | ||
return api.put(`/users/user/${id}`, user); | ||
} | ||
|
||
export const UserAdminAPI = { getUsers, createUser, deleteUser, updateUser }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { User } from "@/types/users"; | ||
|
||
export type UserCreation = Omit<User, "_id">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum UserRole { | ||
user = "user", | ||
admin = "admin", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.