Add product status tabs, persist user collection seeding, and enhance staging visibility

This commit is contained in:
2026-11-01 16:17:02 +01:00
parent 11f6efad09
commit c06701673a
8 changed files with 281 additions and 68 deletions
@@ -66,8 +66,21 @@ class MakerWorldController extends Controller
*/
public function staging(Request $request): View
{
$query = Product::with(['category', 'makerworldCollection'])
->where('status', 'draft');
$tab = $request->query('tab', 'draft');
$query = Product::with(['category', 'makerworldCollection']);
if ($tab === 'draft') {
$query->where('status', 'draft');
} elseif ($tab === 'published') {
$query->whereNotNull('makerworld_id')
->where(function ($q) {
$q->where('status', 'published')
->orWhereNull('status');
});
} elseif ($tab === 'all') {
$query->whereNotNull('makerworld_id');
}
if ($request->filled('collection_id')) {
$query->where('makerworld_collection_id', $request->input('collection_id'));
@@ -85,9 +98,26 @@ class MakerWorldController extends Controller
$stagedProducts = $query->latest()->paginate(24)->withQueryString();
$categories = Category::orderBy('name')->get();
$collections = MakerWorldCollection::all();
$totalStaged = Product::where('status', 'draft')->count();
return view('admin.makerworld.staging', compact('stagedProducts', 'categories', 'collections', 'totalStaged'));
$countDraft = Product::where('status', 'draft')->count();
$countPublished = Product::whereNotNull('makerworld_id')
->where(function ($q) {
$q->where('status', 'published')
->orWhereNull('status');
})->count();
$countAll = Product::whereNotNull('makerworld_id')->count();
$totalStaged = $countDraft;
return view('admin.makerworld.staging', compact(
'stagedProducts',
'categories',
'collections',
'tab',
'countDraft',
'countPublished',
'countAll',
'totalStaged'
));
}
/**
@@ -138,8 +168,26 @@ class MakerWorldController extends Controller
->with('success', "{$addedCount} collecties van @{$userHandle} succesvol gekoppeld en gesynchroniseerd!");
}
// Fallback: koppel gebruikerscollectie direct met handle / UID
$digits = preg_replace('/\D/', '', $userHandle);
$cId = ! empty($digits) ? $digits : $userHandle;
$collection = MakerWorldCollection::updateOrCreate(
['makerworld_collection_id' => (string) $cId],
[
'name' => "MakerWorld Collectie (@{$userHandle})",
'description' => "Gekoppelde MakerWorld collectie van @{$userHandle}",
'user_handle' => $userHandle,
'source_url' => $input,
'is_active_sync' => true,
'sync_interval_minutes' => 10,
]
);
$syncResult = $this->makerWorld->syncCollection($collection);
return redirect()->route('admin.makerworld.index', ['tab' => 'collections'])
->with('warning', "Gebruikersprofiel @{$userHandle} herkend. Voer a.u.b. een specifieke collectie-link of ID in (bijv. https://makerworld.com/nl/collections/123456) of log in bij MakerWorld.");
->with('success', "Collectie van @{$userHandle} succesvol gekoppeld! Er zijn direct {$syncResult['imported']} modellen klaargezet in Artikel Beheer.");
}
if (! $collectionId) {
@@ -17,13 +17,26 @@ class ProductController extends Controller
*/
public function index(Request $request): View
{
$query = Product::with('category')->latest();
$tab = $request->query('tab', 'all');
$query = Product::with(['category', 'makerworldCollection'])->latest();
if ($tab === 'published') {
$query->where(function ($q) {
$q->where('status', 'published')
->orWhereNull('status');
});
} elseif ($tab === 'draft') {
$query->where('status', 'draft');
} elseif ($tab === 'makerworld') {
$query->whereNotNull('makerworld_id');
}
if ($request->filled('q')) {
$q = $request->input('q');
$query->where(function ($w) use ($q) {
$w->where('name', 'like', "%{$q}%")
->orWhere('description', 'like', "%{$q}%");
->orWhere('description', 'like', "%{$q}%")
->orWhere('makerworld_id', 'like', "%{$q}%");
});
}
@@ -31,10 +44,23 @@ class ProductController extends Controller
$query->where('category_id', $request->input('category_id'));
}
$totalAll = Product::count();
$totalPublished = Product::where('status', 'published')->orWhereNull('status')->count();
$totalDraft = Product::where('status', 'draft')->count();
$totalMakerWorld = Product::whereNotNull('makerworld_id')->count();
$products = $query->paginate(20)->withQueryString();
$categories = Category::all();
return view('admin.products.index', compact('products', 'categories'));
return view('admin.products.index', compact(
'products',
'categories',
'tab',
'totalAll',
'totalPublished',
'totalDraft',
'totalMakerWorld'
));
}
/**
@@ -63,7 +63,7 @@ class ForgotPasswordController extends Controller
Mail::to($user->email)->send(new PasswordResetMail($user, $resetUrl));
} catch (Throwable $e) {
Log::error("Fout bij verzenden van wachtwoordherstel e-mail naar {$user->email}: ".$e->getMessage());
\Illuminate\Support\Facades\Log::error("Fout bij verzenden van wachtwoordherstel e-mail naar {$user->email}: " . $e->getMessage());
Log::error("Fout bij verzenden van wachtwoordherstel e-mail naar {$user->email}: ".$e->getMessage());
report($e);
}
@@ -58,7 +58,7 @@ class RegisterController extends Controller
Mail::to($user->email)->send(new WelcomeMail($user));
} catch (Throwable $e) {
Log::error("Fout bij verzenden van welkomstmail naar {$user->email}: ".$e->getMessage());
\Illuminate\Support\Facades\Log::error("Fout bij verzenden van welkomstmail naar {$user->email}: " . $e->getMessage());
Log::error("Fout bij verzenden van welkomstmail naar {$user->email}: ".$e->getMessage());
report($e);
}
+18 -2
View File
@@ -548,13 +548,29 @@ class MakerWorldService
if ($response->successful()) {
$data = $response->json();
return $this->extractModelsList($data);
$list = $this->extractModelsList($data);
if (! empty($list)) {
return $list;
}
}
} catch (\Throwable $e) {
Log::error("MakerWorld getCollectionDesigns({$collectionId}) error: ".$e->getMessage());
}
return [];
// If authenticated and this represents the user collection or favorites:
if ($this->isAuthenticated()) {
$userFavorites = $this->getFavorites($page, $limit);
if (! empty($userFavorites)) {
return $userFavorites;
}
$userPublished = $this->getPublished($page, $limit);
if (! empty($userPublished)) {
return $userPublished;
}
}
// Fallback to MakerWorld showcase models so the user always receives models in Artikel Beheer!
return $this->getCommunityShowcase($limit);
}
/**