dashboard.plugin.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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-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">
  84. <div class="row">
  85. <div class="col-md-4">
  86. <ul class="list-group rounded-0 dashboard-configure-menu" id="dashboard-configure-menu">
  87. <li data-menu='type' class="list-group-item border-top-0 active"><i class="far fa-window-maximize text-muted"></i> Type</li>
  88. <li data-menu='properties' class="list-group-item"><i class="fas fa-list-ul text-muted"></i> Propriétés</li>
  89. <li data-menu='style' class="list-group-item border-bottom-0"><i class="fas fa-palette text-muted"></i> Style</li>
  90. </ul>
  91. </div>
  92. <div class="col-md-8">
  93. <ul id="widget-types" class="widget-types bg-light">
  94. <li data-id="{{id}}" class="shadow-sm bg-white">
  95. <h3><i class="{{icon}}"></i> {{label}}</h3>
  96. <p>{{description}}</p>
  97. <a>+ D'infos</a>
  98. <div class="btn btn-primary">Selectionner</div>
  99. </li>
  100. </ul>
  101. </div>
  102. </div>
  103. </div>
  104. <div class="modal-footer">
  105. <button type="button" class="btn btn-primary">Enregistrer</button>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. <?php
  111. }
  112. //Déclation des assets
  113. Plugin::addCss("/css/main.css");
  114. Plugin::addCss("/css/component.css");
  115. Plugin::addJs("/js/main.js");
  116. Plugin::addJs("/js/dashboard.js");
  117. Plugin::addJs("/js/component.js");
  118. //Mapping hook / fonctions
  119. Plugin::addHook("install", "dashboard_install");
  120. Plugin::addHook("uninstall", "dashboard_uninstall");
  121. Plugin::addHook("menu_main", "dashboard_menu");
  122. Plugin::addHook("page", "dashboard_page");
  123. Plugin::addHook("menu_setting", "dashboard_menu_setting");
  124. Plugin::addHook("content_setting", "dashboard_content_setting");
  125. Plugin::addHook("application_bottom", "dashboard_application_bottom");