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.TABLE_HEADING.DATE_HOUR}} | +{{CONSTANTS.LABELS.PROFILE.TABLE_HEADING.CONTRIBUTION_TYPE}} | +{{CONSTANTS.LABELS.PROFILE.TABLE_HEADING.ITEM_TYPE}} | +{{CONSTANTS.LABELS.PROFILE.TABLE_HEADING.LOCATION}} | +{{CONSTANTS.LABELS.PROFILE.TABLE_HEADING.POINT_ID}} | +{{CONSTANTS.LABELS.PROFILE.TABLE_HEADING.ACTIONS}} | +
---|---|---|---|---|---|
{{ moment(contribution.date).format('DD MMMM YYYY / hh:mm') }} | +{{ contribution.type }} | +{{ contribution.item_type }} | +{{ contribution.location }} | +{{ contribution.point_id }} | ++ + {{CONSTANTS.LABELS.PROFILE.TABLE_CONTENT.VIEW_ON_MAP}} + + + {{CONSTANTS.LABELS.PROFILE.TABLE_CONTENT.PENDING}} + + | +