Skip to content

Commit

Permalink
SAK-45054 Add Lessons items to Tasks widget (sakaiproject#10198)
Browse files Browse the repository at this point in the history
SAK-45054 Add Lessons items to Tasks widget
  • Loading branch information
ropemar authored Jan 31, 2022
1 parent 61fd6fd commit 5138e02
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,15 @@ public ResourceProperties getEntityResourceProperties(Reference ref) {
*/
public String getEntityUrl(Reference ref)
{
//Just return a URL to the top of the page based on the item's pageId and toolId
String URL = "";
long id = idFromRef(ref.getReference());
if ("page".equals(ref.getSubType())) {
SimplePage currentPage = simplePageToolDao.getPage(id);
URL = String.format("%s/site/%s/page/%s", ServerConfigurationService.getPortalUrl(), currentPage.getSiteId(), currentPage.getToolId());
return URL;
}
//Just return a URL to the top of the page based on the item's pageId and toolId
SimplePageItem item = simplePageToolDao.findItem(id);
String URL = "";
if (item != null) {
URL = item.getURL();
if (URL == null || "".equals(URL) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
import org.sakaiproject.site.api.SitePage;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.site.api.ToolConfiguration;
import org.sakaiproject.tasks.api.Priorities;
import org.sakaiproject.tasks.api.Task;
import org.sakaiproject.tasks.api.TaskService;
import org.sakaiproject.time.api.UserTimeService;
import org.sakaiproject.tool.api.Placement;
import org.sakaiproject.tool.api.SessionManager;
Expand Down Expand Up @@ -294,6 +297,11 @@ public enum Status {
private String dropDown;
private String points;
private String mimetype;
@Getter @Setter private boolean createTask;
@Getter @Setter private boolean questionCreateTask;
@Getter @Setter private boolean commentsCreateTask;
@Getter @Setter private boolean studentContentsCreateTask;

// for BLTI, values window, inline, and null for in a new page with navigation
// but sameWindow should also be set properly, based on the format
private String format;
Expand Down Expand Up @@ -461,6 +469,7 @@ public String[] getNewColorLabelsI18n() {
@Setter private UserDirectoryService userDirectoryService;
@Setter private FormattedText formattedText;
@Setter private UserTimeService userTimeService;
@Getter @Setter private TaskService taskService;

private LessonEntity forumEntity = null;
public void setForumEntity(Object e) {
Expand Down Expand Up @@ -1024,7 +1033,6 @@ public void setReplacefile(boolean replacefile) {
this.replacefile = replacefile;
}


public void setNewWindow(boolean newWindow) {
this.newWindow = newWindow;
}
Expand Down Expand Up @@ -2173,6 +2181,10 @@ public String deleteItem(SimplePageItem i) {

b = simplePageToolDao.deleteItem(i);

// Delete task
String reference = "/lessonbuilder/item/" + i.getId();
taskService.removeTaskByReference(reference);

if (b) {
// minimize opening for race conditions on sequence number by forcing new fetches
simplePageToolDao.setRefreshMode();
Expand Down Expand Up @@ -4421,7 +4433,7 @@ public String editTitle() {
if (StringUtils.isBlank(pageTitle)) {
return "notitle";
}

// because we're using a security advisor, need to make sure it's OK ourselves
if (!canEditPage()) {
return "permission-failed";
Expand Down Expand Up @@ -4599,6 +4611,14 @@ public SecurityAdvice isAllowed(String userId, String function, String reference
if (needRecompute)
recomputeGradebookEntries(page.getPageId(), points);
// points, not newPoints because API wants a string

// Create or update a task
String reference = "/lessonbuilder/page/" + page.getPageId();
if (this.createTask) {
createOrUpdateTask(reference, page.getSiteId(), page.getTitle(), null);
} else {
updateTask(reference, page.getTitle(), null);
}

if (pageItem.getPageId() == 0) {
return "reload";
Expand Down Expand Up @@ -7327,6 +7347,9 @@ public String addComment() {
SimplePageComment commentObject = simplePageToolDao.makeComment(itemId, currentPageId, userId, comment, idManager.createUuid(), html);
commentObject.setPoints(grade);

// Complete user task
this.completeUserTask(itemId, userId);

saveItem(commentObject, false);
}else {
SimplePageComment commentObject = simplePageToolDao.findCommentById(Long.valueOf(editId));
Expand Down Expand Up @@ -7423,6 +7446,15 @@ public String updateComments() {
comment.setGradebookPoints(null);
}

// Create or update a task
String reference = "/lessonbuilder/item/" + comment.getId();
String title = getPage(comment.getPageId()).getTitle() + " - " + messageLocator.getMessage("simplepage.comments-task-title");
if (this.commentsCreateTask) {
createOrUpdateTask(reference, getCurrentSiteId(), title, null);
} else {
updateTask(reference, title, null);
}

// for forced comments, the UI won't ever do this, but if
// it does, update will fail with permissions
update(comment);
Expand Down Expand Up @@ -7603,6 +7635,9 @@ public int compare(Object o1, Object o2) {
newPage.setTopParent(page.getId());
update(newPage, false);

// Complete user task
this.completeUserTask(itemId, user.getId());

try {
updatePageItem(containerItem.getId());
updatePageObject(newPage.getPageId());
Expand Down Expand Up @@ -7830,6 +7865,15 @@ public String updateQuestion() {
setItemGroups(item, selectedGroups);

saveOrUpdate(item);

// Create or update a task
String reference = "/lessonbuilder/item/" + item.getId();
String title = getPage(item.getPageId()).getTitle() + " - " + messageLocator.getMessage("simplepage.question-task-title");
if (this.questionCreateTask) {
createOrUpdateTask(reference, getCurrentSiteId(), title, null);
} else {
updateTask(reference, title, null);
}

if(questionType.equals("multipleChoice")) {
simplePageToolDao.syncQRTotals(item);
Expand Down Expand Up @@ -7947,6 +7991,9 @@ public String answerMultipleChoiceQuestion() {

gradeQuestionResponse(response);

// Complete user task
this.completeUserTask(questionId, userId);

saveItem(response);

return "success";
Expand Down Expand Up @@ -7978,6 +8025,9 @@ public String answerShortanswerQuestion() {
response.setShortanswer(questionResponse);
gradeQuestionResponse(response);

// Complete user task
this.completeUserTask(questionId, userId);

saveItem(response);

return "success";
Expand Down Expand Up @@ -8144,6 +8194,15 @@ public String updateStudent() {
ungradeStudentPageComments(page);
}

// Create or update a task
String reference = "/lessonbuilder/item/" + itemId;
String title = getPage(page.getPageId()).getTitle() + " - " + messageLocator.getMessage("simplepage.student-contents-task-title");
if (this.studentContentsCreateTask) {
createOrUpdateTask(reference, getCurrentSiteId(), title, null);
} else {
updateTask(reference, title, null);
}

update(page);

return "success";
Expand Down Expand Up @@ -9208,4 +9267,43 @@ public String addTwitterTimeline(){
public boolean isGradebookExists() {
return (this.getCurrentTool(this.GRADEBOOK_TOOL_ID) != null || this.getCurrentTool(this.GRADEBOOK_CLASSIC_TOOL_ID) != null);
}

private void updateTask(String reference, String title, Date dueDate) {
Optional<Task> taskOpt = taskService.getTask(reference);
if (taskOpt.isPresent()) {
Task task = taskOpt.get();
task.setDescription(title);
task.setDue(dueDate == null ? null : dueDate.toInstant());
taskService.saveTask(task);
}
}

private void createOrUpdateTask(String reference, String siteId, String title, Date dueDate) {
Optional<Task> taskOpt = taskService.getTask(reference);
if (!taskOpt.isPresent()) {
try {
Task task = new Task();
task.setSiteId(siteId);
task.setReference(reference);
task.setSystem(true);
task.setDescription(title);
task.setDue(dueDate == null ? null : dueDate.toInstant());
Site site = siteService.getSite(siteId);
Set<String> users = site.getUsersIsAllowed("section.role.student");
taskService.createTask(task, users, Priorities.HIGH);
} catch (Exception e) {
log.error(messageLocator.getMessage("simplepage.errorCreatingTask"), e);
}
} else {
Task task = taskOpt.get();
task.setDescription(title);
task.setDue(dueDate == null ? null : dueDate.toInstant());
taskService.saveTask(task);
}
}

private void completeUserTask(Long itemId, String userId) {
taskService.completeUserTaskByReference("/lessonbuilder/item/" + itemId, Arrays.asList(userId) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5024,6 +5024,7 @@ private void createEditTitleDialog(UIContainer tofill, SimplePage page, SimplePa
if (points != null) {
pointString = points.toString();
}
UIBoundBoolean.make(form, "page-task", "#{simplePageBean.createTask}", true);

if(!simplePageBean.isStudentPage(page)) {
UIOutput.make(form, "csssection");
Expand Down Expand Up @@ -5184,7 +5185,9 @@ private void createCommentsDialog(UIContainer tofill) {
}
UIBoundBoolean.make(form, "comments-graded", "#{simplePageBean.graded}");
UIInput.make(form, "comments-max", "#{simplePageBean.maxPoints}");


UIBoundBoolean.make(form, "comments-create-task", "#{simplePageBean.commentsCreateTask}", true);

UIBoundBoolean.make(form, "comments-required", "#{simplePageBean.required}");
UIBoundBoolean.make(form, "comments-prerequisite", "#{simplePageBean.prerequisite}");

Expand Down Expand Up @@ -5231,6 +5234,8 @@ private void createStudentContentDialog(UIContainer tofill, SimplePage currentPa

UIBoundBoolean.make(form, "student-graded", "#{simplePageBean.graded}");
UIInput.make(form, "student-max", "#{simplePageBean.maxPoints}");

UIBoundBoolean.make(form, "student-create-task", "#{simplePageBean.studentContentsCreateTask}", true);

UIOutput gradeBook = UIOutput.make(form, "gradeBookStudentsDiv");
UIOutput gradeBook2 = UIOutput.make(form, "gradeBookStudentCommentsDiv");
Expand Down Expand Up @@ -5282,6 +5287,8 @@ private void createQuestionDialog(UIContainer tofill, SimplePage currentPage) {
UIInput.make(form, "question-gradebook-title", "#{simplePageBean.gradebookTitle}");
UIInput.make(form, "question-max", "#{simplePageBean.maxPoints}");

UIBoundBoolean.make(form, "question-create-task", "#{simplePageBean.questionCreateTask}", true);

UIInput.make(form, "question-multiplechoice-answer-complete", "#{simplePageBean.addAnswerData}");
UIInput.make(form, "question-multiplechoice-answer-id", null);
UIBoundBoolean.make(form, "question-multiplechoice-answer-correct");
Expand Down
5 changes: 5 additions & 0 deletions lessonbuilder/tool/src/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ simplepage.notreleased.text=Note: This page will not be available to standard us
simplepage.page.gradebook=Create Gradebook item when page is completed.
simplepage.points=points
simplepage.endmenu=End of menu. Use Escape to close it.
simplepage.createtask=Create a task on student's dashboard
simplepage.errorCreatingTask=There was an error when attempting to create a Task.
simplepage.question-task-title=Answer question
simplepage.comments-task-title=Add comments
simplepage.student-contents-task-title=Add contents

simplepage.overquota=Unable to add resource: it would take your site over its quota
simplepage.resourceerror=Unable to add resource: {}
Expand Down
5 changes: 5 additions & 0 deletions lessonbuilder/tool/src/resources/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ simplepage.notreleased.text=Nota\: Esta p\u00e1gina no estar\u00e1 disponible al
simplepage.page.gradebook=A\u00f1adir \u00edtem en Calificaciones cuando la p\u00e1gina est\u00e9 completada
simplepage.points=puntos
simplepage.endmenu=Final del men\u00fa. Use la tecla "Esc" para cerrarlo.
simplepage.createtask=Crear una tarea en el widget de Tareas.
simplepage.errorCreatingTask=Hubo un error al intentar crear una tarea.
simplepage.question-task-title=Responder pregunta
simplepage.comments-task-title=A\u00f1adir comentarios
simplepage.student-contents-task-title=A\u00f1adir contenidos

simplepage.overquota=Imposible a\u00f1adir un recurso\: se sobrepasar\u00e1 la cuota de recursos del sitio
simplepage.resourceerror=Imposible a\u00f1adir el recurso\: {}
Expand Down
6 changes: 5 additions & 1 deletion lessonbuilder/tool/src/webapp/WEB-INF/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ simplePageBean.newOwner,
simplePageBean.forumSummaryHeight,
simplePageBean.forumSummaryDropDown,
simplePageBean.addCalendar,
simplePageBean.addForumSummary
simplePageBean.addForumSummary,
simplePageBean.createTask,
simplePageBean.questionCreateTask,
simplePageBean.commentsCreateTask,
simplePageBean.studentContentsCreateTask
</value>
</property>
</bean>
Expand Down
1 change: 1 addition & 0 deletions lessonbuilder/tool/src/webapp/WEB-INF/requestContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
<property name="userDirectoryService" ref="org.sakaiproject.user.api.UserDirectoryService"/>
<property name="formattedText" ref="org.sakaiproject.util.api.FormattedText" />
<property name="userTimeService" ref="org.sakaiproject.time.api.UserTimeService"/>
<property name="taskService" ref="org.sakaiproject.tasks.api.TaskService"/>
</bean>

<!-- Over-riding the CommonsMultipartResolver to have multiple files incoming under the same form input name -->
Expand Down
10 changes: 7 additions & 3 deletions lessonbuilder/tool/src/webapp/removePage.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
%><%@ page import="org.sakaiproject.event.cover.EventTrackingService" %><%
%><%@ page import="org.sakaiproject.lessonbuildertool.api.LessonBuilderEvents" %><%
%><%@ page import="org.sakaiproject.lessonbuildertool.SimplePage" %><%
%><%@ page import="org.apache.commons.text.StringEscapeUtils" %>
%><%@ page import="org.apache.commons.text.StringEscapeUtils" %><%
%><%@ page import="org.sakaiproject.tasks.api.TaskService" %>



<html xmlns="http://www.w3.org/1999/xhtml">
Expand All @@ -40,6 +42,8 @@
SimplePageToolDao dao = (SimplePageToolDao)ComponentManager
.get(SimplePageToolDao.class);
TaskService taskService = (TaskService)ComponentManager.get(TaskService.class);
String siteId = request.getParameter("site");
Site site = null;
Expand Down Expand Up @@ -99,8 +103,8 @@
}
EventTrackingService.post(EventTrackingService.newEvent(LessonBuilderEvents.PAGE_REMOVE, "/lessonbuilder/page/" + simplePage.getPageId(), true));
out.println("<script>parent.location.replace(\"/portal/site/" + URLEncoder.encode(site.getId(), "UTF-8") + "\")</script>");
taskService.removeTaskByReference("/lessonbuilder/page/" + simplePage.getPageId());
out.println("<script>parent.location.replace(\"/portal/site/" + URLEncoder.encode(site.getId(), "UTF-8") + "\")</script>");
%>

Expand Down
20 changes: 19 additions & 1 deletion lessonbuilder/tool/src/webapp/templates/ShowPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,13 @@ <h4 class="panel-title">
</p>
</div>

<div id="tasks">
<p class="checkbox">
<input type="checkbox" name="page-task" id="page-task" rsf:id="page-task" />
<label for="page-task"><span rsf:id="msg=simplepage.createtask"></span></label>
</p>
</div>

<div rsf:id="csssection">

<hr />
Expand Down Expand Up @@ -2012,6 +2019,10 @@ <h4 class="panel-title">
<input type="text" name="comments-max" id="comments-max" rsf:id="comments-max" size="5" maxlength="5"/>
</p>
</div>
<p class="checkbox">
<input type="checkbox" name="comments-create-task" id="comments-create-task" rsf:id="comments-create-task" />
<label for="comments-create-task"><span rsf:id="msg=simplepage.createtask"></span></label>
</p>
<p class="checkbox">
<input type="checkbox" name="comments-prerequisite" id="comments-prerequisite" rsf:id="comments-prerequisite" />
<label for="comments-prerequisite"><span rsf:id="msg=simplepage.prerequisites_label"></span></label>
Expand Down Expand Up @@ -2095,7 +2106,10 @@ <h4 class="panel-title">
</p>
<br /><br />
</div>

<p class="checkbox">
<input type="checkbox" name="student-create-task" id="student-create-task" rsf:id="student-create-task" />
<label for="student-create-task"><span rsf:id="msg=simplepage.createtask"></span></label>
</p>
<p class="checkbox">
<input type="checkbox" name="student-comments" id="student-comments" rsf:id="student-comments" />
<label for="student-comments"><span rsf:id="msg=simplepage.student-comments"></span></label>
Expand Down Expand Up @@ -2379,6 +2393,10 @@ <h4 class="panel-title">
<input type="text" name="question-max" id="question-max" rsf:id="question-max" />
</p>
</div>
<p class="checkbox">
<input type="checkbox" name="question-create-task" id="question-create-task" rsf:id="question-create-task" />
<label for="question-create-task"><span rsf:id="msg=simplepage.createtask"></span></label>
</p>
<div class="longtext">
<label for="question-correct-text"><span rsf:id="msg=simplepage.correct-text"></span></label><br />
<textarea rsf:id="question-correct-text" name="question-correct-text" id="question-correct-text" rows="3" columns="30"></textarea>
Expand Down

0 comments on commit 5138e02

Please sign in to comment.