Browse Source

Dashboard : wip

carruesco 1 year ago
parent
commit
36a413f5f8

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

@@ -119,16 +119,12 @@ class DashboardWidget extends Entity{
 
 	
 
-	public function getContent(&$widget){
-	
+	public function refresh(&$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){

+ 2 - 2
plugin/dashboard/action.php

@@ -20,7 +20,7 @@ Action::register('dashboard_widget_search',function(&$response){
 	$response['widgets'] = array();
 	foreach($widgets as $widget){
 		$model = DashboardWidget::model($widget->model);
-		$model->getContent($widget);
+		$model->refresh($widget);
 		$response['widgets'][] = $widget->toData();
 	}
 });
@@ -153,7 +153,7 @@ Action::register('dashboard_widget_refresh',function(&$response){
 		if(!isset($model->content) || is_string($model->content) || !isset($widgets[$model->model]) ) continue;
 	
 		foreach($widgets[$model->model] as $currentWidget){
-			$model->getContent($currentWidget);
+			$model->refresh($currentWidget);
 			$response['rows'][] = $currentWidget;
 		}
 	}

+ 116 - 19
plugin/navigation/navigation.plugin.php

@@ -250,28 +250,125 @@ Plugin::addHook("menu_user", function(&$userMenu){
 
 
 
-function navigation_widget(&$widgets){
-	global $myUser;
-	require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
-
-	$modelWidget = new DashboardWidget();
-	$modelWidget->model = 'menu';
-	$modelWidget->title = 'Menu';
-	$modelWidget->icon = 'far fa-compass';
-	$modelWidget->background = '#130f40';
-	$modelWidget->load = 'action.php?action=navigation_widget_load';
-	$modelWidget->js = [Plugin::url().'/js/widget.js?v=0'];
-	$modelWidget->css = [Plugin::url().'/css/widget.css?v=0'];
-	$modelWidget->configure = 'action.php?action=navigation_widget_configure';
-	$modelWidget->configure_callback = 'navigation_widget_configure_save';
-	$modelWidget->configure_init = 'navigation_widget_configure_init';
-	$modelWidget->description = "Affiche un menu sélectionné";
-	$widgets[] = $modelWidget;
-}
+// function navigation_widget(&$widgets){
+// 	global $myUser;
+// 	require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
+
+// 	$modelWidget = new DashboardWidget();
+// 	$modelWidget->model = 'menu';
+// 	$modelWidget->title = 'Menu';
+// 	$modelWidget->icon = 'far fa-compass';
+// 	$modelWidget->background = '#130f40';
+// 	$modelWidget->load = 'action.php?action=navigation_widget_load';
+// 	$modelWidget->js = [Plugin::url().'/js/widget.js?v=0'];
+// 	$modelWidget->css = [Plugin::url().'/css/widget.css?v=0'];
+// 	$modelWidget->configure = 'action.php?action=navigation_widget_configure';
+// 	$modelWidget->configure_callback = 'navigation_widget_configure_save';
+// 	$modelWidget->configure_init = 'navigation_widget_configure_init';
+// 	$modelWidget->description = "Affiche un menu sélectionné";
+// 	$widgets[] = $modelWidget;
+// }
+
+Plugin::addHook('widget',function(&$models){
+		
+		$model = new DashboardWidget();
+		$model->icon = 'far fa-compass';
+		$model->headerBackground = '#130f40';
+		$model->description = 'Affiche un menu sélectionné';
+		$model->label = 'Menu';
+		$model->width = 3;
+		$model->height = 3;
+		$model->model = 'menu';
+		$model->css = array(__DIR__.'/css/widget.css?v='.time());
+		$model->js = array(__DIR__.'/js/widget.js?v='.time());
+		
+		$model->content = function(&$widget){
+	
+
+			global $myUser;
+			User::check_access('navigation','read');
+			Plugin::need('dashboard/DashboardWidget');
+		
+
+			if(empty($widget->meta['label'])){
+				$widget->meta['label'] =  'Bloc Menu';
+			}else{
+				$widget->meta['label'] =  '';
+				$widget->meta['icon'] = '';
+			}
 
+			if(empty($widget->meta['url'])) $widget->meta['url'] = '';
+			ob_start();
+
+				$icon = empty($widget->meta['icon']) ? 'far fa-bookmark' : $widget->meta['icon'];
+				$color = empty($widget->meta['color'])? '#ffffff': $widget->meta['color'];
+
+				$url = navigation_meta_link($widget->meta['url']);
+				$label = navigation_meta_link($widget->meta['label']);
+
+				?>
+				<div style="background: <?php echo $color; ?>" class="widgetNavigationContainer">
+					<?php  if(!empty($widget->meta['label'])): ?>
+						<a href="<?php echo $url; ?>" <?php if(!empty($widget->meta['redirect'])) echo 'target="_blank"'; ?> >
+							<i class="<?php echo $icon; ?>"></i>
+							<?php echo $label; ?>
+						</a>
+					<?php else: ?>
+						<h4 class="noContent"><i class="far fa-compass"></i> Aucun menu spécifié</h4>
+					<?php endif; ?>
+
+				</div>
+			<?php
+
+			$widget->content = ob_get_clean();
+		};
+
+		$model->configure = function($widget){
+			if(empty($widget->meta['label'])) $widget->meta['label'] =  'Bloc Menu';
+			if(empty($widget->meta['url'])) $widget->meta['url'] = '';
+			?>
+			<div id="navigation-widget-form">
+			<label for="">Icone / Titre / Couleur :</label>
+			<div class="input-group mb-2">
+				<input class="form-control" type="text" data-type="icon" value="<?php echo empty($widget->meta['icon'])?'far fa-bookmark':$widget->meta['icon'];  ?>" id="widget-icon">
+				<input class="form-control" type="text" value="<?php echo $widget->meta['label']; ?>" id="widget-label">
+				<input class="form-control" type="text" data-type="color" value="<?php echo empty($widget->meta['color'])?'#000000':$widget->meta['color']; ?>" id="widget-color">
+			</div>
+			<label for="">Adresse URL :</label>
+			<div class="input-group mb-2">
+				<div class="input-group-prepend">
+					<div class="input-group-text">
+						<label for="widget-redirect" class="pointer mb-0">Redirection</label>
+				    	<input data-type="checkbox" name="widget-redirect" id="widget-redirect" <?php echo $widget->meta['redirect'] ? 'checked' : ''; ?>>
+				    </div>
+				</div>
+				<input class="form-control text-success" type="text" value="<?php echo $widget->meta['url']; ?>" id="widget-url">
+				<div class="input-group-append">
+					<a href="<?php echo $widget->meta['url']; ?>" target="_blank" class="text-success text-decoration-none input-group-text"><i class="fas fa-globe"></i></a>
+				</div>
+			</div>
+		</div>
+			<?php
+		};
+
+		$model->save = function($widget,$form){
+
+			$url =  str_replace(ROOT_URL.'/','',$form['widget-url']);
+			$widget->meta['url'] = $url;
+			$widget->meta['redirect'] = $form['widget-redirect'];
+			$widget->meta['icon'] = $form['widget-icon'];
+			$widget->meta['label'] = $form['widget-label'];
+			$widget->meta['color'] = $form['widget-color'];
+
+
+			$widget->save();
+		};
+
+		$models[$model->model] = $model;
+});
 
 //Mapping hook / fonctions
-Plugin::addHook("widget", "navigation_widget");
+//Plugin::addHook("widget", "navigation_widget");
 Plugin::addHook("install", "navigation_install");
 Plugin::addHook("uninstall", "navigation_uninstall");
 

+ 0 - 21
plugin/navigation/widget.configure.php

@@ -1,21 +0,0 @@
-<div id="navigation-widget-form">
-	<label for="">Icone / Titre / Couleur :</label>
-	<div class="input-group mb-2">
-		<input class="form-control" type="text" data-type="icon" value="<?php echo empty($widget->data('icon'))?'far fa-bookmark':$widget->data('icon');  ?>" id="widget-icon">
-		<input class="form-control" type="text" value="<?php echo $widget->data('title'); ?>" id="widget-title">
-		<input class="form-control" type="text" data-type="color" value="<?php echo empty($widget->data('color'))?'#000000':$widget->data('color'); ?>" id="widget-color">
-	</div>
-	<label for="">Adresse URL :</label>
-	<div class="input-group mb-2">
-		<div class="input-group-prepend">
-			<div class="input-group-text">
-				<label for="widget-redirect" class="pointer mb-0">Redirection</label>
-		    	<input data-type="checkbox" name="widget-redirect" id="widget-redirect" <?php echo $widget->data('redirect') ? 'checked' : ''; ?>>
-		    </div>
-		</div>
-		<input class="form-control text-success" type="text" value="<?php echo $widget->data('url'); ?>" id="widget-url">
-		<div class="input-group-append">
-			<a href="<?php echo $widget->data('url'); ?>" target="_blank" class="text-success text-decoration-none input-group-text"><i class="fas fa-globe"></i></a>
-		</div>
-	</div>
-</div>

+ 0 - 21
plugin/navigation/widget.php

@@ -1,21 +0,0 @@
-<?php
-global $myUser;
-
-$icon = empty($widget->data('icon')) ? 'far fa-bookmark' : $widget->data('icon');
-$color = empty($widget->data('color'))? '#ffffff': $widget->data('color');
-
-$url = navigation_meta_link($widget->data('url'));
-$title = navigation_meta_link($widget->data('title'));
-
-?>
-<div style="background: <?php echo $color; ?>" class="widgetNavigationContainer">
-	<?php  if(!empty($widget->data('title'))): ?>
-		<a href="<?php echo $url; ?>" <?php if(!empty($widget->data('redirect'))) echo 'target="_blank"'; ?> >
-			<i class="<?php echo $icon; ?>"></i>
-			<?php echo $title; ?>
-		</a>
-	<?php else: ?>
-		<h4 class="noContent"><i class="far fa-compass"></i> Aucun menu spécifié</h4>
-	<?php endif; ?>
-
-</div>