Compare commits
4 Commits
6bdd210162
...
a62220c9d0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a62220c9d0 | ||
|
|
a5036b7d6f | ||
|
|
27b8058ba8 | ||
|
|
58091726a4 |
134
app/Filament/Resources/TempLiveReadingResource.php
Normal file
134
app/Filament/Resources/TempLiveReadingResource.php
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||||
|
use App\Filament\Resources\TempLiveReadingResource\RelationManagers;
|
||||||
|
use App\Models\MfmMeter;
|
||||||
|
use App\Models\TempLiveReading;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
use Filament\Forms\Components\Section;
|
||||||
|
|
||||||
|
class TempLiveReadingResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = TempLiveReading::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
protected static ?string $navigationGroup = 'Power House';
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
Section::make('')
|
||||||
|
->schema([
|
||||||
|
Forms\Components\Select::make('plant_id')
|
||||||
|
->label('Plant')
|
||||||
|
->relationship('plant', 'name')
|
||||||
|
->reactive()
|
||||||
|
->required(),
|
||||||
|
Forms\Components\Select::make('mfm_meter_id')
|
||||||
|
->label('MFM Meter ID')
|
||||||
|
->required()
|
||||||
|
->reactive()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
if (!$plantId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return MfmMeter::where('plant_id', $plantId)
|
||||||
|
->pluck('sequence', 'id')
|
||||||
|
->toArray();
|
||||||
|
}),
|
||||||
|
Forms\Components\TextInput::make('register_data')
|
||||||
|
->label('Register Data')
|
||||||
|
->required(),
|
||||||
|
Forms\Components\Hidden::make('created_by')
|
||||||
|
->default(Filament::auth()->user()?->name),
|
||||||
|
])
|
||||||
|
->columns(3),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
Tables\Columns\TextColumn::make('id')
|
||||||
|
->label('ID')
|
||||||
|
->numeric()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
|
->numeric()
|
||||||
|
->sortable(),
|
||||||
|
// Tables\Columns\TextColumn::make('mfm_meter_id.sequence')
|
||||||
|
// ->label('Sequence')
|
||||||
|
// ->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('mfmMeter.name')
|
||||||
|
->label('Name')
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('register_data')
|
||||||
|
->label('Register Data')
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
Tables\Columns\TextColumn::make('updated_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
Tables\Columns\TextColumn::make('deleted_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
Tables\Filters\TrashedFilter::make(),
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
Tables\Actions\ViewAction::make(),
|
||||||
|
Tables\Actions\EditAction::make(),
|
||||||
|
])
|
||||||
|
->bulkActions([
|
||||||
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||||
|
Tables\Actions\RestoreBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListTempLiveReadings::route('/'),
|
||||||
|
'create' => Pages\CreateTempLiveReading::route('/create'),
|
||||||
|
'view' => Pages\ViewTempLiveReading::route('/{record}'),
|
||||||
|
'edit' => Pages\EditTempLiveReading::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()
|
||||||
|
->withoutGlobalScopes([
|
||||||
|
SoftDeletingScope::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\TempLiveReadingResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateTempLiveReading extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TempLiveReadingResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\TempLiveReadingResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditTempLiveReading extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TempLiveReadingResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\ViewAction::make(),
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
Actions\ForceDeleteAction::make(),
|
||||||
|
Actions\RestoreAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\TempLiveReadingResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListTempLiveReadings extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = TempLiveReadingResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TempLiveReadingResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\TempLiveReadingResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewTempLiveReading extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TempLiveReadingResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Models/TempLiveReading.php
Normal file
31
app/Models/TempLiveReading.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class TempLiveReading extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'plant_id',
|
||||||
|
'mfm_meter_id',
|
||||||
|
'register_data',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'created_by',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function plant(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Plant::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mfmMeter(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(MfmMeter::class, 'mfm_meter_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
106
app/Policies/TempLiveReadingPolicy.php
Normal file
106
app/Policies/TempLiveReadingPolicy.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Access\Response;
|
||||||
|
use App\Models\TempLiveReading;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class TempLiveReadingPolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*/
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('view-any TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the model.
|
||||||
|
*/
|
||||||
|
public function view(User $user, TempLiveReading $templivereading): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('view TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can create models.
|
||||||
|
*/
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('create TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*/
|
||||||
|
public function update(User $user, TempLiveReading $templivereading): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('update TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete the model.
|
||||||
|
*/
|
||||||
|
public function delete(User $user, TempLiveReading $templivereading): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('delete TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete any models.
|
||||||
|
*/
|
||||||
|
public function deleteAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('delete-any TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore the model.
|
||||||
|
*/
|
||||||
|
public function restore(User $user, TempLiveReading $templivereading): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('restore TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore any models.
|
||||||
|
*/
|
||||||
|
public function restoreAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('restore-any TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can replicate the model.
|
||||||
|
*/
|
||||||
|
public function replicate(User $user, TempLiveReading $templivereading): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('replicate TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can reorder the models.
|
||||||
|
*/
|
||||||
|
public function reorder(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('reorder TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete the model.
|
||||||
|
*/
|
||||||
|
public function forceDelete(User $user, TempLiveReading $templivereading): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('force-delete TempLiveReading');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete any models.
|
||||||
|
*/
|
||||||
|
public function forceDeleteAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('force-delete-any TempLiveReading');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?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
|
||||||
|
{
|
||||||
|
$sql = <<<'SQL'
|
||||||
|
CREATE TABLE temp_live_readings (
|
||||||
|
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
|
||||||
|
plant_id BIGINT NOT NULL,
|
||||||
|
mfm_meter_id BIGINT NOT NULL,
|
||||||
|
|
||||||
|
register_data TEXT NOT NULL,
|
||||||
|
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
|
deleted_at TIMESTAMP,
|
||||||
|
|
||||||
|
created_by TEXT NULL,
|
||||||
|
|
||||||
|
UNIQUE (created_at, mfm_meter_id),
|
||||||
|
FOREIGN KEY (plant_id) REFERENCES plants (id),
|
||||||
|
FOREIGN KEY (mfm_meter_id) REFERENCES mfm_meters (id)
|
||||||
|
|
||||||
|
);
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
DB::statement($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('temp_live_readings');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user