dashboard.plugin.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. //Déclaration d'un item de menu dans le menu principal
  3. function dashboard_menu(&$menuItems){
  4. global $myUser;
  5. if(!$myUser->can('dashboard','read')) return;
  6. $menuItems[] = array(
  7. 'sort'=>3,
  8. 'url'=>'index.php?module=dashboard',
  9. 'label'=>'Dashboard',
  10. 'icon'=> 'far fa-object-ungroup',
  11. 'color'=> '#273c75'
  12. );
  13. }
  14. //Cette fonction va générer une page quand on clique sur Dashboard dans menu
  15. function dashboard_page(){
  16. global $_, $myUser;
  17. if(isset($_['module'])) return;
  18. $page = !isset($_['page']) ? 'list.dashboard' : $_['page'];
  19. $page = str_replace('..','',$page);
  20. $file = __DIR__.SLASH.'page.'.$page.'.php';
  21. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  22. require_once($file);
  23. }
  24. //Fonction executée lors de l'activation du plugin
  25. function dashboard_install($id){
  26. if($id != 'fr.core.dashboard') return;
  27. Entity::install(__DIR__);
  28. }
  29. //Fonction executée lors de la désactivation du plugin
  30. function dashboard_uninstall($id){
  31. if($id != 'fr.core.dashboard') return;
  32. Entity::uninstall(__DIR__);
  33. }
  34. //Déclaration des sections de droits du plugin
  35. Right::register('dashboard',array('label'=>'Gestion des droits sur le plugin Dashboard'));
  36. //Déclaration du menu de réglages
  37. function dashboard_menu_setting(&$settingMenu){
  38. global $myUser;
  39. if(!$myUser->can('dashboard','configure')) return;
  40. $settingMenu[]= array(
  41. 'sort' =>1,
  42. 'url' => 'setting.php?section=global.dashboard',
  43. 'icon' => 'fas fa-angle-right',
  44. 'label' => 'Dashboard'
  45. );
  46. }
  47. //Déclaration des pages de réglages
  48. function dashboard_content_setting(){
  49. global $_;
  50. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  51. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  52. }
  53. require_once(__DIR__.SLASH.'action.php');
  54. //Déclaration des settings de base
  55. //Types possibles : voir FieldType.class.php. Un simple string définit une catégorie.
  56. Configuration::setting('dashboard',array(
  57. "Général",
  58. //'dashboard_enable' => array("label"=>"Activer","type"=>"boolean"),
  59. ));
  60. function dashboard_application_bottom(){
  61. ?>
  62. <template id="dashboard-widget-template">
  63. <div class="dashboard-widget" data-id="{{id}}" data-width="{{width}}" data-height="{{height}}">
  64. <div class="dashboard-widget-header">
  65. <div class="widget-header-icon"><i class="fas fa-question"></i></div>
  66. <div class="widget-header-title">{{label}}</div>
  67. <ul class="widget-header-options"></ul>
  68. </div>
  69. <div class="dashboard-widget-content"></div>
  70. <div class="dashboard-widget-resize py-1 px-2"><i class="fas fa-chevron-right"></i></div>
  71. </div>
  72. </template>
  73. <!-- Modal Dashboard -->
  74. <div class="modal fade dashboard-modal" id="dashboard-modal" tabindex="-1" role="dialog" aria-hidden="true">
  75. <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
  76. <div class="modal-content">
  77. <div class="modal-header">
  78. <h5 class="modal-title" id="exampleModalLabel">Configuration</h5>
  79. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  80. <span aria-hidden="true">&times;</span>
  81. </button>
  82. </div>
  83. <div class="modal-body p-0 overflow-hidden">
  84. <div class="container-fluid py-0 h-100">
  85. <div class="row h-100">
  86. <div class="col-md-3 border-right px-0 overflow-auto h-100 dashboard-configure-menu" id="dashboard-configure-menu">
  87. <ul class="nav nav-tabs flex-column dashboard-configure-menu rounded-0 border-0" id="dashboard-configure-menu" role="tablist" aria-orientation="vertical">
  88. <li data-menu='model' class="nav-item border-bottom">
  89. <a class="nav-link border-0 rounded-0 active" id="model-tab" data-toggle="tab" role="tab" aria-controls="model" aria-selected="true">
  90. <i class="far fa-window-maximize mr-1"></i>Modèle
  91. </a>
  92. </li>
  93. <li data-menu='properties' class="nav-item border-bottom">
  94. <a class="nav-link border-0 rounded-0" id="properties-tab" data-toggle="tab" role="tab" aria-controls="properties" aria-selected="false">
  95. <i class="fas fa-list-ul mr-1"></i>Propriétés
  96. </a>
  97. </li>
  98. <li data-menu='style' class="nav-item border-bottom">
  99. <a class="nav-link border-0 rounded-0" id="style-tab" data-toggle="tab" role="tab" aria-controls="style" aria-selected="false">
  100. <i class="fas fa-palette mr-1"></i>Style
  101. </a>
  102. </li>
  103. </ul>
  104. </div>
  105. <template id="configure-model">
  106. <ul id="widget-models" class="widget-models bg-light">
  107. <li data-model="{{model}}" class="shadow-sm bg-white hidden">
  108. <h3><div class="widget-model-chip" style="background-color: {{headerBackground
  109. }};color: {{iconColor}}"><i class="{{icon}}"></i></div> {{label}}</h3>
  110. <p>{{excerpt}}</p>
  111. <i onclick="event.stopPropagation();$(this).parent().find('.long-description').toggleClass('hidden')" title="plus d'information sur le widget" class="fas fa-info-circle widget-model-info"></i>
  112. <hr/>
  113. <div class="hidden long-description text-muted">{{description}}<br>
  114. Créé par <i class="fas fa-user"></i> {{creator}} le <i>{{created}}</i>
  115. </div>
  116. <div class="checked"><i class="fas fa-check"></i></div>
  117. </li>
  118. </ul>
  119. </template>
  120. <template id="properties-model">
  121. <div class="p-3">
  122. <h3>Propriétés</h3>
  123. <div id="dashboard-properties-form"></div>
  124. <div class="btn btn-primary mt-1" id="dashboard-properties-save">Enregistrer</div>
  125. </div>
  126. </template>
  127. <template id="configure-style">
  128. <div class="row">
  129. <div class="col">
  130. <table class="table" id="configure-style-table">
  131. <tbody>
  132. <tr>
  133. <th colspan="2" class="align-middle">En-tête</th>
  134. </tr>
  135. <tr>
  136. <td><input type="text" data-type="icon" id="widget-header-icon"></td>
  137. <td class="align-middle">Icône</td>
  138. </tr>
  139. <tr>
  140. <td><input type="text" data-type="color" id="widget-header-icon-color"></td>
  141. <td class="align-middle">Couleur Icône</td>
  142. </tr>
  143. <tr>
  144. <td><input type="text" data-type="color" id="widget-header-title-color"></td>
  145. <td class="align-middle">Couleur titre</td>
  146. </tr>
  147. <tr>
  148. <td><input type="text" data-type="color" id="widget-header-background"></td>
  149. <td class="align-middle">Couleur de fond</td>
  150. </tr>
  151. <tr>
  152. <th colspan="2" class="align-middle">Corps</th>
  153. </tr>
  154. <tr>
  155. <td><input type="text" data-type="color" id="widget-body-background"></td>
  156. <td class="align-middle">Couleur de fond</td>
  157. </tr>
  158. <tr>
  159. <td><input type="text" data-type="color" id="widget-body-color"></td>
  160. <td class="align-middle">Couleur texte</td>
  161. </tr>
  162. </tbody>
  163. </table>
  164. </div>
  165. <div class="col dashboard-container">
  166. <!-- -->
  167. <div class="dashboard-widget dashboard-widget-customizer widget-draggable widget-resizeable widget-removable ui-draggable">
  168. <div class="dashboard-widget-header" style="background-color: rgb(0, 123, 255);">
  169. <div class="widget-header-icon ui-draggable-handle"><i class="far fa-user"></i></div>
  170. <div class="widget-header-title ui-draggable-handle">Titre</div>
  171. <ul class="widget-header-options"><li class="widget-option-configure" title="Configurer"><i class="fas fa-ellipsis-v"></i></li><li class="widget-option-delete" title="Supprimer"><i class="fa fa-times"></i></li></ul>
  172. </div>
  173. <div class="dashboard-widget-content"><div class="text-center m-auto">Contenu</div></div>
  174. <div class="dashboard-widget-resize py-1 px-2"><i class="fas fa-chevron-right"></i></div>
  175. </div>
  176. <!-- -->
  177. </div>
  178. </div>
  179. </template>
  180. <div class="col-md-9 px-0 overflow-auto h-100 dashboard-configure-content" id="dashboard-configure-content">
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. <div class="modal-footer">
  186. <button type="button" class="btn" data-dismiss="modal">Fermer</button>
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. <?php
  192. }
  193. Plugin::addHook('widget',function(&$models){
  194. $model = new DashboardWidget();
  195. $model->icon = 'far fa-user';
  196. $model->headerBackground = 'rgb(0, 123, 255)';
  197. $model->description = 'Une Horloge toute couillone';
  198. $model->label = 'Horloge';
  199. $model->width = 3;
  200. $model->height = 3;
  201. $model->model = 'clock';
  202. $model->css = array(__DIR__.'/css/widget-clock.css?v='.time());
  203. $model->js = array(__DIR__.'/js/widget-clock.js?v='.time());
  204. $model->live = true;
  205. $model->content = function(&$widget){
  206. if(empty($widget->meta['hour-format'])) $widget->meta['hour-format'] = 'H:i:s';
  207. $widget->content = '<div class="text-center m-auto widget-clock-content">'.date($widget->meta['hour-format']).'</div>';
  208. $widget->label = 'Horloge '.date($widget->meta['hour-format']);
  209. };
  210. $model->configure = function($widget){
  211. if(empty($widget->meta['hour-format'])) $widget->meta['hour-format'] = 'H:i:s';
  212. ?>
  213. <label>Format de l'heure : </label>
  214. <input class="form-control" type="text" id="hour-format" placeholder="H:i:s" value="<?php echo $widget->meta['hour-format']; ?>">
  215. <?php
  216. };
  217. $model->save = function($widget,$form){
  218. $widget->meta['hour-format'] = $form['hour-format'];
  219. $widget->save();
  220. };
  221. $models[$model->model] = $model;
  222. });
  223. //Déclation des assets
  224. Plugin::addCss("/css/main.css");
  225. Plugin::addCss("/css/component.css?v=2");
  226. Plugin::addJs("/js/main.js");
  227. Plugin::addJs("/js/dashboard.js?v=2");
  228. Plugin::addJs("/js/component.js?v=2");
  229. //Mapping hook / fonctions
  230. Plugin::addHook("install", "dashboard_install");
  231. Plugin::addHook("uninstall", "dashboard_uninstall");
  232. Plugin::addHook("menu_main", "dashboard_menu");
  233. Plugin::addHook("page", "dashboard_page");
  234. Plugin::addHook("menu_setting", "dashboard_menu_setting");
  235. Plugin::addHook("content_setting", "dashboard_content_setting");
  236. Plugin::addHook("application_bottom", "dashboard_application_bottom");