diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 461a0865..22a4348f 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Api; +use App\Http\Resources\UserResource; use App\Models\User; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -28,7 +29,7 @@ public function profile(): \Illuminate\Http\JsonResponse { return response()->json( [ - 'data' => User::find(Auth::id()), + 'data' => new UserResource(User::find(Auth::id())), ]); } } diff --git a/app/Models/User.php b/app/Models/User.php index 0b1111e7..5ae271ce 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,6 +3,9 @@ namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; +use App\Filament\Resources\IssuesResource; +use App\Http\Resources\IssueResource; +use App\Http\Resources\MapPointResource; use Filament\Models\Contracts\FilamentUser; use Filament\Models\Contracts\HasName; use Filament\Panel; @@ -72,4 +75,62 @@ public function getFullnameAttribute($value) { return "{$this->firstname} {$this->lastname}"; } + + public function getContributions() + { + $mapPoints = MapPointResource::collection(MapPoint::with('type', 'service', 'fields.field')->where('created_by', $this->id)->get()); + $issues = IssueResource::collection(Issue::with('type', 'map_point', 'map_point.fields.field')->where('reporter_id', $this->id)->get()); + + $contributions = []; + if (!empty($mapPoints)) + { + foreach ($mapPoints->collection->toArray() as $mapPoint) + { + $contributions[] = + [ + 'date' => $mapPoint['created_at'], + 'type' => __('common.contribution_types.point'), + 'item_type' => $mapPoint['service']['display_name'].' ('.$mapPoint['type']['display_name'].')', + 'location' => self::getAddress($mapPoint['fields']), + 'status' => $mapPoint['status'], + 'point_id' => $mapPoint['id'] + ]; + } + } + + if (!empty($issues)) + { + foreach ($issues->collection->toArray() as $issue) + { + $contributions[] = + [ + 'date' => $issue['created_at'], + 'type' => __('common.contribution_types.issue'), + 'item_type' => $issue['type']['title'], + 'location' => self::getAddress($issue['map_point']['fields']), + 'status' => $issue['status'], + 'point_id' => $issue['point_id'] + ]; + } + } + + return $contributions; + } + + private static function getAddress($fields) + { + if (!empty($fields)) + { + foreach ($fields as $field) + { + if ($field['field']['field_name'] == 'address') + { + return $field['value']; + } + } + } + + return null; + + } } diff --git a/lang/en/common.php b/lang/en/common.php index 4b98a66b..5e49066d 100644 --- a/lang/en/common.php +++ b/lang/en/common.php @@ -17,4 +17,8 @@ 'sun' => 'Sunday', ], 'closed' => 'Closed', + 'contribution_types' => [ + 'point' => 'New Point', + 'issue' => 'Issue Report' + ], ]; diff --git a/lang/ro/common.php b/lang/ro/common.php index b2f2930d..aae85158 100644 --- a/lang/ro/common.php +++ b/lang/ro/common.php @@ -17,4 +17,8 @@ 'sun' => 'Duminica', ], 'closed' => 'Inchis', + 'contribution_types' => [ + 'point' => 'Adăugare punct nou', + 'issue' => 'Raportare problemă' + ], ]; diff --git a/resources/js/app.js b/resources/js/app.js index 9ee78a62..eeafe9b0 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -8,6 +8,7 @@ import {LoadingPlugin} from 'vue-loading-overlay'; import 'vue-loading-overlay/dist/css/index.css'; import {addAuthToken} from "./general.js"; + const app = createApp(App); app.use(router) diff --git a/resources/js/components/profilePage.vue b/resources/js/components/profilePage.vue index d9453d8b..aa92a017 100644 --- a/resources/js/components/profilePage.vue +++ b/resources/js/components/profilePage.vue @@ -82,21 +82,21 @@

{{CONSTANTS.LABELS.PROFILE.HEADING}}

-
+
-
+
{{this.userInfo.firstname}} {{this.userInfo.lastname}}
-
Membru din 23 Mai 2022
+
{{CONSTANTS.LABELS.PROFILE.MEMBER_FROM}} {{moment(this.userInfo.created_at).format('DD MMMM YYYY')}}
{{CONSTANTS.LABELS.PROFILE.EMAIL}}
{{this.userInfo.email}}
-
@@ -125,7 +174,7 @@ import {getUserProfile} from "../general.js"; import { Disclosure, DisclosureButton, DisclosurePanel, Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue' import { Bars3Icon, BellIcon, XMarkIcon } from '@heroicons/vue/24/outline' import { ArrowLeftIcon, PencilSquareIcon } from '@heroicons/vue/20/solid' - +import moment from 'moment'; export default { @@ -148,6 +197,7 @@ export default { return { userInfo: {}, + moment, isAuthenticated: false, }; }, @@ -156,6 +206,7 @@ export default async getUserInfo () { this.userInfo = await getUserProfile(); + console.log(`user`, this.userInfo); if (Object.keys(this.userInfo).length > 0) { diff --git a/resources/js/constants.js b/resources/js/constants.js index 45e1c9ce..205fcbd7 100644 --- a/resources/js/constants.js +++ b/resources/js/constants.js @@ -99,8 +99,24 @@ export const CONSTANTS = { HEADING: `Profilul meu`, EMAIL: `Email`, - MEMBER_FROM: `Membru din {date}`, + MEMBER_FROM: `Membru din `, EDIT: `Modifică`, + CONTRIBUTIONS: `contribuții`, + CONTRIBUTIONS_TITLE: `Contribuții hartă`, + TABLE_HEADING: + { + DATE_HOUR: `Data / ora`, + CONTRIBUTION_TYPE: `Contribuție`, + ITEM_TYPE: `Tip`, + LOCATION: `Locație`, + POINT_ID: `ID punct`, + ACTIONS: `Acțiuni`, + }, + TABLE_CONTENT: + { + VIEW_ON_MAP: `Vezi pe hartă`, + PENDING: 'În așteptare', + } }, LOCATION: {