Skip to content

Commit

Permalink
GEDCOM Export/Import - Prepare interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
MGeurts committed Dec 31, 2024
1 parent 9c8ec20 commit 300a355
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 76 deletions.
83 changes: 79 additions & 4 deletions app/Livewire/Gedcom/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,94 @@

namespace App\Livewire\Gedcom;

use Illuminate\View\View;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use TallStackUi\Traits\Interactions;

class Export extends Component
{
// -----------------------------------------------------------------------
use Interactions;

public $user = null;

public Collection $teamPersons;

public string $format = 'gedcom';

public array $formats = [];

public string $encoding = 'utf8';

public array $encodings = [];

public string $filename;

public string $line_endings = 'windows';

public function mount(): void
{
//
$this->user = Auth()->user();

$this->teamPersons = Auth::user()->currentTeam->persons->sortBy('name')->values();

$this->formats = [
['value' => 'gedcom', 'label' => 'GEDCOM', 'extension' => '.ged'],
['value' => 'zip', 'label' => 'ZIP', 'extension' => '.zip'],
['value' => 'zipmedia', 'label' => 'ZIP ' . __('gedcom.includes_media'), 'extension' => '.zip'],
['value' => 'gedzip', 'label' => 'GEDZIP ' . __('gedcom.includes_media'), 'extension' => '.gdz'],
];

$this->encodings = [
['value' => 'utf8', 'label' => 'UTF-8'],
['value' => 'unicode', 'label' => 'UNICODE (UTF16-BE)'],
['value' => 'ansel', 'label' => 'ANSEL'],
['value' => 'ascii', 'label' => 'ASCII'],
['value' => 'ansi', 'label' => 'ANSI (CP1252)'],

];

$this->setFilename();
}

public function updatedFormat(): void
{
$this->setFilename();
}

// -----------------------------------------------------------------------
private function setFilename(): void
{
$this->filename = $this->cleanString(Auth()->user()->currentTeam->name) . '-' . now()->format('Y-m-d-H-i-s') . $this->getExtension();
}

private function getExtension(): string
{
return collect($this->formats)->where('value', $this->format)->first()['extension'];
}

private function cleanString(string $string): string
{
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars
$string = preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one

return strtolower($string);
}

public function exportTeam(): void
{
$this->validate([
'format' => 'required',
'encoding' => 'required',
'filename' => 'required',
]);

$this->toast()->success(__('app.download'), strtoupper(__('app.under_construction')))->send();
}

// -----------------------------------------------------------------------
public function render(): View
public function render()
{
return view('livewire.gedcom.export');
}
Expand Down
48 changes: 1 addition & 47 deletions app/Livewire/Gedcom/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,53 +61,7 @@ public function mount(): void

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

// 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(asset('storage/imports/' . $this->file->getClientOriginalName()));
$gedcom = $parser->parse('storage/imports/demo.ged');

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

$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: 'stream', content: $line);
$this->output .= $line;

$count_indi++;
}

usleep(250);
}
// -----------------------------------------------------------------------
$this->output .= '<br/><div>Done.</div><div>Imported ' . $count_indi . ' individuals.</div><div>Imported ' . $count_fam . ' families.</div>';

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

// -----------------------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion lang/de/gedcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
'team_create_new_gedcom' => 'Erstellen Sie ein neues Team, importiert aus einer GEDCOM-Datei, um mit anderen zusammenzuarbeiten.',
'team_gedcom_reference' => 'Referenz',
'team_gedcom_specifications' => 'GEDCOM Specificationen',
'team_gedcom_version' => 'Maximal GEDCOM version 5.5.5',
'team_gedcom_version' => 'GEDCOM version 5.5 oder 7',
'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',

'filename' => 'Dateiname',
'format' => 'Format',
'includes_media' => '(einschließlich Mediendateien)',
'character_encoding' => 'Zeichenkodierung',
'line_endings' => 'Zeilenenden',
'line_endings_windows' => 'CR/LF (Windows)',
'line_endings_unix' => 'LF (Unix)',
];
10 changes: 9 additions & 1 deletion lang/en/gedcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
'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_version' => 'GEDCOM version 5.5 or 7',
'team_gedcom_hint' => 'Let\'s create a team based on a GEDCOM file',
'team_gedcom_tip' => 'Drag and drop your GEDCOM file here',

'filename' => 'Filename',
'format' => 'Format',
'includes_media' => '(includes media files)',
'character_encoding' => 'Character encoding',
'line_endings' => 'Line endings',
'line_endings_windows' => 'CR/LF (Windows)',
'line_endings_unix' => 'LF (Unix)',
];
10 changes: 9 additions & 1 deletion lang/es/gedcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
'team_create_new_gedcom' => 'Cree un nuevo equipo, importado desde un archivo GEDCOM, para colaborar con otros.',
'team_gedcom_reference' => 'Referencia',
'team_gedcom_specifications' => 'Especificaciones de GEDCOM',
'team_gedcom_version' => 'GEDCOM máxima versión 5.5.5',
'team_gedcom_version' => 'GEDCOM versión 5.5 0 7',
'team_gedcom_hint' => 'Creemos un equipo basado en un archivo GEDCOM',
'team_gedcom_tip' => 'Arrastre y suelte su archivo GEDCOM aquí',

'filename' => 'Nombre del archivo',
'format' => 'Formato',
'includes_media' => '(incluye archivos multimedia)',
'character_encoding' => 'Codificación de caracteres',
'line_endings' => 'Finales de línea',
'line_endings_windows' => 'CR/LF (Windows)',
'line_endings_unix' => 'LF (Unix)',
];
10 changes: 9 additions & 1 deletion lang/fr/gedcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
'team_create_new_gedcom' => 'Créez une nouvelle équipe, importée d\'un fichier GEDCOM, pour collaborer avec d\'autres.',
'team_gedcom_reference' => 'Référence',
'team_gedcom_specifications' => 'Spécifications GEDCOM',
'team_gedcom_version' => 'Version maximale GEDCOM 5.5.5',
'team_gedcom_version' => 'Version GEDCOM 5.5 ou 7',
'team_gedcom_hint' => 'Créons une équipe basée sur un fichier GEDCOM',
'team_gedcom_tip' => 'Glissez et déposez votre fichier GEDCOM ici',

'filename' => 'Nom de fichier',
'format' => 'Format',
'includes_media' => '(inclut les fichiers multimédias)',
'character_encoding' => 'Codage des caractères',
'line_endings' => 'Fins de lignes',
'line_endings_windows' => 'CR/LF (Windows)',
'line_endings_unix' => 'LF (Unix)',
];
10 changes: 9 additions & 1 deletion lang/nl/gedcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
'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_version' => 'GEDCOM versie 5.5 of 7',
'team_gedcom_hint' => 'Laten we een team creëren op basis van een GEDCOM-bestand',
'team_gedcom_tip' => 'Sleep uw GEDCOM-bestand hierheen',

'filename' => 'Bestandsnaam',
'format' => 'Formaat',
'includes_media' => '(inclusief mediabestanden)',
'character_encoding' => 'Karaktercodering',
'line_endings' => 'Lijnuiteinden',
'line_endings_windows' => 'CR/LF (Windows)',
'line_endings_unix' => 'LF (Unix)',
];
10 changes: 9 additions & 1 deletion lang/pt/gedcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
'team_create_new_gedcom' => 'Crie uma nova equipe, importada de um arquivo GEDCOM, para colaborar com outras pessoas.',
'team_gedcom_reference' => 'Referência',
'team_gedcom_specifications' => 'Especificações GEDCOM',
'team_gedcom_version' => 'Máximo GEDCOM versão 5.5.5',
'team_gedcom_version' => 'GEDCOM versão 5.5 ou 7',
'team_gedcom_hint' => 'Vamos criar uma equipe baseada em um arquivo GEDCOM',
'team_gedcom_tip' => 'Arraste e solte seu arquivo GEDCOM aqui',

'filename' => 'Nome do arquivo',
'format' => 'Formatar',
'includes_media' => '(inclui arquivos de mídia)',
'character_encoding' => 'Codificação de caracteres',
'line_endings' => 'Finais de linha',
'line_endings_windows' => 'CR/LF (Windows)',
'line_endings_unix' => 'LF (Unix)',
];
10 changes: 9 additions & 1 deletion lang/vi/gedcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
'team_create_new_gedcom' => 'Tạo một đội mới, được nhập từ tệp GEDCOM, để hợp tác với những người khác.',
'team_gedcom_reference' => 'Tham chiếu',
'team_gedcom_specifications' => 'Thông số GEDCOM',
'team_gedcom_version' => 'Phiên bản GEDCOM tối đa 5.5.5',
'team_gedcom_version' => 'GEDCOM phiên bản 5.5 hoặc 7',
'team_gedcom_hint' => 'Hãy tạo một đội dựa trên tệp GEDCOM',
'team_gedcom_tip' => 'Kéo và thả tệp GEDCOM của bạn vào đây',

'filename' => 'Tên tệp',
'format' => 'Định dạng',
'includes_media' => '(bao gồm các tập tin media)',
'character_encoding' => 'Mã hóa ký tự',
'line_endings' => 'Kết thúc dòng',
'line_endings_windows' => 'CR/LF (Windows)',
'line_endings_unix' => 'LF (Unix)',
];
10 changes: 9 additions & 1 deletion lang/zh_cn/gedcom.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
'team_create_new_gedcom' => '创建一个新的家族,从 GEDCOM 文件导入,以便与他人合作。',
'team_gedcom_reference' => '参考',
'team_gedcom_specifications' => 'GEDCOM 规范',
'team_gedcom_version' => '最大 GEDCOM 版本 5.5.5',
'team_gedcom_version' => 'GEDCOM 版本 5.5 或 7',
'team_gedcom_hint' => '让我们基于 GEDCOM 文件创建一个家族',
'team_gedcom_tip' => '将您的 GEDCOM 文件拖放到这里',

'filename' => '文件名',
'format' => '格式',
'includes_media' => '(包括媒体文件)',
'character_encoding' => '字符编码',
'line_endings' => '行结尾',
'line_endings_windows' => '回车/换行(Windows)',
'line_endings_unix' => '低频(Unix)',
];
84 changes: 83 additions & 1 deletion resources/views/livewire/gedcom/export.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,85 @@
<div>
<x-under-construction />
<x-form-section submit="exportTeam">
<x-slot name="title">
<div class="dark:text-gray-400">
{{ __('team.team_details') }}
</div>
</x-slot>

<x-slot name="description">
<div class="dark:text-gray-100">
{{ __('gedcom.gedcom_export') }}
</div>

<div>
<br />
<hr class="my-2 h-0.5 border-t-0 bg-neutral-600 dark:bg-neutral-400 opacity-100 dark:opacity-75" />
<x-under-construction />
</div>
</x-slot>

<x-slot name="form" enctype="multipart/form-data">
<div class="col-span-6">
<x-label value="{{ __('team.owner') }} :" />

<div class="flex items-center mt-2">
<img class="object-cover w-12 h-12 rounded-full" src="{{ $this->user->profile_photo_url }}" alt="{{ $this->user->name }}">

<div class="leading-tight ms-4">
<div class="text-sm text-gray-700">{{ $this->user->name }}</div>
<div class="text-sm text-gray-700">{{ $this->user->email }}</div>
</div>
</div>
</div>

<div class="col-span-6">
<hr class="my-2 h-0.5 border-t-0 bg-neutral-600 dark:bg-neutral-400 opacity-100 dark:opacity-75" />
</div>

{{-- filename --}}
<div class="col-span-6">
<x-ts-input id="filename" type="text" class="block w-full mt-1" wire:model="filename" label="{{ __('gedcom.filename') }} : *" required readonly />

<x-input-error for="name" class="mt-2" />
</div>

{{-- format --}}
<div class="col-span-6">
<x-ts-select.styled wire:model.live="format" id="format" :options="$formats" select="label:label|value:value" label="{{ __('gedcom.format') }} : *" required />

<x-input-error for="format" class="mt-2" />
</div>

{{-- encoding --}}
<div class="col-span-6">
<x-ts-select.styled wire:model.live="encoding" id="encoding" :options="$encodings" select="label:label|value:value" label="{{ __('gedcom.character_encoding') }} : *" required />

<x-input-error for="encoding" class="mt-2" />
</div>

{{-- line endings --}}
<div class="col-span-6">
<x-label for="line_endings" class="mr-5" value="{{ __('gedcom.line_endings') }} : *" />

<div class="flex">
<div class="mt-3 mb-[0.125rem] mr-4 inline-block min-h-[1.5rem] pl-[1.5rem]">
<x-ts-radio color="primary" wire:model="line_endings" name="line_endings" id="line_ending_windows" value="windows" label="{{ __('gedcom.line_endings_windows') }}" />
</div>

<div class="mt-3 mb-[0.125rem] mr-4 inline-block min-h-[1.5rem] pl-[1.5rem]">
<x-ts-radio color="primary" wire:model="line_endings" name="line_endings" id="line_ending_unix" value="unix" label="{{ __('gedcom.line_endings_unix') }}" />
</div>
</div>

<x-input-error for="line_endings" class="mt-2" />
</div>
</x-slot>

<x-slot name="actions">
<x-ts-button type="submit" color="primary">
<x-ts-icon icon="download" class="inline-block size-5" />
{{ __('app.download') }}
</x-ts-button>
</x-slot>
</x-form-section>
</div>
Loading

0 comments on commit 300a355

Please sign in to comment.