Skip to content

Commit

Permalink
Merge pull request #31 from riodwanto/feat/general-improvement
Browse files Browse the repository at this point in the history
Feat/general improvement
  • Loading branch information
riodwanto authored Sep 16, 2024
2 parents f3804ba + 0e3a27b commit 9c1f0e2
Show file tree
Hide file tree
Showing 84 changed files with 2,903 additions and 277 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
APP_NAME=SuperDuperFiStarterKit
APP_NAME="Superduper Starter Kit"
APP_VERSION=1.15.0
APP_ENV=local
APP_KEY=
APP_DEBUG=true
Expand Down
78 changes: 42 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,26 @@

#### Features

- 🛡 [Filament Shield](#plugins-used) for managing role access
- 👨🏻‍🦱 customizable profile page from [Filament Breezy](#plugins-used)
- 🌌 Managable media with [Filament Spatie Media](#plugins-used)
- 🖼 Theme settings for changing panel color
- 💌 Setting mail on the fly in Mail settings
- 🅻 Lang Generator
- Etc..

- 🛡 [Filament Shield](#plugins-used) for managing role access
- 👨🏻‍🦱 customizable profile page from [Filament Breezy](#plugins-used)
- 🌌 Managable media with [Filament Spatie Media](#plugins-used)
- 🖼 Theme settings for changing panel color
- 💌 Setting mail on the fly in Mail settings
- 🅻 Lang Generator
- Etc..

#### Latest update
###### Version: v1.14.xx
- New UserResource UI form
- Add avatar to user add & edit
- New Theme settings UI

##### Version: v1.15.xx

- Add *opcodesio/log-viewer*
- Add new plugins
- Bugs fix & Improvement
- Forgot Password
- User Verification
- Etc

[Version Releases](https://github.com/riodwanto/superduper-filament-starter-kit/releases)

###### Upcoming:
- ~~Filament Multi Tenancy 🔥~~
- Add opcodesio/log-viewer for general log viewer
- Member Module
- Some Improvement
- ...

*Sadly, Filament Multi-Tenancy will not be included in this starter kit. This repository will focus on improvements for non-multi-tenants, since many rooms should be improved.*
**But, I'll release on different repo for Multi Tenancy usecase.** ☕️

<a href="https://buymeacoffee.com/riodewanto" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

Expand Down Expand Up @@ -98,21 +88,29 @@ email: superadmin@starter-kit.com
password: superadmin
```

#### Performance

*It's recommend to run below command as suggested in [Filament Documentation](https://filamentphp.com/docs/3.x/panels/installation#improving-filament-panel-performance) for improving panel perfomance.*

```bash
php artisan icons:cache
```

Please see this [Improving Filament panel performance](https://filamentphp.com/docs/3.x/panels/installation#improving-filament-panel-performance) documentation for further improvement

#### Language Generator
This project include lang generator.
```

This project include lang generator.

```bash
php artisan superduper:lang-translate [from] [to]
```

Generator will look up files inside folder `[from]`. Get all variables inside the file; create a file and translate using `translate.googleapis.com`.

This is what the translation process looks like.
```

```bash
❯ php artisan superduper:lang-translate en fr es

🔔 Translate to 'fr'
Expand All @@ -121,17 +119,24 @@ This is what the translation process looks like.
🔔 Translate to 'es'
1/3 [▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░] 33% -- 🔄 Processing: page.php
```
###### Usage example
* Single output
```

##### Usage example

- Single output

```bash
php artisan superduper:lang-translate en fr
```
* Multiple output
```

- Multiple output

```bash
php artisan superduper:lang-translate en es ar fr pt-PT pt-BR zh-CN zh-TW
```

###### If you are using json translation
```

```bash
php artisan superduper:lang-translate en fr --json
```

Expand All @@ -141,14 +146,17 @@ These are [Filament Plugins](https://filamentphp.com/plugins) use for this proje

| **Plugin** | **Author** |
| :-------------------------------------------------------------------------------------------------- | :-------------------------------------------------- |
| [Filament Spatie Media Library](https://github.com/filamentphp/spatie-laravel-media-library-plugin) | [Filament Official](https://github.com/filamentphp) |
| [Filament Spatie Settings](https://github.com/filamentphp/spatie-laravel-settings-plugin) | [Filament Official](https://github.com/filamentphp) |
| [Filament Spatie Tags](https://github.com/filamentphp/spatie-laravel-tags-plugin) | [Filament Official](https://github.com/filamentphp) |
| [Filament Spatie Media Library](https://github.com/filamentphp/spatie-laravel-media-library-plugin) | [Filament Official](https://github.com/filamentphp) |
| [Filament Spatie Settings](https://github.com/filamentphp/spatie-laravel-settings-plugin) | [Filament Official](https://github.com/filamentphp) |
| [Filament Spatie Tags](https://github.com/filamentphp/spatie-laravel-tags-plugin) | [Filament Official](https://github.com/filamentphp) |
| [Shield](https://github.com/bezhanSalleh/filament-shield) | [bezhansalleh](https://github.com/bezhansalleh) |
| [Exceptions](https://github.com/bezhansalleh/filament-exceptions) | [bezhansalleh](https://github.com/bezhansalleh) |
| [Breezy](https://github.com/jeffgreco13/filament-breezy) | [jeffgreco13](https://github.com/jeffgreco13) |
| [Logger](https://github.com/z3d0x/filament-logger) | [z3d0x](https://github.com/z3d0x) |
| [Ace Code Editor](https://github.com/riodwanto/filament-ace-editor) | [riodwanto](https://github.com/riodwanto) |
| [Filament Record Navigation Plugin](https://github.com/josespinal/filament-record-navigation) | [josespinal](https://github.com/josespinal) |
| [Filament media manager](https://github.com/tomatophp/filament-media-manager) | [tomatophp](https://github.com/tomatophp) |
| [Filament Menu Builder](https://github.com/datlechin/filament-menu-builder) | [datlechin](https://github.com/datlechin) |

#### Plugins Recommendation

Expand All @@ -157,7 +165,6 @@ Other recommendations for your starter, in my personal opinion:
- [Rupadana - API Resources](https://filamentphp.com/plugins/rupadana-api-service) : Generate API for your Resources.
- [Bezhan Salleh - Language Switch](https://filamentphp.com/plugins/bezhansalleh-language-switch) : Zero config Language Switcher plugin for Filament Panels.
- [Kenepa - Resource Lock](https://filamentphp.com/plugins/kenepa-resource-lock) : Resource locking when other user begins editing a resource.
- [Baptiste Bouillot - Jobs monitor](https://filamentphp.com/plugins/croustibat-jobs-monitor) : Monitor background jobs.
- [Ralph J. Smit - Components](https://filamentphp.com/plugins/ralphjsmit-components) : A collection of handy components.
- [Tapp Network - Laravel Auditing](https://filamentphp.com/plugins/tapp-network-laravel-auditing) : Resource locking when other user begins editing a resource.
- [Shuvro Roy - Spatie Laravel Health](https://filamentphp.com/plugins/shuvroroy-spatie-laravel-health) : Health monitoring for Filament.
Expand All @@ -169,4 +176,3 @@ Other recommendations for your starter, in my personal opinion:
Filament Starter is provided under the [MIT License](LICENSE.md).

If you discover a bug, please [open an issue](https://github.com/riodwanto/superduper-filament-starter-kit/issues).

50 changes: 17 additions & 33 deletions app/Console/Commands/GenerateLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Stichoza\GoogleTranslate\GoogleTranslate;

class GenerateLang extends Command
{
Expand Down Expand Up @@ -32,21 +32,20 @@ public function handle()
}
}

if ($onlyJson):
if ($onlyJson) {
$this->processJsonFile($sourcePath, $from, $targets);
else :
} else {
$this->processDirectory($sourcePath, $from, $targets, $specificFile);
endif;
}

$this->info("\n\n All files have been translate. \n");
$this->info("\n\n All files have been translated. \n");
}

protected function processJsonFile(string $sourceFile, string $from, array|string $targets) :void
protected function processJsonFile(string $sourceFile, string $from, array|string $targets): void
{
foreach ($targets as $to) {
$this->info("\n\n 🔔 Translate to '{$to}'");

// get content of json file
$translations = json_decode(File::get($sourceFile), true, 512, JSON_THROW_ON_ERROR);

$bar = $this->output->createProgressBar(count($translations));
Expand Down Expand Up @@ -129,8 +128,8 @@ protected function translateArray($content, $source, $target, $bar = null)
$bar?->advance();
}
return $content;
} else if ($content === '' || $content === null){
$this->error("Translation value missing, make sure all translation values are not empty, in source file!");
} else if ($content === '' || $content === null) {
$this->error("Translation value missing, make sure all translation values are not empty, in the source file!");
exit();
} else {
return $this->translateUsingGoogleTranslate($content, $source, $target);
Expand All @@ -139,32 +138,18 @@ protected function translateArray($content, $source, $target, $bar = null)

public function translateUsingGoogleTranslate($content, string $source, string $target)
{
if (is_array($content)) {
$translatedArray = [];
foreach ($content as $key => $value) {
$translatedArray[$key] = $this->translateUsingGoogleTranslate($value, $source, $target);
}
return $translatedArray;
} else {
$response = Http::retry(3)
->throw()
->get('https://translate.googleapis.com/translate_a/single?client=gtx&sl=' . $source . '&tl=' . $target . '&dt=t&q=' . urlencode($content));
$response = json_decode($response->body());
$translatedText = '';
foreach ($response[0] as $translation) {
$translatedText .= $translation[0];
}
return !empty($translatedText) ? $translatedText : $content;
try {
// Use Stichoza\GoogleTranslate\GoogleTranslate for translation
$tr = new GoogleTranslate();
$tr->setSource($source);
$tr->setTarget($target);
return $tr->translate($content);
} catch (\Exception $e) {
$this->error("Failed to translate text: " . $e->getMessage());
return $content; // Return original text if translation fails
}
}

/**
* Convert an array to a string representation using short array syntax.
*
* @param array $array The array to convert.
* @param int $indentLevel The current indentation level (for formatting).
* @return string The array as a string.
*/
protected function arrayToString(array $array, $indentLevel = 1)
{
$indent = str_repeat(' ', $indentLevel); // 4 spaces for indentation
Expand All @@ -176,7 +161,6 @@ protected function arrayToString(array $array, $indentLevel = 1)
$entryValue = $this->arrayToString($value, $indentLevel + 1);
$entries[] = "$indent$entryKey => $entryValue";
} else {
// Escape single quotes inside strings
$entryValue = is_string($value) ? "'" . addcslashes($value, "'") . "'" : $value;
$entries[] = "$indent$entryKey => $entryValue";
}
Expand Down
32 changes: 16 additions & 16 deletions app/Filament/Pages/Setting/ManageGeneral.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@ public function form(Form $form): Form
->required(),
]),
Forms\Components\Grid::make()->schema([
Forms\Components\TextInput::make('brand_logoHeight')
->label(fn () => __('page.general_settings.fields.brand_logoHeight'))
->required()
->columnSpanFull()
->maxWidth('w-1/2'),
Forms\Components\Grid::make()->schema([
Forms\Components\TextInput::make('brand_logoHeight')
->label(fn () => __('page.general_settings.fields.brand_logoHeight'))
->required()
->columnSpan(2),
Forms\Components\FileUpload::make('brand_logo')
->label(fn () => __('page.general_settings.fields.brand_logo'))
->image()
->directory('sites')
->visibility('public')
->moveFiles()
->required()
->columnSpan(2),
])
->columnSpan(2),
Forms\Components\FileUpload::make('site_favicon')
->label(fn () => __('page.general_settings.fields.site_favicon'))
->image()
->directory('sites')
->visibility('public')
->moveFiles()
->acceptedFileTypes(['image/x-icon', 'image/vnd.microsoft.icon'])
->required(),
->required(),

Forms\Components\FileUpload::make('site_favicon')
->label(fn () => __('page.general_settings.fields.site_favicon'))
->image()
->directory('sites')
->visibility('public')
->moveFiles()
->acceptedFileTypes(['image/x-icon', 'image/vnd.microsoft.icon'])
->required(),
]),
])->columns(4),
]),
Forms\Components\Tabs::make('Tabs')
Expand Down
12 changes: 11 additions & 1 deletion app/Filament/Resources/BannerCategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('parent_id')
->label('Parent Category')
->options(BannerCategory::all()->pluck('name', 'id'))
->searchable()
->nullable()
->columnSpan('full'),

Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
Expand Down Expand Up @@ -71,6 +78,9 @@ public static function table(Table $table): Table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('parent.name')->label('Sub Category of')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('slug')
->searchable(),
Tables\Columns\TextColumn::make('is_active')->label('Status')
Expand All @@ -97,7 +107,7 @@ public static function table(Table $table): Table
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->hiddenLabel()->tooltip('Edit'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
21 changes: 10 additions & 11 deletions app/Filament/Resources/BannerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Filament\Resources\BannerResource\Pages;
use App\Models\Banner;
use Filament\Forms;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
Expand All @@ -15,6 +14,7 @@
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use League\CommonMark\CommonMarkConverter;
use TomatoPHP\FilamentMediaManager\Form\MediaManagerInput;

class BannerResource extends Resource
{
Expand Down Expand Up @@ -75,13 +75,12 @@ public static function form(Form $form): Form
Forms\Components\Section::make('Image')
->description('Upload banner images here')
->schema([
SpatieMediaLibraryFileUpload::make('media')
MediaManagerInput::make('images')
->hiddenLabel()
->helperText('Select and upload images for the banner')
->collection('banners')
->multiple()
->reorderable()
->required(),
->schema([
])
->defaultItems(1)
->minItems(1),
])
->compact(),
]),
Expand Down Expand Up @@ -141,7 +140,7 @@ public static function table(Table $table): Table
return $table
->columns([
SpatieMediaLibraryImageColumn::make('media')->label('Images')
->collection('banners')
->collection('images')
->wrap(),
Tables\Columns\TextColumn::make('title')
->description(fn(Model $record): string => strip_tags((new CommonMarkConverter())->convert($record->description)->getContent()))
Expand Down Expand Up @@ -200,9 +199,9 @@ public static function table(Table $table): Table
}),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\ViewAction::make(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\ViewAction::make()->hiddenLabel()->tooltip('Detail'),
Tables\Actions\EditAction::make()->hiddenLabel()->tooltip('Edit'),
Tables\Actions\DeleteAction::make()->hiddenLabel()->tooltip('Delete'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Loading

0 comments on commit 9c1f0e2

Please sign in to comment.