Browse Source

Dashboard : wip

carruesco 1 year ago
parent
commit
08744ba71d
2 changed files with 16 additions and 5 deletions
  1. 12 0
      plugin/dashboard/DashboardWidget.class.php
  2. 4 5
      plugin/dashboard/action.php

+ 12 - 0
plugin/dashboard/DashboardWidget.class.php

@@ -119,6 +119,18 @@ class DashboardWidget extends Entity{
 
 	
 
+	public function getContent(&$widget){
+	
+		if(!isset($this->content) || is_string($this->content)  ) return $this->content;
+		
+		$method = $this->content;
+		
+		$widget->meta = json_decode($widget->meta,true);
+		if(!is_array($widget->meta)) $widget->meta = array();
+		$method($widget);
+		
+	}
+
 	public static function model($slug = null){
 		$model = array();
 		Plugin::callHook('widget',array(&$models));

+ 4 - 5
plugin/dashboard/action.php

@@ -19,6 +19,8 @@ Action::register('dashboard_widget_search',function(&$response){
 
 	$response['widgets'] = array();
 	foreach($widgets as $widget){
+		$model = DashboardWidget::model($widget->model);
+		$model->getContent($widget);
 		$response['widgets'][] = $widget->toData();
 	}
 });
@@ -149,12 +151,9 @@ Action::register('dashboard_widget_refresh',function(&$response){
 
 	foreach(DashboardWidget::model() as $model){
 		if(!isset($model->content) || is_string($model->content) || !isset($widgets[$model->model]) ) continue;
-		
-		$method = $model->content;
+	
 		foreach($widgets[$model->model] as $currentWidget){
-			$currentWidget->meta = json_decode($currentWidget->meta,true);
-			if(!is_array($currentWidget->meta)) $currentWidget->meta = array();
-			$method($currentWidget);
+			$model->getContent($currentWidget);
 			$response['rows'][] = $currentWidget;
 		}
 	}