Skip to content

Commit

Permalink
Software Twig UI 1
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Apr 29, 2024
1 parent aaedd26 commit 78a07b6
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 364 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -270,6 +270,7 @@ The present file will list all changes made to the project; according to the
- `NetworkName::getInternetNameFromID()`
- `NetworkPort::getNetworkPortInstantiationsWithNames()`
- `NetworkPort::resetConnections()`
- `OlaLevel::showForSLA()`. Replaced by `LevelAgreementLevel::showForLA()`.
- `PlanningExternalEvent::addVisibilityRestrict()`
- `Plugin::migrateItemType()`
- `ProfileRight::updateProfileRightAsOtherRight()`
Expand Down Expand Up @@ -298,7 +299,7 @@ The present file will list all changes made to the project; according to the
- `Search::sylk_clean()`
- `SlaLevel::showForSLA()`. Replaced by `LevelAgreementLevel::showForLA()`.
- `SLM::setTicketCalendar()`
- `OlaLevel::showForSLA()`. Replaced by `LevelAgreementLevel::showForLA()`.
- `SoftwareLicense::getSonsOf()`
- `Toolbox::canUseCas()`
- `Toolbox::checkValidReferer()`
- `Toolbox::clean_cross_side_scripting_deep()`
Expand Down
21 changes: 12 additions & 9 deletions src/Html.php
Expand Up @@ -839,8 +839,8 @@ public static function getConfirmationOnActionScript($string, $additionalactions
*
* @since 0.85
*
* @param $id HTML ID of the progress bar
* @param $options array progress status
* @param string $id HTML ID of the progress bar
* @param array $options progress status options
* - create do we have to create it ?
* - message add or change the message
* - percent current level
Expand All @@ -850,7 +850,6 @@ public static function getConfirmationOnActionScript($string, $additionalactions
**/
public static function progressBar($id, array $options = [])
{

$params = [
'create' => false,
'message' => null,
Expand Down Expand Up @@ -938,17 +937,21 @@ public static function progressBar($id, array $options = [])
* Create a Dynamic Progress Bar
*
* @param string $msg initial message (under the bar)
* @param array $options See {@link Html::progressBar()} for available options (excluding message)
*
* @return void
* @return string|void
**/
public static function createProgressBar($msg = " ")
public static function createProgressBar($msg = null, array $options = [])
{
$options = array_replace([
'create' => true,
'display' => true
], $options);
$options['message'] = $msg;

$options = ['create' => true];
if ($msg != " ") {
$options['message'] = $msg;
if (!$options['display']) {
return self::progressBar('doaction_progress', $options);
}

self::progressBar('doaction_progress', $options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Item_SoftwareVersion.php
Expand Up @@ -482,7 +482,7 @@ private static function showInstallations($searchID, $crit)
$order = "ASC";
}

if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($refcolumns[$_GET["sort"]])) {
if (!empty($_GET["sort"]) && isset($refcolumns[$_GET["sort"]])) {
// manage several param like location,compname : order first
$tmp = explode(",", $_GET["sort"]);
$sort = "`" . implode("` $order,`", $tmp) . "`";
Expand Down
103 changes: 55 additions & 48 deletions src/Software.php
Expand Up @@ -229,7 +229,7 @@ public function getSpecificMassiveActions($checkitem = null)
) {
$actions[__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'compute_software_category']
= "<i class='fas fa-calculator'></i>" .
__('Recalculate the category');
__s('Recalculate the category');
}

if (
Expand All @@ -238,7 +238,7 @@ public function getSpecificMassiveActions($checkitem = null)
) {
$actions[__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'replay_dictionnary']
= "<i class='fas fa-undo'></i>" .
__('Replay the dictionary rules');
__s('Replay the dictionary rules');
}

if ($isadmin) {
Expand Down Expand Up @@ -890,9 +890,7 @@ public function showMergeCandidates()

$ID = $this->getField('id');
$this->check($ID, UPDATE);
$rand = mt_rand();

echo "<div class='center'>";
$iterator = $DB->request([
'SELECT' => [
'glpi_softwares.id',
Expand Down Expand Up @@ -923,46 +921,45 @@ public function showMergeCandidates()
]);
$nb = count($iterator);

if ($nb) {
$link = Toolbox::getItemTypeFormURL('Software');
Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
$massiveactionparams
= ['num_displayed' => min($_SESSION['glpilist_limit'], $nb),
'container' => 'mass' . __CLASS__ . $rand,
'specific_actions'
=> [__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'merge'
=> __('Merge')
],
'item' => $this
];
Html::showMassiveActions($massiveactionparams);

echo "<table class='tab_cadre_fixehov'>";
echo "<tr><th width='10'>";
echo Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
echo "</th>";
echo "<th>" . __('Name') . "</th>";
echo "<th>" . Entity::getTypeName(1) . "</th>";
echo "<th>" . _n('Installation', 'Installations', Session::getPluralNumber()) . "</th>";
echo "<th>" . SoftwareLicense::getTypeName(Session::getPluralNumber()) . "</th></tr>";

foreach ($iterator as $data) {
echo "<tr class='tab_bg_2'>";
echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
echo "<td><a href='" . $link . "?id=" . $data["id"] . "'>" . $data["name"] . "</a></td>";
echo "<td>" . $data["entity"] . "</td>";
echo "<td class='right'>" . Item_SoftwareVersion::countForSoftware($data["id"]) . "</td>";
echo "<td class='right'>" . SoftwareLicense::countForSoftware($data["id"]) . "</td></tr>\n";
}
echo "</table>\n";
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
} else {
echo __('No item found');
$entries = [];
$software = new self();
foreach ($iterator as $data) {
$software->getFromDB($data["id"]);
$entries[] = [
'name' => $software->getLink(),
'entity' => $data["entity"],
'installations' => Item_SoftwareVersion::countForSoftware($data["id"]),
'licenses' => SoftwareLicense::countForSoftware($data["id"])
];
}

echo "</div>";
TemplateRenderer::getInstance()->display('components/datatable.html.twig', [
'is_tab' => true,
'nopager' => true,
'nofilter' => true,
'nosort' => true,
'columns' => [
'name' => __('Name'),
'entity' => Entity::getTypeName(1),
'installations' => _n('Installation', 'Installations', Session::getPluralNumber()),
'licenses' => SoftwareLicense::getTypeName(Session::getPluralNumber())
],
'formatters' => [
'name' => 'raw_html',
],
'entries' => $entries,
'total_number' => count($entries),
'filtered_number' => count($entries),
'showmassiveactions' => true,
'massiveactionparams' => [
'num_displayed' => count($entries),
'container' => 'mass' . static::class . mt_rand(),
'specific_actions' => [
__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'merge' => __('Merge')
],
'item' => $this
]
]);
}

/**
Expand All @@ -981,16 +978,26 @@ public function merge($item, $html = true)
$ID = $this->getField('id');

if ($html) {
echo "<div class='center'>";
echo "<table class='tab_cadrehov'><tr><th>" . __('Merging') . "</th></tr>";
echo "<tr class='tab_bg_2'><td>";
Html::createProgressBar(__('Work in progress...'));
echo "</td></tr></table></div>\n";
$twig_params = [
'merge_msg' => __('Merging'),
'progress' => Html::progressBar('doaction_progress', [
'message' =>__('Work in progress...'),
'create' => true,
'display' => false
])
];
// language=Twig
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
{% import 'components/form/fields_macros.html.twig' as fields %}
<div class="text-center">
{{ fields.htmlField('', progress, merge_msg) }}
</div>
TWIG, $twig_params);
}

$item = array_keys($item);

// Search for software version
// Search for software version
$req = $DB->request(['FROM' => "glpi_softwareversions", 'WHERE' => ["softwares_id" => $item]]);
$i = 0;

Expand Down

0 comments on commit 78a07b6

Please sign in to comment.