Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
pardalsalcap authored and github-actions[bot] committed Nov 22, 2023
1 parent 3d011a4 commit 56efa51
Show file tree
Hide file tree
Showing 22 changed files with 193 additions and 199 deletions.
45 changes: 23 additions & 22 deletions resources/lang/es/addresses.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<?php

return [
'address_type_column'=>'Tipo de dirección',
'address_column'=>'Dirección',
'city_id_column'=>'Ciudad',
'state_id_column'=>'Provincia',
'country_id_column'=>'País',
'address_type_column' => 'Tipo de dirección',
'address_column' => 'Dirección',
'city_id_column' => 'Ciudad',
'state_id_column' => 'Provincia',
'country_id_column' => 'País',

'address_field'=>'Dirección',
'city_id_field'=>'Ciudad',
'state_id_field'=>'Provincia',
'country_id_field'=>'País',
'number_field'=>'Número',
'stair_field'=>'Escalera',
'floor_field'=>'Piso',
'door_field'=>'Puerta',
'address_type_field'=>'Tipo de dirección',
'lat_field'=>'Latitud',
'lon_field'=>'Longitud',
'address_field' => 'Dirección',
'city_id_field' => 'Ciudad',
'state_id_field' => 'Provincia',
'country_id_field' => 'País',
'number_field' => 'Número',
'stair_field' => 'Escalera',
'floor_field' => 'Piso',
'door_field' => 'Puerta',
'address_type_field' => 'Tipo de dirección',
'lat_field' => 'Latitud',
'lon_field' => 'Longitud',

'state_id_placeholder'=>'Selecciona un país primero',
'state_id_placeholder_step2'=>'Selecciona una provincia',
'city_id_placeholder'=>'Selecciona una provincia primero',
'state_id_placeholder' => 'Selecciona un país primero',
'state_id_placeholder_step2' => 'Selecciona una provincia',
'city_id_placeholder' => 'Selecciona una provincia primero',

'navigation' => 'Direcciones',
'model_label' => 'Dirección',
'model_label_plural' => 'Direcciones',
'navigation_group' => 'Localizaciones',

'relation_address_plural'=>'Direcciones',
'relation_address'=>'Dirección',
'relation_address_title'=>'Direcciones para este registro',
'relation_address_plural' => 'Direcciones',
'relation_address' => 'Dirección',
'relation_address_title' => 'Direcciones para este registro',
];
1 change: 1 addition & 0 deletions resources/stubs/ContinentResource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace App\Filament\Resources;

class ContinentResource extends \Pardalsalcap\LinterLocations\Resources\ContinentResource
Expand Down
69 changes: 40 additions & 29 deletions src/Commands/LinterLocationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Pardalsalcap\LinterLocations\Commands;

use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Pardalsalcap\LinterLocations\Models\City;
use Pardalsalcap\LinterLocations\Models\Community;
use Pardalsalcap\LinterLocations\Models\Continent;
use Exception;
use Pardalsalcap\LinterLocations\Models\Country;
use Pardalsalcap\LinterLocations\Models\State;
use Pardalsalcap\LinterLocations\Traits\LocationsTrait;
Expand All @@ -30,7 +30,6 @@ public function handle(): int
$this->loadConfiguration();
$this->populateDatabase();


$this->info('Installation completed.');

return self::SUCCESS;
Expand Down Expand Up @@ -59,7 +58,7 @@ protected function populateContinents(): int
try {
$check = Continent::count();
if ($check) {
throw new Exception("The continents table already has data");
throw new Exception('The continents table already has data');
}

$continentsData = $this->loadJson('continents.json');
Expand All @@ -78,19 +77,21 @@ protected function populateContinents(): int
'lat' => $this->adaptCoordinates($data['location']['latitude']),
'lon' => $this->adaptCoordinates($data['location']['longitude']),
'translations' => json_encode($trimmed_translations),
'created_at' => now()->format("Y-m-d H:i:s"),
'updated_at' => now()->format("Y-m-d H:i:s"),
'created_at' => now()->format('Y-m-d H:i:s'),
'updated_at' => now()->format('Y-m-d H:i:s'),
];
}
DB::transaction(function () use ($continents) {
DB::table('continents')->insert($continents);
});
$this->info('Continents table populated successfully');

return self::SUCCESS;
} catch (Exception $e) {
// Log the error and rethrow the exception
Log::error($e->getMessage());
$this->error($e->getMessage());

return self::FAILURE;
}
}
Expand All @@ -101,7 +102,7 @@ public function populateCountries(): int
try {
$check = Country::count();
if ($check) {
throw new Exception("The countries table already has data");
throw new Exception('The countries table already has data');
}

$countries = $this->loadJson('countries.json');
Expand All @@ -125,18 +126,20 @@ public function populateCountries(): int
'continent_id' => $continent_id,
'lat' => $this->adaptCoordinates($country['latlng'][0] ?? null),
'lon' => $this->adaptCoordinates($country['latlng'][1] ?? null),
'created_at' => now()->format("Y-m-d H:i:s"),
'updated_at' => now()->format("Y-m-d H:i:s"),
'created_at' => now()->format('Y-m-d H:i:s'),
'updated_at' => now()->format('Y-m-d H:i:s'),
];
}
DB::transaction(function () use ($countries_data) {
DB::table('countries')->insert($countries_data);
});
$this->info('Countries table populated successfully');

return self::SUCCESS;
} catch (Exception $e) {
Log::error($e->getMessage());
$this->error($e->getMessage());

return self::FAILURE;
}

Expand All @@ -148,18 +151,18 @@ public function populateCommunities(): int
try {
$check = Community::count();
if ($check) {
throw new Exception("The communities table already has data");
throw new Exception('The communities table already has data');
}

$spain = Country::where('iso', 'ES')->first();
if (!$spain) {
throw new Exception("The country Spain was not found");
if (! $spain) {
throw new Exception('The country Spain was not found');
}
$communities = $this->loadJson('/spain/states.json');
$arr = [];
$communities_data = [];
foreach ($communities as $value) {
if (!isset($arr[$value['fields']['cod_ccaa']])) {
if (! isset($arr[$value['fields']['cod_ccaa']])) {
$arr[$value['fields']['cod_ccaa']] = [
'name' => $value['fields']['ccaa'],
'latitude' => $value['fields']['geo_point_2d'][0] ?? null,
Expand All @@ -179,18 +182,20 @@ public function populateCommunities(): int
'country_id' => $spain->id,
'lat' => $this->adaptCoordinates($value['latitude']),
'lon' => $this->adaptCoordinates($value['longitude']),
'created_at' => now()->format("Y-m-d H:i:s"),
'updated_at' => now()->format("Y-m-d H:i:s"),
'created_at' => now()->format('Y-m-d H:i:s'),
'updated_at' => now()->format('Y-m-d H:i:s'),
];
}
DB::transaction(function () use ($communities_data) {
DB::table('communities')->insert($communities_data);
});
$this->info('Communities table populated successfully');

return self::SUCCESS;
} catch (Exception $e) {
Log::error($e->getMessage());
$this->error($e->getMessage());

return self::FAILURE;
}
}
Expand All @@ -201,20 +206,20 @@ public function populateStates(): int
try {
$check = State::count();
if ($check) {
throw new Exception("The states table already has data");
throw new Exception('The states table already has data');
}

$spain = Country::where('iso', 'ES')->first();
if (!$spain) {
throw new Exception("The country Spain was not found");
if (! $spain) {
throw new Exception('The country Spain was not found');
}

$states = $this->loadJson('/spain/states.json');
$communities = Community::all();
$arr = [];
$states_data = [];
foreach ($states as $value) {
if (!isset($arr[$value['fields']['codigo']])) {
if (! isset($arr[$value['fields']['codigo']])) {
$arr[$value['fields']['codigo']] = [
'name' => $value['fields']['provincia'],
'community_iso' => $value['fields']['cod_ccaa'],
Expand All @@ -236,18 +241,20 @@ public function populateStates(): int
'community_id' => $communities->where('iso', $value['community_iso'])->first()->id,
'lat' => $this->adaptCoordinates($value['geo_point_2d'][0] ?? null),
'lon' => $this->adaptCoordinates($value['geo_point_2d'][1] ?? null),
'created_at' => now()->format("Y-m-d H:i:s"),
'updated_at' => now()->format("Y-m-d H:i:s"),
'created_at' => now()->format('Y-m-d H:i:s'),
'updated_at' => now()->format('Y-m-d H:i:s'),
];
}
DB::transaction(function () use ($states_data) {
DB::table('states')->insert($states_data);
});
$this->info('States table populated successfully');

return self::SUCCESS;
} catch (Exception $e) {
Log::error($e->getMessage());
$this->error($e->getMessage());

return self::FAILURE;
}
}
Expand All @@ -257,7 +264,7 @@ public function populateCities(): int
try {
$check = City::count();
if ($check) {
throw new Exception("The cities table already has data");
throw new Exception('The cities table already has data');
}
$this->comment('Installing spanish cities');
$cities = $this->loadJson('/spain/cities.json');
Expand All @@ -273,19 +280,19 @@ public function populateCities(): int
}
$check = City::count();
if ($check) {
throw new Exception("The cities table already has data");
throw new Exception('The cities table already has data');
}

$spain = Country::where('iso', 'ES')->first();
if (!$spain) {
throw new Exception("The country Spain was not found");
if (! $spain) {
throw new Exception('The country Spain was not found');
}
$cities_data[] = [
'state_id' => $states->where('iso', $town['parent_code'])->first()?->id,
'name' => $town['label'],
'translations' => json_encode($translations),
'created_at' => now()->format("Y-m-d H:i:s"),
'updated_at' => now()->format("Y-m-d H:i:s"),
'created_at' => now()->format('Y-m-d H:i:s'),
'updated_at' => now()->format('Y-m-d H:i:s'),
];
}
}
Expand All @@ -294,32 +301,36 @@ public function populateCities(): int
DB::table('cities')->insert($cities_data);
});
$this->info('Cities table populated successfully');

return self::SUCCESS;
} catch (Exception $e) {
Log::error($e->getMessage());
$this->error($e->getMessage());

return self::FAILURE;
}
}

public function loadJson($file_name)
{
// Construct the path relative to the package's directory
$path = base_path('vendor/pardalsalcap/linter-locations/resources/datasets/' . $file_name);
$path = base_path('vendor/pardalsalcap/linter-locations/resources/datasets/'.$file_name);

try {
// Check if the file exists and is readable
if (!file_exists($path) || !is_readable($path)) {
if (! file_exists($path) || ! is_readable($path)) {
throw new Exception("JSON file not found or not readable: $path");
}

// Proceed with reading the file
$jsonContent = file_get_contents($path);

return json_decode($jsonContent, true);
} catch (Exception $e) {
// Log the error and rethrow the exception
Log::error("Error loading JSON file: $file_name, Error: " . $e->getMessage());
Log::error("Error loading JSON file: $file_name, Error: ".$e->getMessage());
$this->error($e->getMessage());

return self::FAILURE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/LinterLocationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Pardalsalcap\LinterLocations;

use Pardalsalcap\LinterLocations\Commands\LinterLocationsCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Pardalsalcap\LinterLocations\Commands\LinterLocationsCommand;

class LinterLocationsServiceProvider extends PackageServiceProvider
{
Expand Down
3 changes: 1 addition & 2 deletions src/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Pardalsalcap\LinterLocations\Models;

use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Pardalsalcap\LinterLocations\Traits\HasTranslations;
use Pardalsalcap\LinterLocations\Traits\LocationsTrait;
use App\Models\User;

/**
* @property int $id
Expand Down Expand Up @@ -51,5 +51,4 @@ public function users(): BelongsToMany
{
return $this->belongsToMany('App\Models\User', 'addressables', 'address_id', 'addressable_id', 'id', 'id')->withPivot(['address_type']);
}

}
1 change: 1 addition & 0 deletions src/Models/AddressUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class AddressUser extends Model
{
protected $keyType = 'integer';

public $timestamps = false;

protected $fillable = ['address_id', 'user_id', 'address_type', 'created_at', 'updated_at'];
Expand Down
7 changes: 2 additions & 5 deletions src/Models/Addressable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Illuminate\Database\Eloquent\Model;

/**
* @property integer $address_id
* @property integer $addressable_id
* @property int $address_id
* @property int $addressable_id
* @property string $addressable_type
* @property Address $address
*/
Expand All @@ -32,9 +32,6 @@ class Addressable extends Model
*/
protected $fillable = ['address_id', 'addressable_id', 'addressable_type'];

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function address(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo('App\Models\Address');
Expand Down
4 changes: 2 additions & 2 deletions src/Repositories/ContinentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class ContinentRepository extends LinterLocationsRepository
{
public static function selectBox ()
public static function selectBox()
{
return ;

}
}
Loading

0 comments on commit 56efa51

Please sign in to comment.