Quellcode durchsuchen

fix: authorization for dashboard

Muhammad Iqbal Afandi vor 3 Jahren
Ursprung
Commit
7725f81fe1

+ 29
- 8
app/Http/Controllers/DashboardController.php Datei anzeigen

@@ -6,6 +6,7 @@ use App\Models\Member;
6 6
 use App\Models\Mutation;
7 7
 use App\Models\TypeMember;
8 8
 use App\Models\TypeVehicle;
9
+use App\Models\User;
9 10
 use App\Services\MutationService;
10 11
 use Carbon\Carbon;
11 12
 use Illuminate\Http\Request;
@@ -20,13 +21,15 @@ class DashboardController extends Controller
20 21
      */
21 22
     public function __invoke(Request $request)
22 23
     {
23
-        $member = Member::get();
24
+        $members = Member::get();
24 25
 
25
-        $typeMember = TypeMember::get();
26
+        $typeMembers = TypeMember::get();
26 27
 
27
-        $typeVehicle = TypeVehicle::get();
28
+        $typeVehicles = TypeVehicle::get();
28 29
 
29
-        $mutation = Mutation::whereYear('created_at', date('Y'))
30
+        $users = User::get();
31
+
32
+        $mutations = Mutation::whereYear('created_at', date('Y'))
30 33
             ->get()
31 34
             ->groupBy([
32 35
                 fn($mutation) => $mutation->type,
@@ -41,31 +44,49 @@ class DashboardController extends Controller
41 44
                 //     'amount' => ...,
42 45
                 //     'amountLabel' => ...,
43 46
                 //     'value' => ...,
47
+                //     'roleId' => [...,...]
44 48
                 // ],
45 49
                 [
46 50
                     'title' => __('words.member'),
47 51
                     'icon' => 'pi pi-id-card',
48
-                    'amount' => $member->count(),
52
+                    'amount' => $members->count(),
49 53
                     'amountLabel' => __('words.total'),
54
+                    'roleId' => [3],
50 55
                 ],
51 56
                 [
52 57
                     'title' => __('words.type_member'),
53 58
                     'icon' => 'pi pi-id-card',
54
-                    'amount' => $typeMember->count(),
59
+                    'amount' => $typeMembers->count(),
55 60
                     'amountLabel' => __('words.total'),
61
+                    'roleId' => [2],
56 62
                 ],
57 63
                 [
58 64
                     'title' => __('words.type_vehicle'),
59 65
                     'icon' => 'pi pi-car',
60
-                    'amount' => $typeVehicle->count(),
66
+                    'amount' => $typeVehicles->count(),
67
+                    'amountLabel' => __('words.total'),
68
+                    'roleId' => [3],
69
+                ],
70
+                [
71
+                    'title' => __('words.user'),
72
+                    'icon' => 'pi pi-user',
73
+                    'amount' => $users->count(),
61 74
                     'amountLabel' => __('words.total'),
75
+                    'roleId' => [1],
62 76
                 ],
63 77
             ],
64 78
             'barStatistics' => [
79
+                // [
80
+                //     'title' => ...,
81
+                //     'description' => ...,
82
+                //     'data' => ...,
83
+                //     'roleId' => [..., ...],
84
+                // ],
65 85
                 [
66 86
                     'title' => __('words.mutation_statistic'),
67 87
                     'description' => __('words.per_year') . ' ' . date('Y'),
68
-                    'data' => (new MutationService)->statistic($mutation),
88
+                    'data' => (new MutationService)->statistic($mutations),
89
+                    'roleId' => [2, 3],
69 90
                 ],
70 91
             ],
71 92
         ]);

+ 1
- 0
lang/en/words.php Datei anzeigen

@@ -36,5 +36,6 @@ return [
36 36
     'type_vehicle' => 'Type Kendaraan',
37 37
     'top_up_rank' => 'Top Up',
38 38
     'top_up_number_rank' => 'Top Up :number Rank',
39
+    'user' => 'User',
39 40
 
40 41
 ];

+ 1
- 0
lang/id/words.php Datei anzeigen

@@ -36,5 +36,6 @@ return [
36 36
     'type_vehicle' => 'Jenis Kendaraan',
37 37
     'top_up_rank' => 'Top Up',
38 38
     'top_up_number_rank' => 'Peringkat :number Top Up',
39
+    'user' => 'User',
39 40
 
40 41
 ];

+ 17335
- 264
public/js/resources_js_pages_home_Index_vue.js
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 1
- 1
public/js/vue.js Datei anzeigen

@@ -58396,7 +58396,7 @@ module.exports = JSON.parse('{"name":"axios","version":"0.21.4","description":"P
58396 58396
 /******/ 		// This function allow to reference async chunks
58397 58397
 /******/ 		__webpack_require__.u = (chunkId) => {
58398 58398
 /******/ 			// return url for filenames based on template
58399
-/******/ 			return "js/" + chunkId + ".js?id=" + {"node_modules_chart_js_auto_auto_esm_js":"10c6b388645ceb22","resources_js_pages_auth_ForgotPassword_vue":"5b9f0529bda25a9b","resources_js_pages_auth_Login_vue":"61b9c9ae1ae9da32","resources_js_pages_auth_ResetPassword_vue":"b091193a1e114ce8","resources_js_pages_auth_VerifyEmail_vue":"d9853eae0a0235f2","resources_js_pages_expense_Create_vue":"24ce2fe5d7bc72c8","resources_js_pages_expense_Index_vue":"798dbf6d69320567","resources_js_pages_expense_Show_vue":"d5681c75fde77308","resources_js_pages_expense_TableHeader_js":"eed3f0613f167cfd","resources_js_pages_home_Index_vue":"b922dc090509ea08","resources_js_pages_member_Create_vue":"fc1cd382141d2c70","resources_js_pages_member_Edit_vue":"33eee7f2667de50d","resources_js_pages_member_Index_vue":"cf14eae2779192d8","resources_js_pages_member_TableHeader_js":"51dbf053f7ddd45c","resources_js_pages_mutation_Report_vue":"0c0abe807726ddb5","resources_js_pages_mutation_TableHeader_js":"7822e888aa3c52fc","resources_js_pages_parkingfee_Create_vue":"4d1d60defdf2c684","resources_js_pages_topup_Create_vue":"d4b2fe633c0691f2","resources_js_pages_topup_Index_vue":"b2565eb99363b9ba","resources_js_pages_topup_Show_vue":"cd5e15ada76e9fbe","resources_js_pages_topup_TableHeader_js":"601b7c0a855ce64e","resources_js_pages_typemember_Create_vue":"06b9f61209ca7651","resources_js_pages_typemember_Edit_vue":"4d8a32f046a9a08b","resources_js_pages_typemember_Index_vue":"73b3a8ec31100c62","resources_js_pages_typemember_TableHeader_js":"ac1d31a59f8d464e","resources_js_pages_typevehicle_Create_vue":"75389ee20755d74a","resources_js_pages_typevehicle_Edit_vue":"09a18fe1169d4335","resources_js_pages_typevehicle_Index_vue":"d15b150b4fdee4ad","resources_js_pages_typevehicle_TableHeader_js":"a40378918fbe74e1","resources_js_pages_user_Create_vue":"9b13f9080e20bf2d","resources_js_pages_user_Edit_vue":"4edf8db4d7073eac","resources_js_pages_user_Index_vue":"9c791e4ceac6a483","resources_js_pages_user_Show_vue":"2431556dd033ddb2","resources_js_pages_user_TableHeader_js":"0d87fd422fe40491"}[chunkId] + "";
58399
+/******/ 			return "js/" + chunkId + ".js?id=" + {"node_modules_chart_js_auto_auto_esm_js":"10c6b388645ceb22","resources_js_pages_auth_ForgotPassword_vue":"5b9f0529bda25a9b","resources_js_pages_auth_Login_vue":"61b9c9ae1ae9da32","resources_js_pages_auth_ResetPassword_vue":"b091193a1e114ce8","resources_js_pages_auth_VerifyEmail_vue":"d9853eae0a0235f2","resources_js_pages_expense_Create_vue":"24ce2fe5d7bc72c8","resources_js_pages_expense_Index_vue":"798dbf6d69320567","resources_js_pages_expense_Show_vue":"d5681c75fde77308","resources_js_pages_expense_TableHeader_js":"eed3f0613f167cfd","resources_js_pages_home_Index_vue":"ad1968615775596e","resources_js_pages_member_Create_vue":"fc1cd382141d2c70","resources_js_pages_member_Edit_vue":"33eee7f2667de50d","resources_js_pages_member_Index_vue":"cf14eae2779192d8","resources_js_pages_member_TableHeader_js":"51dbf053f7ddd45c","resources_js_pages_mutation_Report_vue":"0c0abe807726ddb5","resources_js_pages_mutation_TableHeader_js":"7822e888aa3c52fc","resources_js_pages_parkingfee_Create_vue":"4d1d60defdf2c684","resources_js_pages_topup_Create_vue":"d4b2fe633c0691f2","resources_js_pages_topup_Index_vue":"b2565eb99363b9ba","resources_js_pages_topup_Show_vue":"cd5e15ada76e9fbe","resources_js_pages_topup_TableHeader_js":"601b7c0a855ce64e","resources_js_pages_typemember_Create_vue":"06b9f61209ca7651","resources_js_pages_typemember_Edit_vue":"4d8a32f046a9a08b","resources_js_pages_typemember_Index_vue":"73b3a8ec31100c62","resources_js_pages_typemember_TableHeader_js":"ac1d31a59f8d464e","resources_js_pages_typevehicle_Create_vue":"75389ee20755d74a","resources_js_pages_typevehicle_Edit_vue":"09a18fe1169d4335","resources_js_pages_typevehicle_Index_vue":"d15b150b4fdee4ad","resources_js_pages_typevehicle_TableHeader_js":"a40378918fbe74e1","resources_js_pages_user_Create_vue":"9b13f9080e20bf2d","resources_js_pages_user_Edit_vue":"4edf8db4d7073eac","resources_js_pages_user_Index_vue":"9c791e4ceac6a483","resources_js_pages_user_Show_vue":"2431556dd033ddb2","resources_js_pages_user_TableHeader_js":"0d87fd422fe40491"}[chunkId] + "";
58400 58400
 /******/ 		};
58401 58401
 /******/ 	})();
58402 58402
 /******/ 	

+ 0
- 29
resources/js/components/AppCardStatistic.vue Datei anzeigen

@@ -1,29 +0,0 @@
1
-<script setup>
2
-defineProps({
3
-  data: {
4
-    type: Object,
5
-    required: true,
6
-  },
7
-})
8
-</script>
9
-
10
-<template>
11
-  <Card class="h-full">
12
-    <template #content>
13
-      <div class="flex justify-content-between mb-3">
14
-        <div>
15
-          <span class="block text-500 font-medium mb-3">{{ data.title }}</span>
16
-          <div v-if="data.value" class="text-900 font-medium text-xl">{{ data.value }}</div>
17
-        </div>
18
-        <div
19
-          class="flex align-items-center justify-content-center bg-orange-100 border-round"
20
-          style="width: 2.5rem; height: 2.5rem"
21
-        >
22
-          <i class="text-orange-500 text-xl" :class="data.icon"></i>
23
-        </div>
24
-      </div>
25
-      <span class="text-green-500 font-medium">{{ data.amount }} </span>
26
-      <span class="text-500"> {{ ' ' + data.amountLabel }}</span>
27
-    </template>
28
-  </Card>
29
-</template>

+ 47
- 30
resources/js/pages/home/Index.vue Datei anzeigen

@@ -1,6 +1,6 @@
1 1
 <script setup>
2 2
 import { Head } from '@inertiajs/inertia-vue3'
3
-import AppCardStatistic from '@/components/AppCardStatistic.vue'
3
+import { includes } from 'lodash'
4 4
 import AppLayout from '@/layouts/AppLayout.vue'
5 5
 
6 6
 defineProps({
@@ -110,31 +110,54 @@ const pieChartOption = {
110 110
     <Head title="Dashboard" />
111 111
 
112 112
     <div class="grid">
113
-      <div class="col-12 flex flex-wrap justify-content-between card-statistic">
114
-        <div v-for="cardStatistic in cardStatistics" class="flex-grow-1">
115
-          <AppCardStatistic :data="cardStatistic" />
113
+      <template v-for="cardStatistic in cardStatistics">
114
+        <div v-if="includes(cardStatistic.roleId, $page.props.auth.user.role_id)" class="col-12 md:col-4 xl:col-3">
115
+          <Card class="h-full">
116
+            <template #content>
117
+              <div class="flex justify-content-between mb-3">
118
+                <div>
119
+                  <span class="block text-500 font-medium mb-3">{{ cardStatistic.title }}</span>
120
+                  <div v-if="cardStatistic.value" class="text-900 font-medium text-xl">{{ cardStatistic.value }}</div>
121
+                </div>
122
+                <div
123
+                  class="flex align-items-center justify-content-center bg-orange-100 border-round"
124
+                  style="width: 2.5rem; height: 2.5rem"
125
+                >
126
+                  <i class="text-orange-500 text-xl" :class="cardStatistic.icon"></i>
127
+                </div>
128
+              </div>
129
+              <span class="text-green-500 font-medium">{{ cardStatistic.amount }} </span>
130
+              <span class="text-500"> {{ ' ' + cardStatistic.amountLabel }}</span>
131
+            </template>
132
+          </Card>
116 133
         </div>
117
-      </div>
134
+      </template>
135
+    </div>
118 136
 
119
-      <div v-for="barStatistic in barStatistics" class="col-12 md:col-6">
120
-        <Card>
121
-          <template #title>
122
-            <div class="flex flex-column">
123
-              <span>{{ barStatistic.title }}</span>
124
-              <span v-if="barStatistic.description" class="text-base font-normal">{{ barStatistic.description }}</span>
125
-            </div>
126
-          </template>
127
-          <template v-if="Object.keys(barStatistic.data).length" #content>
128
-            <Chart
129
-              type="bar"
130
-              :width="600"
131
-              :height="300"
132
-              :data="barChart(barStatistic.data)"
133
-              :options="barChartOption"
134
-            />
135
-          </template>
136
-        </Card>
137
-      </div>
137
+    <div class="grid">
138
+      <template v-for="barStatistic in barStatistics">
139
+        <div v-if="includes(barStatistic.roleId, $page.props.auth.user.role_id)" class="col-12 md:col-6">
140
+          <Card>
141
+            <template #title>
142
+              <div class="flex flex-column">
143
+                <span>{{ barStatistic.title }}</span>
144
+                <span v-if="barStatistic.description" class="text-base font-normal">{{
145
+                  barStatistic.description
146
+                }}</span>
147
+              </div>
148
+            </template>
149
+            <template v-if="Object.keys(barStatistic.data).length" #content>
150
+              <Chart
151
+                type="bar"
152
+                :width="600"
153
+                :height="300"
154
+                :data="barChart(barStatistic.data)"
155
+                :options="barChartOption"
156
+              />
157
+            </template>
158
+          </Card>
159
+        </div>
160
+      </template>
138 161
 
139 162
       <!-- <div v-for="barHorizontalStatistic in barHorizontalStatistics" class="col-12 md:col-6">
140 163
         <Card>
@@ -180,9 +203,3 @@ const pieChartOption = {
180 203
     </div>
181 204
   </AppLayout>
182 205
 </template>
183
-
184
-<style scoped>
185
-.card-statistic {
186
-  gap: 1rem;
187
-}
188
-</style>