File tree 11 files changed +45
-38
lines changed
11 files changed +45
-38
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ import RoleBadge from "@/Components/RoleBadge.vue";
36
36
<p class =" truncate" >
37
37
{{ $page.props.auth.user.login }}
38
38
</p >
39
- <RoleBadge :role =" $page.props.auth.user.role.name " />
39
+ <RoleBadge :role =" $page.props.auth.user.role" />
40
40
</div >
41
41
</div >
42
42
<nav class =" grid space-y-1 pt-2" >
Original file line number Diff line number Diff line change 1
1
<script setup>
2
- import { computed } from ' vue' ;
3
- import { trans } from ' laravel-vue-i18n' ;
2
+ import { getRoleName } from " @/Utils/role.js" ;
4
3
5
4
const props = defineProps ({
6
5
role: {
7
- type: String ,
6
+ type: Object ,
8
7
required: true ,
9
8
},
10
9
});
11
-
12
- const roleName = computed (() => {
13
- return trans (` role.name.${ props .role .toLowerCase ()} ` , ' role.name.unknown' );
14
- });
15
10
</script >
16
11
17
12
<template >
18
13
<div class =" badge badge-secondary rounded" >
19
- {{ roleName }}
14
+ {{ getRoleName(role) }}
20
15
</div >
21
16
</template >
Original file line number Diff line number Diff line change 2
2
import DashboardLayout from ' @/Layouts/Dashboard.vue' ;
3
3
import { useForm } from ' @inertiajs/vue3' ;
4
4
import { ref , watch , computed } from ' vue' ;
5
+ import { getRoleName } from ' @/Utils/role' ;
6
+ import { getGenderName } from " @/Utils/gender" ;
5
7
import BackButton from " @/Components/Buttons/BackButton.vue" ;
6
8
import CreateButton from " @/Components/Buttons/CreateButton.vue" ;
7
9
import InputError from " @/Components/InputError.vue" ;
@@ -146,7 +148,7 @@ const store = () => {
146
148
class =" select select-bordered w-full focus:ring-1 focus:ring-offset-2 focus:ring-offset-base-200 focus:ring-orange-500"
147
149
v-model =" form.role" >
148
150
<option disabled value =" " >{{ ('Назначьте роль пользователю') }}</option >
149
- <option v-for =" role in roles" :key =" role.id" :value =" role.id" >{{ role.name }}</option >
151
+ <option v-for =" role in roles" :key =" role.id" :value =" role.id" >{{ getRoleName( role) }}</option >
150
152
</select >
151
153
<InputError :message =" form.errors.role" />
152
154
</div >
@@ -225,7 +227,7 @@ const store = () => {
225
227
class =" select select-bordered w-full focus:ring-1 focus:ring-offset-2 focus:ring-offset-base-200 focus:ring-orange-500"
226
228
v-model =" form.gender" >
227
229
<option disabled value =" " >{{ ('Укажите пол пользователя') }}</option >
228
- <option v-for =" gender in genders" :value =" gender.id" >{{ gender.name }}</option >
230
+ <option v-for =" gender in genders" :value =" gender.id" >{{ getGenderName( gender) }}</option >
229
231
</select >
230
232
<InputError :message =" form.errors.gender" />
231
233
</div >
Original file line number Diff line number Diff line change 2
2
import DashboardLayout from ' @/Layouts/Dashboard.vue' ;
3
3
import { useForm } from ' @inertiajs/vue3' ;
4
4
import { ref , watch , computed } from ' vue' ;
5
+ import { getRoleName } from ' @/Utils/role' ;
6
+ import { getGenderName } from " @/Utils/gender" ;
5
7
import BackButton from " @/Components/Buttons/BackButton.vue" ;
6
8
import UpdateButton from " @/Components/Buttons/UpdateButton.vue" ;
7
9
import InputError from " @/Components/InputError.vue" ;
@@ -139,7 +141,7 @@ function update() {
139
141
v-model =" form.role"
140
142
required >
141
143
<option disabled >{{ ('Назначьте роль пользователю...') }}</option >
142
- <option v-for =" role in roles" :key =" role.id" :value =" role.id" >{{ role.name }}</option >
144
+ <option v-for =" role in roles" :key =" role.id" :value =" role.id" >{{ getRoleName( role) }}</option >
143
145
</select >
144
146
<InputError :message =" form.errors.role" />
145
147
</div >
@@ -218,7 +220,7 @@ function update() {
218
220
class =" select select-bordered w-full focus:ring-1 focus:ring-offset-2 focus:ring-offset-base-200 focus:ring-orange-500"
219
221
v-model =" form.gender" >
220
222
<option disabled value =" " >{{ ('Укажите пол пользователя') }}</option >
221
- <option v-for =" gender in genders" :value =" gender.id" >{{ gender.name }}</option >
223
+ <option v-for =" gender in genders" :value =" gender.id" >{{ getGenderName( gender) }}</option >
222
224
</select >
223
225
<InputError :message =" form.errors.gender" />
224
226
</div >
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ const confirmDeleteUser = (id) => {
116
116
</div >
117
117
</td >
118
118
<td >
119
- <RoleBadge :role =" user.role.name " />
119
+ <RoleBadge :role =" user.role" />
120
120
</td >
121
121
<td >{{ user.created_at }}</td >
122
122
<td >
Original file line number Diff line number Diff line change
1
+ import { trans } from 'laravel-vue-i18n' ;
2
+
3
+ export const getGenderName = ( gender , separator = '-' ) => {
4
+ if ( ! gender ?. name ) {
5
+ return trans ( 'gender.name.unknown' ) ;
6
+ }
7
+
8
+ const formattedgenderName = gender . name . toLowerCase ( ) . replace ( / \s + / g, separator ) ;
9
+ const translation = trans ( `gender.name.${ formattedgenderName } ` ) ;
10
+
11
+ return translation === `gender.name.${ formattedgenderName } ` ? gender . name : translation ;
12
+ } ;
Original file line number Diff line number Diff line change
1
+ import { trans } from 'laravel-vue-i18n' ;
2
+
3
+ export const getRoleName = ( role , separator = '-' ) => {
4
+ if ( ! role ?. name ) {
5
+ return trans ( 'role.name.unknown' ) ;
6
+ }
7
+
8
+ const formattedRoleName = role . name . toLowerCase ( ) . replace ( / \s + / g, separator ) ;
9
+ const translation = trans ( `role.name.${ formattedRoleName } ` ) ;
10
+
11
+ return translation === `role.name.${ formattedRoleName } ` ? role . name : translation ;
12
+ } ;
Original file line number Diff line number Diff line change 25
25
"role.name.user" : " User" ,
26
26
"role.name.unknown" : " Unknown role" ,
27
27
28
+ "gender.name.male" : " Male" ,
29
+ "gender.name.female" : " Female" ,
30
+ "gender.name.not-specified" : " Not specified" ,
31
+
28
32
"dashboard.page.main.title" : " Dashboard" ,
29
33
"dashboard.page.settings.title" : " System settings" ,
30
34
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 25
25
"role.name.user" : " Пользователь" ,
26
26
"role.name.unknown" : " Неизвестная роль" ,
27
27
28
+ "gender.name.male" : " Мужской" ,
29
+ "gender.name.female" : " Женский" ,
30
+ "gender.name.not-specified" : " Не указано" ,
31
+
28
32
"dashboard.page.main.title" : " Панель управления" ,
29
33
"dashboard.page.settings.title" : " Настройки системы" ,
30
34
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments