Skip to content

Commit

Permalink
- Finishing monitoring create page (now renamed as daily achievement …
Browse files Browse the repository at this point in the history
…sub menu)

- Fix database design and model relationship
- Add daily achievement assert on monitoring feature test
  • Loading branch information
ianriizky committed Feb 1, 2022
1 parent 907d711 commit b604c13
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Models\Monitoring;
use Illuminate\Http\Request;

class MonitoringController extends Controller
class DailyAchievementController extends Controller
{
/**
* Display index page.
Expand All @@ -14,7 +14,7 @@ class MonitoringController extends Controller
*/
public function index()
{
return view('monitoring.index');
return view('monitoring.daily-achievement.index');
}

/**
Expand All @@ -24,7 +24,7 @@ public function index()
*/
public function create()
{
return view('monitoring.create');
return view('monitoring.daily-achievement.create');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
class Achievement extends Model
{
use HasFactory,
Concerns\Achievement\Attribute;
Concerns\Achievement\Attribute,
Concerns\Achievement\Relation;

/**
* {@inheritDoc}
Expand Down
48 changes: 48 additions & 0 deletions app/Models/Concerns/Achievement/Relation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Models\Concerns\Achievement;

use App\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property int|null $user_id Foreign key of \App\Models\User.
* @property-read \App\Models\User|null $user
*
* @see \App\Models\Achievement
*/
trait Relation
{
/**
* Define an inverse one-to-one or many relationship with \App\Models\User.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

/**
* Return \App\Models\User model relation value.
*
* @return \App\Models\User|null
*/
public function getUserRelationValue(): ?User
{
return $this->getRelationValue('user');
}

/**
* Set \App\Models\User model relation value.
*
* @param \App\Models\User $user
* @return $this
*/
public function setUserRelationValue(User $user)
{
$this->user()->associate($user);

return $this;
}
}
13 changes: 0 additions & 13 deletions app/Models/Concerns/Education/Attribute.php

This file was deleted.

13 changes: 0 additions & 13 deletions app/Models/Concerns/Monitoring/Attribute.php

This file was deleted.

47 changes: 43 additions & 4 deletions app/Models/Concerns/User/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace App\Models\Concerns\User;

use App\Models\Achievement;
use App\Models\Branch;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @property int $branch_id Foreign key of \App\Models\Branch.
* @property-read \App\Models\Branch $branch
* @property int|null $branch_id Foreign key of \App\Models\Branch.
* @property-read \App\Models\Branch|null $branch
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\Achievement> $achievements
*
* @see \App\Models\User
*/
Expand All @@ -26,9 +30,9 @@ public function branch(): BelongsTo
/**
* Return \App\Models\Branch model relation value.
*
* @return \App\Models\Branch
* @return \App\Models\Branch|null
*/
public function getBranchRelationValue(): Branch
public function getBranchRelationValue(): ?Branch
{
return $this->getRelationValue('branch');
}
Expand All @@ -45,4 +49,39 @@ public function setBranchRelationValue(Branch $branch)

return $this;
}

/**
* Define a one-to-many relationship with App\Models\Achievement.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function achievements(): HasMany
{
return $this->hasMany(Achievement::class);
}

/**
* Return collection of \App\Models\Achievement model relation value.
*
* @return \Illuminate\Database\Eloquent\Collection<\App\Models\Achievement>
*/
public function getAchievementsRelationValue(): Collection
{
return $this->getCollectionValue('achievements', Achievement::class);
}

/**
* Set collection of \App\Models\Achievement model relation value.
*
* @param \Illuminate\Database\Eloquent\Collection<\App\Models\Achievement> $achievements
* @return $this
*/
public function setAchievementsRelationValue(Collection $achievements)
{
if ($this->isCollectionValid($achievements, Achievement::class)) {
$this->setRelation('achievements', $achievements);
}

return $this;
}
}
19 changes: 0 additions & 19 deletions app/Models/Education.php

This file was deleted.

19 changes: 0 additions & 19 deletions app/Models/Monitoring.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
* @see \App\Models\Education
* @see \App\Models\Achievement
*/
return new class extends Migration
{
Expand All @@ -16,8 +17,9 @@
*/
public function up()
{
Schema::create('educations', function (Blueprint $table) {
Schema::create('achievements', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(User::class)->nullable()->constrained()->cascadeOnUpdate()->nullOnDelete();

$table->string('name');
$table->timestamps();
Expand All @@ -31,6 +33,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('educations');
Schema::dropIfExists('achievements');
}
};
4 changes: 2 additions & 2 deletions resources/views/components/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
</a>

<ul class="dropdown-menu">
<li class="nav-item @if (Route::is('monitoring.create')) active @endif">
<a href="{{ route('monitoring.create') }}" class="nav-link">
<li class="nav-item @if (Route::is('monitoring.daily-achievement.*')) active @endif">
<a href="{{ route('monitoring.daily-achievement.index') }}" class="nav-link">
<span class="narrow-line-height">Input Pencapaian Harian</span>
</a>
</li>
Expand Down
41 changes: 41 additions & 0 deletions resources/views/monitoring/daily-achievement/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@extends('layouts.admin')

@section('content')
<section class="section">
<div class="section-header">
<h1>@lang('Create') Input Pencapaian Harian</h1>

<div class="section-header-breadcrumb">
<div class="breadcrumb-item">
<a href="{{ route('monitoring.index') }}">
<i class="fas @lang('icon.monitoring')"></i> <span>@lang('menu.monitoring')</span>
</a>
</div>

<div class="breadcrumb-item">
<a href="{{ route('monitoring.daily-achievement.index') }}">
<span>Input Pencapaian Harian</span>
</a>
</div>

<div class="breadcrumb-item">
<a href="{{ route('monitoring.daily-achievement.create') }}">
<span>@lang('Create')</span>
</a>
</div>
</div>
</div>

<form action="">
@csrf

<div class="section-body">
<div class="card">
<div class="card-body">

</div>
</div>
</div>
</form>
</section>
@endsection
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@section('content')
<section class="section">
<div class="section-header">
<h1>@lang('menu.monitoring')</h1>
<h1>Input Pencapaian Harian</h1>

<div class="section-header-breadcrumb">
<div class="breadcrumb-item">
Expand All @@ -13,7 +13,7 @@
</div>

<div class="breadcrumb-item">
<a href="{{ route('monitoring.create') }}">
<a href="{{ route('monitoring.daily-achievement.index') }}">
<span>Input Pencapaian Harian</span>
</a>
</div>
Expand All @@ -22,8 +22,14 @@

<div class="section-body">
<div class="card">
<div class="card-body">
<div class="card-header">
<a href="{{ route('monitoring.daily-achievement.create') }}" class="btn btn-success">
<i class="fas fa-plus-square"></i> <span>@lang('Create')</span>
</a>
</div>

<div class="card-body">
Halaman Input Pencapaian Harian
</div>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions resources/views/monitoring/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<div class="article-title">
<h2>
<a href="{{ route('monitoring.create') }}">Input Pencapaian Harian</a>
<a href="{{ route('monitoring.daily-achievement.index') }}">Input Pencapaian Harian</a>
</h2>
</div>
</div>
Expand All @@ -37,7 +37,9 @@
</p>

<div class="article-cta">
<a href="{{ route('monitoring.create') }}" class="btn btn-primary">@lang('New')</a>
<a href="{{ route('monitoring.daily-achievement.index') }}" class="btn btn-primary">@lang('View')</a>

<a href="{{ route('monitoring.daily-achievement.create') }}" class="btn btn-success">@lang('Create')</a>
</div>
</div>
</article>
Expand Down
9 changes: 6 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

use App\Http\Controllers\AchievementController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\MonitoringController;
use App\Http\Controllers\DailyAchievementController;
use Illuminate\Support\Facades\Route;

/*
Expand Down Expand Up @@ -40,7 +39,11 @@
Route::view('/employee-get-cin', 'education.employee-get-cin')->name('employee-get-cin');
});

Route::resource('monitoring', MonitoringController::class);
Route::prefix('/monitoring')->name('monitoring.')->group(function () {
Route::view('/', 'monitoring.index')->name('index');

Route::resource('daily-achievement', DailyAchievementController::class);
});

Route::prefix('/achievement')->name('achievement.')->controller(AchievementController::class)->group(function () {
Route::view('/', 'achievement.index')->name('index');
Expand Down
Loading

0 comments on commit b604c13

Please sign in to comment.