Skip to content

Commit

Permalink
fix: fix addresses report list (#6725)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Jun 29, 2023
1 parent d356688 commit 9c86677
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function execute(array $data): TemplatePage
'template_id' => $data['template_id'],
'name' => $data['name'] ?? null,
'name_translation_key' => $data['name_translation_key'] ?? null,
'slug' => Str::slug($data['name'] ?? $data['name_translation_key'], '-'),
'slug' => Str::slug($data['name'] ?? $data['name_translation_key'], '-', language: currentLang()),
'type' => $this->valueOrNull($data, 'type'),
'position' => $newPosition,
'can_be_deleted' => $this->valueOrTrue($data, 'can_be_deleted'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function execute(array $data): TemplatePage
->findOrFail($data['template_page_id']);

$this->templatePage->name = $data['name'];
$this->templatePage->slug = Str::slug($data['name'], '-');
$this->templatePage->slug = Str::slug($data['name'], '-', language: currentLang());
$this->templatePage->save();

return $this->templatePage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReportAddressesCitiesController extends Controller
public function show(Request $request, string $vaultId, string $city)
{
$vault = Vault::findOrFail($vaultId);
$city = utf8_decode(urldecode($city));
$city = mb_convert_encoding(urldecode($city), 'UTF-8');

return Inertia::render('Vault/Reports/Address/Cities/Index', [
'layoutData' => VaultIndexViewHelper::layoutData($vault),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReportAddressesCountriesController extends Controller
public function show(Request $request, string $vaultId, string $country)
{
$vault = Vault::findOrFail($vaultId);
$country = utf8_decode(urldecode($country));
$country = mb_convert_encoding(urldecode($country), 'UTF-8');

return Inertia::render('Vault/Reports/Address/Countries/Index', [
'layoutData' => VaultIndexViewHelper::layoutData($vault),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function data(Vault $vault): array
'url' => [
'index' => route('vault.reports.addresses.cities.show', [
'vault' => $vault->id,
'city' => urlencode(utf8_encode($address->city)),
'city' => urlencode(mb_convert_encoding($address->city, 'UTF-8')),
]),
],
])
Expand All @@ -47,7 +47,7 @@ public static function data(Vault $vault): array
'url' => [
'index' => route('vault.reports.addresses.countries.show', [
'vault' => $vault->id,
'country' => urlencode(utf8_encode($address->country)),
'country' => urlencode(mb_convert_encoding($address->country, 'UTF-8')),
]),
],
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public static function data(Vault $vault, string $city): array
{
$addresses = $vault->addresses()
->whereNotNull('city')
->where('city', Str::ucfirst($city))
->orWhere('city', Str::lcfirst($city))
->where('city', 'like', $city)
->with('contacts')
->get()
->map(fn (Address $address) => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public static function data(Vault $vault, string $country): array
{
$addresses = $vault->addresses()
->whereNotNull('country')
->where('country', Str::ucfirst($country))
->orWhere('country', Str::lcfirst($country))
->where('country', 'like', $country)
->with('contacts')
->get()
->map(fn (Address $address) => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function execute(array $data): Label
'vault_id' => $data['vault_id'],
'name' => $data['name'],
'description' => $this->valueOrNull($data, 'description'),
'slug' => Str::slug($data['name'], '-'),
'slug' => Str::slug($data['name'], '-', language: currentLang()),
'bg_color' => $data['bg_color'],
'text_color' => $data['text_color'],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function execute(array $data): Tag
$this->tag = Tag::create([
'vault_id' => $data['vault_id'],
'name' => $data['name'],
'slug' => Str::slug($data['name'], '-'),
'slug' => Str::slug($data['name'], '-', language: currentLang()),
]);

return $this->tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function execute(array $data): Label
$label->bg_color = $data['bg_color'];
$label->text_color = $data['text_color'];
$label->description = $this->valueOrNull($data, 'description');
$label->slug = Str::slug($data['name'], '-');
$label->slug = Str::slug($data['name'], '-', language: currentLang());
$label->save();

return $label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function execute(array $data): Tag
->findOrFail($data['tag_id']);

$tag->name = $data['name'];
$tag->slug = Str::slug($data['name'], '-');
$tag->slug = Str::slug($data['name'], '-', language: currentLang());
$tag->save();

return $tag;
Expand Down
14 changes: 10 additions & 4 deletions app/Helpers/WikipediaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ public static function getInformation(string $topic): array
'format' => 'json',
]);

$url = 'https://en.wikipedia.org/w/api.php?'.$query;
$lang = currentLang();
$url = "https://$lang.wikipedia.org/w/api.php?$query";

$response = Http::get($url)->throw();
$response = null;
try {
$response = Http::get($url)->throw();
} catch (\Illuminate\Http\Client\RequestException) {
// Ignore the exception.
}

if ($response->json('query.pages.*.missing')[0] === true) {
if ($response === null || $response->json('query.pages.*.missing')[0] === true) {
return [
'url' => null,
'description' => null,
Expand All @@ -35,7 +41,7 @@ public static function getInformation(string $topic): array
}

return [
'url' => 'https://en.wikipedia.org/wiki/'.Str::slug($topic),
'url' => "https://$lang.wikipedia.org/wiki/".Str::slug($topic, language: $lang),
'description' => $response->json('query.pages.*.description')[0],
'thumbnail' => $response->json('query.pages.*.thumbnail.source')[0],
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { ref } from 'vue';
import { nextTick, ref } from 'vue';
import { useForm } from '@inertiajs/vue3';
import JetActionMessage from '@/Components/Jetstream/ActionMessage.vue';
import JetActionSection from '@/Components/Jetstream/ActionSection.vue';
Expand Down

0 comments on commit 9c86677

Please sign in to comment.