Commit c0f57e7d authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon

Bug 1813987: Display a page in view mode

The blocks saved with the new layout
are now displayed in page edit and view mode

behatnotneeded

Change-Id: Ic8c1011745593be552cc1a4377a7351cc9a04bb9
parent 6cee4292
......@@ -364,7 +364,7 @@ function toggleDetailsBtn() {
$('#details-btn').off('click');
$('#details-btn').on('click', function(e) {
var detailsActive = 0;
var headers = $('#main-column-container').find('.block-header');
var headers = $('#column-container').find('.block-header');
if (!$('#details-btn').hasClass('active')) {
$('#details-btn').addClass('active');
......
......@@ -257,9 +257,21 @@
});
}
//Private Methods
/////////////////
function init() {
ViewManager.init = function(grid, blocks) {
// load blocks for view in edit mode
$.each(blocks, function(blockid, block) {
grid.addWidget(
$('<div id="block_' + blockid + '"><div class="grid-stack-item-content">'
+ block.content +
'<div/><div/>'),
block.positionx,
block.positiony,
block.width,
block.height,
null, null, null, null, null,
blockid);
});
// Set private variables
contentEditor = $('[data-role="content-toolbar"]');
......@@ -323,6 +335,8 @@
} // init
//Private Methods
/////////////////
function equalHeights (){
var rows = $('.js-col-row'),
......@@ -343,7 +357,6 @@
}
}
function attachAccordion(){
// Update the status of a collapsible block category by adding/removing class 'expanded'
$j('div#content-editor-foldable div.block-category-title').on('click', function() {
......@@ -939,7 +952,6 @@
*
*/
$(function() {
init();
/**
* changes the intructions so they are for ajax
*/
......@@ -983,6 +995,10 @@ function wire_blockoptions() {
return ViewManager.blockOptions();
}
function init(grid, blocks) {
return ViewManager.init(grid, blocks);
}
/* GRIDSTACK functions */
function addNewWidget(blockContent, grid, dimensions) {
var node = {
......
......@@ -2180,7 +2180,11 @@ class View {
}
public function get_grid_datastructure() {
/**
* Gets the view blocks in an array to be easily loaded in js gridstack
* @param boolean $editing whether we are in the edit more or not
*/
public function get_blocks($editing=false) {
$sql = '
SELECT bi.id, bi.view,positionx, positiony, width, height, blocktype, title, configdata
FROM {block_instance_dimension} bd
......@@ -2203,17 +2207,22 @@ class View {
}
}
$blockcontent = '';
$blockcontent = array();
foreach($this->grid as $blockinstance) {
$result = $blockinstance->render_editing();
$smarty = smarty_core();
$smarty->assign('blockcontent', $result['html']);
$smarty->assign('id', $blockinstance->get('id'));
$smarty->assign('width', $blockinstance->get('width'));
$smarty->assign('height', $blockinstance->get('height'));
$smarty->assign('positionx', $blockinstance->get('positionx'));
$smarty->assign('positiony', $blockinstance->get('positiony'));
$blockcontent .= $smarty->fetch('view/gridcell.tpl');
if ($editing) {
$result = $blockinstance->render_editing();
$result = $result['html'];
}
else {
$result = $blockinstance->render_viewing();
}
$block = array();
$block['content'] = $result;
$block['width'] = $blockinstance->get('width');
$block['height'] = $blockinstance->get('height');
$block['positionx'] = $blockinstance->get('positionx');
$block['positiony'] = $blockinstance->get('positiony');
$blockcontent[$blockinstance->get('id')] = $block;
}
return $blockcontent;
}
......@@ -2264,20 +2273,36 @@ class View {
* Returns the HTML for the rows of this view
*/
public function build_rows($editing=false, $exporting=false, $versioning=false) {
if (get_config('new_layout')) {
$result = $this->get_grid_datastructure();
}
else {
$numrows = $this->get('numrows');
$result = '';
for ($i = 1; $i <= $numrows; $i++) {
$result .= $this->build_columns($i, $editing, $exporting, $versioning);
}
$numrows = $this->get('numrows');
$result = '';
for ($i = 1; $i <= $numrows; $i++) {
$result .= $this->build_columns($i, $editing, $exporting, $versioning);
}
return $result;
}
/**
* Checks if the view is using the new layout
* A view uses the new layout if has data on the new layout tables
* or if doesn't have any blocks
*/
public function uses_new_layout() {
$viewid = $this->get('id');
$sql = "SELECT DISTINCT view FROM {block_instance} bi
INNER JOIN {block_instance_dimension} bd
ON bi.id = bd.block
WHERE bi.view = ?";
$usesnewlayout = get_field_sql($sql, array($viewid));
$sql = "SELECT DISTINCT view
FROM {block_instance}
WHERE view = ? ";
$hasblocks = get_field_sql($sql, array($viewid));
return ($usesnewlayout || !$hasblocks);
}
/**
* Returns the HTML for the columns of this view
*/
......
......@@ -45,9 +45,12 @@
<div class="col">
<div id="bottom-pane" data-role="workspace">
<div id="column-container" class="user-page-content">
{if $newlayout}
<div class="grid-stack">
{$columns|safe}
</div>
{else}
{$columns|safe}
{/if}
</div>
</div>
</div>
......
......@@ -26,14 +26,13 @@
<div id="view" class="view-container">
<div id="bottom-pane">
<div id="column-container" class="user-page-content">
{if $viewcontent}
{$viewcontent|safe}
{else}
<div class="alert alert-info">
<span class="icon icon-lg icon-info-circle left" role="presentation" aria-hidden="true"></span>
{str tag=nopeerassessmentrequired section=artefact.peerassessment}
<div class="container-fluid">
<div class="grid-stack">
{if $viewcontent}
{$viewcontent|safe}
{/if}
</div>
{/if}
</div>
</div>
</div>
<div class="viewfooter view-container">
......
......@@ -161,19 +161,30 @@ require_once('pieforms/pieform/elements/select.php');
$inlinejs .= pieform_element_select_get_inlinejs();
$inlinejs .= "jQuery(window).on('pageupdated', {}, function() { dock.init(jQuery(document)); });";
$inlinejs .="
$(function () {
var options = {
verticalMargin: 10,
float: true, //to place a block in any part of the page and the position will remain fixed
resizable: false,
};
var grid = $('.grid-stack');
grid.gridstack(options);
grid = $('.grid-stack').data('gridstack');
grid.resizable('.grid-stack-item', true);
});
";
if ($newlayout = $view->uses_new_layout()) {
$blocks = $view->get_blocks(true);
$blocksencode = json_encode($blocks);
$inlinejs .="
$(function () {
var options = {
verticalMargin: 10,
float: true, //to place a block in any part of the page and the position will remain fixed
resizable: false,
};
var grid = $('.grid-stack');
grid.gridstack(options);
grid = $('.grid-stack').data('gridstack');
grid.resizable('.grid-stack-item', true);
// should add the blocks one by one
var blocks = {$blocksencode};
init(grid, blocks);
});
";
}
else {
// Build content before initialising smarty in case pieform elements define headers.
$viewcontent = $view->build_rows(true);
}
// The form for adding blocks via the keyboard
$addform = pieform(array(
......@@ -197,8 +208,6 @@ $addform = pieform(array(
),
));
// Build content before initialising smarty in case pieform elements define headers.
$viewcontent = $view->build_rows(true);
// Get the placeholder block info
$placeholderblock = PluginBlockType::get_blocktypes_for_category('shortcut', $view, 'placeholder');
......@@ -280,9 +289,12 @@ if ($collection = $view->get('collection')) {
}
$smarty->assign('collectionid', $collectionid);
// The HTML for the columns in the view
$columns = $viewcontent;
$smarty->assign('columns', $columns);
$smarty->assign('newlayout', $newlayout);
if (!$newlayout) {
// The HTML for the columns in the view
$columns = $viewcontent;
$smarty->assign('columns', $columns);
}
$smarty->assign('issiteview', isset($institution) && ($institution == 'mahara'));
......
......@@ -262,7 +262,13 @@ function releaseview_submit() {
redirect($view->get_url());
}
$javascript = array('paginator', 'viewmenu', 'js/collection-navigation.js', 'js/jquery/jquery-mobile/jquery.mobile.custom.min.js', 'js/jquery/jquery-ui/js/jquery-ui.min.js');
$javascript = array('paginator', 'viewmenu', 'js/collection-navigation.js',
'js/jquery/jquery-mobile/jquery.mobile.custom.min.js',
'js/jquery/jquery-ui/js/jquery-ui.min.js',
'js/lodash/lodash.js',
'js/gridstack/gridstack.js',
'js/gridstack/gridstack.jQueryUI.js',
);
$blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
if (is_plugin_active('externalvideo', 'blocktype')) {
......@@ -347,7 +353,40 @@ if ($owner && $owner == $USER->get('id')) {
// if the view doesn't have a peer assessment block
if (!$USER->has_peer_role_only($view) || $view->has_peer_assessement_block()
|| ($USER->is_admin_for_user($view->get('owner')) && $view->is_objectionable())) {
$viewcontent = $view->build_rows(); // Build content before initialising smarty in case pieform elements define headers.
if ($newlayout = $view->uses_new_layout()) {
$blocks = $view->get_blocks();
$blocks = json_encode($blocks);
$blocksjs = <<<EOF
$(function () {
var options = {
verticalMargin: 10,
float: true,
ddPlugin: false,
};
var grid = $('.grid-stack');
grid.gridstack(options);
grid = $('.grid-stack').data('gridstack');
// should add the blocks one by one
var blocks = {$blocks};
$.each(blocks, function(blockid, block) {
grid.addWidget(
$('<div id="block_' + blockid + '"><div class="grid-stack-item-content">'
+ block.content +
'<div/><div/>'),
block.positionx,
block.positiony,
block.width,
block.height,
null, null, null, null, null,
blockid);
});
});
EOF;
}
else {
$viewcontent = $view->build_rows(); // Build content before initialising smarty in case pieform elements define headers.
}
}
$smarty = smarty(
......@@ -474,7 +513,7 @@ EOF;
if ($showdetails = get_account_preference($USER->get('id'), 'view_details_active')) {
$javascript .= <<<EOF
jQuery(function($) {
var headers = $('#main-column-container').find('.block-header');
var headers = $('#column-container').find('.block-header');
$('#details-btn').addClass('active');
headers.removeClass('d-none');
});
......@@ -500,7 +539,7 @@ if (!empty($blocktype_toolbar['toolbarhtml'])) {
$smarty->assign('toolbarhtml', join("\n", $blocktype_toolbar['toolbarhtml']));
}
$smarty->assign('canremove', $can_edit);
$smarty->assign('INLINEJAVASCRIPT', $javascript . $inlinejs);
$smarty->assign('INLINEJAVASCRIPT', $javascript . $inlinejs . $blocksjs);
$smarty->assign('viewid', $viewid);
$smarty->assign('viewtype', $viewtype);
$smarty->assign('feedback', $feedback);
......@@ -578,7 +617,13 @@ if ($showmnetlink) {
$smarty->assign('viewdescription', ArtefactTypeFolder::append_view_url($view->get('description'), $view->get('id')));
$smarty->assign('viewinstructions', ArtefactTypeFolder::append_view_url($view->get('instructions'), $view->get('id')));
$smarty->assign('viewcontent', (isset($viewcontent) ? $viewcontent : null));
$smarty->assign('newlayout', $newlayout);
if ($newlayout) {
$smarty->assign('blocks', (isset($blocks) ? $blocks : null));
}
else {
$smarty->assign('viewcontent', (isset($viewcontent) ? $viewcontent : null));
}
$smarty->assign('releaseform', $releaseform);
if (isset($ltisubmissionform)) {
$smarty->assign('ltisubmissionform', $ltisubmissionform);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment