Commit 98a47860 authored by mathieso's avatar mathieso

Various things

parent 66f7334c
/**
* @file
* Give username field focus on page load.
*/
(function ($, Drupal) {
return;
"use strict";
Drupal.skillingSettings.usernameFocusInitialized = false;
Drupal.behaviors.usernameFocus = {
attach: function (context, settings) {
if ( Drupal.skillingSettings.usernameFocusInitialized ) {
return;
}
Drupal.skillingSettings.usernameFocusInitialized = true;
$(document).ready(function() {
$("form#user-login-form #edit-name").focus();
});
}
}
})(jQuery, Drupal);
......@@ -14,6 +14,9 @@ X - initial valuies of new config flags and shit.
? Students can't see/edit their first/last name.
# Exercise
# Subm
Show submit new button when should not abe able to.
......
......@@ -331,3 +331,7 @@ adjust-list-links:
version: 1.x
js:
libraries/adjust-list-links/adjust-list-links.js: {}
#username-focus:
# version: 1.x
# js:
# libraries/username-focus/username-focus.js: {}
......@@ -31,7 +31,7 @@ skilling.lessonlist:
skilling.exercises:
title: 'Exercises'
description: 'Tasks for students'
route_name: view.exercises.list
route_name: skilling.exercise_list
menu_name: main
parent: skilling.lists
weight: 20
......
......@@ -655,6 +655,8 @@ function skilling_alter_fib_edit_form(&$form, FormStateInterface $form_state) {
function skilling_form_user_login_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// Focus to username field when form first displays.
// $form['#attached']['library'][] = 'skilling/username-focus';
// Prevent login form caching.
Drupal::service('page_cache_kill_switch')->trigger();
$referer = $_SERVER["HTTP_REFERER"];
......
......@@ -15,6 +15,15 @@ skilling.lists:
requirements:
_permission: 'access content'
# For anyone, exercise list, what is shown depends on whether there is a current class.
skilling.exercise_list:
path: '/exercises'
defaults:
_controller: '\Drupal\skilling\Controller\ListsController::showExercisesList'
_title: 'Exercises'
requirements:
_permission: 'access content'
# Submissions report for students.
skilling.show_student_submissions:
path: '/skilling/submissions'
......
......@@ -335,10 +335,6 @@ class SkillingAccessChecker {
public function isNodeAccess(NodeInterface $node, $operation) {
// Only check content types that are controlled by Skilling.
$contentType = $node->bundle();
// if ($contentType == 'aa') {
// return TRUE;
// }
//
if (!in_array($contentType, SkillingConstants::SKILLING_CONTENT_TYPES)) {
// Not a Skilling content type. Other code determines its fate.
return TRUE;
......
......@@ -4,6 +4,8 @@ namespace Drupal\skilling\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Link;
use Drupal\skilling\CurrentClass;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Menu\MenuLinkTreeInterface;
......@@ -19,19 +21,32 @@ class ListsController extends ControllerBase {
*/
protected $menuLinkTree;
/**
* Current class service.
*
* @var \Drupal\skilling\CurrentClass
*/
protected $currentClass;
/**
* Constructs a new ListsController object.
*/
public function __construct(MenuLinkTreeInterface $menu_link_tree) {
$this->menuLinkTree = $menu_link_tree;
public function __construct(
MenuLinkTreeInterface $menuLinkTree,
CurrentClass $currentClass
) {
$this->menuLinkTree = $menuLinkTree;
$this->currentClass = $currentClass;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/* @noinspection PhpParamsInspection */
return new static(
$container->get('menu.link_tree')
$container->get('menu.link_tree'),
$container->get('skilling.current_class')
);
}
......@@ -53,6 +68,30 @@ class ListsController extends ControllerBase {
return $output;
}
/**
* Create exercise list. Render an embedded display of a view. Which one
* depends on whether there is a current class.
*
* @return array
*/
public function showExercisesList() {
$result = [];
/** @var \Drupal\views\ViewExecutable $view */
$view = Views::getView('exercises');
$result['view'] = $this->t('Exercises view embed error.');
if (is_object($view)) {
$display = is_null($this->currentClass->getCurrentClass())
? 'no_current_class' // User has no current classs.
: 'with_current_class';
$view->setDisplay($display);
$view->preExecute();
$view->execute();
$result['view'] = $view->buildRenderable($display);
}
return $result;
}
/**
* Show lists.
*
......
......@@ -16,7 +16,7 @@ use Drupal\views\ResultRow;
*
* @ViewsField("exercise_due_date")
*/
class ExerciseDueDate extends FieldPluginBase {
class ExerciseDueDate extends Drupal\views\Plugin\views\field\Date { //FieldPluginBase {
/**
* {@inheritdoc}
......@@ -57,7 +57,7 @@ class ExerciseDueDate extends FieldPluginBase {
$classStartDate = $currentClass->getStartDate();
$classStartDate = new DateTime($classStartDate);
$dayExerDue = $exerciseDueData['day'] - 1;
$result = $utilities->getCalendarDateFromDayOffset(
$result = $utilities->getCalendarDateFromDayOffsetFormatted(
$classStartDate,
$dayExerDue
);
......@@ -65,23 +65,6 @@ class ExerciseDueDate extends FieldPluginBase {
}
}
return $result;
/** @var \Drupal\node\Entity\Node $class */
$class = $values->_entity;
$classStartDate = $class->field_when_starts->value;
$classStartDate = new DateTime($classStartDate);
// Get the day offset the event happens.
/** @var \Drupal\paragraphs\ParagraphInterface $calendarEvent */
$calendarEvent = $values->_relationship_entities['field_calendar_events'];
$eventDayOffset = $calendarEvent->field_day->value;
// Compute the event date.
$eventDate = clone $classStartDate;
$eventDate->add(new DateInterval('P' . $eventDayOffset . 'D'));
// Format the event date.
$dateFormat = 'D, M j, Y';
$eventDateFormatted = $eventDate->format($dateFormat);
return $eventDateFormatted;
}
}
......@@ -34,12 +34,9 @@ class MaxSubmissions extends FieldPluginBase {
/**
* {@inheritdoc}
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\skilling\Exception\SkillingValueMissingException
* @throws \Drupal\skilling\Exception\SkillingWrongTypeException
* @throws \Drupal\skilling\Exception\SkillingException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Exception
* @param \Drupal\views\ResultRow $row
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
*/
public function render(ResultRow $row) {
// Default if exercise not in class, or no current class.
......
......@@ -975,6 +975,27 @@ class Utilities {
return $result;
}
/**
* Compute date to display, given date and days offset.
*
* @param \DateTime $startDate
* Start date
* @param $offset
* Offset in days
*
* @return DateTime
* Date.
*
* @throws \Exception
*/
public function getCalendarDateFromDayOffset(
DateTime $startDate,
$offset) {
$eventDate = clone $startDate;
$eventDate->add(new DateInterval('P' . $offset . 'D'));
return $eventDate;
}
/**
* Compute date to display, given date and days offset.
*
......@@ -990,13 +1011,12 @@ class Utilities {
*
* @throws \Exception
*/
public function getCalendarDateFromDayOffset(
public function getCalendarDateFromDayOffsetFormatted(
DateTime $startDate,
$offset,
$dateFormat = 'D, M j, Y') {
$eventDate = clone $startDate;
$eventDate->add(new DateInterval('P' . $offset . 'D'));
// Format the date.
$eventDate = $this->getCalendarDateFromDayOffset($startDate, $offset);
// Format the date
$eventDateFormatted = $eventDate->format($dateFormat);
return $eventDateFormatted;
......
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