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

Bug 1813987: Exporting views with grid layout

In exporting section:
/export/index.php

- Show preview of page both for old layout pages and
new grid layout
- Export views and collections with new grid layout
in html
- Export views and collections with new grid layout
in leap2A
- views with old layout are exported as before

NOTE
borrow some code from https://reviews.mahara.org/#/c/10157/
as an early rebase (the patch is not on master yet)

behatnotneeded

Change-Id: I0c36c110c6b9ef7ae3edc4d0662a0dbab302684a
parent 7b17b833
......@@ -51,7 +51,7 @@ class PluginExportHtml extends PluginExport {
* These javascript files will be included in index.html via the
* export/html/templates/header.tpl
*/
private $scripts = array('jquery', 'bootstrap.min', 'dock', 'modal');
private $scripts = array('jquery', 'bootstrap.min', 'dock', 'modal', 'lodash', 'gridstack', 'gridlayout');
/**
* constructor. overrides the parent class
......@@ -418,8 +418,13 @@ class PluginExportHtml extends PluginExport {
}
$smarty->assign('feedback', $feedback);
}
$smarty->assign('view', $outputfilter->filter($view->build_rows(false, true)));
if (!$view->uses_new_layout()) {
$smarty->assign('view', $outputfilter->filter($view->build_rows(false, true)));
}
else {
$smarty->assign('newlayout', true);
$smarty->assign('blocks', $view->get_blocks(false, true));
}
$content = $smarty->fetch('export:html:view.tpl');
if (!file_put_contents("$directory/index.html", $content)) {
throw new SystemException("Could not write view page for view $viewid");
......@@ -805,6 +810,9 @@ private function get_folder_modals(&$idarray, BlockInstance $bi) {
$jsdir = $staticdir . 'theme/' . $theme . '/static/js/';
$directoriestocopy[get_config('docroot') . 'lib/bootstrap/assets/javascripts/bootstrap.min.js'] = $jsdir . 'bootstrap.min.js';
$directoriestocopy[get_config('docroot') . 'js/jquery/jquery.js'] = $jsdir . 'jquery.js';
$directoriestocopy[get_config('docroot') . 'js/lodash/lodash.js'] = $jsdir . 'lodash.js';
$directoriestocopy[get_config('docroot') . 'js/gridstack/gridstack.js'] = $jsdir . 'gridstack.js';
$directoriestocopy[get_config('docroot') . 'js/gridlayout.js'] = $jsdir . 'gridlayout.js';
foreach ($this->pluginstaticdirs as $dir) {
$destinationdir = str_replace('export/html/', '', $dir);
......
......@@ -72,7 +72,13 @@ if ($viewids = get_column_sql('SELECT id FROM {view} WHERE owner = ? AND type =
'viewlink' => $view->get_url(true, true),
);
}
$jsfiles = array('js/preview.js', 'js/export.js');
$jsfiles = array(
'js/preview.js',
'js/export.js',
'js/lodash/lodash.js',
'js/gridstack/gridstack.js',
'js/gridlayout.js',
);
$collections = get_records_sql_array('
SELECT c.id, c.name, c.description
......
......@@ -290,17 +290,27 @@ class PluginExportLeap extends PluginExport {
}
$this->smarty->assign('contenttype', 'xhtml');
if ($viewcontent = self::parse_xhtmlish_content($view->build_rows(false, true), $view->get('id'))) {
$this->smarty->assign('content', clean_html($viewcontent, true));
if (!$view->uses_new_layout()) {
if ($viewcontent = self::parse_xhtmlish_content($view->build_rows(false, true), $view->get('id'))) {
$this->smarty->assign('content', clean_html($viewcontent, true));
}
$this->smarty->assign('viewdata', $config['rows']);
$layout = $view->get_layout();
$widths = '';
foreach ($layout->rows as $row){
$widths .= $row['widths'] . '-';
}
$widths = substr($widths, 0, -1);
$this->smarty->assign('layout', $widths);
}
$this->smarty->assign('viewdata', $config['rows']);
$layout = $view->get_layout();
$widths = '';
foreach ($layout->rows as $row){
$widths .= $row['widths'] . '-';
else {
if ($viewblocks = self::parse_xhtmlish_content($view->get_blocks(false, true), $view->get('id'))) {
$this->smarty->assign('content', clean_html($viewblocks, true));
$this->smarty->assign('blocks', $config['grid']);
}
$this->smarty->assign('newlayout', true);
}
$widths = substr($widths, 0, -1);
$this->smarty->assign('layout', $widths);
$this->smarty->assign('type', $config['type']);
$ownerformat = ($config['ownerformat']) ? $config['ownerformat'] : FORMAT_NAME_DISPLAYNAME;
$this->smarty->assign('ownerformat', $ownerformat);
......@@ -466,27 +476,49 @@ class PluginExportLeap extends PluginExport {
* this limitation later.
*/
private function rewrite_artefact_ids($config) {
foreach ($config['rows'] as &$row) {
foreach ($row['columns'] as &$column) {
$newlayout = isset($config['newlayout']) && $config['newlayout'];
if (!$newlayout) {
foreach ($config['rows'] as &$row) {
foreach ($row['columns'] as &$column) {
foreach ($column as &$blockinstance) {
if (isset($blockinstance['config']['artefactid'])) {
$id = json_decode($blockinstance['config']['artefactid']);
if ($id[0] != null) {
$blockinstance['config']['artefactid'] = json_encode(array('portfolio:artefact' . $id[0]));
}
else {
$blockinstance['config']['artefactid'] = null;
}
if (isset($blockinstance['config']['artefactid'])) {
$id = json_decode($blockinstance['config']['artefactid']);
if ($id[0] != null) {
$blockinstance['config']['artefactid'] = json_encode(array('portfolio:artefact' . $id[0]));
}
else if (isset($blockinstance['config']['artefactids'])) {
$ids = json_decode($blockinstance['config']['artefactids']);
if ($ids[0]) {
$blockinstance['config']['artefactids'] = json_encode(array(array_map(array($this, 'prepend_artefact_identifier'), $ids[0])));
}
else {
$blockinstance['config']['artefactid'] = null;
}
}
else if (isset($blockinstance['config']['artefactids'])) {
$ids = json_decode($blockinstance['config']['artefactids']);
if ($ids[0]) {
$blockinstance['config']['artefactids'] = json_encode(array(array_map(array($this, 'prepend_artefact_identifier'), $ids[0])));
}
}
}
} // cols
} //rows
}
else {
foreach ($config['grid'] as &$blockinstance) {
if (isset($blockinstance['config']['artefactid'])) {
$id = json_decode($blockinstance['config']['artefactid']);
if ($id[0] != null) {
$blockinstance['config']['artefactid'] = json_encode(array('portfolio:artefact' . $id[0]));
}
else {
$blockinstance['config']['artefactid'] = null;
}
} // cols
} //rows
}
else if (isset($blockinstance['config']['artefactids'])) {
$ids = json_decode($blockinstance['config']['artefactids']);
if ($ids[0]) {
$blockinstance['config']['artefactids'] = json_encode(array(array_map(array($this, 'prepend_artefact_identifier'), $ids[0])));
}
}
}
}
return $config;
}
......@@ -639,10 +671,23 @@ class PluginExportLeap extends PluginExport {
$dom = new DomDocument();
$topel = $dom->createElement('tmp');
$tmp = new DomDocument();
if (strpos($content, '<') === false && strpos($content, '>') === false) {
libxml_after();
return false;
if (is_array($content)) {
$contenthtml = '';
foreach ($content as $block) {
if (strpos($block['content'], '<') === false && strpos($block['content'], '>') === false) {
continue;
}
$contenthtml .= '<div id="block_' . $block['id'] . '"' .
' positionx=' . $block['positionx'] .
' positiony=' . $block['positiony'] .
' width=' . $block['width'] .
' height=' . $block['height'] . '>' .
$block['content'] . '</div>';
}
$content = $contenthtml;
}
if (@$tmp->loadXML('<div>' . $content . '</div>')) {
$topel->setAttribute('type', 'xhtml');
$content = $dom->importNode($tmp->documentElement, true);
......
This diff is collapsed.
......@@ -64,6 +64,7 @@ class View {
private $instructions;
private $instructionscollapsed=0;
private $newlayout = 1;
private $grid;
const UNSUBMITTED = 0;
const SUBMITTED = 1;
......@@ -2179,7 +2180,7 @@ public function get_blocks($editing=false, $exporting=false, $versioning=false)
else {
$blocks = $versioning->blocks;
}
$this->grid = array();
if (is_array($blocks) || is_object($blocks)) {
foreach ($blocks as $block) {
require_once(get_config('docroot') . 'blocktype/lib.php');
......@@ -3156,33 +3157,61 @@ public function get_blocks($editing=false, $exporting=false, $versioning=false)
'title' => $this->get('title'),
'description' => $this->get('description'),
'type' => $this->get('type'),
'layout' => $this->get('layout'),
'tags' => $this->get('tags'),
'numrows' => $this->get('numrows'),
'ownerformat' => $this->get('ownerformat'),
'instructions' => $this->get('instructions'),
);
// Export view content
$data = $this->get_row_datastructure();
foreach ($data as $rowkey => $row) {
foreach ($row as $colkey => $column) {
if (!$this->uses_new_layout()) {
$config['layout'] = $this->get('layout');
$config['numrows'] = $this->get('numrows');
// Export view content
$data = $this->get_row_datastructure();
foreach ($data as $rowkey => $row) {
foreach ($row as $colkey => $column) {
$config['rows'][$rowkey]['columns'][$colkey] = array();
foreach ($column['blockinstances'] as $bi) {
safe_require('blocktype', $bi->get('blocktype'));
$classname = generate_class_name('blocktype', $bi->get('blocktype'));
$method = 'export_blockinstance_config';
if (method_exists($classname, $method . "_$format")) {
$method .= "_$format";
}
$config['rows'][$rowkey]['columns'][$colkey][] = array(
'blocktype' => $bi->get('blocktype'),
'title' => $bi->get('title'),
'config' => call_static_method($classname, $method, $bi),
);
}
} // cols
} // rows
safe_require('blocktype', $bi->get('blocktype'));
$classname = generate_class_name('blocktype', $bi->get('blocktype'));
$method = 'export_blockinstance_config';
if (method_exists($classname, $method . "_$format")) {
$method .= "_$format";
}
$config['rows'][$rowkey]['columns'][$colkey][] = array(
'blocktype' => $bi->get('blocktype'),
'title' => $bi->get('title'),
'config' => call_static_method($classname, $method, $bi),
);
}
} // cols
} // rows
}
else {
$config['newlayout'] = true;
// Export view content
$this->get_blocks(false, true);
$data = $this->grid;
$config['grid'] = array();
foreach ($data as $bi) {
safe_require('blocktype', $bi->get('blocktype'));
$classname = generate_class_name('blocktype', $bi->get('blocktype'));
$method = 'export_blockinstance_config';
if (method_exists($classname, $method . "_$format")) {
$method .= "_$format";
}
$config['grid'][] = array(
'blocktype' => $bi->get('blocktype'),
'title' => $bi->get('title'),
'positionx' => $bi->get('positionx'),
'positiony' => $bi->get('positiony'),
'height' => $bi->get('height'),
'width' => $bi->get('width'),
'config' => call_static_method($classname, $method, $bi),
);
}
}
return $config;
}
......
......@@ -11,7 +11,7 @@ function modal_handler(e) {
$(modal).find('.feedbacktable .list-group-lite').addClass('fullwidth');
}
jQuery(function($) {
jQuery(window).on('blocksloaded', {}, function() {
"use strict";
$('[data-target="#configureblock"]').each(function(i, obj) {
......
{include file="export:html:header.tpl"}
{if $newlayout}
<script>
$(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 = {json_encode arg=$blocks};
loadGrid(grid, blocks);
jQuery(document).trigger('blocksloaded');
});
</script>
{/if}
{if $collectionmenu}
<div class="breadcrumbs collection">
<ul>
......@@ -20,7 +40,19 @@
</div>
{/if}
{$view|safe}
{if $view}
{$view|safe}
{elseif !$blocks}
<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>
{else}
<div class="container-fluid">
<div class="grid-stack">
</div>
</div>
{/if}
{if $feedback && $feedback->count}
<div class="viewfooter">
......
{include file="export:leap:entry.tpl" skipfooter=true}
<mahara:view{if $layout} mahara:layout="{$layout}"{/if}{if $type} mahara:type="{$type}"{/if} mahara:ownerformat="{$ownerformat}">
{foreach from=$viewdata item=row}
<mahara:row>
{foreach from=$row['columns'] item=column}
<mahara:view{if $newlayout} mahara:newlayout="1"{/if}{if $layout} mahara:layout="{$layout}"{/if}{if $type} mahara:type="{$type}"{/if} mahara:ownerformat="{$ownerformat}">
{if !$newlayout}
{foreach from=$viewdata item=row}
<mahara:row>
{foreach from=$row['columns'] item=column}
<mahara:column>
{foreach from=$column item=blockinstance}
{foreach from=$column item=blockinstance}
<mahara:blockinstance mahara:blocktype="{$blockinstance.blocktype}" mahara:blocktitle="{$blockinstance.title}">
{foreach from=$blockinstance.config key=fieldname item=fieldvalue}
{foreach from=$blockinstance.config key=fieldname item=fieldvalue}
<mahara:{$fieldname}>{$fieldvalue}</mahara:{$fieldname}>
{/foreach}
{/foreach}
</mahara:blockinstance>
{/foreach}
{/foreach}
</mahara:column>
{/foreach}
</mahara:row>
{/foreach}
{/foreach}
</mahara:row>
{/foreach}
{else}
{foreach from=$blocks item=bi}
<mahara:blockinstance mahara:blocktype="{$bi.blocktype}" mahara:blocktitle="{$bi.title}" mahara:positionx="{$bi.positionx}" mahara:positiony="{$bi.positiony}" mahara:height="{$bi.height}" mahara:width="{$bi.width}">
{foreach from=$bi.config key=fieldname item=fieldvalue}
<mahara:{$fieldname}>{$fieldvalue}</mahara:{$fieldname}>
{/foreach}
</mahara:blockinstance>
{/foreach}
{/if}
</mahara:view>
{include file="export:leap:entryfooter.tpl"}
<h2>
{$viewtitle}
{if $ownername}
{str tag=by section=view}
{$ownername}
{/if}
</h2>
<p class="view-description">
{$viewdescription|clean_html|safe}
</p>
<p class="view-instructions">
{$viewinstructions|clean_html|safe}
</p>
<div id="view" class="view-container">
<div id="bottom-pane">
<div id="column-container">
{$viewcontent|safe}
</div>
</div>
{if $tags}
<div class="viewfooter">
<div class="tags">
<strong>{str tag=tags}:</strong>
{list_tags owner=0 tags=$tags}
{if $newlayout}
<script>
$(function () {
var options = {
verticalMargin: 10,
float: true,
ddPlugin: false,
};
var grid = $('.grid-stack');
grid.gridstack(options);console.log(grid);
grid = $('.grid-stack').data('gridstack');
// should add the blocks one by one
var blocks = {json_encode arg=$blocks};
loadGrid(grid, blocks);
jQuery(document).trigger('blocksloaded');
});
</script>
{/if}
<h2>
{$viewtitle}
{if $ownername}
{str tag=by section=view}
{$ownername}
{/if}
</h2>
<p class="view-description">
{$viewdescription|clean_html|safe}
</p>
<p class="view-instructions">
{$viewinstructions|clean_html|safe}
</p>
<div id="view" class="view-container">
<div id="bottom-pane">
<div id="column-container">
<div class="container-fluid">
<div class="grid-stack">
{if $viewcontent}
{$viewcontent|safe}
{/if}
</div>
</div>
</div>
</div>
{if $tags}
<div class="viewfooter">
<div class="tags">
<strong>{str tag=tags}:</strong>
{list_tags owner=0 tags=$tags}
</div>
</div>
{/if}
{/if}
</div>
......@@ -26,7 +26,14 @@ $smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('ownername', $view->formatted_owner());
$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', $view->build_rows(false, true));
if (!$view->uses_new_layout()) {
$smarty->assign('viewcontent', $view->build_rows(false, true));
}
else {
$smarty->assign('newlayout', true);
$smarty->assign('blocks', $view->get_blocks());
}
list($tagcount, $alltags) = $view->get_all_tags_for_view();
$smarty->assign('tags', $alltags);
......
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