-
Notifications
You must be signed in to change notification settings - Fork 28
[GT-187] Add feature selecting multiple sites #475
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
base: dev
Are you sure you want to change the base?
Changes from all commits
a87a37c
b3dd024
bf7c1ca
4843949
211dec0
fc5a9e9
294ebd1
2fce820
876e490
4a40ac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <?php | ||
|
|
||
| /*_____________________________________________________________________________ | ||
| *============================================================================= | ||
| * File: downtime_utils.php | ||
| * Description: Helper functions which can be re-used while adding | ||
| * or editing a downtime. | ||
| * | ||
| * License information | ||
| * | ||
| * Copyright 2023 STFC | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| /*====================================================== */ | ||
| require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php'; | ||
|
|
||
| /** | ||
| * Sorts the impacted IDs into impacted services and impacted endpoints. | ||
| * | ||
| * @param array $impactedIDs An array of `impactedIDs` which user has selected. | ||
| * | ||
| * @return array `serviceWithEndpoints` An array with | ||
| * 'SiteID->serviceID->EndpointID(s)' details. | ||
| */ | ||
| function endpointToServiceMapping($impactedIDs) | ||
| { | ||
| $serviceWithEndpoints = []; | ||
|
|
||
| /** | ||
| * For each impacted ID, sort between endpoints and services | ||
| * using the prepended letter. | ||
| */ | ||
| foreach ($impactedIDs as $impactedID) { | ||
| $indexPosition = 0; | ||
|
|
||
| list($siteID, $serviceID, $idType) = explode(':', $impactedID); | ||
| /** | ||
| * `idType` => It will have either `s` followed by service ID or | ||
| * `e` followed by endpoint ID. | ||
| */ | ||
| $trimmedID = str_replace(['s', 'e'], '', $idType); | ||
|
|
||
| if (strpos($idType, 's') === $indexPosition) { | ||
| continue; | ||
| } | ||
|
|
||
| // Using '+' to ensure we have an integer value after type coercion. | ||
| $serviceWithEndpoints[$siteID][$serviceID]['endpointIDs'][] = | ||
| +$trimmedID; | ||
| } | ||
|
|
||
| return $serviceWithEndpoints; | ||
| } | ||
|
|
||
| /** | ||
| * Unset a given variable, helper method to destroy the specified variables. | ||
| * | ||
| * @param mixed $downtimeObj Object to destroy specified variables. | ||
| * @param string $fromLocation Location from where the | ||
| * function is being called. | ||
| */ | ||
| function unsetVariables($downtimeObj, $fromLocation) | ||
| { | ||
| if ($fromLocation == "edit") { | ||
| unset($downtimeObj['DOWNTIME']['EXISTINGID']); | ||
| unset($downtimeObj['isEdit']); | ||
| } | ||
|
|
||
| unset($downtimeObj['SELECTED_SINGLE_SITE']); | ||
|
|
||
| return $downtimeObj; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,20 +19,34 @@ | |
| * limitations under the License. | ||
| * | ||
| /*====================================================== */ | ||
| use Doctrine\Common\Collections\ArrayCollection; | ||
| use Exception; | ||
|
|
||
| function getServiceandEndpointList() { | ||
| require_once __DIR__ . '/../utils.php'; | ||
| require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php'; | ||
|
|
||
| $params = []; | ||
| $dn = Get_User_Principle(); | ||
| $user = \Factory::getUserService()->getUserByPrinciple($dn); | ||
| $params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user); | ||
| $siteIDs = $_REQUEST['site_id']; | ||
|
|
||
| if (!isset($_REQUEST['site_id']) || !is_numeric($_REQUEST['site_id']) ){ | ||
| throw new Exception("An id must be specified"); | ||
| if (empty($siteIDs)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this change equivalent to the old functionality? what if a non numeric string is passed in via
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say Not an equivalent. We are now passing an array of Number. So I don't think it would be an issue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when you loop through the siteIDs later, can you add an |
||
| throw new Exception("Please select at least one site."); | ||
| } | ||
| $site = \Factory::getSiteService()->getSite($_REQUEST['site_id']); | ||
| $services = $site->getServices(); | ||
| $params['services'] = $services; | ||
|
|
||
| $siteIdWithServices = new ArrayCollection(); | ||
|
|
||
| foreach ($siteIDs as $siteID) { | ||
| // Using '+' to ensure we have integer value after type coercion. | ||
| $siteID = +$siteID; | ||
| $site = \Factory::getSiteService()->getSite($siteID); | ||
| $siteIdWithServices[$siteID] = $site->getServices(); | ||
| } | ||
|
|
||
| $params['siteIdWithServices'] = $siteIdWithServices; | ||
|
|
||
| show_view("downtime/view_nested_endpoints_list.php", $params, null, true); | ||
| } | ||
|
|
||
|
|
@@ -41,19 +55,29 @@ function editDowntimePopulateEndpointTree() { | |
| require_once __DIR__ . '/../utils.php'; | ||
| require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php'; | ||
|
|
||
| $params = []; | ||
| $dn = Get_User_Principle(); | ||
| $user = \Factory::getUserService()->getUserByPrinciple($dn); | ||
| $params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user); | ||
| $siteIDs = $_REQUEST['site_id']; | ||
|
|
||
| if (!isset($_REQUEST['site_id']) || !is_numeric($_REQUEST['site_id']) ){ | ||
| throw new Exception("A site id must be specified"); | ||
| if (empty($_REQUEST['site_id'])) { | ||
| throw new Exception("Please select at least one site."); | ||
| } | ||
| if (!isset($_REQUEST['dt_id']) || !is_numeric($_REQUEST['dt_id']) ){ | ||
| throw new Exception("A downtime id must be specified"); | ||
| } | ||
| $site = \Factory::getSiteService()->getSite($_REQUEST['site_id']); | ||
| $services = $site->getServices(); | ||
| $params['services'] = $services; | ||
|
|
||
| $siteIdWithServices = new ArrayCollection(); | ||
|
|
||
| foreach ($siteIDs as $siteID) { | ||
| // Using '+' to ensure we have integer value after type coercion. | ||
| $siteID = +$siteID; | ||
| $site = \Factory::getSiteService()->getSite($siteID); | ||
| $siteIdWithServices[$siteID] = $site->getServices(); | ||
| } | ||
|
|
||
| $params['siteIdWithServices'] = $siteIdWithServices; | ||
|
|
||
| $downtime = \Factory::getDowntimeService()->getDowntime($_REQUEST['dt_id']); | ||
| $params['downtime'] = $downtime; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.