Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
NuwanJ committed Oct 16, 2024
1 parent ff2e611 commit df71d83
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 136 deletions.
17 changes: 11 additions & 6 deletions app/Domains/Taxonomy/Models/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Taxonomy extends Model
];

public static $propertyType = [
'string'=>'String',
'string' => 'String',
'integer' => 'Integer Number',
'float' => 'Floating Point Number',
'date' => 'Date',
Expand All @@ -49,16 +49,21 @@ public function user()
return $this->belongsTo(User::class, 'created_by');
}

public function user_created()
{
return $this->belongsTo(User::class, 'created_by');
}

public function user_updated()
{
return $this->belongsTo(User::class, 'created_by');
}

public function terms()
{
return $this->hasMany(TaxonomyTerm::class, 'taxonomy_id');
}

/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
protected static function newFactory()
{
return TaxonomyFactory::new();
Expand Down
17 changes: 11 additions & 6 deletions app/Domains/Taxonomy/Models/TaxonomyTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public function user()
return $this->belongsTo(User::class, 'created_by');
}

public function user_created()
{
return $this->belongsTo(User::class, 'created_by');
}

public function user_updated()
{
return $this->belongsTo(User::class, 'created_by');
}

public function taxonomy()
{
return $this->belongsTo(Taxonomy::class, 'taxonomy_id');
Expand All @@ -55,7 +65,7 @@ public function children()
public function getMetadata($code)
{
$metadata = json_decode($this->metadata, true);

if (is_array($metadata)) {
foreach ($metadata as $item) {
if ($item['code'] === $code) {
Expand All @@ -66,11 +76,6 @@ public function getMetadata($code)
return null;
}

/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
protected static function newFactory()
{
return TaxonomyTermFactory::new();
Expand Down
12 changes: 5 additions & 7 deletions app/Http/Livewire/Backend/TaxonomyTermTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public function mount($taxonomy)
public function columns(): array
{
return [
Column::make("Code", "code")
->searchable()->sortable(),
Column::make("Name", "name")
->searchable()->sortable(),
Column::make("Taxonomy", "taxonomy.name")
->searchable()
->sortable(),
Column::make("Code", "code")
->searchable()->sortable(),
Column::make("Taxonomy Parent", "parent_id"),
Column::make("Created by", "created_by")
->sortable(),
Column::make("Updated by", "updated_by")
Expand All @@ -53,6 +51,6 @@ public function query(): Builder

public function rowView(): string
{
return 'backend.taxonomy.terms.index-table-row';
return 'backend.taxonomy.terms.index-table-row';
}
}
}
4 changes: 2 additions & 2 deletions resources/views/backend/taxonomy/index-table-row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</x-livewire-tables::table.cell>

<x-livewire-tables::table.cell>
{{ User::find($row->created_by)->name ?? 'N/A' }}
{{ $row->user_created->name ?? 'N/A' }}
</x-livewire-tables::table.cell>

<x-livewire-tables::table.cell>
{{ User::find($row->updated_by)->name ?? 'N/A' }}
{{ $row->user_updated->name ?? 'N/A' }}
</x-livewire-tables::table.cell>

<x-livewire-tables::table.cell>
Expand Down
175 changes: 103 additions & 72 deletions resources/views/backend/taxonomy/terms/create.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@extends('backend.layouts.app')

@section('title', __('Create Taxonomy Term'))

@section('content')
<div>

Expand All @@ -9,101 +11,131 @@
<form method="POST" action="{{ route('dashboard.taxonomy.terms.store', $taxonomy) }}">
@csrf

<div class="term py-2 pt-3" style="border: 1px solid rgb(207, 207, 207); border-radius:5px">
<div class="term py-2 pt-3" style="border: 1px solid rgb(207, 207, 207); border-radius:5px">

<div class="col-12 pb-3">
<strong>Term Configurations</strong>
</div>
<div class="col-12 pb-3">
<strong>Term Configurations</strong>
</div>

<!-- Taxonomy -->
<div class="col-12 py-2">
<div class="col ps-0">
<label for="drop1">Taxonomy*</label>
</div>

<div class="col-12 py-2">
<div class="col ps-0">
<label for="drop1">Parent Taxonomy Term ( Optional)</label>
<div class="col-md-12 px-0">
{!! Form::text('taxonomy_name', $taxonomy->name, ['class' => 'form-control', 'readonly']) !!}
{!! Form::hidden('taxonomy_id', $taxonomy->id, ['class' => 'form-control', 'readonly']) !!}
</div>
</div>
<select name="parent_id" class="form-select">

<!-- Parent Taxonomy Term -->
<div class="col-12 py-2">
<div class="col ps-0">
<label for="drop1">Parent Taxonomy Term ( Optional)</label>
</div>
<select name="parent_id" class="form-select">
<option value="" selected>Select</option>
@foreach($parentTerms as $term)
@foreach ($parentTerms as $term)
<option value="{{ $term->id }}">{{ $term->name }}</option>
@endforeach
</select>
</div>

<div class="col-12 py-2">
<div class="col ps-0">
<label for="drop1">Taxonomy*</label>
</div>
<select name="taxonomy_id" class="form-select">
<option value="" selected>Select</option>
@foreach($taxonomy_id as $tax_id)
<option value="{{ $tax_id->id }}">{{ $tax_id->name }}</option>
@endforeach
</select>
</div>

<div class="col-12 py-2">
<div class="col ps-0">
<label for="drop1">Taxonomy Term Code*</label>
</select>
</div>
<div class="col-md-12 px-0">
{!! Form::text('code', '', ['class' => 'form-control']) !!}
</div>
</div>

<div class="col-12 py-2">
<div class="col ps-0">
<label for="drop1">Taxonomy Term Name*</label>
</div>
<div class="col-md-12 px-0">
{!! Form::text('name', '', ['class' => 'form-control']) !!}
</div>
</div>
</div>

<div class="metadata py-3 mt-5 mb-3" style="border: 1px solid rgb(207, 207, 207); border-radius:5px">

<div class="col-12 pb-3">
<strong>Metadata</strong>
</div>
<!-- Taxonomy Term Code -->
<div class="col-12 py-2">
<div class="col ps-0">
<label for="drop1">Taxonomy Term Code*</label>
</div>
<div class="col-md-12 px-0">
{!! Form::text('code', '', ['class' => 'form-control']) !!}
</div>
</div>

@foreach(json_decode($taxonomy->properties, true) as $property)
<!-- Taxonomy Term Name -->
<div class="col-12 py-2">
<div class="col ps-0">
<label >{{ $property['name'] }} ({{\App\Domains\Taxonomy\Models\Taxonomy::$propertyType[$property['data_type']]}})</label>
<label for="drop1">Taxonomy Term Name*</label>
</div>
<div class="col-md-12 px-0">
@switch($property['data_type'])
@case('string')
{!! Form::text("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}
{!! Form::text('name', '', ['class' => 'form-control']) !!}
</div>
</div>
</div>

<!-- Metadata Section -->
<div class="metadata py-3 mt-5 mb-3" style="border: 1px solid rgb(207, 207, 207); border-radius:5px">

<div class="col-12 pb-3">
<strong>Metadata</strong>
</div>

@foreach (json_decode($taxonomy->properties, true) as $property)
<div class="col-12 py-2">
<div class="col ps-0">
<label>{{ $property['name'] }}
({{ \App\Domains\Taxonomy\Models\Taxonomy::$propertyType[$property['data_type']] }})
</label>
</div>
<div class="col-md-12 px-0">
@switch($property['data_type'])
@case('string')
{!! Form::text("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}
@break
@case('integer')
{!! Form::number("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code'], 'step' => '1']) !!}

@case('integer')
{!! Form::number("metadata[{$property['code']}]", null, [
'class' => 'form-control',
'id' => $property['code'],
'step' => '1',
]) !!}
@break
@case('float')
{!! Form::number("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code'], 'step' => 'any']) !!}

@case('float')
{!! Form::number("metadata[{$property['code']}]", null, [
'class' => 'form-control',
'id' => $property['code'],
'step' => 'any',
]) !!}
@break
@case('boolean')
<div class="form-check">
{!! Form::checkbox("metadata[{$property['code']}]", 1, null, ['class' => 'form-check-input', 'id' => $property['code']]) !!}
</div>

@case('boolean')
<div class="form-check">
{!! Form::checkbox("metadata[{$property['code']}]", 1, null, [
'class' => 'form-check-input',
'id' => $property['code'],
]) !!}
</div>
@break
@case('date')
{!! Form::date("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}

@case('date')
{!! Form::date("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}
@break
@case('datetime')
{!! Form::datetimeLocal("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}

@case('datetime')
{!! Form::datetimeLocal("metadata[{$property['code']}]", null, [
'class' => 'form-control',
'id' => $property['code'],
]) !!}
@break
@case('url')
{!! Form::url("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}

@case('url')
{!! Form::url("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}
@break
@case('image')
{!! Form::file("metadata[{$property['code']}]", ['class' => 'form-control', 'id' => $property['code']]) !!}

@case('image')
{!! Form::file("metadata[{$property['code']}]", ['class' => 'form-control', 'id' => $property['code']]) !!}
@break
@default
{!! Form::text("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}
@endswitch

@default
{!! Form::text("metadata[{$property['code']}]", null, ['class' => 'form-control', 'id' => $property['code']]) !!}
@endswitch
</div>
</div>
</div>
@endforeach
</div>
@endforeach
</div>
</x-slot>

<x-slot name="footer">
Expand All @@ -113,5 +145,4 @@
</x-backend.card>

</div>

@endsection
1 change: 0 additions & 1 deletion resources/views/backend/taxonomy/terms/delete.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
</x-backend.card>
</div>
@endsection

Loading

0 comments on commit df71d83

Please sign in to comment.