Skip to content

Commit

Permalink
Testing: GEDCOM Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kreaweb.be committed Jun 29, 2024
1 parent c4b7be6 commit 4b9c69a
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 132 deletions.
106 changes: 74 additions & 32 deletions app/Livewire/Gedcom/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
namespace App\Livewire\Gedcom;

use App\Livewire\Traits\TrimStringsAndConvertEmptyStringsToNull;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Laravel\Jetstream\Events\AddingTeam;
use Livewire\Component;
use Livewire\WithFileUploads;
use TallStackUi\Traits\Interactions;
Expand All @@ -24,13 +27,15 @@ class Import extends Component

public $file = null;

public $output = '<div>Awaiting input ...</div>';

// -----------------------------------------------------------------------
public function rules()
{
return $rules = [
'name' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:255'],
'file' => ['required', 'file', 'mimes:ged'],
'file' => ['required', 'file'],
];
}

Expand All @@ -44,55 +49,92 @@ public function validationAttributes()
return [
'name' => __('team.name'),
'description' => __('team.description'),
'file' => __('team.gedcom_file'),
'file' => __('gedcom.gedcom_file'),
];
}

public function mount(): void
{
$this->user = Auth()->user();
$this->name = null;
$this->description = null;
$this->file = null;
$this->user = Auth()->user();
}

public function importTeam()
public function deleteUpload(array $content): void
{
// if ($this->isDirty()) {
$validated = $this->validate();

if (isset($validated['file'])) {
$this->file = $validated['file'];
/*
the $content contains:
[
'temporary_name',
'real_name',
'extension',
'size',
'path',
'url',
]
*/

if (! $this->uploads) {
return;
}

dump('test');
$files = Arr::wrap($this->uploads);

if ($this->file) {
$parser = new \PhpGedcom\Parser();
$gedcom = $parser->parse($this->file);
/** @var UploadedFile $file */
$file = collect($files)->filter(fn (UploadedFile $item) => $item->getFilename() === $content['temporary_name'])->first();

foreach ($gedcom->getIndi() as $individual) {
echo $individual->getId() . ': ' . current($individual->getName())->getSurn();
}
}
// here we delete the file.
// even if we have a error here, we simply ignore it because as long as the file is not persisted, it is temporary and will be deleted at some point if there is a failure here
rescue(fn () => $file->delete(), report: false);

$this->toast()->success(__('app.create'), $this->file)->flash()->send();
$collect = collect($files)->filter(fn (UploadedFile $item) => $item->getFilename() !== $content['temporary_name']);

// return $this->redirect('/search');
// }
// we guarantee restore of remaining files regardless of upload type, whether you are dealing with multiple or single uploads
$this->file = is_array($this->uploads) ? $collect->toArray() : $collect->first();
}

public function resetTeam(): void
public function importTeam(): void
{
$this->mount();
}
// // validate input
// $input = $this->validate();

public function isDirty(): bool
{
return
$this->name != null or
$this->description != null or
$this->file != null;
// AddingTeam::dispatch($this->user);

// // create and switch team
// $this->user->switchTeam($team = $this->user->ownedTeams()->create([
// 'name' => $input['name'],
// 'description' => $input['description'] ?? null,
// 'personal_team' => false,
// ]));

//if ($this->file) {
//$this->file->storeAs(path: 'public/imports', name: $this->file->getClientOriginalName());

$parser = new \Gedcom\Parser();

$gedcom = $parser->parse('./gedcom/royals_nl.ged');

$this->stream(to: 'output', content: '<div>Processing ...</div>', replace: true);

$count_indi = $count_fam= 0;

foreach ($gedcom->getIndi() as $individual) {
$names = $individual->getName();

if (! empty($names)) {
$name = reset($names); // Get the first name object from the array

$line = '<div>' . $individual->getId() . ' : ' . $name->getSurn() . ', ' . $name->getGivn() . '</div>';
$this->stream(to: 'output', content: $line);

$count_indi++;
}

usleep(100);
}

$this->output = '<div>Done.</div><div>Imported ' . $count_indi . ' individuals.</div><div>Imported ' . $count_fam . ' families.</div>';

$this->toast()->success(__('app.saved'), 'Done.')->send();
//}
}

// -----------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
'throw' => false,
],

// imports
'imports' => [
'driver' => 'local',
'root' => storage_path('app/public/imports'),
'url' => env('APP_URL') . '/storage/imports',
'visibility' => 'public',
'throw' => false,
],

// profile-pictures
'profiles' => [
'driver' => 'local',
Expand Down
2 changes: 2 additions & 0 deletions lang/de/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@
'unauthorized_access' => 'Unautorisierter Zugriff',

'whoops' => 'Upps! Etwas ist schief gelaufen.',

'terminal' => 'Terminal',
];
11 changes: 0 additions & 11 deletions lang/de/team.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
'create' => 'Team erstellen',
'delete' => 'Team löschen',
'description' => 'Beschreibung',
'export' => 'Exportieren',
'gedcom_export' => 'Team exportieren nach GEDCOM',
'gedcom_file' => 'GEDCOM Datei',
'gedcom_import' => 'Team importieren aus GEDCOM',
'id' => 'ID',
'import' => 'Importieren',
'manage' => 'Team verwalten',
'name' => 'Name',
'owner' => 'Besitzer',
Expand All @@ -27,12 +22,6 @@
// Messages
'team_details' => 'Teamdetails',
'team_create_new' => 'Create a new team to collaborate with others.',
'team_create_new_gedcom' => 'Erstellen Sie ein neues Team, um mit anderen zusammenzuarbeiten.',
'team_gedcom_reference' => 'Referenz',
'team_gedcom_specifications' => 'GEDCOM-Spezifikationen',
'team_gedcom_version' => 'Maximale GEDCOM-Version 5.5.5',
'team_gedcom_hint' => 'Lassen Sie uns ein Team basierend auf einer GEDCOM-Datei erstellen.',
'team_gedcom_tip' => 'Ziehen Sie Ihre GEDCOM-Datei per Drag & Drop hierher',

'team_name' => 'Teamname',
'team_information' => 'Der Name und die Eigentümerinformationen des Teams.',
Expand Down
2 changes: 2 additions & 0 deletions lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@
'unauthorized_access' => 'Unauthorized access.',

'whoops' => 'Whoops! Something went wrong.',

'terminal' => 'Terminal',
];
18 changes: 18 additions & 0 deletions lang/en/gedcom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

return [
'export' => 'Export',
'gedcom_export' => 'Export team to GEDCOM',
'gedcom_file' => 'GEDCOM file',
'gedcom_import' => 'Import team from GEDCOM',
'import' => 'Import',

// Messages
'team_create_new_gedcom' => 'Create a new team, imported from a GEDCOM file, to collaborate with others.',
'team_gedcom_reference' => 'Reference',
'team_gedcom_specifications' => 'GEDCOM Specifications',
'team_gedcom_version' => 'Maximal GEDCOM version 5.5.5',
'team_gedcom_hint' => 'Let\'s create a team based on a GEDCOM file',
'team_gedcom_tip' => 'Drag and drop your GEDCOM file here',

];
10 changes: 0 additions & 10 deletions lang/en/team.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
'create' => 'Create team',
'delete' => 'Delete team',
'description' => 'Description',
'export' => 'Export',
'gedcom_export' => 'Export team to GEDCOM',
'gedcom_file' => 'GEDCOM file',
'gedcom_import' => 'Import team from GEDCOM',
'id' => 'ID',
'import' => 'Import',
'manage' => 'Manage team',
Expand All @@ -27,12 +23,6 @@
// Messages
'team_details' => 'Team Details',
'team_create_new' => 'Create a new team to collaborate with others.',
'team_create_new_gedcom' => 'Create a new team, imported from a GEDCOM file, to collaborate with others.',
'team_gedcom_reference' => 'Reference',
'team_gedcom_specifications' => 'GEDCOM Specifications',
'team_gedcom_version' => 'Maximal GEDCOM version 5.5.5',
'team_gedcom_hint' => 'Let\'s create a team based on a GEDCOM file',
'team_gedcom_tip' => 'Drag and drop your GEDCOM file here',

'team_name' => 'Team Name',
'team_information' => 'The team\'s name and owner information.',
Expand Down
2 changes: 2 additions & 0 deletions lang/nl/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@
'unauthorized' => 'Onbevoegde toegang.',

'whoops' => 'Oeps! Er liep iets mis.',

'terminal' => 'Terminal',
];
11 changes: 0 additions & 11 deletions lang/nl/team.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
'create' => 'Team toevoegen',
'delete' => 'Team verwijderen',
'description' => 'Beschrijving',
'export' => 'Exporteren',
'gedcom_export' => 'Team exporteren naar GEDCOM',
'gedcom_file' => 'GEDCOM bestand',
'gedcom_import' => 'Team importeren van GEDCOM',
'id' => 'ID',
'import' => 'Importeren',
'manage' => 'Teambeheer',
'name' => 'Naam',
'owner' => 'Eigenaar',
Expand All @@ -27,12 +22,6 @@
// Messages
'team_details' => 'Teamdetails',
'team_create_new' => 'Creëer een nieuw team om met anderen samen te werken.',
'team_create_new_gedcom' => 'Creëer een nieuw team, geïmporteerd uit een GEDCOM-bestand, om met anderen samen te werken.',
'team_gedcom_reference' => 'Referentie',
'team_gedcom_specifications' => 'GEDCOM Specificaties',
'team_gedcom_version' => 'Maximaal GEDCOM versie 5.5.5',
'team_gedcom_hint' => 'Laten we een team creëren op basis van een GEDCOM-bestand',
'team_gedcom_tip' => 'Sleep uw GEDCOM-bestand hierheen',

'team_name' => 'Teamnaam',
'team_information' => 'De naam van het team en informatie over de eigenaar.',
Expand Down
12 changes: 12 additions & 0 deletions public/css/terminal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.terminal {
background-color: black;
color: green;
font-family: monospace;
padding: 10px;
height: 300px;
overflow-y: auto;
}

.terminal div {
white-space: pre;
}
8 changes: 8 additions & 0 deletions resources/views/back/developer/dependencies.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@
<li class="py-2">
<x-link href="https://gedcom.io/tools/" target="_blank">FamilySearch GEDCOM - Tools</x-link>
</li>

<br />
<hr />
<br />

<li class="py-2">
<x-link href="https://github.com/liberu-genealogy/php-gedcom" target="_blank">liberu-genealogy/php-gedco</x-link> - POSSIBLE CANDIDATE
</li>
</ul>
</x-ts-tab.items>
</x-ts-tab>
Expand Down
8 changes: 0 additions & 8 deletions resources/views/back/developer/test.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@

@php
// ----------------------------------------------------------------------------------------------------------------------
$parser = new App\GedcomParser();
$parser->parse('./gedcom/royals.ged');
echo '<h1>INDIVIDUALS :</h1>';
$parser->outputIndividuals();
echo '<h1>FAMILIES :</h1>';
$parser->outputFamilies();
// ----------------------------------------------------------------------------------------------------------------------
@endphp

</div>
</x-app-layout>
4 changes: 2 additions & 2 deletions resources/views/back/gedcom/export.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@section('title')
&vert; {{ __('team.export') }}
&vert; {{ __('gedcom.export') }}
@endsection

<x-app-layout>
<x-slot name="heading">
{{ __('team.export') }}
{{ __('gedcom.export') }}
</x-slot>

<div class="w-full py-5 space-y-5">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/back/gedcom/import.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@section('title')
&vert; {{ __('team.import') }}
&vert; {{ __('gedcom.import') }}
@endsection

<x-app-layout>
<x-slot name="heading">
{{ __('team.import') }}
{{ __('gedcom.import') }}
</x-slot>

<div class="w-full py-5 space-y-5">
Expand Down
Loading

0 comments on commit 4b9c69a

Please sign in to comment.