diff --git a/src/Bundle/ChillMainBundle/Controller/DashboardHomepageController.php b/src/Bundle/ChillMainBundle/Controller/DashboardHomepageController.php new file mode 100644 index 000000000..c32e061a6 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/DashboardHomepageController.php @@ -0,0 +1,64 @@ + ['Label 1', 'Label 2', 'Label 3'], + 'datasets' => [ + [ + 'label' => 'Dataset 1', + 'data' => [10, 20, 30], + 'backgroundColor' => ['rgba(255, 99, 132, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(255, 206, 86, 0.2)'], + 'borderColor' => ['rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)'], + 'borderWidth' => 1, + ], + ], + ]; + + //Return the chart data as JSON response + return $this->json($chartData); + } + + /** + * @Route("/widget/{context}, name="widget_data") + */ + public function getWidgetData(Request $request, $context, WidgetManager $widgetManager): JsonResponse + { + + //Retrieve data from request in vue component + $requestData = json_decode($request->getContent(),true); + + // Process the widget data using the WidgetManager + $widgetData = $widgetManager->getDataForWidget($requestData, $context); + + // Return the widget data in JSON response + return new JsonResponse($widgetData); + } + + +} + + diff --git a/src/Bundle/ChillMainBundle/Widget/WidgetManager.php b/src/Bundle/ChillMainBundle/Widget/WidgetManager.php new file mode 100644 index 000000000..c160bb54f --- /dev/null +++ b/src/Bundle/ChillMainBundle/Widget/WidgetManager.php @@ -0,0 +1,37 @@ +widgetProvider = $widgetProvider; + } + + public function getDataForWidget($data,$context) + { + //Check if the WidgetProvider supports the given context + if ($this->widgetProvider->supports($data,$context)) { + // Get the widget data using specific Widget implementation + $widgetData = $this->widgetProvider->getDataForWidget($data); + return $widgetData; + } + + // Handle unsupported context + throw new \InvalidArgumentException('Unsupported context.'); + } +} diff --git a/src/Bundle/ChillMainBundle/Widget/WidgetProviderInterface.php b/src/Bundle/ChillMainBundle/Widget/WidgetProviderInterface.php new file mode 100644 index 000000000..d48cf430c --- /dev/null +++ b/src/Bundle/ChillMainBundle/Widget/WidgetProviderInterface.php @@ -0,0 +1,22 @@ + 'bar', + 'data' => $barData, + ]; + } +} diff --git a/src/Bundle/ChillMainBundle/Widget/Widgets/WidgetNumber.php b/src/Bundle/ChillMainBundle/Widget/Widgets/WidgetNumber.php new file mode 100644 index 000000000..f623d29df --- /dev/null +++ b/src/Bundle/ChillMainBundle/Widget/Widgets/WidgetNumber.php @@ -0,0 +1,35 @@ + 'number', + 'data' => $numberData, + ]; + } +}