Skip to content

Commit

Permalink
DASH-220 improve css and where font color applies
Browse files Browse the repository at this point in the history
  • Loading branch information
moodledev committed Jan 12, 2021
1 parent ec30881 commit a5a4fb8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 27 deletions.
24 changes: 14 additions & 10 deletions block_dash.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function get_content() {
$this->content = $bb->get_block_content();

if ($css = $this->get_extra_css()) {
$this->content->text .= sprintf('<style>%s</style>', $css);
$this->content->text .= $css;
}
} catch (\Exception $e) {
$this->content->text = $OUTPUT->notification($e->getMessage() . $e->getTraceAsString(), 'error');
Expand Down Expand Up @@ -171,33 +171,37 @@ public function html_attributes() {
* @return string
*/
public function get_extra_css() {
$css = [];
global $OUTPUT;

$blockcss = [];
$data = [
'block' => $this,
'headerfootercolor' => isset($this->config->headerfootercolor) ? $this->config->headerfootercolor : null
];

$backgroundgradient = isset($this->config->backgroundgradient) ? str_replace(';', '', $this->config->backgroundgradient) : null;

if ($this->get_background_image_url()) {
if ($backgroundgradient) {
$css[] = sprintf('background-image: %s, url(%s);', $backgroundgradient, $this->get_background_image_url()->out());
$blockcss[] = sprintf('background-image: %s, url(%s);', $backgroundgradient, $this->get_background_image_url()->out());
} else {
$css[] = sprintf('background-image: url(%s);', $this->get_background_image_url());
$blockcss[] = sprintf('background-image: url(%s);', $this->get_background_image_url());
}
} elseif ($backgroundgradient) {
$css[] = sprintf('background: %s', $this->config->backgroundgradient);
$blockcss[] = sprintf('background: %s', $this->config->backgroundgradient);
}

if (isset($this->config->css) && is_array($this->config->css)) {
foreach ($this->config->css as $property => $value) {
if (!empty($value)) {
$css[] = sprintf('%s: %s;', $property, $value);
$blockcss[] = sprintf('%s: %s;', $property, $value);
}
}
}

if ($css) {
return sprintf('#inst%s { %s }', $this->instance->id, implode(PHP_EOL, $css));
}
$data['blockcss'] = implode(PHP_EOL, $blockcss);

return null;
return $OUTPUT->render_from_template('block_dash/extra_css', $data);
}

/**
Expand Down
26 changes: 14 additions & 12 deletions classes/local/block_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,25 @@ public function get_block_content() {

$bb->get_configuration()->get_data_source()->get_paginator()->set_current_page(0);

$text .= $OUTPUT->render_from_template('block_dash/block', [
$data = [
'preloaded' => $renderer->render_data_source($bb->get_configuration()->get_data_source()),
'block_instance_id' => $this->blockinstance->instance->id,
'block_context_id' => $this->blockinstance->context->id,
'editing' => $PAGE->user_is_editing() &&
has_capability('block/dash:addinstance', $this->blockinstance->context)
]);
];

if (isset($this->blockinstance->config->header_content)) {
$data['header_content'] = format_text($this->blockinstance->config->header_content['text'],
$this->blockinstance->config->header_content['format']);
}

if (isset($this->blockinstance->config->footer_content)) {
$data['footer_content'] = format_text($this->blockinstance->config->footer_content['text'],
$this->blockinstance->config->footer_content['format']);
}

$text .= $OUTPUT->render_from_template('block_dash/block', $data);

if (is_siteadmin()) {
[$sql, $params] = $bb->get_configuration()->get_data_source()->get_query()->get_sql_and_params();
Expand All @@ -107,16 +119,6 @@ public function get_block_content() {
$content = new \stdClass();
$content->text = $text;

if (isset($this->blockinstance->config->header_content)) {
$content->text = format_text($this->blockinstance->config->header_content['text'],
$this->blockinstance->config->header_content['format']) . $content->text;
}

if (isset($this->blockinstance->config->footer_content)) {
$content->footer = format_text($this->blockinstance->config->footer_content['text'],
$this->blockinstance->config->footer_content['format']);
}

return $content;
}

Expand Down
6 changes: 3 additions & 3 deletions edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ protected function specific_definition($mform) {
$mform->setType('config_backgroundgradient', PARAM_TEXT);
$mform->addHelpButton('config_backgroundgradient', 'backgroundgradient', 'block_dash');

$mform->addElement('text', 'config_css[color]', get_string('fontcolor', 'block_dash'));
$mform->setType('config_css[color]', PARAM_TEXT);
$mform->addHelpButton('config_css[color]', 'fontcolor', 'block_dash');
$mform->addElement('text', 'config_headerfootercolor', get_string('fontcolor', 'block_dash'));
$mform->setType('config_headerfootercolor', PARAM_TEXT);
$mform->addHelpButton('config_headerfootercolor', 'fontcolor', 'block_dash');

$mform->addElement('text', 'config_css[border]', get_string('border', 'block_dash'));
$mform->setType('config_css[border]', PARAM_TEXT);
Expand Down
6 changes: 6 additions & 0 deletions templates/block.mustache
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<div id="dash-{{block_instance_id}}" class="dash-container">
<div class="dash-header-content">
{{{header_content}}}
</div>
{{#editing}}
<button class="dash-edit-preferences btn btn-sm btn-primary mb-2" style="width: 100%;">{{#str}}preferences{{/str}}</button>
{{/editing}}
<div class="dash-block-content">
{{{preloaded}}}
</div>
<div class="dash-footer-content">
{{{footer_content}}}
</div>
</div>

{{#js}}
Expand Down
14 changes: 14 additions & 0 deletions templates/extra_css.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<style>
#inst{{block.instance.id}} {
{{blockcss}}
}
#inst{{block.instance.id}} .dash-header-content,
#inst{{block.instance.id}} .dash-footer-content,
#inst{{block.instance.id}} #instance-{{block.instance.id}}-header,
#inst{{block.instance.id}} .pagination-summary {
{{#headerfootercolor}}
color: {{headerfootercolor}}
{{/headerfootercolor}}
}
</style>
2 changes: 1 addition & 1 deletion templates/paginator.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{#show_page_summary}}
<div>{{summary}}</div>
<div class="pagination-summary">{{summary}}</div>
{{/show_page_summary}}

<nav>
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021011200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2021011201; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2017051509; // Requires this Moodle version.
$plugin->component = 'block_dash'; // Full name of the plugin (used for diagnostics).
$plugin->maturity = MATURITY_BETA;
Expand Down

0 comments on commit a5a4fb8

Please sign in to comment.