Skip to content

Commit

Permalink
SAK-50493 Lessons improve print experience (sakaiproject#12917)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottenhoff authored Sep 27, 2024
1 parent 330898a commit c6ff0ac
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -965,13 +965,11 @@ public int compare(SimpleStudentPage o1, SimpleStudentPage o2) {
List<SimplePageItem> itemList = null;

// items to show
if(httpServletRequest.getParameter("printall") != null && currentPage.getTopParent() != null)
{
itemList = (List<SimplePageItem>) simplePageBean.getItemsOnPage(currentPage.getTopParent());
if(httpServletRequest.getParameter("printall") != null && currentPage.getTopParent() != null) {
itemList = simplePageBean.getItemsOnPage(currentPage.getTopParent());
}
else
{
itemList = (List<SimplePageItem>) simplePageBean.getItemsOnPage(currentPage.getPageId());
else {
itemList = simplePageBean.getItemsOnPage(currentPage.getPageId());
}

// Move all items with sequence <= 0 to the end of the list.
Expand Down
46 changes: 28 additions & 18 deletions lessonbuilder/tool/src/webapp/js/show-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ $(window).load(function () {
document.getElementById(questionToScrollTo).scrollIntoView(true);
}

// Print the current page
document.getElementById('print-view').addEventListener('click', function() {
const url = printView(window.location.href);
const win = window.open(url, '_blank');
win.focus();
win.print();
return false;
});

// Print all pages
document.getElementById('print-all').addEventListener('click', function() {
const url = printViewWithParameter(window.location.href);
const win = window.open(url, '_blank');
win.focus();
win.print();
return false;
});

});

function fixAddBefore(href) {
Expand Down Expand Up @@ -3620,27 +3638,19 @@ function toggleShortUrlOutput(defaultUrl, checkbox, textbox) {
}

function printView(url) {
var i = url.indexOf("/site/");
if (i < 0)
return url;
var j = url.indexOf("/tool/");
if (j < 0)
return url;
return url.substring(0, i) + url.substring(j);
const siteIndex = url.indexOf("/site/");
const toolIndex = url.indexOf("/tool/");
if (siteIndex < 0 || toolIndex < 0) return url;
return url.substring(0, siteIndex) + url.substring(toolIndex);
}

function printViewWithParameter(url) {
var i = url.indexOf("/site/");
if (i < 0)
return url;
var j = url.indexOf("/tool/");
if (j < 0)
return url;
var z = url.indexOf("ShowPage");
if (z < 0)
return url.substring(0, i) + url.substring(j) + '?printall=true';
else
return url.substring(0, i) + url.substring(j) + '&printall=true';
const siteIndex = url.indexOf("/site/");
const toolIndex = url.indexOf("/tool/");
const showPageIndex = url.indexOf("ShowPage");
if (siteIndex < 0 || toolIndex < 0) return url;
const modifiedUrl = url.substring(0, siteIndex) + url.substring(toolIndex);
return showPageIndex < 0 ? `${modifiedUrl}?printall=true` : `${modifiedUrl}&printall=true`;
}

// make columns in a section the same height. Is there a better place to trigger this?
Expand Down
10 changes: 5 additions & 5 deletions lessonbuilder/tool/src/webapp/templates/ShowPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,21 @@ <h3 id="toolbar-label" rsf:id="msg=simplepage.toolbar" class="lb-offscreen"></h3
<!-- /tool-bar -->
<div id="contentButtonsForAllRoles" class="text-end">
<span class="contentButton">
<a role="button" href="#" rsf:id="print-view" id="print-view" onclick="window.open(printView(window.location.href));return false" class="btn btn-link my-1 Mrphs-toolTitleNav__link top-icon">
<a role="button" href="#" rsf:id="print-view" id="print-view" class="btn btn-link my-1 Mrphs-toolTitleNav__link top-icon">
<span rsf:id="msg=simplepage.print_view" class="Mrphs-itemTitle me-1 d-none d-xl-inline-block"></span>
<i class="bi-printer"></i>
<span class="bi-printer" aria-hidden="true"></span>
</a>
</span>
<span class="contentButton">
<a role="button" href="#" rsf:id="print-all" id="print-all" onclick="window.open(printViewWithParameter(window.location.href));return false" class="btn btn-link my-1 Mrphs-toolTitleNav__link top-icon">
<a role="button" href="#" rsf:id="print-all" id="print-all" class="btn btn-link my-1 Mrphs-toolTitleNav__link top-icon">
<span rsf:id="msg=simplepage.print_all" class="Mrphs-itemTitle me-1 d-none d-xl-inline-block"></span>
<i class="bi-printer-fill"></i>
<span class="bi-printer-fill" aria-hidden="true"></span>
</a>
</span>
<span class="contentButton">
<a role="button" href="#" rsf:id="show-pages" id="show-pages" class="btn btn-link my-1 Mrphs-toolTitleNav__link top-icon">
<span rsf:id="msg=simplepage.showallpages" class="Mrphs-itemTitle me-1 d-none d-lg-inline-block"></span>
<i class="bi-list-ol"></i>
<span class="bi-list-ol" aria-hidden="true"></span>
</a>
</span>
</div>
Expand Down
13 changes: 12 additions & 1 deletion library/src/skins/default/src/sass/print.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,26 @@ aside.offcanvas,
height: 32px;
}

.#{$namespace}sakai-lessonbuildertool {
/* This is Lessons in print mode */
div.portletBody {
ul#toolbar,
.lb-offscreen,
.modal-dialog,
a.ui-button,
.edit-col,
.sectionedit,
img.question-image,
.editsection,
.showPollGraph {
display: none !important;
}

[role="listitem"] {
border-bottom: 2px solid black;
margin-bottom: 20px;
padding-bottom: 10px;
}

.oldPortal .portletTitle {
padding-top: 30px !important
}
Expand Down

0 comments on commit c6ff0ac

Please sign in to comment.