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

Admin Panel Upgrade #40

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/Enums/MenuPlacement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php


declare(strict_types=1);

namespace App\Enums;

enum MenuPlacement: string
{
case HEADER = 'header';
case FOOTER = 'footer';
case SIDEBAR = 'sidebar';
case TOPBAR = 'topbar';
case MOBILE_HEADER = 'mobile_header';

public static function values(): array
{
return array_column(self::cases(), 'name', 'value');
}
}
19 changes: 19 additions & 0 deletions app/Enums/MenuType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


declare(strict_types=1);

namespace App\Enums;

enum MenuType: string
{
case LINK = 'link';
case DROPDOWN = 'dropdown';
case MEGAMENU = 'megamenu';
case BUTTON = 'button';

public static function values(): array
{
return array_column(self::cases(), 'name', 'value');
}
}
13 changes: 13 additions & 0 deletions app/Enums/NotificationType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum NotificationType: string
{
case INFO = 'info';
case WARNING = 'warning';
case SUCCESS = 'success';
case DANGER = 'danger';
}
21 changes: 21 additions & 0 deletions app/Enums/PageType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum PageType: string
{
case HOME = 'home';
case ABOUT = 'about';
case TEAM = 'team';
case BLOG = 'blog';
case SERVICE = 'service';
case PORTFOLIO = 'portfolio';
case PROJECT = 'project';

public static function values(): array
{
return array_column(self::cases(), 'name', 'value');
}
}
25 changes: 25 additions & 0 deletions app/Enums/RedirectionStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum RedirectionStatus: string
{
case MOVED_PERMANENTLY = '301';
case PERMANENT_REDIRECT = '308';
case FOUND = '302';
case SEE_OTHER = '303';
case TEMPORARY_REDIRECT = '307';

public static function values(): array
{
return array_column(self::cases(), 'name', 'value');
}

// loop through the values:

// @foreach(App\Enums\PaymentStatus::values() as $key=>$value)
// <option value="{{ $key }}">{{ $value }}</option>
// @endforeach
}
21 changes: 21 additions & 0 deletions app/Enums/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum Status: int
{
case INACTIVE = 0;

case ACTIVE = 1;

// case COMPLETED = 2;

// case CANCELED = 5;

public static function values(): array
{
return array_column(self::cases(), 'name', 'value');
}
}
56 changes: 56 additions & 0 deletions app/Http/Livewire/Language/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace App\Http\Livewire\Language;

use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Component;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;

final class Create extends Component
{
use LivewireAlert;

/** @var string[] */
public $listeners = ['createLanguage'];

public array $languages = [];

public $language;
public $name;
public $code;

public $createLanguage = false;

protected $rules = [
'name' => 'required|max:191',
'code' => 'required',
];

public function createLanguage(): void
{
$this->createLanguage = true;
}

public function create(): void
{
$this->validate();

$this->language->save();

File::copy(App::langPath().('/en.json'), App::langPath().('/'.$this->code.'.json'));

$this->alert('success', __('Data created successfully!'));

$this->emit('resetIndex');

$this->createLanguage = false;
}

public function render()
{
return view('livewire.admin.language.create');
}
}
59 changes: 59 additions & 0 deletions app/Http/Livewire/Language/Edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace App\Http\Livewire\Language;

use Livewire\Component;
use File;
use App;
use App\Models\Language;
use Jantinnerezo\LivewireAlert\LivewireAlert;

final class Edit extends Component
{
use LivewireAlert;

/** @var string[] */
public $listeners = ['editLanguage'];

public array $languages = [];

public $language;
public $name;
public $code;

public $editLanguage = false;

protected $rules = [
'language.name' => 'required|max:191',
'language.code' => 'required',
];

public function editLanguage($id): void
{
$this->language = Language::findOrFail($id);

$this->editLanguage = true;
}

public function update(): void
{
$this->validate();

$this->language->save();

File::copy(App::langPath().('/en.json'), App::langPath().('/'.$this->code.'.json'));

$this->alert('success', __('Data created successfully!'));

$this->emit('resetIndex');

$this->editLanguage = false;
}

public function render()
{
return view('livewire.admin.language.edit');
}
}
64 changes: 64 additions & 0 deletions app/Http/Livewire/Language/EditTranslation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace App\Http\Livewire\Language;

use Livewire\Component;
use App\Models\Language;
use Jantinnerezo\LivewireAlert\LivewireAlert;

final class EditTranslation extends Component
{
use LivewireAlert;
public $language;
public $translations;

public $rules = [
'translations.*.value' => 'required',
];

public function mount($language): void
{
$this->language = Language::where('id', $language)->firstOrFail();
// dd($this->all());
$this->translations = $this->getTranslations();
$this->translations = collect($this->translations)->map(function ($item, $key) {
return [
'key' => $key,
'value' => $item,
];
})->toArray();
}

private function getTranslations()
{
$path = base_path("lang/{$this->language->code}.json");
$content = file_get_contents($path);

return json_decode($content, true);
}

public function updateTranslation(): void
{
$this->validate();

$path = base_path("lang/{$this->language->code}.json");

$data = file_get_contents($path);
$translations = json_decode($data, true);

foreach ($this->translations as $key => $translation) {
$translations[$translation['key']] = $translation['value'];
}

file_put_contents($path, json_encode($translations, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));

$this->alert('success', __('Data created successfully!'));
}

public function render()
{
return view('livewire.admin.language.edit-translation');
}
}
62 changes: 62 additions & 0 deletions app/Http/Livewire/Language/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace App\Http\Livewire\Language;

use Livewire\Component;
use App\Models\Language;
use Artisan;
use Jantinnerezo\LivewireAlert\LivewireAlert;

final class Index extends Component
{
use LivewireAlert;

public $languages = [];

public $language;

protected $listeners = [
'refreshIndex' => '$refresh',
];

public function mount(): void
{
$this->languages = Language::all()->toArray();
}

public function render()
{
return view('livewire.admin.language.index');
}

public function onSetDefault($id): void
{
Language::where('is_default', '=', true)->update(['is_default' => false]);

$this->language = Language::findOrFail($id);

$this->language->is_default = true;

$this->language->save();

$this->alert('success', __('Language updated successfully!'));
}

public function sync($id): void
{
$languages = Language::findOrFail($id);

Artisan::call('translatable:export', ['lang' => $languages->code]);

$this->alert('success', __('Translation updated successfully!'));
}

public function delete(Language $language): void
{
$language->delete();

$this->alert('warning', __('Language deleted successfully!'));
}
}
Loading
Loading