From 334f38c0e82543bfec1864412e93ce27c433e792 Mon Sep 17 00:00:00 2001 From: srosse <stephane.rosse@frentix.com> Date: Mon, 6 Jan 2020 14:25:45 +0100 Subject: [PATCH] OO-4424: dates are mandatory in admin. / coaching of lectures --- .../ui/AbstractTeacherOverviewController.java | 4 +- .../lecture/ui/LecturesMainController.java | 8 +-- .../ui/TeacherOverviewSearchController.java | 57 +++++++++++++++++-- .../ui/TeacherToolOverviewController.java | 19 ++++++- 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/olat/modules/lecture/ui/AbstractTeacherOverviewController.java b/src/main/java/org/olat/modules/lecture/ui/AbstractTeacherOverviewController.java index 769b3e02a83..e1986a76dec 100644 --- a/src/main/java/org/olat/modules/lecture/ui/AbstractTeacherOverviewController.java +++ b/src/main/java/org/olat/modules/lecture/ui/AbstractTeacherOverviewController.java @@ -75,7 +75,7 @@ public abstract class AbstractTeacherOverviewController extends BasicController private TeacherRollCallController rollCallCtrl; private TeacherRollCallWizardController rollCallWizardCtrl; - private TeacherOverviewSearchController searchCtrl; + protected TeacherOverviewSearchController searchCtrl; private TeacherLecturesTableController currentLecturesBlockCtrl; private TeacherLecturesTableController pendingLecturesBlockCtrl; private TeacherLecturesTableController nextLecturesBlockCtrl; @@ -120,7 +120,7 @@ public abstract class AbstractTeacherOverviewController extends BasicController } protected void initTables(UserRequest ureq, boolean withTeachers, boolean withAssessment) { - searchCtrl = new TeacherOverviewSearchController(ureq, getWindowControl(), withRepositoryEntry); + searchCtrl = new TeacherOverviewSearchController(ureq, getWindowControl(), withRepositoryEntry, withRepositoryEntry); listenTo(searchCtrl); mainVC.put("search", searchCtrl.getInitialComponent()); diff --git a/src/main/java/org/olat/modules/lecture/ui/LecturesMainController.java b/src/main/java/org/olat/modules/lecture/ui/LecturesMainController.java index 4fb7d123fa5..0986c05fff1 100644 --- a/src/main/java/org/olat/modules/lecture/ui/LecturesMainController.java +++ b/src/main/java/org/olat/modules/lecture/ui/LecturesMainController.java @@ -44,7 +44,7 @@ public class LecturesMainController extends MainLayoutBasicController implements private final TooledStackedPanel content; private LayoutMain3ColsController columnLayoutCtr; - private final LecturesCoachingController lectureCoochingCtrl; + private final LecturesCoachingController lectureCoachingCtrl; public LecturesMainController(UserRequest ureq, WindowControl wControl) { super(ureq, wControl); @@ -55,15 +55,15 @@ public class LecturesMainController extends MainLayoutBasicController implements // TODO principal LecturesSecurityCallback secCallback = LecturesSecurityCallbackFactory.getSecurityCallback(true, false, false, LectureRoles.lecturemanager, false); - lectureCoochingCtrl = new LecturesCoachingController(ureq, getWindowControl(), content, secCallback); - listenTo(lectureCoochingCtrl); + lectureCoachingCtrl = new LecturesCoachingController(ureq, getWindowControl(), content, secCallback); + listenTo(lectureCoachingCtrl); columnLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), null, content, "lectures"); columnLayoutCtr.addCssClassToMain("o_lectures"); listenTo(columnLayoutCtr); // auto dispose later putInitialPanel(columnLayoutCtr.getInitialComponent()); - content.rootController("[ROOT]", lectureCoochingCtrl); + content.rootController("[ROOT]", lectureCoachingCtrl); } @Override diff --git a/src/main/java/org/olat/modules/lecture/ui/TeacherOverviewSearchController.java b/src/main/java/org/olat/modules/lecture/ui/TeacherOverviewSearchController.java index 019362a6ccf..8232e1c6766 100644 --- a/src/main/java/org/olat/modules/lecture/ui/TeacherOverviewSearchController.java +++ b/src/main/java/org/olat/modules/lecture/ui/TeacherOverviewSearchController.java @@ -50,18 +50,42 @@ import org.springframework.beans.factory.annotation.Autowired; public class TeacherOverviewSearchController extends FormBasicController implements Activateable2 { private TextElement searchEl; - private DateChooser startEl, endEl; + private DateChooser endEl; + private DateChooser startEl; + private Date defaultStartDate; + private Date defaultEndDate; + private final boolean forceDates; private final boolean withSearchString; @Autowired private RepositoryService repositoryService; - public TeacherOverviewSearchController(UserRequest ureq, WindowControl wControl, boolean withSearchString) { + /** + * + * @param ureq The user request + * @param wControl The window control + * @param withSearchString Show the field to search with text + * @param forceDates true if dates are mandatory + */ + public TeacherOverviewSearchController(UserRequest ureq, WindowControl wControl, + boolean withSearchString, boolean forceDates) { super(ureq, wControl, FormBasicController.LAYOUT_VERTICAL); this.withSearchString = withSearchString; + this.forceDates = forceDates; initForm(ureq); } + + public void setDefaultDates(Date start, Date end) { + this.defaultStartDate = start; + this.defaultEndDate = end; + if(startEl != null && defaultStartDate != null) { + startEl.setDate(defaultStartDate); + } + if(endEl != null && defaultEndDate != null) { + endEl.setDate(defaultEndDate); + } + } @Override protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { @@ -71,7 +95,13 @@ public class TeacherOverviewSearchController extends FormBasicController impleme FormLayoutContainer dateLayout = FormLayoutContainer.createHorizontalFormLayout("dateLayout", getTranslator()); formLayout.add(dateLayout); startEl = uifactory.addDateChooser("start", "search.form.start", null, dateLayout); + if(startEl != null) { + startEl.setDate(defaultStartDate); + } endEl = uifactory.addDateChooser("end", "search.form.end", null, dateLayout); + if(endEl != null) { + endEl.setDate(defaultEndDate); + } FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator()); buttonsCont.setRootForm(mainForm); @@ -108,6 +138,25 @@ public class TeacherOverviewSearchController extends FormBasicController impleme } } + @Override + protected boolean validateFormLogic(UserRequest ureq) { + boolean allOk = super.validateFormLogic(ureq); + + if(forceDates) { + if(startEl.getDate() == null) { + startEl.setErrorKey("form.legende.mandatory", null); + allOk &= false; + } + + if(endEl.getDate() == null) { + endEl.setErrorKey("form.legende.mandatory", null); + allOk &= false; + } + } + + return allOk; + } + @Override protected void formOK(UserRequest ureq) { doSearch(ureq); @@ -116,8 +165,8 @@ public class TeacherOverviewSearchController extends FormBasicController impleme @Override protected void formCancelled(UserRequest ureq) { searchEl.setValue(null); - startEl.setDate(null); - endEl.setDate(null); + startEl.setDate(defaultStartDate); + endEl.setDate(defaultEndDate); fireEvent(ureq, Event.CANCELLED_EVENT); } diff --git a/src/main/java/org/olat/modules/lecture/ui/TeacherToolOverviewController.java b/src/main/java/org/olat/modules/lecture/ui/TeacherToolOverviewController.java index 9c9f0b0e4cd..af63949a911 100644 --- a/src/main/java/org/olat/modules/lecture/ui/TeacherToolOverviewController.java +++ b/src/main/java/org/olat/modules/lecture/ui/TeacherToolOverviewController.java @@ -20,6 +20,8 @@ package org.olat.modules.lecture.ui; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -53,7 +55,22 @@ public class TeacherToolOverviewController extends AbstractTeacherOverviewContro super(ureq, wControl, false, "Lectures::UserTools", true, false); this.secCallback = secCallback; initTables(ureq, false, false); - loadModel(null); + + LecturesBlockSearchParameters searchParams = getDefaultSearchParameters(); + searchCtrl.setDefaultDates(searchParams.getStartDate(), searchParams.getEndDate()); + loadModel(searchParams); + } + + private LecturesBlockSearchParameters getDefaultSearchParameters() { + LecturesBlockSearchParameters searchParams = new LecturesBlockSearchParameters(); + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DATE, -14); + Date start = cal.getTime(); + searchParams.setStartDate(start); + cal.add(Calendar.DATE, 28); + Date end = cal.getTime(); + searchParams.setEndDate(end); + return searchParams; } @Override -- GitLab