-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #909 from jpwhite4/novice_user_pull
Initial Prototype of Novice User Portal
- Loading branch information
Showing
14 changed files
with
815 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
{ | ||
"xdmod": { | ||
"portal": { | ||
"js": [ | ||
"gui/js/modules/summary/ChartPortlet.js" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"summary": { | ||
"prefix": "summary", | ||
"controller": "Rest\\Controllers\\SummaryControllerProvider" | ||
} | ||
} |
Oops, something went wrong.