Skip to content

Commit

Permalink
feat(Timeslot): implement Timeslot
Browse files Browse the repository at this point in the history
  • Loading branch information
Lainow authored Feb 29, 2024
1 parent 0325428 commit 5909326
Show file tree
Hide file tree
Showing 24 changed files with 1,016 additions and 30 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/**
* -------------------------------------------------------------------------
* Deploy plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Deploy.
*
* Deploy 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 3 of the License, or
* (at your option) any later version.
*
* Deploy 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 Deploy. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2022-2024 by Deploy plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/deploy
* -------------------------------------------------------------------------
*/

module.exports = {
"root": true,
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ on:
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
generate-ci-matrix:
name: "Generate CI matrix"
uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1"
with:
glpi-version: "10.1.x"
glpi-version: "11.0.x"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ vendor/
.gh_token
composer.lock
*.min.*

lib/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
27 changes: 27 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/**
* -------------------------------------------------------------------------
* Deploy plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Deploy.
*
* Deploy 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 3 of the License, or
* (at your option) any later version.
*
* Deploy 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 Deploy. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2022-2024 by Deploy plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/deploy
* -------------------------------------------------------------------------
*/

module.exports = {
"extends": "stylelint-config-standard",
Expand Down
55 changes: 55 additions & 0 deletions ajax/timeslot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* -------------------------------------------------------------------------
* Deploy plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Deploy.
*
* Deploy 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 3 of the License, or
* (at your option) any later version.
*
* Deploy 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 Deploy. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2022-2024 by Deploy plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/deploy
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Deploy;

use Glpi\Application\View\TemplateRenderer;

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

\Session::checkLoginUser();
$trange = new TimeslotRange();
$id = $_POST['plugin_deploy_timeslots_id'];
TimeslotRange::cleanOldData($_POST);
$_POST = TimeslotRange::cleanInput($_POST);
foreach ($_POST as $timeslot) {
foreach ($timeslot as $range) {
if ((bool)$range['is_enable'] == true) {
$trange->add($range);
}
}
}
$timeslots_data = TimeslotRange::getForTimeslot(Timeslot::getById($id));
echo TemplateRenderer::getInstance()->render('@deploy/timeslot/timeslotrange.html.twig', [
'rand' => mt_rand(),
'timeslot_id' => $id,
'days_list' => TimeslotRange ::getDayList(),
'timeslots_data' => $timeslots_data
]);
2 changes: 1 addition & 1 deletion front/package.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
$action->delete($_POST);
Html::back();
} else if (isset($_POST["add_target"])) {
if ($_POST['plugin_deploy_computers_groups_id'] > 0) {
if ($_POST['plugin_deploy_computers_groups_id'] > 0 && $_POST['plugin_deploy_timeslots_id'] > 0) {
$package_target = new PackageTarget();
$package_target->add($_POST);
}
Expand Down
40 changes: 40 additions & 0 deletions front/timeslot.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* -------------------------------------------------------------------------
* Deploy plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Deploy.
*
* Deploy 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 3 of the License, or
* (at your option) any later version.
*
* Deploy 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 Deploy. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2022-2024 by Deploy plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/deploy
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Deploy;

use Html;
use Session;

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

Session::checkRight("entity", UPDATE);
$dropdown = new Timeslot();
include(GLPI_ROOT . "/front/dropdown.common.form.php");
41 changes: 41 additions & 0 deletions front/timeslot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* -------------------------------------------------------------------------
* Deploy plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Deploy.
*
* Deploy 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 3 of the License, or
* (at your option) any later version.
*
* Deploy 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 Deploy. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2022-2024 by Deploy plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/deploy
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Deploy;

use Html;
use Search;
use Session;

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

Session::checkRight("entity", UPDATE);
$dropdown = new Timeslot();
include(GLPI_ROOT . "/front/dropdown.common.php");
59 changes: 59 additions & 0 deletions front/timeslotrange.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* -------------------------------------------------------------------------
* Deploy plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Deploy.
*
* Deploy 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 3 of the License, or
* (at your option) any later version.
*
* Deploy 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 Deploy. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2022-2024 by Deploy plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/deploy
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Deploy;

use Html;
use Session;

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

Session::checkRight("entity", UPDATE);

if (!isset($_GET["id"])) {
$_GET["id"] = "";
}

$trange = new TimeslotRange();

if (isset($_POST['timeslot']) && !empty($_POST['timeslot'])) {
$_POST['timeslot'] = json_decode($_POST['timeslot'], true);
TimeslotRange::cleanOldData($_POST);
$_POST = TimeslotRange::cleanInput($_POST);
foreach ($_POST as $timeslot) {
foreach ($timeslot as $range) {
if ($range['is_enable'] == true) {
$trange->add($range);
}
}
}
Session::addMessageAfterRedirect(__('Range options saved', 'deploy'), true, INFO);
}
Html::back();
14 changes: 14 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
use GlpiPlugin\Deploy\PackageFile;
use GlpiPlugin\Deploy\PackageTarget;
use GlpiPlugin\Deploy\Profile;
use GlpiPlugin\Deploy\PackageTimeslot;
use GlpiPlugin\Deploy\Repository;
use GlpiPlugin\Deploy\Timeslot;
use GlpiPlugin\Deploy\TimeslotRange;

/**
* -------------------------------------------------------------------------
Expand Down Expand Up @@ -68,6 +71,13 @@
* -------------------------------------------------------------------------
*/

// Define Dropdown tables to be manage in GLPI :
function plugin_deploy_getDropdown()
{
$dropdowns = [Timeslot::class => Timeslot::getTypeName(2)];
return $dropdowns;
}

function plugin_deploy_install()
{
$version = plugin_version_deploy();
Expand All @@ -84,6 +94,8 @@ function plugin_deploy_install()
Group::install($migration);
GroupDynamic::install($migration);
GroupStatic::install($migration);
Timeslot::install($migration);
TimeslotRange::install($migration);

return true;
}
Expand All @@ -106,6 +118,8 @@ function plugin_deploy_uninstall()
Group::uninstall($migration);
GroupDynamic::uninstall($migration);
GroupStatic::uninstall($migration);
Timeslot::uninstall($migration);
TimeslotRange::uninstall($migration);

return true;
}
Loading

0 comments on commit 5909326

Please sign in to comment.