Skip to content

Commit

Permalink
- Add script on webpack.mix.js to compile page js
Browse files Browse the repository at this point in the history
- Use mix() when loading js helpers
- Set try catch handling at getFiles() function on webpack.mix.js
- Create js helpers for page
- Composer install spatie/laravel-enum
- Create periodicity enum class
- Create achievement repository class
- Create form request on laporan pencapain new !check in
- Change deprecated document.ready() of jquery function
  • Loading branch information
ianriizky committed Feb 6, 2022
1 parent b88f520 commit 2de33c8
Show file tree
Hide file tree
Showing 17 changed files with 520 additions and 194 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/public/node_modules
/public/storage
/public/js/helpers/*
/public/js/page/*
/public/js/stisla/*
/public/webfonts
/storage/*.key
Expand Down
27 changes: 27 additions & 0 deletions app/Enum/Periodicity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Enum;

use Spatie\Enum\Laravel\Enum;

/**
* @method static self yearly()
* @method static self monthly()
* @method static self weekly()
* @method static self daily()
*/
class Periodicity extends Enum
{
/**
* {@inheritDoc}
*/
protected static function labels(): array
{
return [
'yearly' => trans('Yearly'),
'monthly' => trans('Monthly'),
'weekly' => trans('Weekly'),
'daily' => trans('Daily'),
];
}
}
56 changes: 23 additions & 33 deletions app/Http/Controllers/AchievementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

namespace App\Http\Controllers;

use App\Models\Achievement;
use App\Http\Requests\Achievement\LaporanPencapaianNewCinChartRequest;
use App\Repositories\AchievementRepository;
use Illuminate\Http\Request;

class AchievementController extends Controller
{
/**
* Create a new instance class.
*
* @param \App\Repositories\AchievementRepository $achievementRepository
* @return void
*/
public function __construct(
protected AchievementRepository $achievementRepository
) {
//
}

/**
* Display index page.
*
Expand All @@ -30,41 +43,18 @@ public function laporanPencapaianNewCin()
/**
* Return laporan pencapaian new cin chart data as json response.
*
* @param \App\Http\Requests\Achievement\LaporanPencapaianNewCinChartRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function laporanPencapaianNewCinChart()
public function laporanPencapaianNewCinChart(LaporanPencapaianNewCinChartRequest $request)
{
return response()->json([
'labels' => [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
],
'datasets' => [
[
'label' => 'Jumlah New CiN',
'data' => [460, 458, 330, 502, 430, 610, 488],
'backgroundColor' => 'rgba(254,86,83,.7)',
'borderColor' => 'rgba(254,86,83,.7)',
'borderWidth' => 2.5,
'pointBackgroundColor' => '#ffffff',
'pointRadius' => 4,
],
[
'label' => 'Target Bulanan',
'data' => [550, 558, 390, 562, 490, 670, 538],
'backgroundColor' => 'rgba(63,82,227,.8)',
'borderColor' => 'transparent',
'borderWidth' => 0,
'pointBackgroundColor' => '#999999',
'pointRadius' => 4,
],
],
]);
$data = $this->achievementRepository->chartLaporanPencapaianNewCin(
$request->date('start_date'),
$request->date('end_date'),
$request->periodicity
);

return response()->json($data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Http\Requests\Achievement;

use App\Enum\Periodicity;
use App\Infrastructure\Foundation\Http\FormRequest;
use Spatie\Enum\Laravel\Http\Requests\TransformsEnums;
use Spatie\Enum\Laravel\Rules\EnumRule;

/**
* @property \App\Enum\Periodicity $periodicity
*/
class LaporanPencapaianNewCinChartRequest extends FormRequest
{
use TransformsEnums;

/**
* {@inheritDoc}
*/
public function authorize()
{
return !is_null($this->user());
}

/**
* {@inheritDoc}
*/
public function rules()
{
return [
'start_date' => ['required', 'date_format:Y-m-d H:i:s'],
'end_date' => ['required', 'date_format:Y-m-d H:i:s'],
'periodicity' => ['sometimes', 'nullable', new EnumRule(Periodicity::class)],
];
}

/**
* List of transformed enum from request.
*
* @return array
*/
public function enums(): array
{
return [
'periodicity' => Periodicity::class,
];
}
}
47 changes: 47 additions & 0 deletions app/Repositories/AchievementRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Repositories;

use App\Enum\Periodicity;
use App\Models\Branch;
use Illuminate\Support\Carbon;

class AchievementRepository
{
/**
* Return chart data of laporan pencapaian new cin.
*
* @param \Illuminate\Support\Carbon $startDate
* @param \Illuminate\Support\Carbon $endDate
* @param \App\Enum\Periodicity $periodicity
* @return array
*/
public function chartLaporanPencapaianNewCin(Carbon $startDate, Carbon $endDate, Periodicity $periodicity): array
{
$branches = Branch::all();

return [
'labels' => $branches->pluck('name'),
'datasets' => [
[
'label' => trans('Number of New CiN'),
'data' => $branches->map(fn (Branch $branch) => rand(1, 100)),
'backgroundColor' => 'rgba(254,86,83,.7)',
'borderColor' => 'rgba(254,86,83,.7)',
'borderWidth' => 2.5,
'pointBackgroundColor' => '#ffffff',
'pointRadius' => 4,
],
[
'label' => trans(':periodicity target', ['periodicity' => $periodicity->label]),
'data' => $branches->map(fn (Branch $branch) => rand(1, 100)),
'backgroundColor' => 'rgba(63,82,227,.8)',
'borderColor' => 'transparent',
'borderWidth' => 0,
'pointBackgroundColor' => '#999999',
'pointRadius' => 4,
],
],
];
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"laravel/framework": "^8.65",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"spatie/laravel-enum": "^3.0",
"spatie/laravel-permission": "^5.5",
"yajra/laravel-datatables-fractal": "^1.6",
"yajra/laravel-datatables-oracle": "~9.0"
Expand Down
Loading

0 comments on commit 2de33c8

Please sign in to comment.