Skip to content

Commit

Permalink
Merge pull request #16 from HE-Arc/dev
Browse files Browse the repository at this point in the history
Toggle button in timeline creation form, link to registration in login
  • Loading branch information
katsulon authored Oct 29, 2024
2 parents 9496a02 + b128f35 commit d2155d7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 25 deletions.
17 changes: 12 additions & 5 deletions timeliner/app/Http/Controllers/TimelineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

class TimelineController extends Controller
{
public function fetchAllAvailable()
public function index()
{
$timelines = Timeline::all();
return view('index', ['timelines'=>$timelines]);
return view('index', ['timelines' => $timelines]);
}

public function timelinelist()
Expand All @@ -25,8 +25,15 @@ public function create()

public function store(Request $request)
{
\App\Models\Timeline::create($request->all());
// TODO solve mass assignement problem
return redirect()->route('home')->with('success','Timeline created successfully.');
$request->validate([
'name' => 'required|min:1|max:25',
'description' => 'required|min:1|max:100',
'private' => 'required|boolean'
]);

Timeline::create($request->all());

return redirect()->route('timeline.index')
->with('success','Timeline created successfully.');
}
}
14 changes: 3 additions & 11 deletions timeliner/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ public function run(): void
{
// User::factory(10)->create();

DB::table('users')->truncate();

User::factory()->create([
'name' => 'Test User',
'email' => '[email protected]',
'password' => '12345'
]);


DB::table('timelines')->insert([
'name' => "Timeline number one",
'private' => false,
'description' => "an important timeline",
]);
DB::table('timelines')->insert([
'name' => "Anne's timeline",
'private' => true,
'description' => "Only for Anne's friends",
]);
$this->call(TimelineSeeder::class);
}
}
31 changes: 31 additions & 0 deletions timeliner/database/seeders/TimelineSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Database\Seeders;

use App\Models\Timeline;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class TimelineSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Timeline::truncate();

$timelines = [
['name' => "Timeline number one", 'private' => false, 'description' => "an important timeline"],
['name' => "Anne's timeline", 'private' => true, 'description' => "Only for Anne's friends"],
];

foreach ($timelines as $timeline) {
Timeline::create(array(
'name' => $timeline['name'],
'private' => $timeline['private'],
'description' => $timeline['description']
));
}
}
}
2 changes: 1 addition & 1 deletion timeliner/resources/views/about.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900 dark:text-gray-100">
{{ __("All rights reserved") }}
<p>Made in He-Arc during the course DevWebI</p>
<p>Made in HE-Arc during the DevWebI course</p>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions timeliner/resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
</div>

<div class="flex items-center justify-end mt-4">
<a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800 mr-4" href="{{ route('register') }}">
{{ __("Not registered yet?") }}

@if (Route::has('password.request'))
<a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('password.request') }}">
{{ __('Forgot your password?') }}
Expand Down
17 changes: 10 additions & 7 deletions timeliner/resources/views/timeline/createtimeline.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@
<div class="col-12 col-lg-6 offset-0 offset-lg-3">
<div class="card">
<div class="card-header">
Nouveau timeline
New timeline
</div>
<div class="card-body">
<div class="form-row">
<div class="form-group col-12">
<label for="inputTitle">Titre</label>
<input type="text" name="name" class="form-control" id="inputTitle">
<label for="inputTitle">Name</label>
<input type="text" name="name" value="{{ old('name') }}" class="form-control" id="inputTitle">
</div>
<div class="form-group col-12">
<!-- TODO accecpt only people that are in the database -->
<!-- TODO accecpt several people -->
<label for="inputDescription">Description</label>
<input type="text" name="description" class="form-control" id="inputDescription">
<input type="text" name="description" value="{{ old('description') }}" class="form-control" id="inputDescription">
</div>

<div class="form-group col-12">
<!-- TODO accecpt only people that are in the database -->
<!-- TODO accecpt several people -->
<label for="inputStatus">Status (public/private)</label>
<input type="text" name="private" class="form-control" id="inputStatus">
<select name="private" class="form-control" id="inputStatus">
<option value="1">Private</option>
<option value="0" {{ old('private')? "":"selected" }}>Public</option>
</select>
</div>
<!--
<div class="row mt-3">
Expand All @@ -49,14 +52,14 @@
-->
<div class="form-group col-6">
<!-- TODO button 'Ajouter' redirect to the detail of the newly created timeline -->
<button class="btn btn-primary" href={{ route('timeline.create') }} type="submit" class="btn btn-primary mt-3">Ajouter</button>
<button class="btn btn-primary" href={{ route('timeline.create') }} type="submit" class="btn btn-primary mt-3">Add</button>
</div>
</div>
</div>
</div>
@if ($errors->any())
<div class="alert alert-danger mt-3 col-12">
<strong>Whoops!</strong> Il y a un problème avec vos entrées.<br><br>
<strong>Oops!</strong> There's a problem with your entries.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
Expand Down
2 changes: 1 addition & 1 deletion timeliner/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;

Route::get('/', [TimelineController::class, 'fetchAllAvailable'])->name('home');
Route::get('/', [TimelineController::class, 'index'])->name('home');

Route::get('about', function () {
return view('about');
Expand Down

0 comments on commit d2155d7

Please sign in to comment.