Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature : advanced options for interactions with the plugin fields #104

Open
wants to merge 71 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
7d83b67
base setup to add advanced options with the plugin fields
ArthurMinfotel May 22, 2024
ebf83c1
fix hook ITEM_ADD for PluginFieldsField
ArthurMinfotel May 22, 2024
ed83b19
display modelcontainers for models, and fields for modelcontainers
ArthurMinfotel May 22, 2024
b698113
fix model install query
ArthurMinfotel May 22, 2024
91cc12d
basic interface to choose action per field
ArthurMinfotel May 23, 2024
42b1515
possibility to choose action to do for all fields in a block
ArthurMinfotel May 23, 2024
db392fe
don't show action 'set value' for 'glpi_item' type field
ArthurMinfotel May 23, 2024
d63cbe4
different behaviors during uninstall done
ArthurMinfotel May 23, 2024
cd978a8
show plugin fields options only for uninstall type models
ArthurMinfotel May 23, 2024
1ef58ed
improved display
ArthurMinfotel May 23, 2024
139b816
temp fix to fields 'type' (from PluginFieldsField) display in contain…
ArthurMinfotel May 24, 2024
e2f79be
add options for replace type models
ArthurMinfotel May 30, 2024
35f46fe
specific actions for plugin fields during replacement
ArthurMinfotel May 30, 2024
3de99d2
fr translations for new texts
ArthurMinfotel May 31, 2024
12a434e
display
ArthurMinfotel May 31, 2024
f658a87
default display preferences for search of new items
ArthurMinfotel May 31, 2024
4040169
Merge remote-tracking branch 'origin/main' into plugin-fields-advance…
ArthurMinfotel Jun 10, 2024
e56ab46
Merged main
ArthurMinfotel Jun 10, 2024
51fd3e2
Merged main
ArthurMinfotel Jun 10, 2024
b1cddbd
removed fr locales update & replace incorrect header
ArthurMinfotel Jun 10, 2024
2abb556
Merge remote-tracking branch 'origin/main' into plugin-fields-advance…
ArthurMinfotel Jul 18, 2024
9d9b0a7
merged main
ArthurMinfotel Jul 18, 2024
bb01202
Add new model type 'replacement then uninstallation'
ArthurMinfotel Jul 22, 2024
e258aae
Merge remote-tracking branch 'origin/main' into plugin-fields-advance…
ArthurMinfotel Jul 22, 2024
9f3839c
lint
ArthurMinfotel Jul 22, 2024
535686c
remove useless break
ArthurMinfotel Jul 22, 2024
df0fa84
Merge branch 'main' into plugin-fields-advanced-compatibility
ArthurMinfotel Jul 22, 2024
8bee174
indentation
ArthurMinfotel Jul 22, 2024
cb2d819
Merge branch 'main' into plugin-fields-advanced-compatibility
ArthurMinfotel Jul 22, 2024
ac15627
start taking into account model type replacement then uninstallation
ArthurMinfotel Jul 23, 2024
dfff24a
fix for replacement then uninstall massive action
ArthurMinfotel Jul 23, 2024
5c16147
Merge branch 'main' into plugin-fields-advanced-compatibility-new-model
ArthurMinfotel Jul 23, 2024
0b63db6
fix translation without domain
ArthurMinfotel Jul 23, 2024
f47b90c
fix translation without domain
ArthurMinfotel Jul 23, 2024
9a69c46
Merge remote-tracking branch 'teclib/main' into plugin-fields-advance…
ArthurMinfotel Jul 23, 2024
e7ff325
take overwrite into account when copying values from plugin fields
ArthurMinfotel Jul 23, 2024
a351176
Merge branch 'plugin-fields-advanced-compatibility' into plugin-field…
ArthurMinfotel Jul 23, 2024
3afc80e
phpcs
ArthurMinfotel Jul 23, 2024
550d4e6
update composer.json config php version
ArthurMinfotel Jul 23, 2024
c334bdd
composer.json set to php 7.4
ArthurMinfotel Jul 23, 2024
6b57e23
Merge remote-tracking branch 'origin/plugin-fields-advanced-compatibi…
ArthurMinfotel Jul 23, 2024
dc1ecab
composer.json set to php 7.4
ArthurMinfotel Jul 23, 2024
6c5f360
phpcs
ArthurMinfotel Jul 23, 2024
6549706
start adaptation for model type 'uninstall then replace'
ArthurMinfotel Jul 30, 2024
aa26092
fix can't update data replacement tab values
ArthurMinfotel Jul 30, 2024
ba49725
Merge branch 'main' into plugin-fields-advanced-compatibility-new-model
ArthurMinfotel Jul 30, 2024
c430b90
Update model.class.php
ArthurMinfotel Jul 30, 2024
0f8cd50
end compatibility with replace then uninstall model type
ArthurMinfotel Jul 31, 2024
feef703
bugfix yesno field type + comments
ArthurMinfotel Jul 31, 2024
dffdd06
translations
ArthurMinfotel Jul 31, 2024
be89a0e
bugfix copy plugin fields values on replace && better restrictions on…
ArthurMinfotel Aug 1, 2024
603503d
Merge remote-tracking branch 'teclib/main' into plugin-fields-advance…
ArthurMinfotel Aug 21, 2024
9474739
bugfix yesno fields raz & bugfix copy value & restrict container crea…
ArthurMinfotel Aug 21, 2024
0544cc9
change class extended by fields related classes to CommonDBChild
ArthurMinfotel Aug 21, 2024
ff5d103
apply restriction on links created with plugin fields in createPlugin…
ArthurMinfotel Aug 21, 2024
e63f26f
Merge branch 'plugin-fields-advanced-compatibility' into plugin-field…
ArthurMinfotel Aug 21, 2024
3d7806a
replacement then uninstall model created during install/update if non…
ArthurMinfotel Aug 21, 2024
f745e59
Merge branch 'main' into plugin-fields-advanced-compatibility-new-model
ArthurMinfotel Aug 21, 2024
c9b7595
fix text & phpdoc & replace multiple if by switch
ArthurMinfotel Aug 21, 2024
2e7f898
Merge remote-tracking branch 'origin/main' into plugin-fields-advance…
ArthurMinfotel Aug 21, 2024
07838e6
Merge remote-tracking branch 'origin/plugin-fields-advanced-compatibi…
ArthurMinfotel Aug 21, 2024
dd0a4fd
Merge remote-tracking branch 'teclib/main' into plugin-fields-advance…
ArthurMinfotel Aug 21, 2024
18232af
regroup action for plugin fields replace and uninstall for modelconta…
ArthurMinfotel Sep 11, 2024
8dde679
debug logs
ArthurMinfotel Sep 11, 2024
a071d5e
allow for modelcontainerfields update to be done through ajax from mo…
ArthurMinfotel Sep 12, 2024
a28d1f2
phpcs
ArthurMinfotel Sep 17, 2024
6db65f7
bump version to 2.9.3
ArthurMinfotel Sep 17, 2024
1243069
fix for uninstall plugin fiels fields (wrong field name used for some…
ArthurMinfotel Sep 19, 2024
7ca28f5
fix for replace plugin fiels fields (wrong field name used for some f…
ArthurMinfotel Sep 19, 2024
5525a07
phpcs
ArthurMinfotel Sep 19, 2024
28cb748
Merge branch 'main' into plugin-fields-advanced-compatibility
ArthurMinfotel Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions ajax/fieldValueInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php

/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall 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.
*
* Uninstall 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 Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();
switch ($_POST['action']) {
case PluginUninstallModelcontainerfield::ACTION_NONE:
case PluginUninstallModelcontainerfield::ACTION_RAZ:
echo "";
break;

case PluginUninstallModelcontainerfield::ACTION_NEW_VALUE:
if (isset($_POST['id']) && $_POST['id']) {
$rand = mt_rand();
if (isset($_POST['rand']) && $_POST['rand']) {
$rand = $_POST['rand'];
}

$pluginUninstallField = new PluginUninstallModelcontainerfield();
$pluginUninstallField->getFromDB($_POST['id']);

$pluginFieldsField = new PluginFieldsField();
$pluginFieldsField->getFromDB($pluginUninstallField->fields['plugin_fields_fields_id']);

$type = $pluginFieldsField->fields['type'];

if ($type === 'glpi_item') {
// TODO handling this case
// Display "allowed values" field
echo __('Allowed values', 'fields') . ' :';

$allowed_itemtypes = !empty($pluginFieldsField->fields['allowed_values'])
? json_decode($pluginFieldsField->fields['allowed_values'])
: [];
echo implode(
', ',
array_map(
function ($itemtype) {
return is_a($itemtype, CommonDBTM::class, true)
? $itemtype::getTypeName(Session::getPluralNumber())
: $itemtype;
},
$allowed_itemtypes
)
);
} else {
$dropdown_matches = [];
$is_dropdown = $type == 'dropdown' || preg_match(
'/^dropdown-(?<class>.+)$/',
$type,
$dropdown_matches
) === 1;

if (in_array($type, ['date', 'datetime'])) {
echo '<i class="pointer fa fa-info" title="' . __s(
"You can use 'now' for date and datetime field"
) . '"></i>';
}

if ($is_dropdown) {
$multiple = (bool)$pluginFieldsField->fields['multiple'];

echo '<div style="line-height:var(--tblr-body-line-height);">';

$itemtype = $type == 'dropdown'
? PluginFieldsDropdown::getClassname($pluginFieldsField->fields['name'])
: $dropdown_matches['class'];
$default_value = $multiple ? json_decode(
$pluginUninstallField->fields['new_value'] ?? $pluginFieldsField->fields['default_value']
) : $pluginUninstallField->fields['new_value'] ?? $pluginFieldsField->fields['default_value'];
Dropdown::show(
$itemtype,
[
'name' => 'new_value' . ($multiple ? '[]' : ''),
'value' => $default_value,
'entity_restrict' => -1,
'multiple' => $multiple,
'rand' => $rand
]
);

echo '</div>';
} else if ($type === 'yesno') {
$value = 0;
if ($pluginUninstallField->fields['new_value'] === 1 || $pluginUninstallField->fields['new_value'] === '1') {
$value = 1;
} else if ($pluginFieldsField->fields['default_value']) {
$value = $pluginFieldsField->fields['default_value'];
}
Dropdown::showYesNo(
'new_value',
$value,
-1,
['rand' => $rand]
);
} else {
$id = 'new_value' . $rand;
echo Html::input(
'new_value',
[
'value' => $pluginUninstallField->fields['new_value'] ?? $pluginFieldsField->fields['default_value'],
'id' => $id
]
);
}
}
}
break;
}
46 changes: 46 additions & 0 deletions ajax/saveField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall 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.
*
* Uninstall 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 Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();

if (isset($_POST['id']) && $_POST['id']) {
$field = new PluginUninstallModelcontainerfield();
$field->check($_POST['id'], UPDATE);
if ($field->update($_POST)) {
Session::addMessageAfterRedirect(__('Field updated', 'uninstall'));
} else {
Session::addMessageAfterRedirect(__('An error has occured'), ERROR);
}
echo "";
}
35 changes: 33 additions & 2 deletions front/model.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,47 @@

if (isset($_POST["add"])) {
$model->check(-1, UPDATE, $_POST);
$model->add($_POST);
if ($id = $model->add($_POST)) {
$relationsCreated = false;
if (isset($_POST['action_plugin_fields_uninstall'])) {
if ($_POST['action_plugin_fields_uninstall'] == PluginUninstallModel::PLUGIN_FIELDS_ACTION_ADVANCED) {
$model->createPluginFieldsRelations($id);
$relationsCreated = true;
}
}
// possible that the relations were created in previous if for replace then uninstall model types
if (isset($_POST['action_plugin_fields_replace']) && !$relationsCreated) {
if ($_POST['action_plugin_fields_replace'] == PluginUninstallModel::PLUGIN_FIELDS_ACTION_ADVANCED) {
$model->createPluginFieldsRelations($id);
}
}
}
Html::back();
} else if (isset($_POST["update"])) {
$model->check($_POST['id'], UPDATE);
$model->update($_POST);
if ($model->update($_POST)) {
$relationsCreated = false;
if (isset($_POST['action_plugin_fields_uninstall'])) {
if ($_POST['action_plugin_fields_uninstall'] == PluginUninstallModel::PLUGIN_FIELDS_ACTION_ADVANCED) {
$model->createPluginFieldsRelations($id);
$relationsCreated = true;
}
}
if (isset($_POST['action_plugin_fields_replace']) && !$relationsCreated) {
if ($_POST['action_plugin_fields_replace'] == PluginUninstallModel::PLUGIN_FIELDS_ACTION_ADVANCED) {
$model->createPluginFieldsRelations($id);
}
}
}
Html::back();
} else if (isset($_POST['purge'])) {
$model->check($_POST['id'], DELETE);
$model->delete($_POST);
$model->redirectToList();
} else if (isset($_GET["load_fields"])) {
$model->check($id, UPDATE);
$model->createPluginFieldsRelations($id);
Html::back();
} else {
Html::header(
PluginUninstallModel::getTypeName(),
Expand Down
51 changes: 51 additions & 0 deletions front/modelcontainer.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall 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.
*
* Uninstall 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 Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');

Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);

$container = new PluginUninstallModelcontainer();
if (isset($_POST["update"])) {
$container->check($_POST['id'], UPDATE);
$container->update($_POST);
Html::back();
} else {
Html::header(
PluginUninstallModelContainer::getTypeName(),
$_SERVER['PHP_SELF'],
"admin",
"PluginUninstallModel",
"model"
);
$container->display(['id' => $_GET['id']]);

Html::footer();
}
58 changes: 58 additions & 0 deletions front/modelcontainerfield.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall 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.
*
* Uninstall 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 Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/

include('../../../inc/includes.php');

Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);

$field = new PluginUninstallModelcontainerfield();

if (isset($_POST["update"])) {
// TODO handling of mandatory when action = SET_VALUE
$field->check($_POST['id'], UPDATE);
$field->update($_POST);
Html::back();
} else {
Html::header(
PluginUninstallModelcontainerfield::getTypeName(),
$_SERVER['PHP_SELF'],
"admin",
"PluginUninstallModel",
"model"
);

if (isset($_GET["id"])) {
PluginUninstallModelcontainerfield::displayFullPageForItem($_GET['id']);
} else {
}


Html::footer();
}
Loading
Loading