Skip to content

Commit

Permalink
128 beui create and edit taxonomy (#174)
Browse files Browse the repository at this point in the history
Co-authored-by: Supun Dulara <[email protected]>
  • Loading branch information
IsharaEkanayaka and supundulara authored Oct 14, 2024
1 parent 787592f commit 4533dd4
Show file tree
Hide file tree
Showing 19 changed files with 510 additions and 138 deletions.
11 changes: 11 additions & 0 deletions app/Domains/Taxonomy/Models/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ class Taxonomy extends Model
'properties',
];

public static $propertyType = [
'string'=>'String',
'integer' => 'Integer Number',
'float' => 'Floating Point Number',
'date' => 'Date',
'datetime' => 'Date Time',
'boolean' => 'Boolean',
'url' => 'URL',
'image' => 'Image'
];

public function user()
{
return $this->belongsTo(User::class, 'created_by');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php

namespace App\Domains\TaxonomyTerms\Models;
namespace App\Domains\Taxonomy\Models;

use App\Domains\Auth\Models\User;
use Database\Factories\TaxonomyTermsFactory;
use Database\Factories\TaxonomyTermFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Domains\TaxonomyTerms\Models\Traits\Scope\TaxonomyTermsScope;

/**
* Class TaxonomyTerms.
* Class TaxonomyTerm.
*/
class TaxonomyTerms extends Model
class TaxonomyTerm extends Model
{
use TaxonomyTermsScope,
HasFactory,
use HasFactory,
LogsActivity;


Expand Down Expand Up @@ -46,6 +44,6 @@ public function user()
*/
protected static function newFactory()
{
return TaxonomyTermsFactory::new();
return TaxonomyTermFactory::new();
}
}

This file was deleted.

22 changes: 0 additions & 22 deletions app/Domains/TaxonomyTerms/Services/TaxonomyTermsService.php

This file was deleted.

46 changes: 41 additions & 5 deletions app/Http/Controllers/Backend/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
use App\Domains\Taxonomy\Models\Taxonomy;

Expand Down Expand Up @@ -31,7 +32,22 @@ public function create()
*/
public function store(Request $request)
{

$validatedData =$request->validate([
'code' => 'required|unique:taxonomies',
'name' => 'required',
'description' => 'nullable',
]);

try{
$taxonomy = new Taxonomy($validatedData);
$taxonomy->properties = $request->properties;
$taxonomy->created_by = Auth::user()->id;
$taxonomy->save();
return redirect()->route('dashboard.taxonomy.index')->with('Success', 'Taxonomy created successfully');
}catch (\Exception $ex) {
Log::error('Failed to create taxonomy', ['error' => $ex->getMessage()]);
return abort(500);
}
}
/**
* Show the form for editing the specified resource.
Expand All @@ -41,13 +57,17 @@ public function store(Request $request)
*/
public function edit(Taxonomy $taxonomy)
{
try{
return view('backend.taxonomy.edit', ['taxonomy' => $taxonomy]);
}catch (\Exception $ex) {
Log::error('Failed to load taxonomy edit page', ['error' => $ex->getMessage()]);
try {
return view('backend.taxonomy.edit', [
'taxonomy' => $taxonomy,
]);
} catch (\Exception $ex) {
Log::error('Failed to load taxonomy edit page', ['error' => $ex->getMessage()]);
return abort(500);
}
}


/**
* Update the specified resource in storage.
*
Expand All @@ -57,6 +77,22 @@ public function edit(Taxonomy $taxonomy)
*/
public function update(Request $request, Taxonomy $taxonomy)
{
$data = $request->validate([
'code' => 'required',
'name' => 'required',
'description' => 'nullable',
]);

try{
$taxonomy->update($data);
$taxonomy->properties = $request->properties;
$taxonomy->updated_by = Auth::user()->id;
$taxonomy->save();
return redirect()->route('dashboard.taxonomy.index')->with('Success', 'Taxonomy updated successfully');
}catch (\Exception $ex) {
Log::error('Failed to update taxonomy', ['error' => $ex->getMessage()]);
return abort(500);
}

}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use App\Domains\TaxonomyTerms\Models\TaxonomyTerms;
use App\Domains\Taxonomy\Models\TaxonomyTerm;

class TaxonomyTermsController extends Controller
class TaxonomyTermController extends Controller
{
/**
* Show the form for creating a new resource.
Expand All @@ -17,7 +17,7 @@ class TaxonomyTermsController extends Controller
public function create()
{
try{
return view('backend.taxonomyTerms.create');
return view('backend.taxonomy.terms.create');
}catch (\Exception $ex) {
Log::error('Failed to load taxonomy terms creation page', ['error' => $ex->getMessage()]);
return abort(500);
Expand All @@ -36,56 +36,55 @@ public function store(Request $request)
/**
* Show the form for editing the specified resource.
*
* @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms
* @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function edit(TaxonomyTerms $taxonomyTerms)
public function edit(TaxonomyTerm $taxonomyTerm)
{
try{
return view('backend.taxonomyTerms.edit', ['taxonomyTerms' => $taxonomyTerms]);
return view('backend.taxonomy.terms.edit', ['taxonomyTerm' => $taxonomyTerm]);
}catch (\Exception $ex) {
Log::error('Failed to load taxonomy terms edit page', ['error' => $ex->getMessage()]);
Log::error('Failed to load taxonomy term edit page', ['error' => $ex->getMessage()]);
return abort(500);
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms
* @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request, TaxonomyTerms $taxonomyTerms)
public function update(Request $request, TaxonomyTerm $taxonomyTerm)
{

}
/**
* Confirm to delete the specified resource from storage.
*
* @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms
* @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function delete(TaxonomyTerms $taxonomyTerms)
public function delete(TaxonomyTerm $taxonomyTerm)
{
return view('backend.taxonomyTerms.delete', compact('taxonomyTerms'));
return view('backend.taxonomy.terms.delete', compact('taxonomyTerm'));
}


/**
* Remove the specified resource from storage.
*
* @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms
* @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm
* @return \Illuminate\Http\RedirectResponse|null
*/
public function destroy(TaxonomyTerms $taxonomyTerms)
public function destroy(TaxonomyTerm $taxonomyTerm)
{
try {
$taxonomyTerms->delete();
return redirect()->route('dashboard.taxonomyTerms.index')->with('Success', 'Taxonomy term was deleted !');
$taxonomyTerm->delete();
return redirect()->route('dashboard.taxonomy.terms.index')->with('Success', 'Taxonomy term was deleted !');
} catch (\Exception $ex) {
Log::error('Failed to delete taxonomy term', ['taxonomyTerms_id' => $taxonomyTerms->id, 'error' => $ex->getMessage()]);
Log::error('Failed to delete taxonomy term', ['taxonomyTerm_id' => $taxonomyTerm->id, 'error' => $ex->getMessage()]);
return abort(500);
}
}
}

}
4 changes: 3 additions & 1 deletion app/Http/Livewire/Backend/TaxonomyTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function columns(): array
->sortable(),
Column::make("Created at", "created_at")
->sortable(),
Column::make("Updated at", "updated_at")
->sortable(),
Column::make("Actions")
];
}
Expand All @@ -39,7 +41,7 @@ public function query(): Builder

public function rowView(): string
{
return 'backend.taxonomies.index-table-row';
return 'backend.taxonomy.index-table-row';
}
}

Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
<?php

namespace Database\Factories;
use App\Domains\TaxonomyTerms\Models\TaxonomyTerms;
use App\Domains\Taxonomy\Models\TaxonomyTerm;
use App\Domains\Auth\Models\User;



use Illuminate\Database\Eloquent\Factories\Factory;

class TaxonomyTermsFactory extends Factory
class TaxonomyTermFactory extends Factory
{



protected $model = TaxonomyTerms::class;
protected $model = TaxonomyTerm::class;

/**
* Define the model's default state.
Expand Down
4 changes: 4 additions & 0 deletions resources/sass/backend/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@
.btn-w-150 {
min-width: 150px !important;
}

[x-cloak] {
display: none !important;
}
60 changes: 0 additions & 60 deletions resources/views/backend/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,66 +58,6 @@
<script src="{{ mix('js/backend.js') }}"></script>
@stack('after-scripts')

<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script>
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
[{
'header': 1
}, {
'header': 2
}], // custom button values
[{
'list': 'ordered'
}, {
'list': 'bullet'
}],
[{
'script': 'sub'
}, {
'script': 'super'
}], // superscript/subscript
[{
'indent': '-1'
}, {
'indent': '+1'
}], // outdent/indent
[{
'size': ['small', false, 'large', 'huge']
}], // custom dropdown
[{
'header': [1, 2, 3, 4, 5, 6, false]
}],
[{
'color': []
}, {
'background': []
}], // dropdown with defaults from theme
[{
'align': []
}],
['clean'] // remove formatting button
];
var quill = new Quill('#editor-container', {
theme: 'snow',
modules: {
toolbar: toolbarOptions
}
});
document.getElementById('submit-button').addEventListener('click', function(event) {
// Get Quill content
var quillContent = quill.root.innerHTML;
// Populate hidden form field with quill data
var description = document.querySelector('textarea[name=description]');
description.value = quillContent;
});
</script>
</body>

</html>
Loading

0 comments on commit 4533dd4

Please sign in to comment.