Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

33 UI create component for course ilos #46

Merged
merged 10 commits into from
Aug 30, 2024
112 changes: 112 additions & 0 deletions app/Http/Controllers/Backend/CourseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace App\Http\Controllers\Backend;
use App\Domains\Announcement\Models\Announcement;
use App\Http\Controllers\Controller;


use Illuminate\Http\Request;

class CourseController extends Controller
{
public function create()
{
return view('backend.courses.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|void
*/
public function store(Request $request)
{
$data = request()->validate([
'area' => ['required', Rule::in(array_keys(Announcement::areas()))],
'type' => ['required', Rule::in(array_keys(Announcement::types()))],
NuwanJ marked this conversation as resolved.
Show resolved Hide resolved
'message' => 'string|required',
'enabled' => 'nullable',
'starts_at' => 'required|date_format:Y-m-d\\TH:i',
'ends_at' => 'required|date_format:Y-m-d\\TH:i', // TODO: Test ends>starts
]);

try {
$announcement = new Announcement($data);
$announcement->enabled = ($request->enabled != null);
$announcement->save();

return redirect()->route('dashboard.announcements.index', $announcement)->with('Success', 'Announcement was created !');
} catch (\Exception $ex) {
return abort(500);
}
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Announcement $announcement
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function edit(Announcement $announcement)
{
$areas = Announcement::areas();
$types = Announcement::types();
return view('backend.announcements.edit', compact('announcement', 'areas', 'types'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Announcement $announcement
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request, Announcement $announcement)
{
$data = request()->validate([
'area' => ['required', Rule::in(array_keys(Announcement::areas()))],
'type' => ['required', Rule::in(array_keys(Announcement::types()))],
NuwanJ marked this conversation as resolved.
Show resolved Hide resolved
'message' => 'string|required',
'enabled' => 'nullable',
'starts_at' => 'required|date_format:Y-m-d\\TH:i',
'ends_at' => 'required|date_format:Y-m-d\\TH:i', // TODO: Test ends>starts
]);

try {
$announcement->enabled = ($request->enabled != null);
$announcement->update($data);
return redirect()->route('dashboard.announcements.index')->with('Success', 'Announcement was updated !');
} catch (\Exception $ex) {
return abort(500);
}
}

/**
* Confirm to delete the specified resource from storage.
*
* @param \App\Models\Announcement $announcement
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function delete(Announcement $announcement)
{
return view('backend.announcements.delete', compact('announcement'));
}


/**
* Remove the specified resource from storage.
*
* @param \App\Models\Announcement $announcement
* @return \Illuminate\Http\RedirectResponse|null
*/
public function destroy(Announcement $announcement)
{
try {
$announcement->delete();
return redirect()->route('dashboard.announcements.index')->with('Success', 'Announcement was deleted !');
} catch (\Exception $ex) {
return abort(500);
}
}
}
40 changes: 40 additions & 0 deletions app/Http/Livewire/Backend/CreateCourses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Livewire\Backend;

use Livewire\Component;

class CreateCourses extends Component
{
public $formStep = 1;

public $ilos = [];
public $knowledge = [];
public $skills = [];
public $attitudes = [];
public $references = [];

protected $listeners = ['itemsUpdated' => 'updateItems'];

public function updateItems($type,$newItems){
$this->$type = $newItems;
$this->emit('refreshItems' . ucfirst($type), $newItems);
}


public function next(){
$this->formStep++;
}

public function previous(){
$this->formStep--;
}

public function submit(){
}

public function render()
{
return view('livewire.backend.create-courses');
}
}
43 changes: 43 additions & 0 deletions app/Http/Livewire/Backend/ItemAdder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Http\Livewire\Backend;

use Livewire\Component;

class ItemAdder extends Component
{
public $type;
public $items = [];
public $size = "col-12";

protected $listeners = ['refreshItems' => 'refreshItems'];

public function mount($type, $items = [])
{
$this->type = $type;
$this->items = $items;
}

public function addItem($item)
{
$this->items[] = $item;
$this->emitUp('itemsUpdated', $this->type, $this->items);
}

public function removeItem($index)
{
unset($this->items[$index]);
$this->items = array_values($this->items);
$this->emitUp('itemsUpdated', $this->type, $this->items);
}

public function refreshItems($items)
{
$this->items = $items;
}

public function render()
{
return view('livewire.backend.item-adder');
}
}
53 changes: 52 additions & 1 deletion public/css/backend.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/frontend.css

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions public/js/backend.js

Large diffs are not rendered by default.

90 changes: 45 additions & 45 deletions public/js/frontend.js

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions resources/sass/backend/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,55 @@
@import '~@coreui/icons/css/free.min.css';

@import '~@coreui/icons/css/brand.min.css';

.step {
display: none;
}

.step.active {
display: block;
}

.step-indicator {
display: flex;
justify-content: center;
margin-bottom: 20px;
}

.step-indicator .step-item {
flex: 1;
text-align: center;
position: relative;
}

.step-indicator .step-item:before {
content: "";
position: absolute;
top: 50%;
left: 0;
right: 0;
border-top: 1px solid #ccc;
z-index: 0;
}

.step-indicator .step-item.active .step-count {
background-color: #007bff;
color: #fff;
}

.step-indicator .step-count {
display: inline-block;
width: 30px;
height: 30px;
line-height: 30px;
border-radius: 50%;
background-color: #ccc;
color: #333;
position: relative;
z-index: 1;
}

.card-title {
text-align: center;
text-decoration: underline;
}
7 changes: 7 additions & 0 deletions resources/views/backend/courses/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@extends('backend.layouts.app')

@section('title', __('Courses'))

@section('content')
@livewire('backend.create-courses')
@endsection
31 changes: 31 additions & 0 deletions resources/views/backend/courses/delete.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@extends('backend.layouts.app')

@section('title', __('Announcement'))

@section('content')
<div>
<x-backend.card>
<x-slot name="header">
Announcements : Delete | {{ $announcement->id }}
</x-slot>

<x-slot name="body">
<p>Are you sure you want to delete
<strong><i>"{{ $announcement->message }}"</i></strong> ?
</p>
<div class="d-flex">
{!! Form::open([
'url' => route('dashboard.announcements.destroy', compact('announcement')),
'method' => 'delete',
'class' => 'container',
]) !!}

<a href="{{ route('dashboard.announcements.index') }}" class="btn btn-light mr-2">Back</a>
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}

{!! Form::close() !!}
</div>
</x-slot>
</x-backend.card>
</div>
@endsection
Loading
Loading