Skip to content

Commit

Permalink
Merge pull request #909 from jpwhite4/novice_user_pull
Browse files Browse the repository at this point in the history
Initial Prototype of Novice User Portal
  • Loading branch information
jpwhite4 authored May 16, 2019
2 parents be2414b + 886aef3 commit be9fff1
Show file tree
Hide file tree
Showing 14 changed files with 815 additions and 2 deletions.
83 changes: 83 additions & 0 deletions classes/CCR/ColumnLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace CCR;

/**
* Helper class to organise the layout of items in columns
*/
class ColumnLayout
{
private $nextRow = array();
private $nextColumn = 0;
private $settings = array();

/*
* @param $columns the default number of columns to manage.
* @param $defaults an array containing the zero-based row and column index for
* each item that may be layed out. The column indexes in the defaults
* may override the number of columns specified in the $columns argument.
*/
public function __construct($columns, $defaults = null)
{
$this->nextRow = array_fill(0, $columns, 0);

if ($defaults !== null) {
$this->settings = $defaults;

foreach ($this->settings as $itemId => $rowcol)
{
list($row, $col) = $rowcol;

if (count($this->nextRow) < ($col + 1)) {
$this->nextRow = array_pad($this->nextRow, $col + 1, 0);
}

$this->nextRow[$col] = max($row + 1, $this->nextRow[$col]);
}
}
}

/**
* number of columns managed by this instance
*/
public function getColumnCount()
{
return count($this->nextRow);
}

/**
* Return the location of the item in the sort order. If the item was specified
* in the defaults then its location is returned. If the item was not in the
* defaults then it will be placed at the next available location. Items
* are layed out left to right top to bottom.
*
* @param mixed $itemId the identifier for the item
* @return array(string, int) an array containing a string encoded index
* that uniqely identifies the item and its relative position and the
* column index.
*/
public function getLocation($itemId)
{
if (!isset($this->settings[$itemId])) {
$this->settings[$itemId] = array($this->nextRow[$this->nextColumn], $this->nextColumn);

$this->nextRow[$this->nextColumn] += 1;
$this->nextColumn = ($this->nextColumn + 1) % $this->getColumnCount();
}

return array(
sprintf("%08X%08x", $this->settings[$itemId][1], $this->settings[$itemId][0]) . $itemId,
$this->settings[$itemId][1]
);
}

/**
* return whether an item has configured layout settings
* @param $itemId the identifier for the item
* @return boolean whether the item has a layout setting
*/
public function hasLayout($itemId)
{
return isset($this->settings[$itemId]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace OpenXdmod\Migration\Version812To850;

use OpenXdmod\Migration\ConfigFilesMigration as AbstractConfigFilesMigration;
use OpenXdmod\Setup\Console;

class ConfigFilesMigration extends AbstractConfigFilesMigration
{
Expand All @@ -15,6 +16,25 @@ class ConfigFilesMigration extends AbstractConfigFilesMigration
public function execute()
{
$this->assertPortalSettingsIsWritable();
$this->writePortalSettingsFile();

$console = Console::factory();

$console->displayMessage(<<<"EOT"
This release of XDMoD features an optional replacement for the summary
tab that is intended to provide easier access to XDMoD's many features
for new or inexperienced (novice) users. Detailed information is available
as https://open.xdmod.org/novice_user.html
EOT
);
$console->displayBlankLine();
$novice_user = $console->prompt(
'Enable Novice User Tab?',
'off',
array('on', 'off')
);

$this->writePortalSettingsFile(array(
'features_novice_user' => $novice_user
));
}
}
15 changes: 15 additions & 0 deletions classes/OpenXdmod/Setup/GeneralSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ public function handle()
$settings['general_email_token_expiration'] = '600';
}

$this->console->displayBlankLine();
$this->console->displayMessage(<<<"EOT"
This release of XDMoD features an optional replacement for the summary
tab that is intended to provide easier access to XDMoD's many features
for new or inexperienced (novice) users. Detailed information is available
as https://open.xdmod.org/novice_user.html
EOT
);
$this->console->displayBlankLine();
$settings['features_novice_user'] = $this->console->prompt(
'Novice User Tab',
$settings['features_novice_user'],
array('on', 'off')
);

$this->saveIniConfig($settings, 'portal_settings');
}
}
195 changes: 195 additions & 0 deletions classes/Rest/Controllers/SummaryControllerProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php

namespace Rest\Controllers;

use Silex\Application;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request;
use DataWarehouse\Query\Exceptions\BadRequestException;

use Models\Services\Acls;
use User\Roles;

class SummaryControllerProvider extends BaseControllerProvider
{
/**
* @see BaseControllerProvider::setupRoutes
*/
public function setupRoutes(Application $app, ControllerCollection $controller)
{
$root = $this->prefix;
$class = get_class($this);

$controller->get("$root/portlets", "$class::getPortlets");

$controller->post("$root/layout", "$class::setLayout");
$controller->delete("$root/layout", "$class::resetLayout");
}

/*
* Get the column layout manager for the user
*
* @return \CCR\ColumnLayout
*/
private function getLayout($user)
{
$defaultLayout = null;
$defaultColumnCount = 2;

if ($user->isPublicUser() === false) {
$layoutStore = new \UserStorage($user, 'summary_layout');
$record = $layoutStore->getById(0);
if ($record) {
$defaultLayout = $record['layout'];
$defaultColumnCount = $record['columns'];
}
}

return new \CCR\ColumnLayout($defaultColumnCount, $defaultLayout);
}

/**
*/
public function getPortlets(Request $request, Application $app)
{
$user = $this->getUserFromRequest($request);

$summaryPortlets = array();

$mostPrivilegedAcl = Acls::getMostPrivilegedAcl($user)->getName();

$layout = $this->getLayout($user);

$roleConfig = \Configuration\XdmodConfiguration::assocArrayFactory('roles.json', CONFIG_DIR);
$presets = $roleConfig['roles'][$mostPrivilegedAcl];

if (isset($presets['summary_portlets'])) {

foreach($presets['summary_portlets'] as $portlet) {
if (isset($portlet['region']) && $portlet['region'] === 'top') {
$chartLocation = 'FW' . $portlet['name'];
$column = -1;
} else {
list($chartLocation, $column) = $layout->getLocation('PP' . $portlet['name']);
}

$summaryPortlets[$chartLocation] = array(
'name' => 'PP' . $portlet['name'],
'type' => $portlet['type'],
'config' => isset($portlet['config']) ? $portlet['config'] : array(),
'column' => $column
);
}
}

$presetCharts = isset($presets['summary_charts']) ? $presets['summary_charts'] : $roleConfig['roles']['default']['summary_charts'];

foreach ($presetCharts as $index => $presetChart)
{
$presetChart['featured'] = true;
$presetChart['aggregation_unit'] = 'Auto';
$presetChart['timeframe_label'] = 'Previous month';

list($chartLocation, $column) = $layout->getLocation('PC' . $index);
$summaryPortlets[$chartLocation] = array(
'name' => 'PC' . $index,
'type' => 'ChartPortlet',
'config' => array(
'name' => 'summary_' . $index,
'chart' => $presetChart
),
'column' => $column
);
}

if ($user->isPublicUser() === false)
{
$queryStore = new \UserStorage($user, 'queries_store');
$queries = $queryStore->get();

if ($queries != null) {
foreach ($queries as $query) {
if (!isset($query['config']) || !isset($query['name'])) {
continue;
}

$queryConfig = json_decode($query['config']);

if (!$queryConfig->featured) {
continue;
}

$name = 'UC' . $query['name'];

if (preg_match('/summary_(?P<index>\S+)/', $query['name'], $matches) > 0) {
if ($layout->hasLayout('PC' . $matches['index'])) {
$name = 'PC' . $matches['index'];
}
}

list($chartLocation, $column) = $layout->getLocation($name);

$summaryPortlets[$chartLocation] = array(
'name' => $name,
'type' => 'ChartPortlet',
'config' => array(
'name' => $query['name'],
'chart' => $queryConfig
),
'column' => $column
);
}
}
}

ksort($summaryPortlets);

return $app->json(array(
'success' => true,
'total' => count($summaryPortlets),
'portalConfig' => array('columns' => $layout->getColumnCount()),
'data' => array_values($summaryPortlets)
));
}

/**
* set the layout metadata
*
*/
public function setLayout(Request $request, Application $app)
{
$user = $this->authorize($request);

$content = json_decode($this->getStringParam($request, 'data', true), true);

if ($content === null || !isset($content['layout']) || !isset($content['columns'])) {
throw new BadRequestException('Invalid data parameter');
}

$storage = new \UserStorage($user, 'summary_layout');

return $app->json(array(
'success' => true,
'total' => 1,
'data' => $storage->upsert(0, $content)
));
}

/**
* clear the layout metadata
*
*/
public function resetLayout(Request $request, Application $app)
{
$user = $this->authorize($request);

$storage = new \UserStorage($user, 'summary_layout');

$storage->del();

return $app->json(array(
'success' => true,
'total' => 1
));
}
}
7 changes: 7 additions & 0 deletions configuration/assets.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
{
"xdmod": {
"portal": {
"js": [
"gui/js/modules/summary/ChartPortlet.js"
]
}
}
}
5 changes: 5 additions & 0 deletions configuration/portal_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ appkernels = "off"
; set to 'off' in Open XDMoD until support has been added.
multiple_service_providers = "off"

; Enable the novice user interface. This replaces the existing
; summary page with a tab that displays information specfic
; to each user's role
novice_user = "off"

[sso]
; Set to "on" to enable the local user option in login modal.
show_local_login = "off"
Expand Down
6 changes: 6 additions & 0 deletions configuration/rest.d/summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"summary": {
"prefix": "summary",
"controller": "Rest\\Controllers\\SummaryControllerProvider"
}
}
Loading

0 comments on commit be9fff1

Please sign in to comment.