dashboard.plugin.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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" href="#model" 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" href="#properties" 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" href="#style" 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><i class="{{icon}}"></i> {{label}}</h3>
  109. <p>{{description}}</p>
  110. <i onclick="e.stopPropagation();$(this).next().toggleClass('hidden')" title="plus d'information sur le widget" class="fas fa-info-circle widget-model-info"></i>
  111. <div class="hidden text-muted">{{description}}</div>
  112. </li>
  113. </ul>
  114. </template>
  115. <template id="configure-style">
  116. <div class="row">
  117. <div class="col">
  118. <table class="table" id="configure-style-table">
  119. <tbody>
  120. <tr>
  121. <th colspan="2" class="align-middle">En-tête</th>
  122. </tr>
  123. <tr>
  124. <td><input type="text" data-type="icon" id="widget-header-icon"></td>
  125. <td class="align-middle">Icône</td>
  126. </tr>
  127. <tr>
  128. <td><input type="text" data-type="color" id="widget-header-icon-color"></td>
  129. <td class="align-middle">Couleur Icône</td>
  130. </tr>
  131. <tr>
  132. <td><input type="text" data-type="color" id="widget-header-title-color"></td>
  133. <td class="align-middle">Couleur titre</td>
  134. </tr>
  135. <tr>
  136. <td><input type="text" data-type="color" id="widget-header-background"></td>
  137. <td class="align-middle">Couleur de fond</td>
  138. </tr>
  139. <tr>
  140. <th colspan="2" class="align-middle">Corps</th>
  141. </tr>
  142. <tr>
  143. <td><input type="text" data-type="color" id="widget-body-background"></td>
  144. <td class="align-middle">Couleur de fond</td>
  145. </tr>
  146. <tr>
  147. <td><input type="text" data-type="color" id="widget-body-color"></td>
  148. <td class="align-middle">Couleur texte</td>
  149. </tr>
  150. </tbody>
  151. </table>
  152. </div>
  153. <div class="col dashboard-container">
  154. <!-- -->
  155. <div class="dashboard-widget dashboard-widget-customizer widget-draggable widget-resizeable widget-removable ui-draggable">
  156. <div class="dashboard-widget-header" style="background-color: rgb(0, 123, 255);">
  157. <div class="widget-header-icon ui-draggable-handle"><i class="far fa-user"></i></div>
  158. <div class="widget-header-title ui-draggable-handle">Titre</div>
  159. <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>
  160. </div>
  161. <div class="dashboard-widget-content"><div class="text-center m-auto">Contenu</div></div>
  162. <div class="dashboard-widget-resize py-1 px-2"><i class="fas fa-chevron-right"></i></div>
  163. </div>
  164. <!-- -->
  165. </div>
  166. </div>
  167. </template>
  168. <div class="col-md-9 px-0 overflow-auto h-100 dashboard-configure-content" id="dashboard-configure-content">
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. <div class="modal-footer">
  174. <button type="button" class="btn">Fermer</button>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. <?php
  180. }
  181. //Déclation des assets
  182. Plugin::addCss("/css/main.css");
  183. Plugin::addCss("/css/component.css");
  184. Plugin::addJs("/js/main.js");
  185. Plugin::addJs("/js/dashboard.js");
  186. Plugin::addJs("/js/component.js");
  187. //Mapping hook / fonctions
  188. Plugin::addHook("install", "dashboard_install");
  189. Plugin::addHook("uninstall", "dashboard_uninstall");
  190. Plugin::addHook("menu_main", "dashboard_menu");
  191. Plugin::addHook("page", "dashboard_page");
  192. Plugin::addHook("menu_setting", "dashboard_menu_setting");
  193. Plugin::addHook("content_setting", "dashboard_content_setting");
  194. Plugin::addHook("application_bottom", "dashboard_application_bottom");