Skip to content

Commit

Permalink
Sync wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Jul 27, 2024
1 parent ff5bf68 commit 4609453
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function up(): void
$table->bigIncrements('id');
$table->string('name')->unique();
$table->string('domain')->unique();
$table->boolean('show_in_menu')->nullable();
$table->tinyInteger('order')->nullable();
$table->boolean('read_only')->nullable();
$table->boolean('locked')->nullable();
$table->boolean('master')->nullable();
$table->string('thumbnail')->nullable();
$table->string('api_token', 80)->unique()->nullable();
$table->boolean('master')->nullable();
$table->boolean('locked')->nullable();
$table->string('lock_reason')->nullable();
$table->boolean('show_in_menu')->nullable();
$table->tinyInteger('order')->nullable();

$table->index('name');
$table->index('domain');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function up(): void
$table->boolean('has_errors')->default(false);
$table->json('field_mappings');

$table->foreign('source_platform_id')->references('id')->on('platforms')->onDelete('cascade');
$table->foreign('target_platform_id')->references('id')->on('platforms')->onDelete('cascade');
$table->foreign('source_platform_id')->references('id')->on('platforms')->onDelete('RESTRICT');
$table->foreign('target_platform_id')->references('id')->on('platforms')->onDelete('RESTRICT');

$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function up(): void
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('platform_id');

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('platform_id')->references('id')->on('platforms')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('RESTRICT');
$table->foreign('platform_id')->references('id')->on('platforms')->onDelete('RESTRICT');

$table->primary(['user_id', 'platform_id']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
return new class extends Migration
{
/**
* Run the migrations.
*/
Expand All @@ -14,13 +15,13 @@ return new class extends Migration {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->string('domain')->unique();
$table->boolean('show_in_menu')->nullable();
$table->tinyInteger('order')->nullable();
$table->boolean('read_only')->nullable();
$table->boolean('locked')->nullable();
$table->boolean('master')->nullable();
$table->string('thumbnail')->nullable();
$table->string('api_token', 80)->unique()->nullable();
$table->boolean('master')->nullable();
$table->boolean('locked')->nullable();
$table->string('lock_reason')->nullable();
$table->boolean('show_in_menu')->nullable();
$table->tinyInteger('order')->nullable();

$table->index('name');
$table->index('domain');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ return new class extends Migration
$table->boolean('has_errors')->default(false);
$table->json('field_mappings');

$table->foreign('source_platform_id')->references('id')->on('platforms')->onDelete('cascade');
$table->foreign('target_platform_id')->references('id')->on('platforms')->onDelete('cascade');
$table->foreign('source_platform_id')->references('id')->on('platforms')->onDelete('RESTRICT');
$table->foreign('target_platform_id')->references('id')->on('platforms')->onDelete('RESTRICT');

$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
return new class extends Migration
{
/**
* Run the migrations.
*/
Expand All @@ -14,8 +15,8 @@ return new class extends Migration {
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('platform_id');

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('platform_id')->references('id')->on('platforms')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('RESTRICT');
$table->foreign('platform_id')->references('id')->on('platforms')->onDelete('RESTRICT');

$table->primary(['user_id', 'platform_id']);

Expand Down
12 changes: 7 additions & 5 deletions packages/sync/resources/lang/de/translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
return [
'single' => 'Sync',
'plural' => 'Syncs',
'platform' => 'Platform',
'platforms' => 'Platforms',
'breadcrumb' => 'Sync',
'title' => 'Sync',
'navigation_label' => 'Sync',
'navigation_group' => 'Moox Sync',
'totalone' => 'Sync Eins',
'totaltwo' => 'Sync Zwei',
'totalthree' => 'Sync Drei',
'navigation_group' => 'Sync',
'totalone' => 'Sync One',
'totaltwo' => 'Sync Two',
'totalthree' => 'Sync Three',
'name' => 'Name',
'started_at' => 'Gestartet',
'started_at' => 'Started at',
'failed' => 'failed',
];
3 changes: 1 addition & 2 deletions packages/sync/src/Models/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Platform extends Model
'domain',
'show_in_menu',
'order',
'read_only',
'locked',
'lock_reason',
'master',
'thumbnail',
'api_token',
Expand All @@ -22,7 +22,6 @@ class Platform extends Model

protected $casts = [
'selection' => 'boolean',
'read_only' => 'boolean',
'locked' => 'boolean',
'master' => 'boolean',
];
Expand Down
8 changes: 5 additions & 3 deletions packages/sync/src/Models/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ class Sync extends Model
{
protected $fillable = [
'title',
'model',
'source_platform_id',
'source_model',
'target_platform_id',
'last_sync',
'has_errors',
'target_model',
'all_fields',
'field_mappings',
'has_errors',
'last_sync',
];

protected $searchableFields = ['*'];
Expand Down
121 changes: 73 additions & 48 deletions packages/sync/src/Resources/PlatformResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PlatformResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-server-stack';

protected static ?string $recordTitleAttribute = 'title';
protected static ?string $recordTitleAttribute = 'name';

public static function form(Form $form): Form
{
Expand All @@ -40,7 +40,7 @@ public static function form(Form $form): Form
TextInput::make('name')
->rules(['max:255', 'string'])
->required()
->unique()
->unique(ignoreRecord: true)
->placeholder('Name')
->columnSpan([
'default' => 12,
Expand All @@ -51,33 +51,44 @@ public static function form(Form $form): Form
TextInput::make('domain')
->rules(['max:255', 'string'])
->required()
->unique(ignoreRecord: true)
->placeholder('Domain')
->columnSpan([
'default' => 12,
'md' => 12,
'lg' => 12,
]),

Toggle::make('show_in_menu')
->rules(['boolean'])
FileUpload::make('thumbnail')
->rules(['file'])
->nullable()
->image()
->placeholder('Thumbnail')
->columnSpan([
'default' => 12,
'md' => 12,
'lg' => 12,
]),

TextInput::make('order')
->rules(['max:255'])
TextInput::make('api_token')
->rules(['max:80'])
->unique(ignoreRecord: true)
->nullable()
->placeholder('Order')
->placeholder('Api Token')
->columnSpan([
'default' => 12,
'md' => 12,
'lg' => 12,
]),
])
->suffixAction(
Action::make('generateToken')
->label('Generate Token')
->icon('heroicon-o-arrow-path')
->action('generateToken')
->hidden(fn ($livewire) => $livewire instanceof ViewRecord)
),

Toggle::make('read_only')
Toggle::make('master')
->rules(['boolean'])
->nullable()
->columnSpan([
Expand All @@ -93,46 +104,51 @@ public static function form(Form $form): Form
'default' => 12,
'md' => 12,
'lg' => 12,
]),
])
->reactive()
->afterStateUpdated(function ($state, callable $set) {
if (! $state) {
$set('lock_reason', null);
}
}),

Toggle::make('master')
->rules(['boolean'])
TextInput::make('lock_reason')
->rules(['max:255'])
->nullable()
->label('Reason')
->columnSpan([
'default' => 12,
'md' => 12,
'lg' => 12,
]),
])
->visible(fn ($get) => $get('locked')),

FileUpload::make('thumbnail')
->rules(['file'])
Toggle::make('show_in_menu')
->rules(['boolean'])
->nullable()
->image()
->placeholder('Thumbnail')
->columnSpan([
'default' => 12,
'md' => 12,
'lg' => 12,
]),
])
->reactive()
->afterStateUpdated(function ($state, callable $set) {
if (! $state) {
$set('order', null);
}
}),

TextInput::make('api_token')
->rules(['max:80'])
->unique()
TextInput::make('order')
->rules(['max:255'])
->nullable()
->placeholder('Api Token')
->unique(ignoreRecord: true)
->placeholder('Order')
->columnSpan([
'default' => 12,
'md' => 12,
'lg' => 12,
])
->suffixAction(
Action::make('generateToken')
->label('Generate Token')
->icon('heroicon-o-arrow-path')
->action('generateToken')
->hidden(fn ($livewire) => $livewire instanceof ViewRecord)
),

->visible(fn ($get) => $get('show_in_menu')),
]),
]),
]);
Expand All @@ -143,39 +159,48 @@ public static function table(Table $table): Table
return $table
->poll('60s')
->columns([
ImageColumn::make('thumbnail')
->toggleable()
->label('')
->square(),
TextColumn::make('name')
->toggleable()
->searchable(true, null, true)
->sortable()
->searchable()
->limit(50),
TextColumn::make('domain')
->toggleable()
->searchable(true, null, true)
->limit(50),
IconColumn::make('show_in_menu')
->toggleable()
->boolean(),
TextColumn::make('order')
->toggleable()
->searchable(true, null, true)
->sortable()
->searchable()
->limit(50),
IconColumn::make('read_only')
IconColumn::make('master')
->toggleable()
->sortable()
->boolean(),
IconColumn::make('locked')
->toggleable()
->sortable()
->boolean(),
IconColumn::make('master')
IconColumn::make('api_token')
->boolean()
->sortable()
->label('Token')
->toggleable(),
IconColumn::make('show_in_menu')
->toggleable()
->sortable()
->label('Menu')
->boolean(),
ImageColumn::make('thumbnail')
->toggleable()
->circular(),
TextColumn::make('api_token')
TextColumn::make('order')
->toggleable()
->sortable()
->searchable()
->limit(30),
->limit(50),
TextColumn::make('created_at')
->dateTime(),
->dateTime()
->sortable()
->toggleable()
->since(),
])
->actions([ViewAction::make(), EditAction::make()])
->bulkActions([DeleteBulkAction::make()]);
Expand Down Expand Up @@ -216,7 +241,7 @@ public static function getNavigationLabel(): string

public static function getBreadcrumb(): string
{
return __('sync::translations.breadcrumb');
return __('sync::translations.platforms');
}

public static function shouldRegisterNavigation(): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class CreatePlatform extends CreateRecord

public function generateToken(): void
{
$this->form->fill([
'api_token' => Str::random(80),
]);
$this->data['api_token'] = Str::random(80);
}
}
Loading

0 comments on commit 4609453

Please sign in to comment.