Skip to content

Commit 6123087

Browse files
committed
Flags wip
1 parent f56e0eb commit 6123087

File tree

7 files changed

+152
-9
lines changed

7 files changed

+152
-9
lines changed

packages/data/src/Filament/Resources/StaticCountryResource.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,17 @@ public static function table(Table $table): Table
163163
{
164164
return $table
165165
->columns([
166-
IconColumn::make('alpha2')
166+
IconColumn::make('flag_icon')
167167
->label('')
168-
->icon(fn (string $state): ?string => @file_exists(base_path("packages/flag-icons-circle/resources/svg/{$state}.svg")) ? "flag-{$state}" : null),
169-
TextColumn::make('alpha2_')
168+
->icon(fn (string $state): string => $state),
169+
TextColumn::make('alpha2')
170170
->label('Alpha-2')
171-
->getStateUsing(fn ($record) => $record->alpha2),
172-
TextColumn::make('alpha3_b')->label(__('data::fields.alpha3_b')),
173-
TextColumn::make('alpha3_t')->label(__('data::fields.alpha3_t')),
174-
TextColumn::make('common_name')->label(__('data::fields.common_name')),
175-
TextColumn::make('native_name')->label(__('data::fields.native_name')),
171+
->searchable()
172+
->sortable(),
173+
TextColumn::make('alpha3_b')->label(__('data::fields.alpha3_b'))->searchable()->sortable(),
174+
TextColumn::make('alpha3_t')->label(__('data::fields.alpha3_t'))->searchable()->sortable(),
175+
TextColumn::make('common_name')->label(__('data::fields.common_name'))->searchable()->sortable(),
176+
TextColumn::make('native_name')->label(__('data::fields.native_name'))->searchable()->sortable(),
176177
TextColumn::make('region')->sortable()->searchable()->toggleable()->label(__('data::fields.region')),
177178
TextColumn::make('subregion')->sortable()->searchable()->toggleable()->label(__('data::fields.subregion')),
178179
TextColumn::make('capital')->label(__('data::fields.capital')),

packages/data/src/Filament/Resources/StaticLocaleResource.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ public static function table(Table $table): Table
104104
{
105105
return $table
106106
->columns([
107-
TextColumn::make('locale')->label(__('data::fields.locale')),
107+
IconColumn::make('language_flag_icon')
108+
->label('L')
109+
->icon(fn (string $state): string => $state),
110+
IconColumn::make('country_flag_icon')
111+
->label('C')
112+
->icon(fn (string $state): string => $state),
113+
TextColumn::make('locale')
114+
->label(__('data::fields.locale')),
108115
TextColumn::make('name')->label(__('data::fields.name'))->sortable()->searchable()->toggleable(),
109116
IconColumn::make('is_official_language')
110117
->label(__('data::fields.is_official_language'))

packages/data/src/Jobs/ImportStaticDataJob.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function handle()
4040
'lin' => 'ln',
4141
'smo' => 'sm',
4242
'mon' => 'mn',
43+
'ita' => 'it',
4344
];
4445

4546
try {

packages/data/src/Models/StaticCountry.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,11 @@ public function timezones()
6868
return $this->belongsToMany(StaticTimezone::class, 'static_countries_static_timezones', 'country_id', 'timezone_id')
6969
->withTimestamps();
7070
}
71+
72+
public function getFlagIconAttribute(): ?string
73+
{
74+
return @file_exists(base_path("packages/flag-icons-circle/resources/svg/{$this->alpha2}.svg"))
75+
? "flag-{$this->alpha2}"
76+
: null;
77+
}
7178
}

packages/data/src/Models/StaticLocale.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
use Moox\Core\Traits\Base\BaseInModel;
99
use Moox\Core\Traits\Simple\SingleSimpleInModel;
1010

11+
/**
12+
* @property-read \Moox\Data\Models\StaticLanguage|null $language
13+
* @property-read \Moox\Data\Models\StaticCountry|null $country
14+
*/
1115
class StaticLocale extends Model
1216
{
1317
use BaseInModel, SingleSimpleInModel;
@@ -18,6 +22,7 @@ class StaticLocale extends Model
1822
'language_id',
1923
'country_id',
2024
'locale',
25+
'flag_country_code',
2126
'name',
2227
'is_official_language',
2328
];
@@ -33,4 +38,23 @@ public function country()
3338
}
3439

3540
protected $casts = [];
41+
42+
public function getLanguageFlagIconAttribute(): ?string
43+
{
44+
return match ($this->language?->alpha2) {
45+
'ar' => 'flag-ar_arab',
46+
default => @file_exists(base_path("packages/flag-icons-circle/resources/svg/{$this->language?->alpha2}.svg"))
47+
? "flag-{$this->language?->alpha2}"
48+
: (@file_exists(base_path("packages/flag-icons-circle/resources/svg/{$this->country?->alpha2}.svg"))
49+
? "flag-{$this->country?->alpha2}"
50+
: null),
51+
};
52+
}
53+
54+
public function getCountryFlagIconAttribute(): ?string
55+
{
56+
return @file_exists(base_path("packages/flag-icons-circle/resources/svg/{$this->country?->alpha2}.svg"))
57+
? "flag-{$this->country?->alpha2}"
58+
: null;
59+
}
3660
}

0 commit comments

Comments
 (0)