Compare commits
No commits in common. "5d9f85b0c035bdcc1be9fd4d23abe5b3a9975208" and "28d98f77226481d2891c18ec7bf3b7452f067fd9" have entirely different histories.
5d9f85b0c0
...
28d98f7722
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\HabitsRequest;
|
|
||||||
use App\Models\Habit;
|
use App\Models\Habit;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@ -21,20 +20,12 @@ public function create()
|
|||||||
return view('habits.create');
|
return view('habits.create');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(HabitsRequest $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
dd($request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$habit = Habit::find($id);
|
|
||||||
|
|
||||||
return view('habits.show', [
|
|
||||||
'habit' => $habit,
|
|
||||||
'entries' => $habit->habitEntries->sortByDesc('date')
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
|
@ -9,8 +9,7 @@ class HabitsRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => ['required', 'string'],
|
'name' => ['required'],
|
||||||
''
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,15 +13,7 @@ class Habit extends Model
|
|||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
'user_id',
|
'user_id'
|
||||||
'type',
|
|
||||||
'value',
|
|
||||||
'suffix',
|
|
||||||
'schedule_value',
|
|
||||||
'schedule_unit',
|
|
||||||
'goal_type',
|
|
||||||
'goal_value',
|
|
||||||
'goal_unit'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function habitEntries(): HasMany {
|
public function habitEntries(): HasMany {
|
||||||
|
@ -12,8 +12,7 @@ class HabitEntry extends Model
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'date',
|
'date'
|
||||||
'note'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function habit(): BelongsTo
|
public function habit(): BelongsTo
|
||||||
|
@ -12,8 +12,7 @@ class HabitEntryFactory extends Factory
|
|||||||
public function definition()
|
public function definition()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'date' => $this->faker->dateTimeThisYear(),
|
'date' => $this->faker->dateTimeThisYear()
|
||||||
'note' => $this->faker->sentence
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,20 +13,6 @@ public function up()
|
|||||||
$table->foreignId('user_id')->constrained();
|
$table->foreignId('user_id')->constrained();
|
||||||
$table->string('name')->default("");
|
$table->string('name')->default("");
|
||||||
|
|
||||||
// Type
|
|
||||||
$table->string('type')->default("todo"); // To do, value
|
|
||||||
$table->float('value')->nullable(); // Amount of suffix
|
|
||||||
$table->string('suffix')->nullable(); // Habit action
|
|
||||||
|
|
||||||
// Schedule
|
|
||||||
$table->integer('schedule_value')->default("1"); // How many schedule_units?
|
|
||||||
$table->string('schedule_unit')->default("day"); // Days, weeks, months
|
|
||||||
|
|
||||||
// Goal
|
|
||||||
$table->string('goal_type')->default('none'); // None, schedule, custom
|
|
||||||
$table->integer('goal_value')->nullable(); // Every how many goal_units?
|
|
||||||
$table->string('goal_unit')->nullable(); // Days, weeks, months
|
|
||||||
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,7 @@ public function up()
|
|||||||
$table->id();
|
$table->id();
|
||||||
|
|
||||||
$table->foreignId('habit_id')->constrained();
|
$table->foreignId('habit_id')->constrained();
|
||||||
$table->date('date')->default(now());
|
$table->date('date');
|
||||||
$table->string('note')->default("");
|
|
||||||
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
@ -25,7 +25,7 @@ public function run(): void
|
|||||||
|
|
||||||
Habit::factory()
|
Habit::factory()
|
||||||
->count(5)
|
->count(5)
|
||||||
->has(HabitEntry::factory()->count(50))
|
->has(HabitEntry::factory()->count(70))
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
<x-app-layout>
|
<x-app-layout>
|
||||||
<x-slot name="header">
|
<x-slot name="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">
|
||||||
{{ __('create new habit') }}
|
{{ __('Create New Habit') }}
|
||||||
</h2>
|
</h2>
|
||||||
</x-slot>
|
</x-slot>
|
||||||
|
|
||||||
<div class="py-12">
|
<div class="py-12">
|
||||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||||
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-md sm:rounded-lg">
|
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-md sm:rounded-lg">
|
||||||
|
|
||||||
<div class="p-6 text-gray-900 dark:text-gray-100">
|
<div class="p-6 text-gray-900 dark:text-gray-100">
|
||||||
|
|
||||||
<div class="w-1/2">
|
<div class="w-1/2">
|
||||||
<form action="{{route('habits.store') }}" method="post">
|
<form action="{{route('habits.store') }}" method="post">
|
||||||
@csrf
|
|
||||||
|
|
||||||
<!-- Name -->
|
<!-- Name -->
|
||||||
<div>
|
<div>
|
||||||
@ -25,32 +24,30 @@
|
|||||||
|
|
||||||
<!-- Type -->
|
<!-- Type -->
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<x-input-label for="habit_type" value="Habit Type"></x-input-label>
|
<x-input-label value="Habit Type"></x-input-label>
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<!-- Radio button 1 -->
|
<!-- Radio button 1 -->
|
||||||
<input id="habit-type-1" type="radio" value="todo" name="type"
|
<input id="habit-type-1" type="radio" value="todo" name="habit-type"
|
||||||
onclick="toggleHabitValueSuffix(true)"
|
onclick="toggleHabitValueSuffix(true)"
|
||||||
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
||||||
<label for="habit-type-1" class="ml-2">Todo / done</label>
|
<label for="habit-type-1" class="ml-2">Todo / done</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<input id="habit-type-2" type="radio" value="value" name="type"
|
<input id="habit-type-2" type="radio" value="value" name="habit-type"
|
||||||
onclick="toggleHabitValueSuffix(false)"
|
onclick="toggleHabitValueSuffix(false)"
|
||||||
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
||||||
<label for="habit-type-2" class="ml-2 ">Value / suffix</label>
|
<label for="habit-type-2" class="ml-2 ">Value / suffix</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Value / Suffix -->
|
<!-- Value / Suffix -->
|
||||||
<x-input-label for="value" value="Value and suffix" class="mt-4"
|
<x-input-label for="suffix" value="Value and suffix" class="mt-4" id="habit-suffix-label"/>
|
||||||
id="habit-suffix-label"/>
|
|
||||||
|
|
||||||
<x-text-input id="habit-value-amount" class="inline-block mt-1" type="number"
|
<x-text-input id="habit-value-amount" class="inline-block mt-1" type="number"
|
||||||
placeholder="Numeric value" min="0"
|
placeholder="Numeric value" min="0"
|
||||||
name="value" disabled/>
|
name="habit-value-amount" disabled/>
|
||||||
<x-input-error :messages="$errors->get('value')" class="mt-2"/>
|
|
||||||
|
|
||||||
<x-text-input id="habit-suffix-name" class="inline-block mt-1 disabled:opacity-50"
|
<x-text-input id="habit-suffix-name" class="inline-block mt-1 disabled:opacity-50"
|
||||||
type="text" name="suffix" disabled
|
type="text" name="habit-suffix-name" disabled
|
||||||
placeholder="Suffix"
|
placeholder="Suffix"
|
||||||
:value="old('suffix')" required autofocus autocomplete="suffix"/>
|
:value="old('suffix')" required autofocus autocomplete="suffix"/>
|
||||||
<x-input-error :messages="$errors->get('suffix')" class="mt-2"/>
|
<x-input-error :messages="$errors->get('suffix')" class="mt-2"/>
|
||||||
@ -59,10 +56,10 @@ class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark
|
|||||||
|
|
||||||
<!-- Schedule -->
|
<!-- Schedule -->
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<x-input-label for="schedule-value" value="Schedule"></x-input-label>
|
<x-input-label for="schedule-unit" value="Schedule"></x-input-label>
|
||||||
<x-text-input id="schedule-value" class="inline-block mt-1" type="number"
|
<x-text-input id="schedule-amount" class="inline-block mt-1" type="number"
|
||||||
placeholder="Numeric value" min="0"
|
placeholder="Numeric value" min="0"
|
||||||
name="schedule-value"/>
|
name="schedule-amount"/>
|
||||||
|
|
||||||
<select name="schedule-unit" id="schedule-unit"
|
<select name="schedule-unit" id="schedule-unit"
|
||||||
class="inline-block w-1/2 border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm">
|
class="inline-block w-1/2 border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm">
|
||||||
@ -77,23 +74,22 @@ class="inline-block w-1/2 border-gray-300 dark:border-gray-700 dark:bg-gray-900
|
|||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<x-input-label value="Goal Type"></x-input-label>
|
<x-input-label value="Goal Type"></x-input-label>
|
||||||
<div class="text-sm my-3">
|
<div class="text-sm my-3">
|
||||||
Adding a goal changes the display mode from the value and suffix to a calculated
|
Adding a goal changes the display mode from the value and suffix to a calculated percentage.
|
||||||
percentage.
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<input id="goal-type-1" type="radio" value="none" name="goal_type"
|
<input id="goal-type-1" type="radio" value="none" name="goal-type"
|
||||||
onclick="toggleGoalSchedule(true)"
|
onclick="toggleGoalSchedule(true)"
|
||||||
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
||||||
<label for="goal-type-1" class="ml-2">No goal</label>
|
<label for="goal-type-1" class="ml-2">No goal</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<input id="goal-type-2" type="radio" value="schedule" name="goal_type"
|
<input id="goal-type-2" type="radio" value="schedule" name="goal-type"
|
||||||
checked="checked" onclick="toggleGoalSchedule(true)"
|
checked="checked" onclick="toggleGoalSchedule(true)"
|
||||||
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
||||||
<label for="goal-type-2" class="ml-2 ">Same as schedule</label>
|
<label for="goal-type-2" class="ml-2 ">Same as schedule</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
<input id="goal-type-3" type="radio" value="custom" name="goal_type"
|
<input id="goal-type-3" type="radio" value="custom" name="goal-type"
|
||||||
onclick="toggleGoalSchedule(false)"
|
onclick="toggleGoalSchedule(false)"
|
||||||
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
|
||||||
<label for="goal-type-3" class="ml-2 ">Custom schedule</label>
|
<label for="goal-type-3" class="ml-2 ">Custom schedule</label>
|
||||||
@ -106,9 +102,9 @@ class="w-4 h-4 text-blue-600 bg-gray-50 border-gray-300 focus:ring-blue-500 dark
|
|||||||
|
|
||||||
<x-text-input id="goal-schedule-amount" class="inline-block mt-1" type="number"
|
<x-text-input id="goal-schedule-amount" class="inline-block mt-1" type="number"
|
||||||
placeholder="Numeric value" min="0" disabled
|
placeholder="Numeric value" min="0" disabled
|
||||||
name="goal_value"/>
|
name="goal-schedule-amount"/>
|
||||||
|
|
||||||
<select name="goal_unit" id="goal-schedule-unit"
|
<select name="goal-schedule-unit" id="goal-schedule-unit"
|
||||||
disabled
|
disabled
|
||||||
class="inline-block w-1/2 border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm disabled:opacity-50">
|
class="inline-block w-1/2 border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 focus:border-indigo-500 dark:focus:border-indigo-600 focus:ring-indigo-500 dark:focus:ring-indigo-600 rounded-md shadow-sm disabled:opacity-50">
|
||||||
<option value="day">Days</option>
|
<option value="day">Days</option>
|
||||||
@ -119,12 +115,6 @@ class="inline-block w-1/2 border-gray-300 dark:border-gray-700 dark:bg-gray-900
|
|||||||
|
|
||||||
<!-- Priority -->
|
<!-- Priority -->
|
||||||
|
|
||||||
<hr class="my-4">
|
|
||||||
<!-- Submit -->
|
|
||||||
<div class="mt-4">
|
|
||||||
<x-primary-button>Create habit</x-primary-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
<br>
|
<br>
|
||||||
|
|
||||||
{{-- Table--}}
|
{{-- Table--}}
|
||||||
|
|
||||||
<table class="table-auto text-left text-gray-500 dark:text-gray-400">
|
<table class="table-auto text-left text-gray-500 dark:text-gray-400">
|
||||||
<thead class="text-gray-900 bg-gray-100 dark:bg-gray-700 dark:text-gray-200">
|
<thead class="text-gray-900 bg-gray-100 dark:bg-gray-700 dark:text-gray-200">
|
||||||
<tr>
|
<tr>
|
||||||
@ -25,10 +24,10 @@
|
|||||||
Habits
|
Habits
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-2">
|
<th scope="col" class="px-6 py-2">
|
||||||
{{-- Edit--}}
|
{{-- Edit--}}
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-2">
|
<th scope="col" class="px-6 py-2">
|
||||||
{{-- Delete--}}
|
{{-- Delete--}}
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
|
|
||||||
@ -44,7 +43,8 @@
|
|||||||
<td class="px-4 py-2">
|
<td class="px-4 py-2">
|
||||||
<form action="{{route('habits.show', $habit)}}" method="get">
|
<form action="{{route('habits.show', $habit)}}" method="get">
|
||||||
@csrf
|
@csrf
|
||||||
<x-secondary-button type="submit">View</x-secondary-button>
|
<x-secondary-button>View</x-secondary-button>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-4 py-2">
|
<td class="px-4 py-2">
|
||||||
@ -64,10 +64,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</x-app-layout>
|
|
||||||
|
|
||||||
|
|
||||||
{{-- <div class="w-auto inline-block">--}}
|
{{-- <div class="w-auto inline-block">--}}
|
||||||
@ -103,3 +100,8 @@
|
|||||||
{{-- </div>--}}
|
{{-- </div>--}}
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-app-layout>
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
<x-app-layout>
|
|
||||||
<x-slot name="header">
|
|
||||||
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
|
|
||||||
{{ __('Habit Details') }}
|
|
||||||
</h2>
|
|
||||||
</x-slot>
|
|
||||||
|
|
||||||
<div class="py-6">
|
|
||||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
|
||||||
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-md sm:rounded-lg">
|
|
||||||
<div class="p-6 text-gray-900 dark:text-gray-100">
|
|
||||||
{{ $habit->name }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="py-6">
|
|
||||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
|
||||||
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-md sm:rounded-lg">
|
|
||||||
<div class="p-6 text-gray-900 dark:text-gray-100">
|
|
||||||
<table class="table-auto text-left text-gray-700 dark:text-gray-400">
|
|
||||||
<thead class="text-gray-900 bg-gray-100 dark:bg-gray-700 dark:text-gray-200">
|
|
||||||
<tr>
|
|
||||||
<th scope="col" class="px-4 py-2">
|
|
||||||
Date
|
|
||||||
</th>
|
|
||||||
<th scope="col" class="px-6 py-2">
|
|
||||||
Note
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@foreach($entries as $entry)
|
|
||||||
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 even:bg-gray-50 hover:bg-gray-100 dark:hover:bg-gray-600">
|
|
||||||
<td class="text-left px-4 py-2">
|
|
||||||
{{$entry->date}}
|
|
||||||
</td>
|
|
||||||
<td class="px-4 py-2">
|
|
||||||
{{$entry->note}}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
@endforeach
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</x-app-layout>
|
|
@ -18,7 +18,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
|
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
|
||||||
<x-nav-link :href="route('habits.index')" :active="request()->routeIs('habits.*')">
|
<x-nav-link :href="route('habits.index')" :active="request()->routeIs('habits.index')">
|
||||||
{{ __('Habits') }}
|
{{ __('Habits') }}
|
||||||
</x-nav-link>
|
</x-nav-link>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user