Explorar o código

added custom colours file to read custom colours from

sirjeff hai 4 semanas
pai
achega
3c54284109
Modificáronse 5 ficheiros con 136 adicións e 67 borrados
  1. 37 0
      Model/CustomColorModel.php
  2. 43 14
      Plugin.php
  3. 6 1
      README.md
  4. 42 45
      Template/header.php
  5. 8 7
      Template/project_branding/show.php

+ 37 - 0
Model/CustomColorModel.php

@@ -0,0 +1,37 @@
+<?php namespace Kanboard\Plugin\OMIProjectBranding\Model;
+
+use Kanboard\Model\ColorModel;
+
+class CustomColorModel extends ColorModel {
+  /**
+  * CustomColorModel Model
+  * Get all available colors.
+  *
+  * @access public
+  * @param bool $prepend
+  * @return array
+  * @author   Dwayne @ OMI NZ
+  */
+  public function getList($prepend = false) {
+    $colors = parent::getList($prepend);
+    $colorFile = DATA_DIR . DIRECTORY_SEPARATOR . "OMIProjectBrandingColours.txt";// Define the path to your color file
+    if (! file_exists($colorFile)) {// Check if the file exists, if not create it
+      $defaultContent = "Aqua=aqua\nBeige=beige\nBlack=black\nDark Blue=darkblue\nFuchsia=fuchsia\nGray=gray\nIndigo=indigo\nMaroon=maroon\nNavy=navy\nOlive=olive\nSlategrey=slategrey\nWhite=white\nWhitesmoke=whitesmoke";
+      file_put_contents($colorFile, $defaultContent);
+    }
+    $handle = fopen($colorFile, "r");// read from $colorFile
+    if ($handle) {
+      while (($line = fgets($handle)) !== false) {
+        $line = trim($line);
+        if (!empty($line)) {
+          list($name, $colorCode) = explode("=", $line, 2);// Split the line into name and color code
+          $colors[trim($colorCode)] = t(trim($name));// Add the color to the list
+        }
+      }
+      fclose($handle);
+    }
+    return $colors;
+  }
+}
+#-
+#plugins/OMIProjectBranding/Model/CustomColorModel.php

+ 43 - 14
Plugin.php

@@ -2,6 +2,7 @@
 
 use Kanboard\Core\Plugin\Base;
 use Kanboard\Core\Translator;
+use Kanboard\Plugin\OMIProjectBranding\Listener\ColorListExtender;
 
 /**
  * Plugin Initialisation
@@ -15,21 +16,49 @@ class Plugin extends Base {
     $this->hook->on("template:project:sidebar", ["template" => "OMIProjectBranding:project/sidebar"]);
     $this->route->addRoute("project/:project_id/branding", "ProjectBrandingController", "show", "OMIProjectBranding");
     $this->template->setTemplateOverride("header", "OMIProjectBranding:header");
+    
+        $this->container['colorModel'] = $this->container->factory(function ($c) {
+            return new \Kanboard\Plugin\OMIProjectBranding\Model\CustomColorModel($c);
+        });
   }
-  
-  public function getClasses() {
-    return [
-      "Plugin\OMIProjectBranding\Controller" => [
-        "ProjectBrandingController",
-      ],
-      "Plugin\OMIProjectBranding\Model" => [
-        "ProjectBrandingModel",
-      ],
-      "Plugin\OMIProjectBranding\Helper" => [
-        "ProjectBrandingHelper",
-      ],
-    ];
-  }
+    
+  public function onColorList(Event $event)
+    {
+        $colors = $event->get('colors');
+        
+        $colors['brand_color_1'] = [
+            'name' => 'Client Primary',
+            'background' => '#1A2B3C',
+            'border' => '#0F1A2B',
+        ];
+        
+        $colors['brand_color_2'] = [
+            'name' => 'Client Secondary',
+            'background' => '#D9E3F1',
+            'border' => '#C4D1E5',
+        ];
+        
+        $event->set('colors', $colors);
+    }
+
+ public function getClasses()
+    {
+        return [
+
+            
+
+            'Plugin\OMIProjectBranding\Controller' => [
+                'ProjectBrandingController',
+            ],
+'Plugin\OMIProjectBranding\Model' => [
+                'ProjectBrandingModel',
+                'CustomColorModel',
+            ],
+            'Plugin\OMIProjectBranding\Helper' => [
+                'ProjectBrandingHelper',
+            ],
+        ];
+    }
   
   public function getPluginName() {
     return "OMI Project Branding";

+ 6 - 1
README.md

@@ -72,7 +72,12 @@ Still WiP so check back later :)
 
 ## Compatibility 
 Compatibility with other Plugins.  
-So far I know it works with Customizer, but it will override the global logo ( which is the point of this plugin ).  
+So far I've used it successfully with Customizer, and WeKanboard.  
+It will override the global logo ( which is the point of this plugin ) in the header when you're in a project.  
+
+Please let me know if there are any issues with the header styles, when using other plugins.  
+[You can add issues here.](/ominz/OMIProjectBranding/issues)  
+
 
 ## Maintainers
 

+ 42 - 45
Template/header.php

@@ -21,59 +21,56 @@ if (isset($project) && isset($project["id"])) {
 
 <?php if (isset($branding["enabled"]) && $branding["enabled"] == 1 && !empty($branding["logo_url"])): ?>
 <style>
-header{
-background-color:<?= $branding['background_color'] ?>;
-}
-.project-header{
- background-color:<?= $branding['second_background_color'] ?>;
-}
-h1 {
- color:<?= $branding['foreground_color'] ?>;
- background-color:<?= $branding['background_color'] ?>;
-}
-span.logo a{
-vertical-align: middle;
-margin-right:5px;
-opacity:1;
-}
+  .page {
+    margin:0 auto;
+  }
+  header{
+    background-color:<?= !empty($branding["background_color"]) ? $branding["background_color"] : "transparent" ?> !important;
+    margin-bottom:0;
+  }
+  .project-header{
+    background-color:<?= !empty($branding["second_background_color"]) ? $branding["second_background_color"] : "transparent" ?>;
+    padding:.5em;
+    height: 1.5em;
+  }
+  h1 {
+    color:<?= !empty($branding["foreground_color"]) ? $branding["foreground_color"] : "initial" ?>;
+    background-color:<?= !empty($branding["background_color"]) ? $branding["background_color"] : "transparent" ?>;
+  }
+  span.logo a{
+    vertical-align: middle;
+    margin-right:5px;
+    opacity:1;
+  }
 </style>
 <?php endif ?>
 
-
 <header>
   <div class="title-container">
-
-  
-  
-<h1>
-    <span class="logo">
-    <?php if (isset($branding["enabled"]) && $branding["enabled"] == 1 && !empty($branding["logo_url"])): ?>
-
+    <h1>
+      <span class="logo">
+      <?php if (isset($branding["enabled"]) && $branding["enabled"] == 1 && !empty($branding["logo_url"])): ?>
       <a href="<?= $this->url->to('DashboardController', 'show') ?>">
         <img src="<?= $branding['logo_url'] ?>" alt="<?= t('Logo') ?>" height="32">
-      </a>
-          
-    <?php else: ?>
-      <?= $this->url->link('K<span>B</span>', 'DashboardController', 'show', array(), false, '', t('Dashboard')) ?>
-    <?php endif ?>
-    </span>
-    <span class="title">
-        <?php if (! empty($project) && ! empty($task)): ?>
-            <?= $this->url->link($this->text->e($project['name']), 'BoardViewController', 'show', array('project_id' => $project['id'])) ?>
-        <?php else: ?>
-            <?= $this->text->e($title) ?>
-            <?php if (! empty($project) && $project['task_limit'] && array_key_exists('nb_active_tasks', $project)): ?>
-              (<span><?= intval($project['nb_active_tasks']) ?></span> / <span title="<?= t('Task limit') ?>"><span class="ui-helper-hidden-accessible"><?= t('Task limit') ?> </span><?= $this->text->e($project['task_limit']) ?></span>)
-            <?php endif ?>
-        <?php endif ?>
-    </span>
-    <?php if (! empty($description)): ?>
+      </a>          
+      <?php else: ?>
+        <?= $this->url->link("K<span>B</span>", "DashboardController", "show", [], false, "", t("Dashboard")) ?>
+      <?php endif ?>
+      </span>
+      <span class="title">
+      <?php if (! empty($project) && ! empty($task)): ?>
+          <?= $this->url->link($this->text->e($project["name"]), "BoardViewController", "show", ["project_id" => $project["id"]]) ?>
+      <?php else: ?>
+          <?= $this->text->e($title) ?>
+          <?php if (! empty($project) && $project["task_limit"] && array_key_exists("nb_active_tasks", $project)): ?>
+            (<span><?= intval($project["nb_active_tasks"]) ?></span> / <span title="<?= t('Task limit') ?>"><span class="ui-helper-hidden-accessible"><?= t("Task limit") ?> </span><?= $this->text->e($project["task_limit"]) ?></span>)
+          <?php endif ?>
+      <?php endif ?>
+      </span>
+      <?php if (! empty($description)): ?>
         <?= $this->app->tooltipHTML($description) ?>
-    <?php endif ?>
-</h1>
-
-
-
+      <?php endif ?>
+    </h1>
   </div>
   <div class="board-selector-container">
     <?php if (! empty($board_selector)): ?>

+ 8 - 7
Template/project_branding/show.php

@@ -5,9 +5,9 @@
 <form method="post" action="<?= $this->url->to('ProjectBrandingController', 'show', ['project_id' => $project['id'], 'plugin' => 'OMIProjectBranding']) ?>" autocomplete="off">
   <?= $this->form->csrf() ?>
   
-  <div class="form-help">
-    <?= t("Configure the logo and primary color for this project.") ?>
-  </div>
+  <p>
+    <?= t("Configure the header logo and colours for this project.") ?>
+  </p>
   
   <?= $this->form->label(t("Enable custom branding"), "enabled") ?>
   <?= $this->form->checkbox("enabled", "", 1, $branding["enabled"] ?? 0) ?>
@@ -16,13 +16,14 @@
   <?= $this->form->text("logo_url", $branding, [], ['placeholder="https://example.com/logo.png"']) ?>
   
   <?= $this->form->label(t("Foreground Color"), "foreground_color") ?>
-  <?= $this->form->text("foreground_color", $branding, [], ['type="color"']) ?>
+  <?= $this->form->colorSelect("foreground_color", $branding) ?>
 
+    
   <?= $this->form->label(t("Background Color"), "background_color") ?>
-  <?= $this->form->text("background_color", $branding, [], ['type="color"']) ?>
-  
+  <?= $this->form->colorSelect("background_color", $branding) ?>
+
   <?= $this->form->label(t("Secondary Background Color"), "second_background_color") ?>
-  <?= $this->form->text("second_background_color", $branding, [], ['type="color"']) ?>
+  <?= $this->form->colorSelect("second_background_color", $branding) ?>
   
   <div class="form-actions">
     <button type="submit" class="btn btn-blue"><?= t("Save") ?></button>