-
-
Notifications
You must be signed in to change notification settings - Fork 178
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 #458 from range-of-motion/create-page-in-spa-proto…
…type-that-shows-activities Create page in SPA prototype that shows activities
- Loading branch information
Showing
6 changed files
with
97 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\ActivityResource; | ||
use App\Models\Activity; | ||
use Illuminate\Http\Request; | ||
|
||
class ActivitiesController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
/** @var ApiKey $apiKey */ | ||
$apiKey = $request->get('apiKey'); | ||
|
||
$activities = Activity::ofSpace($apiKey->user->spaces()->first()->id)->get(); | ||
|
||
return ActivityResource::collection($activities); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class ActivityResource extends JsonResource | ||
{ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'user' => $this->user | ||
? ['id' => $this->user->id, 'name' => $this->user->name] | ||
: null, | ||
'entity_id' => $this->entity_id, | ||
'entity_type' => $this->entity_type, | ||
'action' => $this->action, | ||
'occurred_at' => $this->created_at, | ||
]; | ||
} | ||
} |
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,42 @@ | ||
<script setup> | ||
import { ref } from 'vue'; | ||
import Navigation from '../components/Navigation.vue'; | ||
const activities = ref([]); | ||
const fetchActivities = () => { | ||
fetch('/api/activities', { headers: { 'api-key': localStorage.getItem('api_key') } }) | ||
.then(response => response.json()) | ||
.then(data => { | ||
activities.value = data.sort((a, b) => new Date(b.occurred_at) - new Date(a.occurred_at)); | ||
}); | ||
}; | ||
fetchActivities(); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<Navigation /> | ||
<div class="my-10 mx-auto max-w-3xl"> | ||
<div class="p-5 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg"> | ||
<div class="relative ml-2.5 space-y-5 border-l border-gray-300"> | ||
<div v-for="(activity, i) in activities" :key="i"> | ||
<div class="flex items-start"> | ||
<div class="absolute -left-2.5 w-5 h-5 bg-gray-100 border border-gray-300 ring-8 ring-white rounded-full"></div> | ||
<div class="pl-5"> | ||
<div class="-mt-px text-sm"> | ||
<span>{{ activity.user ? activity.user.name : 'Budget' }} {{ activity.action.split('.')[1] }} {{ activity.action.split('.')[0] }} #{{ activity.entity_id }}</span> | ||
</div> | ||
<div class="mt-1 text-xs text-gray-500">{{ new Date(activity.occurred_at).toJSON().split('T')[0] }}</div> | ||
</div> | ||
</div> | ||
</div> | ||
<!-- Patch (yes, it's ugly) --> | ||
<div class="absolute bottom-0 -left-2 w-4 h-4 bg-white"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
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