Skip to content

Commit

Permalink
Add test for item updates, add clockwork and add the graphcontroller
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbrandB committed Jun 14, 2024
1 parent 00cd2d1 commit e842403
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 213 deletions.
49 changes: 49 additions & 0 deletions app/Http/Controllers/GraphController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Http\Controllers;

use App\Models\Item;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Inertia\Inertia;

class GraphController extends Controller
{
public function index(Request $request)
{
$query = Item::query()
->select('json_items', 'id', 'title', 'photo')
->without('attributes');
$pythonItem = $query->clone()
->where('id', env('PYTHON_ID'))
->firstOrFail();
$items = $query->clone();
$selected = Session::get('selected');
if ($selected) {
$items = $items
->whereIn('id', $selected)
->whereNot('id', env('PYTHON_ID'))
->get();
} else {
$items = $items->whereNot('id', env('PYTHON_ID'))
->get();
}

$nodes = $query->clone()
->whereIn('id', $items->pluck('json_items')->flatten()->unique())
->whereNotIn('id', $items->pluck('id')->toArray())
->get();
return Inertia::render('Test', [
'items' => $items,
'python' => $pythonItem,
'nodes' => $nodes,
]);
}

public function syncSelected(Request $request)
{
$selected = $request->input('selected');
// add the selected items to the selected items in this session
$request->session()->put('selected', $selected ?? []);
}
}
17 changes: 5 additions & 12 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function index(Request $request)
}

return Inertia::render('Items/Index', [
'oldSelectedItems'=> $request->session()->get('selected'),
'items' => $items->get(),
'attributeTypes' => AttributeType::with('attributes')->orderBy('created_at', 'desc')->get(),
'filters' => $filters,
Expand Down Expand Up @@ -55,15 +56,11 @@ public function store(Request $request)
$wiringPhoto?->storeAs('photos/' . $photo->hashName(), ['disk' => 'public']);
$item = new Item();
$item->fill($request->except('attributes', 'photo', 'wiring_photo', 'json_items'));
$json_items = explode(',', $request->input('edges'));
if ($json_items[0] !== "") {
$item->json_items = array_map('intval',$json_items);
}
$item->json_items = $request->input('edges') ?? [];
$item->photo = $photo?->hashName();
$item->wiring_photo = $wiringPhoto?->hashName();
$item->save();
$string = explode(',', $request->input('attributes'));
$item->attributes()->sync($string[0] === "" ? [] : $string);
$item->attributes()->sync($request->input('attributes')??[]);
return to_route('items.show', ['public_id' => $item->public_id]);
}

Expand Down Expand Up @@ -131,13 +128,9 @@ public function update(Request $request, int $id)
}

$item->fill($request->except('attributes', 'photo', 'wiring_photo', 'json_items'));
$json_items = explode(',', $request->input('edges'));
if ($json_items[0] !== "") {
$item->json_items = array_map('intval',$json_items);
}
$item->json_items = $request->input('edges') ?? [];
$item->save();
$string = explode(',', $request->input('attributes'));
$item->attributes()->sync($string[0] === "" ? [] : $string);
$item->attributes()->sync($request->input('attributes')??[]);
return to_route('items.show', ['public_id' => $item->public_id]);
}

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"require-dev": {
"fakerphp/faker": "^1.23",
"itsgoingd/clockwork": "^5.2",
"laravel/breeze": "^2.0",
"laravel/pint": "^1.13",
"laravel/sail": "^1.26",
Expand Down
77 changes: 76 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions database/factories/ItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public function definition(): array
'title' => $this->faker->name,
'description' => $this->faker->paragraph,
'card_description' => $this->faker->text,
'photo' => 'wQb7eXES6yeZYqAg5bVuibbWMYLB3UyqWz2OvJy1.jpg',
'photo' => 'YMPNoUbFbo7TDe0JnjkeiwilJ5rxLTdj48cuWTWx.jpg',
'is_actuator' => $this->faker->boolean,
'pros' => $this->faker->paragraph,
'cons' => $this->faker->paragraph,
'hardware_considerations' => $this->faker->paragraph,
'software_considerations' => $this->faker->paragraph,
'example_code' => $this->faker->paragraph,
'wiring_photo' => 'wQb7eXES6yeZYqAg5bVuibbWMYLB3UyqWz2OvJy1.jpg',
'wiring_photo' => 'SQ0oOJO8YdosGlS9TvtHRHrw687UYJRN5eS25001.jpg',
'wiring_instructions' => $this->faker->paragraph,
'json_items' => [],
];
Expand Down
91 changes: 48 additions & 43 deletions resources/js/CustomComponents/AttributeFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import Pill from "@/CustomComponents/Pill.vue";
import {Attribute, AttributeType} from "@/types";
import {nextTick, ref} from "vue";
const props = defineProps<{
const props = withDefaults(defineProps<{
attributeTypes: AttributeType[],
checkedAttributes: any,
title: string
}>();
checkedAttributes?: {},
title?: string
}>(),{
title: 'filters',
checkedAttributes: {}
});
const emit = defineEmits(['update:checkedAttributes']);
const checkedAttributes = ref(props.checkedAttributes);
console.log(props.checkedAttributes)
console.log(props.title)
const check = (attributeType: { id: number, color: string }, attribute: {
id: number
}, checked: boolean) => nextTick(() => {
console.log(checkedAttributes.value);
if (checked) {
if (!Object.hasOwn(checkedAttributes.value, attributeType.id)) {
checkedAttributes.value[attributeType.id] = {
Expand All @@ -40,43 +45,43 @@ function capitalizeFirstLetter(string: string) {
}
</script>
<template>
<div class="w-full text-2xl text-center font-semibold mt-4">{{ capitalizeFirstLetter(title) }}</div>
<div
class="mx-2 mt-1 flex flex-wrap text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white">
<template v-for="(attributeType, idx) in checkedAttributes">
<pill class="cursor-pointer" @click="check({id:idx, color:attributeType.color}, attribute, false)"
v-for="attribute in attributeType.attributes" :key="attribute.id"
:color="attributeType.color">
{{ attribute.title }} <span class="ms-2 text-red-600">x</span>
</pill>
</template>
<div v-if="Object.entries(checkedAttributes).length<=0" class="w-full p-2 text-center text-gray-500">
No {{ title }} applied
</div>
<div class="w-full text-2xl text-center font-semibold mt-4">{{ capitalizeFirstLetter(title) }}</div>
<div
class="mx-2 mt-1 flex flex-wrap text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white">
<template v-for="(attributeType, idx) in checkedAttributes">
<pill class="cursor-pointer" @click="check({id:idx, color:attributeType.color}, attribute, false)"
v-for="attribute in attributeType.attributes" :key="attribute.id"
:color="attributeType.color">
{{ attribute.title }} <span class="ms-2 text-red-600">x</span>
</pill>
</template>
<div v-if="Object.entries(checkedAttributes).length<=0" class="w-full p-2 text-center text-gray-500">
No {{ title }} applied
</div>
<OpeningComponent v-for="attributeType in attributeTypes" :title="attributeType.title">
<template #title>
<div class="font-bold text-sm md:text-lg p-1 md:p3 rounded rounded-lg"
:class="`bg-${attributeType.color}-100`">{{ attributeType.title }}
</div>
</template>
<template #content>
<ul class="w-full mt-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white">
<li v-for="attribute in attributeType.attributes" :key="attribute.id"
class="w-full border-b border-gray-200 rounded-t-lg dark:border-gray-600">
<div class="flex items-center ps-3">
<input type="checkbox"
:checked="Object.hasOwn(checkedAttributes, attributeType.id) && checkedAttributes[attributeType.id].attributes.some((checkedAttribute: Attribute) => checkedAttribute.id === attribute.id)"
@change="check(attributeType, attribute, ($event as HTMLInputElement|any).target.checked)"
:id="attribute.id.toString()" :value="attribute.id"
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-700 dark:focus:ring-offset-gray-700 focus:ring-2 dark:bg-gray-600 dark:border-gray-500">
<label :for="attribute.id.toString()"
class="w-full py-2 md:py-3 ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">{{
attribute.title
}}</label>
</div>
</li>
</ul>
</template>
</OpeningComponent>
</div>
<OpeningComponent v-for="attributeType in attributeTypes" :title="attributeType.title">
<template #title>
<div class="font-bold text-sm md:text-lg p-1 md:p3 rounded rounded-lg"
:class="`bg-${attributeType.color}-100`">{{ attributeType.title }}
</div>
</template>
<template #content>
<ul class="w-full mt-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white">
<li v-for="attribute in attributeType.attributes" :key="attribute.id"
class="w-full border-b border-gray-200 rounded-t-lg dark:border-gray-600">
<div class="flex items-center ps-3">
<input type="checkbox"
:checked="Object.hasOwn(checkedAttributes, attributeType.id) && checkedAttributes[attributeType.id].attributes.some((checkedAttribute: Attribute) => checkedAttribute.id === attribute.id)"
@change="check(attributeType, attribute, ($event as HTMLInputElement|any).target.checked)"
:id="attribute.id.toString()" :value="attribute.id"
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-700 dark:focus:ring-offset-gray-700 focus:ring-2 dark:bg-gray-600 dark:border-gray-500">
<label :for="attribute.id.toString()"
class="w-full py-2 md:py-3 ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">{{
attribute.title
}}</label>
</div>
</li>
</ul>
</template>
</OpeningComponent>
</template>
29 changes: 11 additions & 18 deletions resources/js/Pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,28 @@ import {Head} from '@inertiajs/vue3';
import Modal from "@/Components/Modal.vue";
import {ref} from "vue";
import SecondaryButton from "@/Components/SecondaryButton.vue";
import Card from "@/Components/Card.vue";
import OpeningCard from "@/CustomComponents/OpeningCard.vue";
</script>

<template>
<Head title="Dashboard"/>
<Head title="About the kit"/>

<AuthenticatedLayout>
<template #header>
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">Dashboard</h2>
</template>

<div class="pt-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900 dark:text-gray-100">Choice helper</div>
</div>
</div>
<card>
<div class="text-2xl font-bold p-6 text-gray-900 dark:text-gray-100">Sports toolkit</div>
</card>
</div>

<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="flex flex-row justify-center items-center">
<div class="w-full p-8 mr-3 bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900 text-2xl dark:text-gray-100">Actuating</div>
</div>
<div class="ml-3 w-full p-8 bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900 text-2xl dark:text-gray-100">Sensing</div>
</div>
</div>
</div>
</div>
<opening-card title="">
<template #content>
<div class="text-2xl font-bold p-6 text-gray-900 dark:text-gray-100">Sports toolkit</div>
</template>
</opening-card>
</AuthenticatedLayout>
</template>
Loading

0 comments on commit e842403

Please sign in to comment.