-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add edges, finish the update and creation of the attributes and types…
… and add some responsiveness
- Loading branch information
Showing
27 changed files
with
861 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Attribute; | ||
use App\Models\AttributeType; | ||
use Illuminate\Http\Request; | ||
use Inertia\Inertia; | ||
|
||
class AttributeController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return Inertia::render('Attributes/Index', [ | ||
'attributeTypes' => AttributeType::with('attributes')->get(), | ||
]); | ||
} | ||
|
||
public function create() | ||
{ | ||
return Inertia::render('Attributes/Edit', [ | ||
'attributeTypes' => AttributeType::all(), | ||
]); | ||
} | ||
|
||
public function store(Request $request) | ||
{ | ||
$id = Attribute::create($request->all())->id; | ||
return to_route('attributes.edit',$id); | ||
} | ||
|
||
public function show($id) | ||
{ | ||
} | ||
|
||
public function edit($id) | ||
{ | ||
$attribute = Attribute::findOrFail($id); | ||
return Inertia::render('Attributes/Edit', [ | ||
'attributeTypes' => AttributeType::all(), | ||
'attribute' => $attribute, | ||
]); | ||
} | ||
|
||
public function update(Request $request, $id) | ||
{ | ||
$attribute = Attribute::findOrFail($id); | ||
$attribute->update($request->all()); | ||
return to_route('attributes.index'); | ||
} | ||
|
||
public function destroy($id) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class Edge extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'from_item_id', | ||
'to_item_id', | ||
'belongsto_item_id' | ||
]; | ||
|
||
public function fromItem(): BelongsTo | ||
{ | ||
return $this->belongsTo(Attribute::class, 'from_item_id'); | ||
} | ||
|
||
public function toItem(): BelongsTo | ||
{ | ||
return $this->belongsTo(Attribute::class, 'to_item_id'); | ||
} | ||
|
||
public function belongsToItem(): BelongsTo | ||
{ | ||
return $this->belongsTo(Attribute::class, 'belongsto_item_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Attribute; | ||
use App\Models\Edge; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Support\Carbon; | ||
|
||
class EdgeFactory extends Factory | ||
{ | ||
protected $model = Edge::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
|
||
'from_attribute_id' => Attribute::factory(), | ||
'to_attribute_id' => Attribute::factory(), | ||
]; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
database/migrations/2024_06_09_223050_create_edges_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::create('edges', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('from_item_id'); | ||
$table->foreignId('to_item_id'); | ||
$table->foreignId('belongsto_item_id'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('edges'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
use App\Models\Attribute; | ||
use App\Models\AttributeType; | ||
use App\Models\Edge; | ||
use App\Models\Item; | ||
use App\Models\Processor; | ||
use App\Models\User; | ||
|
@@ -31,25 +32,48 @@ public function run(): void | |
'email' => '[email protected]', | ||
]); | ||
|
||
$processors = AttributeType::create( | ||
[ | ||
'title' => 'Controllers', | ||
'description' => 'All the controllers you can use to interact with the sensors and actuators', | ||
'color' => 'blue', | ||
] | ||
); | ||
|
||
Attribute::create( | ||
[ | ||
'attribute_type_id' => $processors->id, | ||
'title' => 'Arduino', | ||
'description' => 'A microcontroller that can be used to interact with sensors and actuators', | ||
] | ||
); | ||
|
||
Attribute::create( | ||
[ | ||
'attribute_type_id' => $processors->id, | ||
'title' => 'ESP8266', | ||
'description' => 'The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability produced by Espressif Systems', | ||
] | ||
); | ||
|
||
AttributeType::factory(10)->has( | ||
Attribute::factory()->count(5) | ||
)->create(); | ||
|
||
Item::factory(10)->create(); | ||
foreach (Item::all() as $item) { | ||
$items = Item::factory(10)->create(); | ||
$attributes = Attribute::all(); | ||
foreach ($items as $item) { | ||
$item->attributes()->attach( | ||
Attribute::all()->random(3) | ||
$attributes->random(3) | ||
); | ||
} | ||
|
||
|
||
Processor::create([ | ||
'name' => 'Laptop', | ||
'description' => 'A portable computer', | ||
]); | ||
|
||
|
||
|
||
|
||
for($i = 0; $i < sizeof($items) - 1; $i++) { | ||
Edge::create([ | ||
'from_item_id' => $items->get($i)->id, | ||
'to_item_id' => $items->get($i+1)->id, | ||
'belongsto_item_id' => $items->first()->id, | ||
]); | ||
} | ||
} | ||
} |
Oops, something went wrong.