Skip to content

Commit

Permalink
feat(form): customize icon
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Aug 22, 2019
1 parent 1d14ad9 commit 7635f0e
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 9 deletions.
57 changes: 57 additions & 0 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ public function archiveBuild($release = 'release') {
}
}

$this->createFontAwesomeList();
$this->taskGitStack()
->stopOnFail()
->add('data/font-awesome.php')
->commit('docs(changelog): update changelog')
->run();

// update version in package.json
$this->sourceUpdatePackageJson($version);

Expand Down Expand Up @@ -176,6 +183,7 @@ public function archiveBuild($release = 'release') {
->commit('docs(locales): update translations')
->run();


$rev = 'HEAD';
$pluginName = $this->getPluginName();
$pluginPath = $this->getProjectPath();
Expand Down Expand Up @@ -566,4 +574,53 @@ protected function getFileFromGit($path, $rev) {
}
return $output;
}

protected function createFontAwesomeList() {
$versions = [
[
[
'fa' => 'https://raw.githubusercontent.com/glpi-project/glpi/9.3.4/lib/font-awesome-4.7.0/css/font-awesome.css',
], // GLPI 9.3
'font-awesome_9.3.php',
],
[
[
'fa' => 'https://raw.githubusercontent.com/glpi-project/glpi/9.4.2/lib/font-awesome/webfonts/fa-regular-400.svg',
'fab' => 'https://raw.githubusercontent.com/glpi-project/glpi/9.4.2/lib/font-awesome/webfonts/fa-brands-400.svg',
'fas' => 'https://raw.githubusercontent.com/glpi-project/glpi/9.4.2/lib/font-awesome/webfonts/fa-solid-900.svg',
],
'font-awesome_9.4.php',
],
/* In GLPI 9.5 Font Awesome is a node dependency
[
[
'fa' => 'https://raw.githubusercontent.com/glpi-project/glpi/9.4.2/lib/font-awesome/webfonts/fa-regular-400.svg',
'fab' => 'https://raw.githubusercontent.com/glpi-project/glpi/9.4.2/lib/font-awesome/webfonts/fa-brands-400.svg',
'fas' => 'https://raw.githubusercontent.com/glpi-project/glpi/9.4.2/lib/font-awesome/webfonts/fa-solid-900.svg',
],
'font-awesome_9.5.php',
],
*/
];

foreach ($versions as $version) {
$fanames = [];
$searchRegex = '#glyph-name=\"([^\"]*)\"#i';
foreach ($version[0] as $key => $svgSource) {
$svg = file_get_contents($svgSource);
$matches = null;
preg_match_all($searchRegex, $svg, $matches);
foreach ($matches[1] as $name) {
$fanames["$key fa-$name"] = $name;
}

$list = '<?php' . PHP_EOL . 'return ' . var_export($fanames, true) . ';';
$outFile = __DIR__ . '/data/' . $version[1];
$size = file_put_contents($outFile, $list);
if ($size != strlen($list)) {
throw new RuntimeException('Failed to build the list of font awesome pictograms');
}
}
}
}
}
14 changes: 7 additions & 7 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -827,20 +827,20 @@ form.formcreator_form {
a.plugin_formcreator_formTile_title {
font-size: 1.1em;
padding: 10px 40px 15px 10px;
height: 33px;
line-height: 33px;
display: block;
background: transparent no-repeat top 10px right 10px;
}

.plugin_formcreator_formTile:hover a.plugin_formcreator_formTile_title {
cursor: pointer;
}

.plugin_formcreator_formTile.form a.plugin_formcreator_formTile_title {
background-image: url(../pics/form.png);
}

.plugin_formcreator_formTile.faq a.plugin_formcreator_formTile_title {
background-image: url(../pics/faq.png);
.plugin_formcreator_formTile i.fa, .plugin_formcreator_formTile i.fab, .plugin_formcreator_formTile i.fas {
font-size: 2.5em;
margin-right: 10px;
float: left;
margin: 10px;
}

.plugin_formcreator_formTile_description {
Expand Down
32 changes: 32 additions & 0 deletions data/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* ---------------------------------------------------------------------
* Formcreator is a plugin which allows creation of custom forms of
* easy access.
* ---------------------------------------------------------------------
* LICENSE
*
* This file is part of Formcreator.
*
* Formcreator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Formcreator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Formcreator. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
* @author Thierry Bugier
* @author Jérémy Moreau
* @copyright Copyright © 2011 - 2019 Teclib'
* @license http://www.gnu.org/licenses/gpl.txt GPLv3+
* @link https://github.com/pluginsGLPI/formcreator/
* @link https://pluginsglpi.github.io/formcreator/
* @link http://plugins.glpi-project.org/#/plugin/formcreator
* ---------------------------------------------------------------------
*/
38 changes: 38 additions & 0 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,42 @@ public static function prepareBooleanKeywords($keywords) {

return implode(' ', $matches);
}

/**
* get the list of pictograms available for the current version of GLPI
*
* @return array
*/
public static function getFontAwesomePictoNames() {
if (version_compare(static::getGlpiVersion(), '9.4') < 0) {
$list = require_once(__DIR__ . '/../data/font-awesome_9.3.php');
} else {
$list = require_once(__DIR__ . '/../data/font-awesome_9.4.php');
}
return $list;
}

/**
* Show a dropdown with Font Awesome pictograms
*
* @param string $name name of the HTML input
* @param array $options
* @return mixed
*/
public static function showFontAwesomeDropdown($name, $options = []) {
$items = [];
foreach (static::getFontAwesomePictoNames() as $key => $value) {
$items[$key] = /* '<i class="' . $key . '"></i>' . */ $value;
}

$previewId = $name . '_preview';
$options['on_change'] = 'plugin_formceator_showPictogram(this, "' . $previewId . '")';
$options['display'] = false;
if (!isset($options['value'])) {
$options['value'] = '';
}
$output = Dropdown::showFromArray($name, $items, $options);
$output .= '<i id="' . $previewId . '" class="'. $options['value'] . '"></i>';
echo $output;
}
}
6 changes: 4 additions & 2 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =

$result_forms = $DB->request([
'SELECT' => [
$table_form => ['id', 'name', 'description', 'usage_count', 'is_default'],
$table_form => ['id', 'name', 'icon', 'description', 'usage_count', 'is_default'],
],
'FROM' => $table_form,
'LEFT JOIN' => [
Expand Down Expand Up @@ -869,6 +869,7 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
$formList[] = [
'id' => $form['id'],
'name' => $form['name'],
'icon' => $form['icon'],
'description' => $form['description'],
'type' => 'form',
'usage_count' => $form['usage_count'],
Expand Down Expand Up @@ -950,7 +951,7 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =

$query_forms = [
'SELECT' => [
$table_form => ['id', 'name', 'description', 'usage_count'],
$table_form => ['id', 'name', 'icon', 'description', 'usage_count'],
],
'FROM' => $table_form,
'LEFT JOIN' => [
Expand All @@ -973,6 +974,7 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome =
$formList[] = [
'id' => $form['id'],
'name' => $form['name'],
'icon' => $form['icon'],
'description' => $form['description'],
'type' => 'form',
'usage_count' => $form['usage_count'],
Expand Down
1 change: 1 addition & 0 deletions install/mysql/plugin_formcreator_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_forms` (
`name` varchar(255) NOT NULL,
`entities_id` int(11) NOT NULL DEFAULT '0',
`is_recursive` tinyint(1) NOT NULL DEFAULT '0',
`icon` varchar(255) NOT NULL DEFAULT '',
`access_rights` tinyint(1) NOT NULL DEFAULT '1',
`requesttype` int(11) NOT NULL DEFAULT '0',
`description` varchar(255) DEFAULT NULL,
Expand Down
3 changes: 3 additions & 0 deletions install/upgrade_to_2.9.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ public function upgrade(Migration $migration) {
]
);
}

$table = 'glpi_plugin_formcreator_forms';
$migration->addField($table, 'icon', 'string', ['after' => 'is_recursive']);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions js/scripts.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,3 +1023,11 @@ function plugin_formcreator_changeLDAP(ldap) {
document.getElementById('ldap_filter').value = response;
});
}

/**
* preview of the selected pictogram
*/
function plugin_formceator_showPictogram(id, preview) {
var value = $(id).val();
$('#' + preview).removeClass().addClass(value);
}

0 comments on commit 7635f0e

Please sign in to comment.