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

Bug 1813987: Make view versioning work with gridstack

- Only allow to create a new version if the view
is using new gridstack layout.

In timeline version section:
- For view versions that were created with old layout,
show them as they are
(we dont translate old view versions to new layout)
- For view versions that are created with new grid layout,
they are also displayed in the timeline view with the new grid
layout

behatnotneeded

Change-Id: I1abdae9e5e547dcc9bce97cac127085786dcac8a
parent f342e41b
......@@ -268,6 +268,7 @@ $string['cantversionviewinvalid'] = 'The supplied page identifier is invalid.';
$string['cantversionvieweditpermissions'] = 'You do not permission to edit this page.';
$string['cantversionviewsubmitted'] = 'You cannot edit this page because it has been submitted for assessment. You will have to wait until it is released.';
$string['cantversionviewgroupeditwindow'] = 'You cannot edit this page. It is outside of the group editable date window.';
$string['cantversionoldlayout'] = 'You cannot save a timeline version of a view with an old layout. You need to convert it to the new grid layout. To do this simply edit the page and the layout will be converted.';
$string['invalidcolumn'] = 'Column %s out of range';
......
......@@ -2160,11 +2160,12 @@ class View {
}
/**
* 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) {
/**
* 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, $exporting=false, $versioning=false) {
if (!$versioning) {
$sql = '
SELECT bi.id, bi.view, bi.row, bi.column, bi.order,
positionx, positiony, width, height, blocktype, title, configdata
......@@ -2174,49 +2175,66 @@ class View {
WHERE bi.view = ?
ORDER BY bi.row, bi.column, bi.order';
$blocks = get_records_sql_array($sql, array($this->get('id')));
}
else {
$blocks = $versioning->blocks;
}
if (is_array($blocks) || is_object($blocks)) {
foreach ($blocks as $block) {
require_once(get_config('docroot') . 'blocktype/lib.php');
$block->view_obj = $this;
$b = new BlockInstance($block->id, (array)$block);
if (is_array($blocks) || is_object($blocks)) {
foreach ($blocks as $block) {
require_once(get_config('docroot') . 'blocktype/lib.php');
$block = (object)$block;
$block->view = $this->get('id');
$block->view_obj = $this;
if (!$versioning) {
$blockid = $block->id;
}
else {
$blockid = $block->originalblockid;
}
$b = new BlockInstance($blockid, (array)$block);
if (isset($versioning->newlayout)) {
$b->set('positionx', $block->positionx);
$b->set('positiony', $block->positiony);
$b->set('width', $block->width);
$b->set('height', $block->height);
$b->set('configdata', (array)$block->configdata);
}
else {
$b->set('row', $block->row);
$b->set('column', $block->column);
$b->set('order', $block->order);
$this->grid[]=$b;
}
$this->grid[]=$b;
}
}
$blockcontent = array();
foreach($this->grid as $blockinstance) {
$block = array();
if ($editing) {
$result = $blockinstance->render_editing();
$result = $result['html'];
}
else {
$result = $blockinstance->render_viewing();
if (call_static_method(generate_class_name('blocktype', $blockinstance->get('blocktype')), 'has_static_content')) {
$block['class'] = 'staticblock';
}
}
$block['content'] = $result;
$block['width'] = $blockinstance->get('width');
$block['height'] = $blockinstance->get('height');
$block['positionx'] = $blockinstance->get('positionx');
$block['positiony'] = $blockinstance->get('positiony');
$block['row'] = $blockinstance->get('row');
$block['column'] = $blockinstance->get('column');
$block['order'] = $blockinstance->get('order');
$block['id'] = $blockinstance->get('id');
$blockcontent[] = $block;
$blockcontent = array();
foreach($this->grid as $blockinstance) {
$block = array();
if ($editing) {
$result = $blockinstance->render_editing();
$result = $result['html'];
}
return $blockcontent;
}
else {
$result = $blockinstance->render_viewing($exporting, $versioning);
if (call_static_method(generate_class_name('blocktype', $blockinstance->get('blocktype')), 'has_static_content')) {
$block['class'] = 'staticblock';
}
}
$block['content'] = $result;
$block['width'] = $blockinstance->get('width');
$block['height'] = $blockinstance->get('height');
$block['positionx'] = $blockinstance->get('positionx');
$block['positiony'] = $blockinstance->get('positiony');
$block['row'] = $blockinstance->get('row');
$block['column'] = $blockinstance->get('column');
$block['order'] = $blockinstance->get('order');
$block['id'] = $blockinstance->get('id');
$blockcontent[] = $block;
}
return $blockcontent;
}
/*
*
* wrapper around get_column_datastructure
......@@ -7165,52 +7183,73 @@ class View {
$data = json_decode($data);
$data->version = $versionnumber;
$this->numrows = isset($data->numrows) ? $data->numrows : $this->numrows;
$this->layout = isset($data->layout) ? $data->layout : $this->layout;
$this->description = isset($data->description) ? $data->description : '';
$this->tags = isset($data->tags) && is_array($data->tags) ? $data->tags : array();
$colsperrow = array();
if (isset($data->columnsperrow)) {
foreach ($data->columnsperrow as $k => $v) {
$colsperrow[$k] = $v;
if (!isset($data->newlayout)) {
$this->numrows = isset($data->numrows) ? $data->numrows : $this->numrows;
$this->layout = isset($data->layout) ? $data->layout : $this->layout;
$colsperrow = array();
if (isset($data->columnsperrow)) {
foreach ($data->columnsperrow as $k => $v) {
$colsperrow[$k] = $v;
}
}
}
$this->columnsperrow = $colsperrow;
$this->columns = array();
$layout = $this->get_layout();
for ($i = 1; $i <= $this->numrows; $i++) {
$widths = explode(',', $layout->rows[$i]['widths']);
for ($j = 1; $j <= $data->columnsperrow->{$i}->columns; $j++) {
$this->columns[$i][$j] = array('blockinstances' => array());
$this->columns[$i][$j]['width'] = $widths[$j-1];
$this->columnsperrow = $colsperrow;
$this->columns = array();
$layout = $this->get_layout();
for ($i = 1; $i <= $this->numrows; $i++) {
$widths = explode(',', $layout->rows[$i]['widths']);
for ($j = 1; $j <= $data->columnsperrow->{$i}->columns; $j++) {
$this->columns[$i][$j] = array('blockinstances' => array());
$this->columns[$i][$j]['width'] = $widths[$j-1];
}
}
}
$html = '';
if (!empty($data->blocks)) {
require_once(get_config('docroot') . 'blocktype/lib.php');
usort($data->blocks, function($a, $b) { return $a->order > $b->order; });
if (!isset($data->newlayout)) {
usort($data->blocks, function($a, $b) { return $a->order > $b->order; });
}
foreach ($data->blocks as $k => $v) {
safe_require('blocktype', $v->blocktype);
$bi = new BlockInstance(0,
array(
'id' => $v->originalblockid,
'blocktype' => $v->blocktype,
'title' => $v->title,
'view' => $this->get('id'),
'view_obj' => $this,
'row' => $v->row,
'column' => $v->column,
'order' => $v->order,
'configdata' => serialize((array)$v->configdata),
)
$blockdata = array(
'id' => $v->originalblockid,
'blocktype' => $v->blocktype,
'title' => $v->title,
'view' => $this->get('id'),
'view_obj' => $this,
'configdata' => serialize((array)$v->configdata),
);
if (!isset($data->newlayout)) {
$blockdata['row'] = $v->row;
$blockdata['column'] = $v->column;
$blockdata['order'] = $v->order;
}
else {
$blockdata['positionx'] = $v->positionx;
$blockdata['positiony'] = $v->positiony;
$blockdata['height'] = $v->height;
$blockdata['width'] = $v->width;
}
$bi = new BlockInstance(0, $blockdata);
// Add a fake unique id to allow for pagination etc
$this->columns[$v->row][$v->column]['blockinstances'][] = $bi;
if (!isset($data->newlayout)) {
$this->columns[$v->row][$v->column]['blockinstances'][] = $bi;
}
else {
$this->blocks[] = $bi;
}
}
}
if (!$USER->has_peer_role_only($this) || $this->has_peer_assessement_block()) {
$html = $this->build_rows(false, false, $data);
if (!isset($data->newlayout)) {
$html = $this->build_rows(false, false, $data);
}
else {
$html = $this->get_blocks(false, false, $data);
}
}
else {
$html = '<div class="alert alert-info">
......
......@@ -39,7 +39,25 @@
},
formatTitle: function (title, obj) { return '<h3>' + title + '</h3>'; },
formatSubTitle: function (subTitle, obj) { return '<div class="metadata">' + subTitle + '</div>'; },
formatBodyContent: function (bodyCnt, obj) { return bodyCnt;}
formatBodyContent: function (bodyCnt, obj) {
if (obj.gridlayout) {
var grid = $('<div class="grid-stack"></div>');
var options = {
verticalMargin: 10,
float: true,
ddPlugin: false,
};
grid.gridstack(options);
grid = grid.data('gridstack');
loadGrid(grid, bodyCnt);
var container = $('<div class="container-fluid"></div>').append(grid.container);
return container[0].outerHTML;
}
else {
return bodyCnt;
}
}
});
});
</script>
......
......@@ -31,13 +31,15 @@ if ($groupid && !group_within_edit_window($groupid)) {
throw new AccessDeniedException(get_string('cantversionviewgroupeditwindow', 'view'));
}
if (!$view->uses_new_layout()) {
throw new AccessDeniedException(get_string('cantversionoldlayout', 'view'));
}
$version = new stdClass();
$version->numrows = $view->get('numrows');
$version->layout = $view->get('layout');
$version->description = $view->get('description');
$version->title = $view->get('title');
$version->tags = $view->get('tags');
$version->columnsperrow = $view->get('columnsperrow');
$version->newlayout = true;
$version->blocks = array();
$blocks = get_records_array('block_instance', 'view', $view->get('id'));
......@@ -51,9 +53,10 @@ if ($blocks) {
$bi->blocktype = $oldblock->get('blocktype');
$bi->title = $oldblock->get('title');
$bi->configdata = $oldblock->get('configdata');
$bi->row = $oldblock->get('row');
$bi->column = $oldblock->get('column');
$bi->order = $oldblock->get('order');
$bi->positionx = $oldblock->get('positionx');
$bi->positiony = $oldblock->get('positiony');
$bi->width = $oldblock->get('width');
$bi->height = $oldblock->get('height');
$classname = generate_class_name('blocktype', $oldblock->get('blocktype'));
if (is_callable($classname . '::'. 'get_current_artefacts')) {
......
......@@ -44,6 +44,7 @@ if ($versions->count > 0) {
"assignID" => $value->id,
"taskShortDate" => date('j F', strtotime($value->ctime)),
"taskDetails" => $value->blockdata_formatted->html,
"gridlayout" => isset($value->blockdata_formatted->newlayout),
);
}
}
......
......@@ -50,7 +50,14 @@ if ($versions->total == 0) {
$form = View::get_timeline_form($view, $fromdate, $todate);
$smarty = smarty(array('paginator', 'js/jquery/jquery-ui/js/jquery-ui.min.js', 'js/jTLine/js/jtline.js'), array(), array('view' => array(
$smarty = smarty(array('paginator',
'js/jquery/jquery-ui/js/jquery-ui.min.js',
'js/jTLine/js/jtline.js',
'js/lodash/lodash.js',
'js/gridstack/gridstack.js',
'js/gridlayout.js'),
array(),
array('view' => array(
'versionnumber',
'gotonextversion',
'gotopreviousversion',
......
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