From 7527084a925cfcf0b8f645e7ba974a555ebb37e7 Mon Sep 17 00:00:00 2001 From: Adil Chehabi Date: Sun, 26 Jun 2022 09:30:40 -0400 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=8C=88=20style:=20format=20and=20rena?= =?UTF-8?q?me=20vars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plugin.php | 9 ++++----- controllers/Settings.php | 4 +--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Plugin.php b/Plugin.php index 53cfb53..8ac2103 100644 --- a/Plugin.php +++ b/Plugin.php @@ -57,21 +57,20 @@ public function registerListColumnTypes() /** - * @param $value the JSON value on which the filter is applied + * @param $value the Array value on which the filter is applied * @param $props associative array with the folowing possible keys (see REEDME.md): * 'class','width', 'height', 'inline', 'hFlip', 'vFlip', 'flip', 'rotate', 'align', 'color', 'box' * @return string SVG icon * @throws ApplicationException */ - public function iconify($jsonIcon, $props = []) + public function iconify($iconArray, $props = []) { - $icon = new JsonIcon($jsonIcon); + $icon = new JsonIcon($iconArray); return $icon->iconify($props); } - /** - * @param $value the JSON representation of the icon + * @param $value the Array representation of the icon * @param $column column definition object * @param $record model record object. * @return string SVG icon diff --git a/controllers/Settings.php b/controllers/Settings.php index aa71710..a6a0386 100644 --- a/controllers/Settings.php +++ b/controllers/Settings.php @@ -38,13 +38,12 @@ public function __construct() public function index() { - $this->bodyClass = 'compact-container'; $this->vars['iconSetsPaginator'] = $this->iconSetsPaginator(1); } /** - * Handler for installing icon set + * Handler for installing iconset * @return array|void * @throws \SystemException */ @@ -171,7 +170,6 @@ public function iconSetsPaginator($page) $query->where('is_installed', true); } - // TODO paginate // Active ones first ordred by name $iconSetsPaginator = $query ->orderBy('is_enabled', 'desc') From 9d19c3fb9e8c1b003e73fe767a9d1790753cf002 Mon Sep 17 00:00:00 2001 From: Adil Chehabi Date: Sun, 26 Jun 2022 09:35:41 -0400 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=9E=20fix:save=20icon=20as=20array?= =?UTF-8?q?=20to=20avoid=20JSON=20decoding=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/Helpers.php | 20 +++++++++----------- formwidgets/IconesFinder.php | 6 +++--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/classes/Helpers.php b/classes/Helpers.php index e88f561..4b54c17 100644 --- a/classes/Helpers.php +++ b/classes/Helpers.php @@ -122,7 +122,7 @@ public static function installIconSet($prefix) // For optimal seeding, because number of icons can be huge - $chunks = array_chunk($iconsToSave, 500); + $chunks = array_chunk($iconsToSave, 200); foreach ($chunks as $chunk) { Icon::insert($chunk); @@ -131,26 +131,24 @@ public static function installIconSet($prefix) } /** - * Mape a JSON representation of icon's attributes to an Icon model - * @param $jsonIcon + * Mape the arry representation of icon's attributes to an Icon model + * @param $iconArray * @return Icon */ - public static function mapIcon($jsonIcon) + public static function mapIcon($iconArray) { $keys = [ - "id", "icon_set_id", "name", "parent", "icon_set_name", "body", "hidden", + "id", "icon_set_id", "name", "parent", "icon_set_name", "readable_name", "body", "hidden", "left", "top", "width", "height", "rotate", "hFlip", "vFlip", "inlineTop", "inlineHeight", "verticalAlign" ]; - // We check if the given value is a Json representation of an icon. - $iconArray = json_decode($jsonIcon, true) ?? []; -// dd($iconArray,$jsonIcon, gettype($jsonIcon) ); + // We check if the given value is an Array representation of an icon. $iconArrayKeys = array_keys($iconArray); $isIcon = count(array_diff($keys, $iconArrayKeys)) == 0; if ($isIcon) { - //Although we could grab the model by its Id, We construct the object from the Json, + //Although we could grab the model by its Id, We construct the object from the array, // in case the icon is no more in DB if the icon set is deleted for example $icon = new Icon(); foreach ($iconArray as $key => $attribute) { @@ -158,8 +156,8 @@ public static function mapIcon($jsonIcon) } } else { throw new ApplicationException(trans("chkilel.icones::lang.formwidgets.error_wrong_variable_type", [ - 'variable' => $jsonIcon, - 'type' =>gettype($jsonIcon), + 'variable' => $iconArray, + 'type' =>gettype($iconArray), ])); } diff --git a/formwidgets/IconesFinder.php b/formwidgets/IconesFinder.php index 1d027fa..cf96423 100644 --- a/formwidgets/IconesFinder.php +++ b/formwidgets/IconesFinder.php @@ -116,12 +116,12 @@ public function getSaveValue($value) // To manage the case where the form is saved but the icon is no more in the DB; // for example the icon set is deleted. - // We reuse the existing value stored as JSON, otherwise we will be calling toJSON on null + // We reuse the existing value stored as Jsonable array, otherwise we will be calling toArray on null $serialized = $this->formField->value; $icon = Icon::find($value); if ($icon != null) { - $serialized = $icon->toJSON(); + $serialized = $icon->toArray(); } return $serialized; @@ -146,7 +146,7 @@ public function getLoadValue() } /** - * Return the class to adjust the size of th fied + * Return the class to adjust the size of the field * * @param $size small|large * @return string From cb7ce8208adee9611970509a26e8c36ca1cbffb3 Mon Sep 17 00:00:00 2001 From: Adil Chehabi Date: Sun, 26 Jun 2022 09:38:13 -0400 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=90=9E=20fix:=20update=20compatibilit?= =?UTF-8?q?y=20with=20OCMS=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AJAX framework and CSS classes --- controllers/settings/_icon-sets_list.htm | 122 +++--------------- controllers/settings/_pagination.htm | 101 +++++++++++++++ .../iconesfinder/partials/_iconesfinder.htm | 2 +- 3 files changed, 120 insertions(+), 105 deletions(-) create mode 100644 controllers/settings/_pagination.htm diff --git a/controllers/settings/_icon-sets_list.htm b/controllers/settings/_icon-sets_list.htm index 73790b1..672e385 100644 --- a/controllers/settings/_icon-sets_list.htm +++ b/controllers/settings/_icon-sets_list.htm @@ -1,13 +1,13 @@ -total() / $iconSetsPaginator->perPage()); - $iconSetsWithSamples = $iconSetsPaginator->items(); - ?> +items(); ?> - $iconSet): ?> + $iconSet) : ?> -
+ isEnabled() ? ' active' : null; + $installed = $iconSet->isInstalled() && !$iconSet->isEnabled() ? ' installed' : null + ?> + +
makePartial('icon-sets_list_item', ['iconSet' => $iconSet]) ?>
@@ -19,104 +19,18 @@
-
- - -
- +
+
+ -
- - - Displayed records: - currentPage() - 1) * $iconSetsPaginator->perPage() + 1 ?> - - - currentPage() * $iconSetsPaginator->perPage() ?> - of - total() ?> - - - - currentPage() === 1): ?> - - - - - - - - - - - - - - currentPage() === $iconSetsPaginator->lastPage()): ?> - - - - - - - -
- - - - + +
+ makePartial('pagination', ['iconSetsPaginator' => $iconSetsPaginator]) ?> +
+
+
diff --git a/controllers/settings/_pagination.htm b/controllers/settings/_pagination.htm new file mode 100644 index 0000000..0d9c2d5 --- /dev/null +++ b/controllers/settings/_pagination.htm @@ -0,0 +1,101 @@ +total() / $iconSetsPaginator->perPage()); ?> + +
+
+
+ + + Records: + + currentPage() - 1) * $iconSetsPaginator->perPage() + 1 ?> + - + currentPage() * $iconSetsPaginator->perPage() ?> + + of + + total() ?> + + + + +
+
+
+ + + currentPage() === 1) : ?> + + + + + + + + + + + + + currentPage() === $iconSetsPaginator->lastPage()) : ?> + + + + + + + +
+
+ +
+ + + +
+
+
diff --git a/formwidgets/iconesfinder/partials/_iconesfinder.htm b/formwidgets/iconesfinder/partials/_iconesfinder.htm index 719e870..bf99551 100644 --- a/formwidgets/iconesfinder/partials/_iconesfinder.htm +++ b/formwidgets/iconesfinder/partials/_iconesfinder.htm @@ -6,7 +6,7 @@
-