Skip to content

Commit e3af800

Browse files
committed
Jira settings page + migrations
1 parent 4f29c91 commit e3af800

4 files changed

Lines changed: 126 additions & 2 deletions

File tree

app/Filament/Pages/JiraImport.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Illuminate\Contracts\Support\Htmlable;
2020
use Illuminate\Support\HtmlString;
2121
use Illuminate\Support\Str;
22+
use App\Settings\JiraSettings;
2223

2324
class JiraImport extends Page implements HasForms
2425
{
@@ -51,7 +52,12 @@ class JiraImport extends Page implements HasForms
5152

5253
public function mount(): void
5354
{
54-
$this->form->fill();
55+
$settings = app(JiraSettings::class);
56+
$this->form->fill([
57+
'host' => $settings->host,
58+
'username' => $settings->username,
59+
'token' => $settings->token,
60+
]);
5561
}
5662

5763
public static function shouldRegisterNavigation(): bool
@@ -87,7 +93,7 @@ public function getFormSchema(): array
8793
'class' => 'bg-primary-500 rounded-lg border border-primary-600 text-white font-medium text-sm py-3 px-4'
8894
])
8995
->hiddenLabel()
90-
->content(__('Important: Your jira credentials are only used to communicate with jira REST API, and will not be stored in this application')),
96+
->content(__('Your Jira credentials are used to communicate with the Jira REST API. They will be saved (with the API token encrypted) so you do not need to re-enter them each time.')),
9197

9298
Grid::make()
9399
->schema([
@@ -109,6 +115,12 @@ public function getFormSchema(): array
109115
]),
110116
])
111117
->afterValidation(function () {
118+
$settings = app(JiraSettings::class);
119+
$settings->host = $this->host;
120+
$settings->username = $this->username;
121+
$settings->token = $this->token;
122+
$settings->save();
123+
112124
$this->loadingProjects = true;
113125
$this->dispatch('updateJiraProjects');
114126
}),
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace App\Filament\Pages;
4+
use BackedEnum;
5+
6+
use App\Settings\JiraSettings;
7+
use Filament\Schemas\Components\Section;
8+
use Filament\Schemas\Components\Grid;
9+
use Filament\Schemas\Schema;
10+
use Filament\Forms\Components\TextInput;
11+
use Filament\Actions\Action;
12+
use Filament\Pages\SettingsPage;
13+
use Filament\Support\Enums\Width;
14+
use Illuminate\Contracts\Support\Htmlable;
15+
16+
class ManageJiraSettings extends SettingsPage
17+
{
18+
protected static string | BackedEnum | null $navigationIcon = 'heroicon-o-cloud-arrow-up';
19+
20+
protected static string $settings = JiraSettings::class;
21+
22+
protected Width | string | null $maxContentWidth = Width::Full;
23+
24+
public static function shouldRegisterNavigation(): bool
25+
{
26+
return auth()->user()->can('Import from Jira');
27+
}
28+
29+
public function getHeading(): string|Htmlable
30+
{
31+
return __('Manage Jira settings');
32+
}
33+
34+
public static function getNavigationLabel(): string
35+
{
36+
return __('Jira');
37+
}
38+
39+
public static function getNavigationGroup(): ?string
40+
{
41+
return __('Settings');
42+
}
43+
44+
public function form(Schema $schema): Schema
45+
{
46+
return $schema->columns(1)->components([
47+
Section::make(__('Jira credentials'))
48+
->description(__('Configure your Jira connection credentials. The API token is stored encrypted.'))
49+
->columnSpanFull()
50+
->schema([
51+
Grid::make(2)
52+
->schema([
53+
TextInput::make('host')
54+
->label(__('Host'))
55+
->helperText(__('The URL used to access your Jira account (e.g. https://yourcompany.atlassian.net)'))
56+
->required(),
57+
58+
TextInput::make('username')
59+
->label(__('Username'))
60+
->helperText(__('Your Jira account username (email)'))
61+
->required(),
62+
63+
TextInput::make('token')
64+
->label(__('API Token'))
65+
->helperText(__('Your Jira account API token'))
66+
->password()
67+
->required(),
68+
]),
69+
]),
70+
]);
71+
}
72+
73+
public function getSaveFormAction(): Action
74+
{
75+
return parent::getSaveFormAction()->label(__('Save'));
76+
}
77+
}

app/Settings/JiraSettings.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Settings;
4+
5+
use Spatie\LaravelSettings\Settings;
6+
7+
class JiraSettings extends Settings
8+
{
9+
public string $host;
10+
public string $username;
11+
public string $token;
12+
13+
public static function group(): string
14+
{
15+
return 'jira';
16+
}
17+
18+
public static function encrypted(): array
19+
{
20+
return ['token'];
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Spatie\LaravelSettings\Migrations\SettingsMigration;
4+
5+
class CreateJiraSettings extends SettingsMigration
6+
{
7+
public function up(): void
8+
{
9+
$this->migrator->add('jira.host', '');
10+
$this->migrator->add('jira.username', '');
11+
$this->migrator->addEncrypted('jira.token', '');
12+
}
13+
}

0 commit comments

Comments
 (0)