- Migración: tabla feature_types + columnas feature_type_id (FK) e is_active en features. Modelo FeatureType; Feature gana featureType() + casts is_active. - Catálogo de tipos (FeatureTypeManager, ruta /feature-types): CRUD con modal (nombre, descripción, color), contador de usos; gateado por edit layers. - Editor de elementos del proyecto (FeatureManager, ruta projects.features): tabla Rappasoft ProjectFeaturesTable (filtros nombre/capa/tipo en cabecera), toggle activo/inactivo y borrado individual; modal para editar nombre/tipo/activo. - Acceso: botón "Elementos" en el dashboard del proyecto (edit layers) y enlace a "Tipos de elemento" desde el editor. Tests: FeatureManagementTest (6). Suite 87 passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use App\Traits\LogsActivity;
|
|
|
|
class Feature extends Model
|
|
{
|
|
use SoftDeletes, LogsActivity;
|
|
|
|
const STATUSES = ['planned', 'started', 'in_progress', 'completed', 'verified'];
|
|
|
|
protected $fillable = [
|
|
'layer_id', 'name', 'geometry', 'properties', 'template_id', 'feature_type_id',
|
|
'progress', 'status', 'is_active', 'responsible', 'responsible_user_id',
|
|
'uuid', 'client_updated_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'geometry' => 'array',
|
|
'properties' => 'array',
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
public function featureType()
|
|
{
|
|
return $this->belongsTo(FeatureType::class);
|
|
}
|
|
|
|
public function layer()
|
|
{
|
|
return $this->belongsTo(Layer::class);
|
|
}
|
|
|
|
public function template()
|
|
{
|
|
return $this->belongsTo(InspectionTemplate::class);
|
|
}
|
|
|
|
public function inspections()
|
|
{
|
|
return $this->hasMany(Inspection::class, 'feature_id');
|
|
}
|
|
|
|
public function issues()
|
|
{
|
|
return $this->hasMany(Issue::class);
|
|
}
|
|
|
|
public function responsibleUser()
|
|
{
|
|
return $this->belongsTo(User::class, 'responsible_user_id');
|
|
}
|
|
|
|
public function media()
|
|
{
|
|
return $this->morphMany(Media::class, 'mediable');
|
|
}
|
|
|
|
public function images()
|
|
{
|
|
return $this->morphMany(Media::class, 'mediable')->where('category', 'image');
|
|
}
|
|
|
|
public function getStatusColorAttribute(): string
|
|
{
|
|
return match($this->status) {
|
|
'planned' => '#6b7280',
|
|
'started' => '#3b82f6',
|
|
'in_progress' => '#f59e0b',
|
|
'completed' => '#10b981',
|
|
'verified' => '#8b5cf6',
|
|
default => '#6b7280',
|
|
};
|
|
}
|
|
}
|