예제 #1
0
 public function testOptions()
 {
     $this->assertEquals([], $this->widget->getOptions());
     $options['foo'] = 'bar';
     $this->widget->setOptions($options);
     $this->assertSame($options, $this->widget->getOptions());
 }
예제 #2
0
 public function testDashboard()
 {
     $dashboard = $this->getMock('Oro\\Bundle\\DashboardBundle\\Entity\\Dashboard');
     $this->assertNull($this->widget->getDashboard());
     $this->assertEquals($this->widget, $this->widget->setDashboard($dashboard));
     $this->assertEquals($dashboard, $this->widget->getDashboard());
 }
 /**
  * @param Widget $widget
  */
 protected function updateOptions(Widget $widget)
 {
     $options = $widget->getOptions();
     if (!isset($options['subWidgets'])) {
         return;
     }
     $items = array_map(function ($subWidget) {
         return ['id' => $subWidget, 'show' => true, 'order' => 0];
     }, $options['subWidgets']);
     $options['subWidgets'] = ['items' => $items];
     $widget->setOptions($options);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $dashboard = new Dashboard();
     $dashboard->setName('TestWidgets')->setLabel('TestWidgets')->setIsDefault(false);
     $manager->persist($dashboard);
     $averageOrderAmountChart = new Widget();
     $averageOrderAmountChart->setDashboard($dashboard)->setName('average_order_amount_chart')->setLayoutPosition([1, 0]);
     $newMagentoCustomersChart = new Widget();
     $newMagentoCustomersChart->setDashboard($dashboard)->setName('new_magento_customers_chart')->setLayoutPosition([0, 1]);
     $manager->persist($dashboard);
     $manager->persist($averageOrderAmountChart);
     $manager->persist($newMagentoCustomersChart);
     $manager->flush();
 }
예제 #5
0
 /**
  * @Route("/configure/{id}", name="oro_dashboard_configure", requirements={"id"="\d+"})
  * @Method({"GET", "POST"})
  * @Template("OroDashboardBundle:Dashboard:dialog/configure.html.twig")
  */
 public function configureAction(Request $request, Widget $widget)
 {
     if (!$this->getSecurityFacade()->isGranted('EDIT', $widget->getDashboard())) {
         throw new AccessDeniedException();
     }
     $form = $this->getFormProvider()->getForm($widget->getName());
     $saved = false;
     $form->setData($this->get('oro_dashboard.widget_configs')->getFormValues($widget));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $widget->setOptions($form->getData());
         $this->getEntityManager()->flush();
         $saved = true;
     }
     return ['form' => $form->createView(), 'formAction' => $request->getRequestUri(), 'saved' => $saved];
 }
 private function populateDashboard(DashboardModel $dashboard, ObjectManager $manager)
 {
     $user = $this->getAdminUser($manager);
     $widgetConfiguration = ['ticket_timeline' => [0, 0], 'time_of_response_widget' => [1, 0], 'tickets_by_channels_widget' => [0, 1], 'tickets_by_branches_widget' => [1, 2], 'tickets_by_priority_widget' => [0, 2]];
     foreach ($widgetConfiguration as $name => $position) {
         $widget = new Widget();
         $widget->setDashboard($dashboard->getEntity());
         $widget->setLayoutPosition($position);
         $widget->setName($name);
         $state = new WidgetState();
         $state->setWidget($widget);
         $state->setOwner($user);
         $state->setExpanded(true);
         $manager->persist($widget);
         $manager->persist($state);
     }
 }
예제 #7
0
 /**
  * @param Widget $widget
  * @return array
  */
 public function getFormValues(Widget $widget)
 {
     $options = $widget->getOptions();
     $widgetConfig = $this->configProvider->getWidgetConfig($widget->getName());
     foreach ($widgetConfig['configuration'] as $name => $config) {
         $value = isset($options[$name]) ? $options[$name] : null;
         $options[$name] = $this->valueProvider->getFormValue($config['type'], $config, $value);
     }
     $options = $this->loadDefaultValue($options, $widgetConfig);
     return $options;
 }
예제 #8
0
 /**
  * @param string $name
  * @param array  $layoutPositions
  * @return Widget
  */
 protected function createWidget($name = 'quick_launchpad', array $layoutPositions = [1, 1])
 {
     $dashboard = new Dashboard();
     $dashboard->setName('main');
     $widget = new Widget();
     $widget->setName($name)->setLayoutPosition($layoutPositions)->setDashboard($dashboard);
     $dashboard->addWidget($widget);
     return $widget;
 }
예제 #9
0
 /**
  * Copy widget model by entity
  *
  * @param Widget $sourceWidget
  *
  * @return WidgetModel
  */
 protected function copyWidgetModel(Widget $sourceWidget)
 {
     $widget = new Widget();
     $widget->setLayoutPosition($sourceWidget->getLayoutPosition());
     $widget->setName($sourceWidget->getName());
     return $this->getWidgetModel($widget);
 }
예제 #10
0
 /**
  * @param Widget $widget
  * @return WidgetModel
  */
 public function createWidgetModel(Widget $widget)
 {
     $widgetConfig = $this->configProvider->getWidgetConfig($widget->getName());
     $widgetState = $this->stateManager->getWidgetState($widget);
     return new WidgetModel($widget, $widgetConfig, $widgetState);
 }