Commit fb9c7fc4 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge changes from topic 'WR 303474'

* changes:
  Bug 1813987: Tidying up some lastminute problems
  Bug 1813987: checking old layout tables exists before using them
  Bug 1827445: db_table_exists alternative without changing SQL exceptions
  Bug 1813987: removing layout tables from install
  Bug 1813987: Behat - block creation
  Bug 1813987: Blocks display fixes
  Bug 1813987: Accessibility settings and layout
  Bug 1813987: User should confirm before the view is translated
  Bug 1813987: Creating a view via tags with gridstack
  Bug 1813987: Importing views with grid layout
  Bug 1813987: Exporting views with grid layout
  Bug 1813987: Make view versioning work with gridstack
  Bug 1813987: Copying a page (in old or new layout) creates a page with new layout
  Bug 1813987: Translate old views to new gridstack layout on edit
  Bug 1813987: Making magic block work with gridstack layout
  Bug 1813987: Upgrade to translate site views to new layout
  Bug 1813987: create a block- fixing the saving of a new block
  Bug 1813987: block resizing to fit content
  Bug 1813987: remove layout button from navigation
  Bug 1813987: Display Dashboard and profile page
  Bug 1813987: removing old layout from mahara install
  Bug 1813987: Make the comment block work
  Bug 1813987: Display a page in view mode
  Bug 1813987: allow to choose add block to bottom/top of the grid
  Bug 1813987: Creating a new page with gristack layout
  Bug 1813987: removing helper functions to reorder cells in old layout
  Bug 1813987: Remove 'addcolumn' functionality when editing a view
  Bug 1813987: Remove edit layout section
  Bug 1813987: Creating tables for gridstack page blocks
  Bug 1813987: Adding gristack library
parents 8ccb6979 fa4085d5
......@@ -180,7 +180,9 @@ if ($institution || $add) {
delete_records('institution_registration', 'institution', $values['i']);
delete_records('site_content', 'institution', $values['i']);
delete_records('institution_config', 'institution', $values['i']);
delete_records('usr_custom_layout', 'institution', $values['i']);
if (db_table_exists('usr_custom_layout')) {
delete_records('usr_custom_layout', 'institution', $values['i']);
}
delete_records('usr_registration', 'institution', $values['i']);
if ($versions = get_records_assoc('site_content_version', 'institution', $values['i'])) {
foreach($versions as $version) {
......
......@@ -115,3 +115,23 @@ function addAnnotationFeedbackError(form, data) {
jQuery('#' + id).removeClass('closed').addClass('active');
formError(form, data);
}
function show_se_desc(id) {
$("#instconf_smartevidencedesc_container div:not(.description)").addClass('d-none');
$("#option_" + id).removeClass('d-none');
}
function annotationBlockInit() {
if ($("#instconf_smartevidence").length) {
// block title will be overwritten with framework choice so make it disabled
$("#instconf_title").attr('disabled', true);
// Set up evidence choices and show/hide related descriptions
$("#instconf_smartevidence").select2();
show_se_desc($("#instconf_smartevidence").val());
$("#instconf_smartevidence").on('change', function() {
show_se_desc($(this).val());
});
}
};
......@@ -45,6 +45,10 @@ class PluginBlocktypeAnnotation extends MaharaCoreBlocktype {
return $view->get('group') == null;
}
public static function has_static_content() {
return false;
}
/**
* defines if the title should be shown if there is no content in the block
*
......@@ -428,7 +432,8 @@ class PluginBlocktypeAnnotation extends MaharaCoreBlocktype {
public static function get_instance_javascript(BlockInstance $bi) {
return array(
array(
'file' => 'js/annotation.js'
'file' => 'js/annotation.js',
'initjs' => " annotationBlockInit(); ",
)
);
}
......@@ -444,27 +449,4 @@ class PluginBlocktypeAnnotation extends MaharaCoreBlocktype {
set_field('blocktype_installed', 'active', 0, 'artefactplugin', 'annotation');
}
}
public static function get_instance_config_javascript(BlockInstance $instance) {
return <<<EOF
jQuery(function($) {
function show_se_desc(id) {
$("#instconf_smartevidencedesc_container div:not(.description)").addClass('d-none');
$("#option_" + id).removeClass('d-none');
}
if ($("#instconf_smartevidence").length) {
// block title will be overwritten with framework choice so make it disabled
$("#instconf_title").attr('disabled', true);
// Set up evidence choices and show/hide related descriptions
$("#instconf_smartevidence").select2();
show_se_desc($("#instconf_smartevidence").val());
$("#instconf_smartevidence").on('change', function() {
show_se_desc($(this).val());
});
}
});
EOF;
}
}
......@@ -551,6 +551,10 @@ EOF;
return $view->get('owner') != null;
}
public static function has_static_content() {
return false;
}
}
function translate_ids_to_tags(array $ids) {
......
......@@ -108,4 +108,8 @@ class PluginBlocktypeComment extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -448,4 +448,7 @@ class PluginBlocktypeProfileinfo extends MaharaCoreBlocktype {
return PluginArtefactInternal::import_create_blockinstance_leap($biconfig, $viewconfig);
}
public static function has_static_content() {
return false;
}
}
......@@ -243,4 +243,8 @@ class PluginBlocktypeSocialprofile extends MaharaCoreBlocktype {
return PluginArtefactInternal::import_create_blockinstance_leap($biconfig, $viewconfig);
}
public static function has_static_content() {
return false;
}
}
......@@ -22,10 +22,10 @@ function initTinyMCE(formname) {
}
}
$(function() {
function peerassessmentBlockInit() {
configureAssessmentCancel();
configureModalOpen();
});
};
jQuery(window).on('pageupdated', {}, function() {
configureAssessmentCancel();
......@@ -37,6 +37,9 @@ function configureModalOpen() {
$('.js-peerassessment-modal').on('click', function(e) {
e.stopPropagation();
e.preventDefault();
// needs to initialize the tinyMCE editor when the block is loaded
PieformManager.signal('onload');
var blockid = $(this).data('blockid');
var formname = $('#assessment_feedbackform_' + blockid).find('form')[0].id;
dock.show($('#assessment_feedbackform_' + blockid), false, true);
......
......@@ -142,7 +142,8 @@ class PluginBlocktypePeerassessment extends MaharaCoreBlocktype {
public static function get_instance_javascript(BlockInstance $bi) {
return array(
array(
'file' => 'js/peerassessment.js'
'file' => 'js/peerassessment.js',
'initjs' => " peerassessmentBlockInit(); ",
)
);
}
......@@ -173,4 +174,8 @@ class PluginBlocktypePeerassessment extends MaharaCoreBlocktype {
$artefacts = get_records_sql_array($sql, $values);
return $artefacts;
}
public static function has_static_content() {
return false;
}
}
......@@ -234,4 +234,8 @@ class PluginBlocktypePlans extends MaharaCoreBlocktype {
}
return $artefacts;
}
public static function has_static_content() {
return false;
}
}
......@@ -174,4 +174,7 @@ class PluginBlocktypeEntireresume extends MaharaCoreBlocktype {
return true;
}
public static function has_static_content() {
return false;
}
}
......@@ -636,4 +636,8 @@ class PluginBlocktypeExternalfeed extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -475,4 +475,8 @@ class PluginBlocktypeGroupViews extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -176,4 +176,8 @@ class PluginBlocktypeInbox extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -778,6 +778,9 @@ EOF;
return !(count($roles) == 1 && $roles[0] == 'peer');
}
public static function has_static_content() {
return true;
}
}
......@@ -839,15 +842,15 @@ class BlockInstance {
private $row;
private $column;
private $order;
private $canmoveleft;
private $canmoveright;
private $canmoveup;
private $canmovedown;
private $maxorderincolumn;
private $artefacts = array();
private $temp = array();
private $tags = array();
private $inedit = false;
private $positionx;
private $positiony;
private $width;
private $height;
public function __construct($id=0, $data=null) {
if (!empty($id)) {
......@@ -873,6 +876,30 @@ class BlockInstance {
$this->{$field} = $value;
}
}
$dimensiontable_exists = true;
if (defined('INSTALLER')) {
// Check to see if the table exists yet
require_once('ddl.php');
$dimensiontable_exists = table_exists(new XMLDBTable('block_instance_dimension'));
}
if ($dimensiontable_exists) {
$dimension = get_records_array('block_instance_dimension', 'block', $id);
if (is_array($dimension) && isset($dimension[0])) {
$this->positionx = $dimension[0]->positionx;
$this->positiony = $dimension[0]->positiony;
$this->width = $dimension[0]->width;
$this->height = $dimension[0]->height;
}
}
else {
$this->positionx = 0;
$this->positiony = 0;
$this->width = 4;
$this->height = 3;
}
$this->artefactplugin = blocktype_artefactplugin($this->blocktype);
}
......@@ -1150,7 +1177,6 @@ class BlockInstance {
global $USER;
safe_require('blocktype', $this->get('blocktype'));
$movecontrols = array();
$this->inedit = true;
$blocktypeclass = generate_class_name('blocktype', $this->get('blocktype'));
try {
......@@ -1193,45 +1219,6 @@ class BlockInstance {
$js = '';
$css = '';
}
if (!defined('JSON') && !$jsreply) {
if ($this->get('canmoveleft')) {
$movecontrols[] = array(
'column' => $this->get('column') - 1,
'order' => $this->get('order'),
'title' => $title == '' ? get_string('movethisblockleft', 'view') : get_string('moveblockleft', 'view', "'$title'"),
'arrow' => "icon icon-long-arrow-alt-left",
'dir' => 'left',
);
}
if ($this->get('canmovedown')) {
$movecontrols[] = array(
'column' => $this->get('column'),
'order' => $this->get('order') + 1,
'title' => $title == '' ? get_string('movethisblockdown', 'view') : get_string('moveblockdown', 'view', "'$title'"),
'arrow' => 'icon icon-long-arrow-alt-down',
'dir' => 'down',
);
}
if ($this->get('canmoveup')) {
$movecontrols[] = array(
'column' => $this->get('column'),
'order' => $this->get('order') - 1,
'title' => $title == '' ? get_string('movethisblockup', 'view') : get_string('moveblockup', 'view', "'$title'"),
'arrow' => 'icon icon-long-arrow-alt-up',
'dir' => 'up',
);
}
if ($this->get('canmoveright')) {
$movecontrols[] = array(
'column' => $this->get('column') + 1,
'order' => $this->get('order'),
'title' => $title == '' ? get_string('movethisblockright', 'view') : get_string('moveblockright', 'view', "'$title'"),
'arrow' => 'icon icon-long-arrow-alt-right',
'dir' => 'right',
);
}
}
}
$configtitle = $title == '' ? call_static_method($blocktypeclass, 'get_title') : $title;
......@@ -1244,8 +1231,13 @@ class BlockInstance {
$smarty->assign('row', $this->get('row'));
$smarty->assign('column', $this->get('column'));
$smarty->assign('order', $this->get('order'));
$smarty->assign('positionx', $this->get('positionx'));
$smarty->assign('positiony', $this->get('positiony'));
$smarty->assign('width', $this->get('width'));
$smarty->assign('height', $this->get('height'));
$smarty->assign('blocktype', $this->get('blocktype'));
$smarty->assign('movecontrols', $movecontrols);
$smarty->assign('configurable', call_static_method($blocktypeclass, 'has_instance_config'));
$smarty->assign('configure', $configure); // Used by the javascript to rewrite the block, wider.
$smarty->assign('configtitle', $configtitle);
......@@ -1658,6 +1650,11 @@ class BlockInstance {
$this->rebuild_artefact_list();
// check the table exists in case we need to update a block in the upgrade before the creation of the table
if (db_table_exists('block_instance_dimension') && isset($this->positionx)) {
$this->set_block_dimensions($this->positionx, $this->positiony, $this->width, $this->height);
}
// Tell stuff about this
handle_event('blockinstancecommit', $this);
......@@ -1770,6 +1767,7 @@ class BlockInstance {
call_static_method($classname, 'delete_instance', $this);
}
delete_records('view_artefact', 'block', $this->id);
delete_records('block_instance_dimension', 'block', $this->id);
delete_records('block_instance', 'id', $this->id);
delete_records('tag', 'resourcetype', 'blocktype', 'resourceid', $this->id);
db_commit();
......@@ -1952,6 +1950,10 @@ class BlockInstance {
'row' => $this->get('row'),
'column' => $this->get('column'),
'order' => $this->get('order'),
'positionx' => $this->get('positionx'),
'positiony' => $this->get('positiony'),
'width' => $this->get('width'),
'height' => $this->get('height'),
));
if (($sameowner && $copytype != 'fullinclself') || $copytype == 'reference') {
......@@ -2129,6 +2131,28 @@ class BlockInstance {
public static function group_tabs($groupid, $role) {
return array();
}
public function set_block_dimensions($positionx, $positiony, $width, $height) {
$obj = new StdClass();
$obj->block = $this->id;
$obj->positionx = $positionx;
$obj->positiony = $positiony;
$obj->height = $height;
$obj->width = $width;
if (isset($obj->positionx) && isset($obj->positiony) && isset($obj->height) && isset($obj->width)) {
//TODO: move this inside of the commit
ensure_record_exists('block_instance_dimension', (object) array('block' => $this->id), $obj);
$this->set('positionx', $positionx);
$this->set('positiony', $positiony);
$this->set('height', $height);
$this->set('width', $width);
}
else {
throw new \Exception(get_string('dimensionsnotset', 'view'));
}
}
}
function require_blocktype_plugins() {
......
......@@ -178,4 +178,8 @@ class PluginBlocktypeMyfriends extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -180,4 +180,8 @@ class PluginBlocktypeMyGroups extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -148,4 +148,8 @@ class PluginBlocktypeMyviews extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -157,9 +157,10 @@ class PluginBlocktypeNavigation extends MaharaCoreBlocktype {
array(
'blocktype' => 'navigation',
'title' => $values['title'],
'row' => $instance->get('row'),
'column' => $instance->get('column'),
'order' => 1,
'positionx' => 0,
'positiony' => 0,
'width' => 4,
'height' => 3,
'configdata' => array(
'collection' => $values['collection'],
'retractable' => $values['retractable'],
......
......@@ -97,4 +97,8 @@ class PluginBlocktypeNewViews extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -240,4 +240,8 @@ class PluginBlocktypeRecentForumPosts extends MaharaCoreBlocktype {
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
......@@ -198,7 +198,8 @@ class PluginBlocktypeWall extends MaharaCoreBlocktype {
public function wallpost_js() {
$js = <<<EOF
function wallpost_success(form, data) {
if (jQuery('#wall').length && data.posts && data.block) {
var wall = jQuery('#wall');
if (wall.length && data.posts && data.block) {
var wall = jQuery('#blockinstance_' + data.block + ' div.wall').first();
var temp = jQuery('<div>');
var textareaid = 'wallpost_' + data.block + '_text';
......@@ -215,6 +216,10 @@ function wallpost_success(form, data) {
formSuccess(form, data);
}
}
jQuery( function() {
// needs to initialize the tinyMCE editor when the block is loaded
PieformManager.signal('onload');
});
EOF;
return "<script>$js</script>";
}
......@@ -340,6 +345,10 @@ EOF;
public static function get_artefacts(BlockInstance $instance) {
return array();
}
public static function has_static_content() {
return false;
}
}
class ActivityTypeBlocktypeWallWallpost extends ActivityTypePlugin {
......
......@@ -396,4 +396,8 @@ class PluginBlocktypeWatchlist extends MaharaCoreBlocktype {
return array($views, count($views));
}
public static function has_static_content() {
return false;
}
}
......@@ -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) {