Commit 81b6e8aa authored by mathieso's avatar mathieso

Bug fixes, and move list menu item suppression to client-side.

parent 7386f89d
/**
* @file
* Remove list links for which there are no items.
*/
(function($, Drupal) {
"use strict";
Drupal.skillingSettings.adjustListLinksInitialized = false;
Drupal.behaviors.bookNav = {
attach: function(context, settings) {
if (Drupal.skillingSettings.adjustListLinksInitialized) {
return;
}
Drupal.skillingSettings.adjustListLinksInitialized = true;
$(document).ready(function() {
let contentTypesCounts = drupalSettings.contentTypeCounts;
for (const contentType in contentTypesCounts) {
const count = contentTypesCounts[contentType];
if (count === 0) {
// Remove the menu item.
$("a[data-drupal-link-system-path='" + contentType + "s']").remove();
}
}
});
}
};
})(jQuery, Drupal);
......@@ -2,27 +2,18 @@
Installation
exercises - fields on form out of orcer, many disabled.
- same for manage display
Still need completion score page?
X - add new fields
- test on shared host
X - initial valuies of new config flags and shit.
Starter content
# Starter content
- can't create paragraphs when adding exercises due to class.
- class - start date MT
- description text format not selected.
- description text format not selected
- same for notes
- where referenced for exercises and things not set.
# Sidebars
? Make left wider, or reduce text size, or something.
# Perms
......@@ -31,68 +22,11 @@ of viewing and viewed user.
Replace with field perms module? Or something custom, that can be managed through a GUI?
# Things
After session open for student1
Notice: Undefined index: base in Drupal\views\Plugin\views\query\QueryPluginBase->getEntityTableInfo() (line 292 of /home/kieran/subdomains/s2/web/core/modules/views/src/Plugin/views/query/QueryPluginBase.php) #0 /home/kieran/subdomains/s2/web/core/includes/bootstrap.inc(600): _drupal_error_handler_real(8, 'Undefined index...', '/home/kieran/su...', 292, Array) #1 /home/kieran/subdomains/s2/web/core/modules/views/src/Plugin/views/query/QueryPluginBase.php(292): _drupal_error_handler(8, 'Undefined index...', '/home/kieran/su...', 292, Array) #2
InvalidArgumentException: Field field_badges_awarded is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 587 of /home/kieran/subdomains/s2/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Notice: Undefined index: type in Drupal\field_ui\Form\EntityDisplayFormBase->buildFieldRow() (line 367 of /home/kieran/subdomains/s2/web/core/modules/field_ui/src/Form/EntityDisplayFormBase.php) #0 /home/kieran/subdomains/s2/web/core/includes/bootstrap.inc(600): _drupal_error_handler_real(8, 'Undefined index...', '/home/kieran/su...', 367, Array) #1 /home/kieran/subdomains/s2/web/core/modules/field_ui/src/Form/EntityDisplayFormBase.php(367): _drupal_error_handler(8, 'Undefined index...', '/home/kieran/su...', 367, Array)
# Lessons list
x For anon, Add lesson link in lessons list.
x Add summary to report? Below title.
# Exercise
"Body" title shows for some reason on node display.
- part of installation missing things.
# Embedded reflection for anon
X "(If you were logged..." - italic, get rid of )
# View student account
Member for... out of order.
-SAME THING
x Show portfolio - label to left.
About field not showing on student account view.
# Form
? About field - remove about text format
? Remove body p thing at the bottom
# Exercises list
? Sort by title
# Exerc
# Pattern list
x Sort by name? Screenshot
# Badges
? Hide in menu if there are none.
X Hide block if there are none.
? Hide block if there are none.
# Help
X Help menu? What to do with it?
# Skilling config
......@@ -100,7 +34,7 @@ After install, config form shows initials not required. Student submission asks
Save config form, and it works, when checkbox is clear. Need to explicitly set
the value of the flag during install?
- changed code, did it work?
- changed code, did it work? NO
- check other config flag init code. Some things missing?
......@@ -116,28 +50,12 @@ Instructor can show history for student.
Students can see own history
# Hiding menu items for things that dinna exist
Use client side.
# Exercises and f/b
Seeing labels for exercise view.
Test when exercise not on timeline, how shows for student when inserted.
Wrong icon for no submissions left. Check screen shot.
? Add multifield for exercises on due, even if just use first one.
# Calendar
X New row, initialize max subs to blank, not zero
x Hit sort, max subs goes to undefined.
# Testing
......
......@@ -327,3 +327,7 @@ insert-exercise-styling:
css:
component:
libraries/insert-exercise-styling/insert-exercise-styling.css: {}
adjust-list-links:
version: 1.x
js:
libraries/adjust-list-links/adjust-list-links.js: {}
......@@ -88,6 +88,10 @@ function skilling_page_attachments(array &$attachments) {
$roles = $currentUser->id() ? $currentUser->getRoles() : [];
$attachments['#attached']['drupalSettings']['currentUserRoles'] = $roles;
$attachments['#attached']['drupalSettings']['currentUserName'] = $currentUser->getAccountName();
// Counts of various node types, to customize Lists menu.
$attachments['#attached']['drupalSettings']['contentTypeCounts']
= _skilling_content_types_counts_for_lists_menu();
$attachments['#attached']['library'][] = 'skilling/adjust-list-links';
if ($currentUser->isAuthenticated()) {
// Add notice count display.
/** @var \Drupal\skilling\Notice $noticeService */
......@@ -132,6 +136,31 @@ function skilling_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'skilling/ui-munge';
}
function _skilling_content_types_counts_for_lists_menu() {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager */
$entityTypeManager = Drupal::service('entity_type.manager');
$typesToCount = [
SkillingConstants::LESSON_CONTENT_TYPE,
SkillingConstants::EXERCISE_CONTENT_TYPE,
SkillingConstants::BADGE_CONTENT_TYPE,
SkillingConstants::PATTERN_CONTENT_TYPE,
SkillingConstants::PRINCIPLE_CONTENT_TYPE,
SkillingConstants::MODEL_CONTENT_TYPE,
];
$result = [];
$storage = $entityTypeManager->getStorage('node');
foreach ($typesToCount as $type) {
$count = $storage->getQuery()
->condition('type', $type)
->condition('status', TRUE)
->count()
->execute();
$result[$type] = (integer)$count;
}
return $result;
}
/**
* Implements hook_editor_js_settings_alter().
*/
......@@ -1141,45 +1170,6 @@ function skilling_node_insert(Drupal\node\NodeInterface $node) {
}
}
}
skilling_check_clear_menu_cache($node);
}
/**
* If there are 0 or 1 nodes of a type, clear the menu cache, so the
* main menu gets rebuilt. This will trigger
* skilling_bootstrap_preprocess_menu__main(), to show or hide the
* main menu entries for models and things.
*
* @param \Drupal\node\NodeInterface $node
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function skilling_check_clear_menu_cache(Drupal\node\NodeInterface $node) {
$targetBundles = [
SkillingConstants::EXERCISE_CONTENT_TYPE,
SkillingConstants::PATTERN_CONTENT_TYPE,
SkillingConstants::PRINCIPLE_CONTENT_TYPE,
SkillingConstants::MODEL_CONTENT_TYPE,
SkillingConstants::BADGE_CONTENT_TYPE,
];
$bundle = $node->bundle();
$isTargetBundle = in_array($bundle, $targetBundles);
if ($isTargetBundle) {
/** @var Drupal\skilling\Utilities $utilities */
$utilities = Drupal::service('skilling.utilities');
$count = $utilities->countNodesOfBundle($bundle);
if ($count == 0 || $count == 1) {
// Schedule cache clear.
/** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
$configFactory = Drupal::service('config.factory');
$settings = $configFactory->getEditable(SkillingConstants::SETTINGS_MAIN_KEY);
$settings->set(
SkillingConstants::SETTING_KEY_SCHEDULE_CLEAR_CACHE, TRUE);
$settings->save();
// drupal_flush_all_caches();
}
}
}
/**
......@@ -1439,9 +1429,6 @@ function skilling_node_delete(Node $node) {
}
}
}
// Check bundles where having any nodes influences menu item visibility
// in Lists menu.
skilling_check_clear_menu_cache($node);
}
......
......@@ -42,22 +42,36 @@ class Badging {
$this->submissionsService = $submissionsService;
}
public function updateUserBadges(SkillingUser $student) {
if (!$student->isStudent()) {
return;
}
// Get the total number of challenge completed exercises for the student.
$completedCount = $this->submissionsService->getCountCompletedChallengeExercisesForStudent($student);
/**
* Get the published badges.
*
* @return array|\Drupal\node\NodeInterface[]
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function getPublishedBadges() {
// Get the badges.
$badgeNids = $this->entityTypeManager->getStorage('node')->getQuery()
->condition('type', SkillingConstants::BADGE_CONTENT_TYPE)
->condition('status', TRUE)
->execute();
if (count($badgeNids) === 0) {
return;
return [];
}
/** @var \Drupal\node\NodeInterface[] $badges */
$badges = $this->entityTypeManager->getStorage('node')
->loadMultiple($badgeNids);
return $badges;
}
public function updateUserBadges(SkillingUser $student) {
if (!$student->isStudent()) {
return;
}
// Get the total number of challenge completed exercises for the student.
$completedCount = $this->submissionsService->getCountCompletedChallengeExercisesForStudent($student);
// Get the badges that exist.
$badges = $this->getPublishedBadges();
$badgeNidsUserShouldHave = [];
/** @var \Drupal\node\NodeInterface $badge */
foreach ($badges as $badgeNid => $badge) {
......
......@@ -70,6 +70,4 @@ class SkillingSubscriber implements EventSubscriberInterface {
// Clear the cache.
drupal_flush_all_caches();
}
}
}
}}
......@@ -105,6 +105,11 @@ class BadgeBlock extends BlockBase implements ContainerFactoryPluginInterface {
if ($account->isAnonymous()) {
return AccessResult::forbidden();
}
// Hide block if there are no badges.
$publishedBadges = $this->badgingService->getPublishedBadges();
if (count($publishedBadges) === 0) {
return AccessResult::forbidden();
}
$user = $this->userFactory->makeSkillingUser($account->id());
if (!$return_as_object) {
return $user->isStudent();
......
<?php
namespace Drupal\skilling\Plugin\Filter;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
/**
* @Filter(
* id = "filter_skilling",
* title = @Translation("Skilling Filter"),
* description = @Translation("Translate Skilling markup to HTML."),
* type = Drupal\filter\Plugin\FilterInterface::TYPE_MARKUP_LANGUAGE,
* )
*/
class SkillingFilter extends FilterBase {
/**
* Performs the filter processing.
*
* @param string $text
* The text string to be filtered.
* @param string $langcode
* The language code of the text to be filtered.
*
* @return \Drupal\filter\FilterProcessResult
* The filtered text, wrapped in a FilterProcessResult object, and possibly
* with associated assets, cacheability metadata and placeholders.
*
* @see \Drupal\filter\FilterProcessResult
*/
public function process($text, $langcode) {
// Get the node being viewed, if there is one.
/** @var \Drupal\skilling\Utilities $utilities */
$utilities = \Drupal::service('skilling.utilities');
$currentNode = $utilities->getCurrentNode();
$parser = \Drupal::service('skilling.skillingparser');
$result = $parser->parse($text, $currentNode);
$markup = new FilterProcessResult($result);
$markup->setAttachments(array(
'library' => array('skilling/display'),
));
// Content is not cachable. All of the conditions and things.
$markup->setCacheMaxAge(0);
return $markup;
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
if ($long) {
return $this->t('
<p><a href="https://textile-lang.com/" target="_blank">Textile reference</a></p>
');
}
else {
return $this->t('<a href="https://textile-lang.com/" target="_blank">Textile reference</a>');
}
}
}
......@@ -852,7 +852,7 @@ class Submissions {
public function getSubmissionStatusForStudentExercise(
SkillingUser $student,
$exerciseNid,
array $exerciseDue,
$exerciseDue,
array $submissions = []
) {
// Is the user a student?
......
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