Merge pull request 'ranjith-dev' (#1513) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 27s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 27s
Reviewed-on: #1513
This commit was merged in pull request #1513.
This commit is contained in:
75
app/Filament/Pages/SharedEditor.php
Normal file
75
app/Filament/Pages/SharedEditor.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\SharedClipBoard;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class SharedEditor extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-s-clipboard-document';
|
||||
|
||||
protected static string $view = 'filament.pages.shared-editor';
|
||||
|
||||
protected static ?string $navigationLabel = 'Shared Clipboard';
|
||||
|
||||
protected static ?string $title = 'Shared Clipboard';
|
||||
|
||||
public string $content = '';
|
||||
|
||||
public string $lastSyncedContent = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$clipboard = SharedClipBoard::firstOrCreate(
|
||||
['id' => 1],
|
||||
['content' => '']
|
||||
);
|
||||
|
||||
$this->content = $clipboard->content ?? '';
|
||||
|
||||
$this->lastSyncedContent = $this->content;
|
||||
}
|
||||
|
||||
public function updatedContent(): void
|
||||
{
|
||||
SharedClipBoard::where('id', 1)->update([
|
||||
'content' => $this->content,
|
||||
]);
|
||||
|
||||
$this->lastSyncedContent = $this->content;
|
||||
}
|
||||
|
||||
public function refreshSharedContent(): void
|
||||
{
|
||||
$sharedContent = SharedClipBoard::find(1)?->content ?? '';
|
||||
|
||||
// Do not overwrite text that this user is editing.
|
||||
if (
|
||||
$this->content === $this->lastSyncedContent
|
||||
&& $sharedContent !== $this->lastSyncedContent
|
||||
) {
|
||||
$this->content = $sharedContent;
|
||||
|
||||
$this->lastSyncedContent = $sharedContent;
|
||||
}
|
||||
}
|
||||
|
||||
public function clearContent(): void
|
||||
{
|
||||
SharedClipBoard::where('id', 1)->update([
|
||||
'content' => '',
|
||||
]);
|
||||
|
||||
$this->content = '';
|
||||
|
||||
$this->lastSyncedContent = '';
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view shared clipboard page');
|
||||
}
|
||||
|
||||
}
|
||||
15
app/Models/SharedClipBoard.php
Normal file
15
app/Models/SharedClipBoard.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SharedClipBoard extends Model
|
||||
{
|
||||
|
||||
protected $fillable = [
|
||||
'content',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('shared_clip_boards', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->longText('content')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('shared_clip_boards');
|
||||
}
|
||||
};
|
||||
@@ -292,5 +292,7 @@ class PermissionSeeder extends Seeder
|
||||
Permission::updateOrCreate(['name' => 'view test certificate page']);
|
||||
Permission::updateOrCreate(['name' => 'view process order rejection dashboard']);
|
||||
|
||||
Permission::updateOrCreate(['name' => 'view shared clipboard page']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user