Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDLSITE-7917: Frontpage editable blocks #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions amd/build/contributedstrings.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/contributedstrings.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions amd/build/listcontributors.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/listcontributors.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions amd/src/contributedstrings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
define([], function() {
return {
init: function(contributedstrings) {
const contributedstringsElements = document.querySelectorAll('.contributedstrings');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that

class="contributedstrings"

is appropriate selector here. We should not use CSS selectors and identifiers for JS integration. An element that has special meaning for a JS (such as its content is provided like in this case) should be identified via data attribute. See https://moodledev.io/docs/5.0/guides/javascript

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, my content comes from an HTML block, and moodle filters all these data attributes from this type of content.
This class actually is inside a strong tag. I tried to add data-contributed-strings, and the editor changes that to data-contributed-strings="" but finally is filtered and disappears in the page, the same happens if I use an attribute with content like data-contributed-strings="placeholder".
¿Do you know how to change that from a class and works?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I had forgotten that this is the user contents now and that it gets filtered. Ok, never mind then.

contributedstringsElements.forEach(element => {
element.textContent = contributedstrings;
});
}
};
});
10 changes: 10 additions & 0 deletions amd/src/listcontributors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
define([], function() {
return {
init: function(listcontributors) {
const listcontributorsElements = document.querySelectorAll('.listcontributors');
listcontributorsElements.forEach(element => {
element.innerHTML = listcontributors;
});
}
};
});
2 changes: 1 addition & 1 deletion classes/stats_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public function frontpage_contribution_stats(): array {

$links = array();
foreach ($recent as $contributor) {
$links[] = '<a href="'.$CFG->wwwroot.'/user/profile.php?id='.$contributor->id.'">'.s(fullname($contributor)).'</a>';
$links[] = '<a style="color: #0077b8; text-decoration: underline;" href="'.$CFG->wwwroot.'/user/profile.php?id='.$contributor->id.'">'.s(fullname($contributor)).'</a>';
}

$links = get_string('contributethankslist', 'local_amos', [
Expand Down
60 changes: 12 additions & 48 deletions templates/frontpage.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,18 @@
{}
}}

<h1 class="brandheader" style="margin: 1.5rem 0 0">Translation</h1>

<div class="card-deck my-2">
<div class="card">
<div class="lead card-header">{{#str}} amos, local_amos {{/str}}</div>
<div class="card-body">
<div>{{#str}} about, local_amos {{/str}}</div>
</div>
</div>
<div class="card">
<div class="lead card-header">{{#str}} contribute, local_amos {{/str}}</div>
<div class="card-body">
<p>{{#str}} contributestats, local_amos, {"count": {{#quote}} {{{contributedstrings}}} {{/quote}} } {{/str}}</p>
<p>{{#str}} contributethanks, local_amos, { "listcontributors": {{#quote}} {{{listcontributors}}} {{/quote}} } {{/str}}</p>
<p class="text-center">
<a class="btn btn-large btn-success" href="/local/amos/">{{#str}} contributenow, local_amos {{/str}}</a>
<a class="btn btn-large btn-secondary" href="/local/amos/credits.php">{{#str}} creditstitleshort, local_amos {{/str}}</a>
</p>
</div>
</div>
<div class="card">
<div class="lead card-header">{{#str}} quicklinks, local_amos {{/str}}</div>
<div class="card-body">
<ul class="unstyled">
<li>
<a href="/local/amos/view.php">
{{#str}} quicklinks_amos, local_amos {{/str}}
</a>
</li>
<li>
<a href="/course/view.php?id=2">
{{#str}} quicklinks_forum, local_amos {{/str}}
</a>
</li>
<li>
<a href="/mod/page/view.php?id=9">
{{#str}} quicklinks_newcomers, local_amos {{/str}}
</a>
</li>
<li>
<a href="https://docs.moodle.org/dev/AMOS_manual">
{{#str}} quicklinks_manual, local_amos {{/str}}
</a>
</li>
</ul>
</div>
</div>
</div>
{{#js}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need those scripts at all? Could not this simple replacement be put here into the JS section completely?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it in the module to maintain the standard, replicating what I did in other JavaScript developments like this, related to the HTML content of Moodle.org pages.
I could simplify it and place the content directly outside the AMD module, but that way, we wouldn't keep the code separate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it is a fair argument. It just initially looked and felt as an overkill to me. But I agree it is how it should be by the book :-)

{{#contributedstrings}}
require(['local_amos/contributedstrings'], function(contributedstrings) {
contributedstrings.init('{{{contributedstrings}}}');
});
{{/contributedstrings}}
{{#listcontributors}}
require(['local_amos/listcontributors'], function(listcontributors) {
listcontributors.init('{{#str}} contributethanks, local_amos, { "listcontributors": {{#quote}} {{{listcontributors}}} {{/quote}} } {{/str}}');
});
{{/listcontributors}}
{{/js}}

<div class="card">
<div class="lead card-header">{{#str}} availablelangs, core_install {{/str}}</div>
Expand Down
Loading