Added Premium Domains and Gmail Users to dashboard, also added flush cache upon setting update
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Filament\Pages;
|
|||||||
|
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\ZEmail;
|
use App\Models\ZEmail;
|
||||||
|
use Artisan;
|
||||||
use Ddeboer\Imap\Server;
|
use Ddeboer\Imap\Server;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\Checkbox;
|
use Filament\Forms\Components\Checkbox;
|
||||||
@@ -45,6 +46,8 @@ class Settings extends Page implements HasForms
|
|||||||
$this->applyDefaults($imapSettings, [
|
$this->applyDefaults($imapSettings, [
|
||||||
'protocol' => 'imap',
|
'protocol' => 'imap',
|
||||||
'default_account' => 'default',
|
'default_account' => 'default',
|
||||||
|
'premium_protocol' => 'imap',
|
||||||
|
'premium_default_account' => 'default',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->applyDefaults($configurationSettings, [
|
$this->applyDefaults($configurationSettings, [
|
||||||
@@ -56,6 +59,8 @@ class Settings extends Page implements HasForms
|
|||||||
$transformMap = [
|
$transformMap = [
|
||||||
'domains' => 'domain',
|
'domains' => 'domain',
|
||||||
'gmailUsernames' => 'gmailUsername',
|
'gmailUsernames' => 'gmailUsername',
|
||||||
|
'premium_domains' => 'premium_domain',
|
||||||
|
'premium_gmailUsernames' => 'premium_gmailUsername',
|
||||||
'forbidden_ids' => 'forbidden_id',
|
'forbidden_ids' => 'forbidden_id',
|
||||||
'blocked_domains' => 'blocked_domain',
|
'blocked_domains' => 'blocked_domain',
|
||||||
];
|
];
|
||||||
@@ -145,7 +150,7 @@ class Settings extends Page implements HasForms
|
|||||||
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
Section::make('Imap')
|
Section::make('Public Mailbox Imap')
|
||||||
->description('Enter your imap server')
|
->description('Enter your imap server')
|
||||||
->collapsed()
|
->collapsed()
|
||||||
->schema([
|
->schema([
|
||||||
@@ -164,6 +169,25 @@ class Settings extends Page implements HasForms
|
|||||||
Checkbox::make('imap_settings.cc_check')->label('Check CC Field')->default(false)->helperText('If enabled, we will check the CC field as well while fetching mails.'),
|
Checkbox::make('imap_settings.cc_check')->label('Check CC Field')->default(false)->helperText('If enabled, we will check the CC field as well while fetching mails.'),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
Section::make('Premium Mailbox Imap')
|
||||||
|
->description('Enter your imap server')
|
||||||
|
->collapsed()
|
||||||
|
->schema([
|
||||||
|
TextInput::make('imap_settings.premium_host')->label('Hostname')->required(),
|
||||||
|
TextInput::make('imap_settings.premium_port')->label('Port')->required(),
|
||||||
|
Select::make('imap_settings.premium_encryption')->options([
|
||||||
|
'none' => 'None',
|
||||||
|
'ssl' => 'SSL',
|
||||||
|
'tls' => 'TLS'
|
||||||
|
]),
|
||||||
|
Checkbox::make('imap_settings.premium_validate_cert')->label('Validate Encryption Certificate')->default(false),
|
||||||
|
TextInput::make('imap_settings.premium_username')->label('Username')->required(),
|
||||||
|
TextInput::make('imap_settings.premium_password')->label('Password')->required(),
|
||||||
|
TextInput::make('imap_settings.premium_default_account')->label('Default Account')->placeholder('default'),
|
||||||
|
TextInput::make('imap_settings.premium_protocol')->label('Protocol')->placeholder('imap'),
|
||||||
|
Checkbox::make('imap_settings.premium_cc_check')->label('Check CC Field')->default(false)->helperText('If enabled, we will check the CC field as well while fetching mails.'),
|
||||||
|
]),
|
||||||
|
|
||||||
Section::make('Configuration')
|
Section::make('Configuration')
|
||||||
->description('Enter your configuration')
|
->description('Enter your configuration')
|
||||||
->collapsed()
|
->collapsed()
|
||||||
@@ -230,6 +254,24 @@ class Settings extends Page implements HasForms
|
|||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
Section::make('Premium Domains & Gmail Usernames')
|
||||||
|
->collapsed()
|
||||||
|
->columns(2)
|
||||||
|
->schema([
|
||||||
|
Repeater::make('configuration_settings.premium_domains')
|
||||||
|
->statePath('configuration_settings.premium_domains')
|
||||||
|
->columnSpan(1)
|
||||||
|
->schema([
|
||||||
|
TextInput::make('premium_domain')->label('Premium Domain')->required()->maxLength(30),
|
||||||
|
]),
|
||||||
|
Repeater::make('configuration_settings.premium_gmailUsernames')
|
||||||
|
->statePath('configuration_settings.premium_gmailUsernames')
|
||||||
|
->columnSpan(1)
|
||||||
|
->schema([
|
||||||
|
TextInput::make('premium_gmailUsername')->label('Premium Gmail Username')->required()->maxLength(30),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
|
||||||
Section::make('Mailbox Configuration')
|
Section::make('Mailbox Configuration')
|
||||||
->collapsed()
|
->collapsed()
|
||||||
->schema([
|
->schema([
|
||||||
@@ -300,9 +342,31 @@ class Settings extends Page implements HasForms
|
|||||||
Action::make('save')
|
Action::make('save')
|
||||||
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
|
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
|
||||||
->submit('save'),
|
->submit('save'),
|
||||||
|
Action::make('flushCache')
|
||||||
|
->label(__('Flush Cache'))
|
||||||
|
->color('danger')
|
||||||
|
->icon('heroicon-m-no-symbol')
|
||||||
|
->action('flushCache')
|
||||||
|
->requiresConfirmation(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function flushCache(): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Artisan::call('cache:clear');
|
||||||
|
Notification::make()
|
||||||
|
->title('Cache flushed successfully')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Error : '.$e->getMessage())
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function save(): void
|
public function save(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -318,13 +382,17 @@ class Settings extends Page implements HasForms
|
|||||||
}
|
}
|
||||||
foreach ([
|
foreach ([
|
||||||
'protocol' => 'imap',
|
'protocol' => 'imap',
|
||||||
'default_account' => 'default'
|
'default_account' => 'default',
|
||||||
|
'premium_protocol' => 'imap',
|
||||||
|
'premium_default_account' => 'default',
|
||||||
] as $key => $default) {
|
] as $key => $default) {
|
||||||
$data['imap_settings'][$key] ??= $default;
|
$data['imap_settings'][$key] ??= $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pluckMap = [
|
$pluckMap = [
|
||||||
'domains' => 'domain',
|
'domains' => 'domain',
|
||||||
|
'premium_domains' => 'premium_domain',
|
||||||
|
'premium_gmailUsernames' => 'premium_gmailUsername',
|
||||||
'gmailUsernames' => 'gmailUsername',
|
'gmailUsernames' => 'gmailUsername',
|
||||||
'forbidden_ids' => 'forbidden_id',
|
'forbidden_ids' => 'forbidden_id',
|
||||||
'blocked_domains' => 'blocked_domain'
|
'blocked_domains' => 'blocked_domain'
|
||||||
|
|||||||
Reference in New Issue
Block a user