Skip to content

Commit

Permalink
add metadata to the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Aug 20, 2023
1 parent 40e4065 commit 014b463
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 49 deletions.
33 changes: 19 additions & 14 deletions app/Http/Controllers/MetaDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

use App\Http\Resources\MetaDataResource;
use App\Models\MetaData;
use Illuminate\Http\Request;

class MetaDataController extends Controller
{

public function index() {
return inertia("MetaData/Index", [
'meta_data' => MetaDataResource::collection(auth()->user()->meta_data)
public function index()
{
return inertia('MetaData/Index', [
'meta_data' => MetaDataResource::collection(auth()->user()->meta_data),
]);
}

public function store() {
public function store()
{
$validated = request()->validate([
'label' => ['required'],
'content' => ['required'],
Expand All @@ -26,16 +26,19 @@ public function store() {
MetaData::create($validated);

request()->session()->flash('flash.banner', 'Created 🏄');
return to_route("meta_data.index");

return to_route('meta_data.index');
}

public function edit(MetaData $meta_data) {
return inertia("MetaData/Edit", [
'meta_data' => new MetaDataResource($meta_data)
public function edit(MetaData $meta_data)
{
return inertia('MetaData/Edit', [
'meta_data' => new MetaDataResource($meta_data),
]);
}

public function update(MetaData $meta_data) {
public function update(MetaData $meta_data)
{
$validated = request()->validate([
'label' => ['required'],
'content' => ['required'],
Expand All @@ -46,10 +49,12 @@ public function update(MetaData $meta_data) {
$meta_data->update($validated);

request()->session()->flash('flash.banner', 'Updated 🌮');
return to_route("meta_data.index");

return to_route('meta_data.index');
}

public function create() {
return inertia("MetaData/Create");
public function create()
{
return inertia('MetaData/Create');
}
}
1 change: 0 additions & 1 deletion app/Models/MetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

}
1 change: 0 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;
use App\Models\MetaData;

/**
* @property int $id
Expand Down
4 changes: 2 additions & 2 deletions database/factories/MetaDataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class MetaDataFactory extends Factory
public function definition(): array
{
return [
"user_id" => User::factory(),
'user_id' => User::factory(),
'label' => fake()->word,
'content' => fake()->words(3, true),
'active' => 1
'active' => 1,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function up(): void
Schema::create('meta_data', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(User::class);
$table->string("label");
$table->longText("content");
$table->boolean("active")
$table->string('label');
$table->longText('content');
$table->boolean('active')
->default(1);
$table->timestamps();
});
Expand Down
7 changes: 3 additions & 4 deletions resources/js/Pages/Dashboard/Components/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ChevronRightIcon class="h-5 w-5" aria-hidden="true" />
</button>
</div>
<div class="mt-6 grid grid-cols-7 text-center text-xs leading-6 text-gray-500">
<div class="mt-6 grid grid-cols-7 text-center text-xs leading-6 text-gray-300">
<div>M</div>
<div>T</div>
<div>W</div>
Expand All @@ -20,9 +20,8 @@
<div>S</div>
<div>S</div>
</div>
<div class="isolate mt-2 grid grid-cols-7 gap-px rounded-lg bg-gray-200 dark:bg-slate-800 text-sm shadow ring-1 ring-gray-200
dark:border-gray-700
">
<div class="isolate mt-2 grid grid-cols-7 gap-px rounded-lg bg-gray-400 dark:bg-slate-600
text-sm shadow ring-1 ring-gray-800 dark:border-gray-700">
<button v-for="(day, dayIdx) in days" :key="day.date" type="button"
:class="['py-1.5 hover:bg-gray-100 focus:z-10', day.isCurrentMonth ? 'bg-white dark:text-gray-300 dark:bg-slate-500' : 'bg-gray-50 dark:bg-gray-400 dark:text-gray-100', (day.isSelected || day.isToday) && 'font-semibold', day.isSelected && 'text-white', !day.isSelected && day.isCurrentMonth && !day.isToday && 'text-gray-900', !day.isSelected && !day.isCurrentMonth && !day.isToday && 'text-gray-400', day.isToday && !day.isSelected && 'text-indigo-600', dayIdx === 0 && 'rounded-tl-lg', dayIdx === 6 && 'rounded-tr-lg', dayIdx === days.length - 7 && 'rounded-bl-lg', dayIdx === days.length - 1 && 'rounded-br-lg']">
<time :datetime="day.date"
Expand Down
8 changes: 6 additions & 2 deletions resources/js/Pages/Dashboard/Show.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<template>
<AppLayout title="Dashboard">
<template #header>
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight flex justify-between">
Dashboard
<SecondaryButtonLink
class="z-50"
:href="route('messages.create')">new message</SecondaryButtonLink>
</h2>
</template>
<main>

<div class="mx-auto max-w-7xl px-4 py-16 sm:px-6 lg:px-8 rounded-t">
<div class="mx-auto max-w-7xl px-4 py8 sm:px-6 lg:px-8 rounded-t">
<div class="mx-auto grid max-w-2xl grid-cols-1 grid-rows-1 items-start gap-x-8 gap-y-8 lg:mx-0 lg:max-w-none lg:grid-cols-3">
<!-- Schedule -->
<div class="lg:col-start-3 lg:row-end-1">
Expand Down Expand Up @@ -79,6 +82,7 @@ import { BellIcon, XMarkIcon as XMarkIconOutline } from '@heroicons/vue/24/outli
import { CheckCircleIcon } from '@heroicons/vue/24/solid'
import Calendar from "./Components/Calendar.vue";
import Activities from "./Components/Activities.vue";
import SecondaryButtonLink from "@/Components/SecondaryButtonLink.vue";
const navigation = [
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Messages/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</h2>
</template>
<main>
<div class="mx-auto max-w-7xl px-4 py-4 sm:px-6 lg:px-8 rounded-t">
<div class="mx-auto max-w-7xl px-4 py-4 sm:px-2 lg:px-2 rounded-t">
<div class="mx-auto grid max-w-2xl grid-cols-1 grid-rows-1 items-start gap-x-8 gap-y-8 lg:mx-0 lg:max-w-none lg:grid-cols-3">
<div class="lg:col-start-3 lg:row-end-1 rounded border-gray-200 border dark:border-gray-500 p-4">
<HTwo>Start your Thread</HTwo>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/MetaData/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</h2>
</template>
<main>
<div class="mx-auto max-w-7xl px-4 py-4 sm:px-6 lg:px-8 rounded-t">
<div class="mx-auto max-w-7xl px-4 py-4 sm:px-2 lg:px-2 rounded-t">
<div class="mx-auto grid max-w-2xl grid-cols-1 grid-rows-1 items-start gap-x-8 gap-y-8 lg:mx-0 lg:max-w-none lg:grid-cols-3">
<div class="lg:col-start-3 lg:row-end-1 rounded border-gray-200 border dark:border-gray-500 p-4">
<HTwo>Your Meta Data</HTwo>
Expand Down
31 changes: 14 additions & 17 deletions tests/Feature/Http/Controllers/MetaDataControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use App\Models\MetaData;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class MetaDataControllerTest extends TestCase
Expand All @@ -18,43 +16,42 @@ public function test_metadata(): void
$user = User::factory()->create();

$this->actingAs($user)->get(
route("meta_data.index")
route('meta_data.index')
)->assertStatus(200);
}

public function test_store(): void
{
$user = User::factory()->create();

$this->assertDatabaseCount("meta_data", 0);
$this->assertDatabaseCount('meta_data', 0);
$this->actingAs($user)->post(
route("meta_data.store"),
route('meta_data.store'),
[
'label' => "Foobar",
'content' => "Foobar",
'label' => 'Foobar',
'content' => 'Foobar',
]
)->assertStatus(302);
$this->assertDatabaseCount("meta_data", 1);
$this->assertDatabaseCount('meta_data', 1);
}

public function test_update(): void
{
$user = User::factory()->create();

$meta_data = MetaData::factory()->create();
$this->assertDatabaseCount("meta_data", 1);
$this->assertDatabaseCount('meta_data', 1);
$this->actingAs($user)->put(
route("meta_data.update", [
'meta_data' => $meta_data->id
route('meta_data.update', [
'meta_data' => $meta_data->id,
]),
[
'label' => "Foobar",
'content' => "Foobar",
'label' => 'Foobar',
'content' => 'Foobar',
]
)->assertStatus(302);
$this->assertDatabaseCount("meta_data", 1);
$this->assertEquals("Foobar", $meta_data->refresh()->label);
$this->assertEquals("Foobar", $meta_data->refresh()->content);
$this->assertDatabaseCount('meta_data', 1);
$this->assertEquals('Foobar', $meta_data->refresh()->label);
$this->assertEquals('Foobar', $meta_data->refresh()->content);
}

}
5 changes: 2 additions & 3 deletions tests/Feature/Models/MetaDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace Tests\Feature\Models;

use App\Models\MetaData;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class MetaDataTest extends TestCase
{
/**
* A basic feature test example.
*/
public function test_factory() {
public function test_factory()
{
$model = MetaData::factory()->create();

$this->assertNotNull($model->user->id);
Expand Down

0 comments on commit 014b463

Please sign in to comment.