Add Calculationpresets and Calculator modules with CRUD functionality, migrations, and UI components.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Calculationpreset;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use App\Models\Calculationpreset as Model;
|
||||
use Livewire\WithPagination;
|
||||
use Livewire\Attributes\title;
|
||||
|
||||
#[title('Calculationpreset')]
|
||||
class Calculationpreset extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public Model $calculationpreset ;
|
||||
|
||||
public $search = '';
|
||||
|
||||
public function create(){
|
||||
return $this->redirectRoute('calculationpresets.create', navigate: true);
|
||||
}
|
||||
|
||||
public function show($id){
|
||||
return $this->redirectRoute('calculationpresets.show', $id);
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
return $this->redirectRoute('calculationpresets.edit', $id);
|
||||
}
|
||||
|
||||
public function delete($id){
|
||||
@Auth::check();
|
||||
Model::destroy($id);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.calculationpreset.index', [
|
||||
'calculationpresets' => Model::search('name', $this->search)->paginate(25)
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Calculationpreset;
|
||||
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use App\Models\Calculationpreset as Model;
|
||||
use Livewire\Attributes\title;
|
||||
|
||||
#[title('Create Calculationpreset')]
|
||||
class CreateCalculationpreset extends Component
|
||||
{
|
||||
public Model $calculationpreset ;
|
||||
|
||||
public string $name = '';
|
||||
public string $description = '';
|
||||
public float $price_kwh = 0;
|
||||
public float $factor_printer = 0;
|
||||
public float $factor_maintenance = 0;
|
||||
public float $factor_price = 0;
|
||||
|
||||
|
||||
#[Validate('required')]
|
||||
public function save(){
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string', 'max:255'],
|
||||
'price_kwh' => ['required', 'numeric'],
|
||||
'factor_printer' => ['nullable', 'numeric'],
|
||||
'factor_maintenance' => ['nullable', 'numeric'],
|
||||
'factor_price' => ['nullable', 'numeric']
|
||||
]);
|
||||
|
||||
$calculationpreset = new Model();
|
||||
$calculationpreset->name = $this->name;
|
||||
$calculationpreset->description = $this->description;
|
||||
$calculationpreset->price_kwh = $this->price_kwh;
|
||||
$calculationpreset->factor_printer = $this->factor_printer;
|
||||
$calculationpreset->factor_maintenance = $this->factor_maintenance;
|
||||
$calculationpreset->factor_price = $this->factor_price;
|
||||
$calculationpreset->save();
|
||||
|
||||
return $this->redirectRoute('calculationpresets.show', $calculationpreset->id, navigate: true);
|
||||
}
|
||||
|
||||
public function cancel(){
|
||||
return $this->redirectRoute('calculationpresets.index', navigate: true);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.calculationpreset.create', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Calculationpreset;
|
||||
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use App\Models\Calculationpreset as Model;
|
||||
use Livewire\Attributes\title;
|
||||
|
||||
#[title('Edit Calculationpreset')]
|
||||
class EditCalculationpreset extends Component
|
||||
{
|
||||
public Model $calculationpreset ;
|
||||
|
||||
public string $name = '';
|
||||
public string $description = '';
|
||||
public float $price_kwh = 0;
|
||||
public float $factor_printer = 0;
|
||||
public float $factor_maintenance = 0;
|
||||
public float $factor_price = 0;
|
||||
|
||||
#[Validate('required')]
|
||||
public function save(){
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string', 'max:255'],
|
||||
'price_kwh' => ['required', 'numeric'],
|
||||
'factor_printer' => ['nullable', 'numeric'],
|
||||
'factor_maintenance' => ['nullable', 'numeric'],
|
||||
'factor_price' => ['nullable', 'numeric']
|
||||
]);
|
||||
|
||||
$this->calculationpreset->update([
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'price_kwh' => $this->price_kwh,
|
||||
'factor_printer' => $this->factor_printer,
|
||||
'factor_maintenance' => $this->factor_maintenance,
|
||||
'factor_price' => $this->factor_price
|
||||
]);
|
||||
|
||||
return $this->redirectRoute('calculationpresets.show', $this->calculationpreset->id, navigate: true);
|
||||
}
|
||||
|
||||
public function cancel(){
|
||||
return $this->redirectRoute('calculationpresets.index', navigate: true);
|
||||
}
|
||||
|
||||
public function mount(Model $calculationpreset){
|
||||
$this->calculationpreset = $calculationpreset;
|
||||
$this->name = $calculationpreset->name;
|
||||
$this->description = $calculationpreset->description;
|
||||
$this->price_kwh = $calculationpreset->price_kwh;
|
||||
$this->factor_printer = $calculationpreset->factor_printer;
|
||||
$this->factor_maintenance = $calculationpreset->factor_maintenance;
|
||||
$this->factor_price = $calculationpreset->factor_price;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.calculationpreset.create', [
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Calculationpreset;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\Calculationpreset as Model;
|
||||
use Livewire\Attributes\title;
|
||||
|
||||
#[title('Show Calculationpreset')]
|
||||
class ShowCalculationpreset extends Component
|
||||
{
|
||||
|
||||
public Model $calculationpreset ;
|
||||
|
||||
public function back(){
|
||||
return redirect()->route('calculationpresets.index');
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
return redirect()->route('calculationpresets.edit', $id);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.calculationpreset.show', [
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user