Browse Source

Dashboard : wip

carruesco 1 year ago
parent
commit
afe6bc00a9

+ 4 - 6
class/Entity.class.php

@@ -424,7 +424,7 @@ class Entity {
      * @return <Array<Entity>> $Entity
      */
 
-    public static function loadAll($columns = array(), $order = null, $limit = null, $selColumn = array('*'), $joins = 0,$alterator = null) {
+    public static function loadAll($columns = array(), $order = null, $limit = null, $selColumn = array('*'), $joins = 0) {
         $class = get_called_class();
         $instance = new $class();
         $connector = $instance->connector;
@@ -478,7 +478,7 @@ class Entity {
         $sql = $connector::select();
         $sql = Entity::render($sql,$data);
 
-        return $instance->customQuery($sql, $values, true, $joins,$alterator);
+        return $instance->customQuery($sql, $values, true, $joins);
     }
 
 
@@ -858,7 +858,7 @@ class Entity {
         return $instance->customQuery($query, $data, $fill,$joins);
     }
 
-    public function customQuery($query, $data = array(), $fill = false,$joins = 0,$alterator =null) {
+    public function customQuery($query, $data = array(), $fill = false,$joins = 0) {
         $query = str_replace('{{table}}', $this->tableName(true,$this), $query);
         $mapping = $this->fieldMapping;
         $query = preg_replace_callback('/{{([^}]*)}}/si', function($match) use ($mapping){
@@ -900,9 +900,7 @@ class Entity {
             foreach ($queryReturn as $key => $value) {
                 if(!is_numeric($key)) $object->foreignColumns[$key] = $value;
             }
-            if(isset($alterator)){
-                $alterator($object);
-            }
+           
             $objects[] = $object;
             unset($object);
         }

+ 1 - 6
plugin/dashboard/DashboardWidget.class.php

@@ -69,12 +69,7 @@ class DashboardWidget extends Entity{
 		if(is_array($this->meta)) $this->meta = json_encode($this->meta);
 		parent::save();
 	}
-	public static function loadAll($columns = array(), $order = null, $limit = null, $selColumn = array('*'), $joins = 0,$alterator = null){
-		return parent::loadAll($columns, $order, $limit, $selColumn, $joins,function(&$item){
-			$item->meta = json_decode($item->meta,true);
-			if(!is_array($item->meta)) $item->meta = array();
-		});
-	}
+
 
 	public function toArray($decoded=false){
 		return array_merge(array(

+ 11 - 2
plugin/dashboard/action.php

@@ -151,9 +151,12 @@ Action::register('dashboard_widget_refresh',function(&$response){
 		if(!isset($model->content) || is_string($model->content) || !isset($widgets[$model->model]) ) continue;
 		
 		$method = $model->content;
-		foreach($widgets[$model->model] as $currentWidget)
+		foreach($widgets[$model->model] as $currentWidget){
+			$currentWidget->meta = json_decode($currentWidget->meta,true);
+			if(!is_array($currentWidget->meta)) $currentWidget->meta = array();
 			$method($currentWidget);
 			$response['rows'][] = $currentWidget;
+		}
 	}
 });
 
@@ -166,6 +169,9 @@ Action::register('dashboard_widget_configure',function(&$response){
 	if(empty($_['id'])) throw new Exception('Aucun identifiant renseigné');
 
 	$widget = DashboardWidget::getById($_['id'],1);
+	$widget->meta = json_decode($widget->meta,true);
+	if(!is_array($widget->meta)) $widget->meta = array();
+
 	if(!$widget) throw new Exception('Widget introuvable');
 
 	switch($_['type']){
@@ -200,11 +206,14 @@ Action::register('dashboard_widget_configure_form',function(&$response){
 
 	$widget = DashboardWidget::getById($_['id'],1);
 
-	if(!is_array($widget->meta)) $widget->meta = array();
+	
 	
 	if(!$widget) throw new Exception('Widget introuvable');
 	$model = DashboardWidget::model($widget->model);
 
+	$widget->meta = json_decode($widget->meta,true);
+	if(!is_array($widget->meta)) $widget->meta = array();
+
 	$configure = $model->configure;
 	$configure($widget);
 	exit();

+ 4 - 1
plugin/dashboard/dashboard.plugin.php

@@ -218,11 +218,13 @@ Plugin::addHook('widget',function(&$models){
 		$model->model = 'clock';
 		$model->css = array(__DIR__.'/css/widget-clock.css?v='.time());
 		$model->js = array(__DIR__.'/js/widget-clock.js?v='.time());
+		
 		$model->content = function(&$widget){
 			if(empty($widget->meta['hour-format'])) $widget->meta['hour-format'] = 'H:i:s';
 			$widget->content = '<div class="text-center m-auto widget-clock-content">'.date($widget->meta['hour-format']).'</div>';
 			$widget->label = 'Horloge '.date($widget->meta['hour-format']);
 		};
+
 		$model->configure = function($widget){
 			if(empty($widget->meta['hour-format'])) $widget->meta['hour-format'] = 'H:i:s';
 			?>
@@ -230,11 +232,12 @@ Plugin::addHook('widget',function(&$models){
 			<input class="form-control" type="text" id="hour-format" placeholder="H:i:s" value="<?php echo $widget->meta['hour-format']; ?>">
 			<?php
 		};
-		$model->save = function($widget,$form){
 
+		$model->save = function($widget,$form){
 			$widget->meta['hour-format'] = $form['hour-format'];
 			$widget->save();
 		};
+
 		$models[$model->model] = $model;
 });
 

+ 3 - 1
plugin/dashboard/js/component.js

@@ -166,7 +166,9 @@ function init_components_dashboard(input){
 		 						id :  widget.id,
 		 						meta : $('#dashboard-properties-form').toJson()
 			 				};
-			 				$.action(bundle);
+			 				$.action(bundle,function(){
+			 					$.message('success','sauvegardé');
+			 				});
 			 			});
 			 			
 			 		break;

+ 3 - 1
plugin/dashboard/page.list.dashboard.php

@@ -2,7 +2,6 @@
 global $myUser,$conf;
 if(!$myUser->can('dashboard','read')) return;
 require_once(__DIR__.SLASH.'Dashboard.class.php');
-require_once(__DIR__.SLASH.'DashboardWidget.class.php');
 
 if(Dashboard::rowCount(array('scope'=>'home','uid'=>$myUser->login))==0){
     $dashboard = new Dashboard();
@@ -11,6 +10,9 @@ if(Dashboard::rowCount(array('scope'=>'home','uid'=>$myUser->login))==0){
     $dashboard->save();
 }
 
+
+
+
 ?>
 <div class="plugin-dashboard">
     <div class="row">