Skip to content
Snippets Groups Projects
Commit 2c1a45a6 authored by fkiefer's avatar fkiefer
Browse files

enable choice of binders and owned sections

enable floating entries with ownership
parent 2103afc4
No related branches found
No related tags found
No related merge requests found
Showing
with 123 additions and 55 deletions
......@@ -137,7 +137,7 @@ public interface PortfolioService {
* @param summary
* @param section
*/
public Page appendNewPage(String title, String summary, String imagePath, SectionRef section);
public Page appendNewPage(Identity owner, String title, String summary, String imagePath, SectionRef section);
public Page getPageByKey(Long key);
......
......@@ -142,18 +142,19 @@ public class PageDAO {
public List<Page> getOwnedPages(IdentityRef owner) {
StringBuilder sb = new StringBuilder();
sb.append("select page from pfpage as page")
.append(" inner join page.section as section")
.append(" inner join section.binder as binder")
.append(" inner join fetch page.body as body")
.append(" left join page.section as section")
.append(" left join section.binder as binder")
.append(" where exists (select pageMember from bgroupmember as pageMember")
.append(" inner join pageMember.identity as ident on (ident.key=:ownerKey and pageMember.role='").append(GroupRoles.owner.name()).append("')")
.append(" where pageMember.group.key=binder.baseGroup.key or pageMember.group.key=page.baseGroup.key")
.append(" where pageMember.group.key=page.baseGroup.key or pageMember.group.key=binder.baseGroup.key or pageMember.group.key=page.baseGroup.key")
.append(" )");
return dbInstance.getCurrentEntityManager()
List<Page> pages = dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Page.class)
.setParameter("ownerKey", owner.getKey())
.getResultList();
return pages;
}
public Page loadByKey(Long key) {
......
......@@ -282,9 +282,11 @@ public class PortfolioServiceImpl implements PortfolioService {
}
@Override
public Page appendNewPage(String title, String summary, String imagePath, SectionRef section) {
Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
return pageDao.createAndPersist(title, summary, null, reloadedSection, null);
public Page appendNewPage(Identity owner, String title, String summary, String imagePath, SectionRef section) {
Section reloadedSection = section == null ? null : binderDao.loadSectionByKey(section.getKey());
Page page = pageDao.createAndPersist(title, summary, null, reloadedSection, null);
groupDao.addMembership(page.getBaseGroup(), owner, PortfolioRoles.owner.name());
return page;
}
@Override
......
......@@ -100,7 +100,7 @@ public class PageImpl implements Persistable, ModifiedInfo, CreateInfo, Page {
@JoinColumn(name="fk_group_id", nullable=false, insertable=true, updatable=false)
private Group baseGroup;
@ManyToOne(targetEntity=SectionImpl.class,fetch=FetchType.LAZY,optional=false)
@ManyToOne(targetEntity=SectionImpl.class,fetch=FetchType.LAZY,optional=true)
@JoinColumn(name="fk_section_id", nullable=true, insertable=true, updatable=true)
private Section section;
......
......@@ -70,8 +70,16 @@ public class PageRow {
public String getSectionTitle() {
return section.getTitle();
}
public boolean isSection () {
if(section == null){
return false;
}
return true;
}
public String getSectionLongTitle() {
long pos = section.getPos();
return (pos+1) + ". " + section.getTitle();
}
......
......@@ -101,7 +101,7 @@ public class MyPageListController extends AbstractPageListController {
private void doCreateNewPage(UserRequest ureq) {
if(newPageCtrl != null) return;
newPageCtrl = new PageMetadataEditController(ureq, getWindowControl(), null, false, null, false);
newPageCtrl = new PageMetadataEditController(ureq, getWindowControl(), null, true, null, true);
listenTo(newPageCtrl);
String title = translate("create.new.page");
......
......@@ -173,7 +173,7 @@ public class PageController extends FormBasicController implements TooledControl
binder = portfolioService.getBinderBySection(section);
}
editMetadataCtrl = new PageMetadataEditController(ureq, getWindowControl(), binder, false, section, false, page);
editMetadataCtrl = new PageMetadataEditController(ureq, getWindowControl(), binder, true, section, true, page);
listenTo(editMetadataCtrl);
String title = translate("edit.page.metadata");
......
......@@ -20,8 +20,10 @@
package org.olat.modules.portfolio.ui;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.olat.core.gui.UserRequest;
......@@ -74,6 +76,10 @@ public class PageMetadataEditController extends FormBasicController {
private final boolean chooseBinder;
private final boolean chooseSection;
private final boolean allowFloatingEntry;
private boolean floatingEntry = false;
@Autowired
private PortfolioService portfolioService;
......@@ -88,6 +94,7 @@ public class PageMetadataEditController extends FormBasicController {
this.chooseBinder = chooseBinder;
this.chooseSection = chooseSection;
this.allowFloatingEntry = false;
initForm(ureq);
}
......@@ -104,6 +111,7 @@ public class PageMetadataEditController extends FormBasicController {
this.chooseBinder = chooseBinder;
this.chooseSection = chooseSection;
this.allowFloatingEntry = false;
initForm(ureq);
}
......@@ -138,44 +146,45 @@ public class PageMetadataEditController extends FormBasicController {
}
}
//list of binder
if(chooseBinder) {
// list of binder
if (chooseBinder) {
List<Binder> binders = portfolioService.searchOwnedBinders(getIdentity());
String[] theKeys = new String[binders.size()+1];
String[] theValues = new String[binders.size()+1];
for (int i = 0; i < binders.size(); ++i) {
theKeys[i] = binders.get(i).getKey().toString();
theValues[i] = StringHelper.escapeHtml(binders.get(i).getTitle());
}
theKeys[binders.size()] = "none";
theValues[binders.size()] = "none";
bindersEl = uifactory.addDropdownSingleselect("binders", "page.binders", formLayout, theKeys, theValues, null);
bindersEl.addActionListener(FormEvent.ONCHANGE);
if (currentBinder == null) {
currentBinder = binders.get(0);
} else {
for (String key : theKeys) {
if (key.equals(currentBinder.getKey().toString()))
bindersEl.select(key, true);
}
}
} else {
String[] theKeys = new String[] { currentBinder.getKey().toString() };
String[] theValues = new String[]{ StringHelper.escapeHtml(currentBinder.getTitle()) };
String[] theValues = new String[] { StringHelper.escapeHtml(currentBinder.getTitle()) };
bindersEl = uifactory.addDropdownSingleselect("binders", "page.binders", formLayout, theKeys, theValues, null);
bindersEl.setEnabled(false);
}
//list of sections
if(chooseSection) {
if(chooseBinder) {
} else {
List<Section> sections = portfolioService.getSections(currentBinder);
if(sections.isEmpty()) {
//wrong
} else {
int numOfSections = sections.size();
String selectedKey = null;
String[] theKeys = new String[numOfSections];
String[] theValues = new String[numOfSections];
for(int i=0; i<numOfSections; i++) {
Long sectionKey = sections.get(i).getKey();
theKeys[i] = sectionKey.toString();
theValues[i] = (i + 1) + ". " + StringHelper.escapeHtml(sections.get(i).getTitle());
if(currentSection != null && currentSection.getKey().equals(sectionKey)) {
selectedKey = theKeys[i];
}
}
sectionsEl = uifactory.addDropdownSingleselect("sections", "page.sections", formLayout, theKeys, theValues, null);
if(selectedKey != null) {
sectionsEl.select(selectedKey, true);
}
}
}
} else {
retrieveSections(formLayout, true);
} else {// currently never used
String[] theKeys = new String[] { currentSection.getKey().toString() };
String[] theValues = new String[]{ StringHelper.escapeHtml(currentSection.getTitle()) };
sectionsEl = uifactory.addDropdownSingleselect("sections", "page.sections", formLayout, theKeys, theValues, null);
......@@ -192,6 +201,42 @@ public class PageMetadataEditController extends FormBasicController {
}
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
protected void retrieveSections(FormItemContainer formLayout, boolean updateBox) {
List<Section> sections = portfolioService.getSections(currentBinder);
if (sections.isEmpty()) {
// wrong
} else {
int numOfSections = sections.size();
String selectedKey = null;
String[] theKeys = new String[numOfSections];
String[] theValues = new String[numOfSections];
for (int i = 0; i < numOfSections; i++) {
Long sectionKey = sections.get(i).getKey();
theKeys[i] = sectionKey.toString();
theValues[i] = (i + 1) + ". " + StringHelper.escapeHtml(sections.get(i).getTitle());
if (currentSection != null && currentSection.getKey().equals(sectionKey)) {
selectedKey = theKeys[i];
}
}
if (updateBox) {
sectionsEl = uifactory.addDropdownSingleselect("sections", "page.sections", formLayout, theKeys,
theValues, null);
} else {
sectionsEl.setKeysAndValues(theKeys, theValues, null);
}
if (selectedKey != null) {
sectionsEl.select(selectedKey, true);
}
}
}
protected void updateSections (){
}
@Override
protected boolean validateFormLogic(UserRequest ureq) {
......@@ -202,34 +247,37 @@ public class PageMetadataEditController extends FormBasicController {
@Override
protected void formOK(UserRequest ureq) {
if(page == null) {
if (page == null) {
String title = titleEl.getValue();
String summary = summaryEl.getValue();
SectionRef selectSection = null;
if(sectionsEl.isOneSelected() && sectionsEl.isEnabled()) {
if (sectionsEl.isOneSelected() && sectionsEl.isEnabled() && sectionsEl.isVisible()) {
String selectedKey = sectionsEl.getSelectedKey();
selectSection = new SectionKeyRef(new Long(selectedKey));
}
String imagePath = null;
if(fileUpload.getUploadFile() != null) {
imagePath = portfolioService.addPosterImageForPage(fileUpload.getUploadFile(), fileUpload.getUploadFileName());
if (fileUpload.getUploadFile() != null) {
imagePath = portfolioService.addPosterImageForPage(fileUpload.getUploadFile(),
fileUpload.getUploadFileName());
}
portfolioService.appendNewPage(title, summary, imagePath, selectSection);
portfolioService.appendNewPage(getIdentity(), title, summary, imagePath, selectSection);
} else {
page.setTitle(titleEl.getValue());
page.setSummary(summaryEl.getValue());
if(fileUpload.getUploadFile() != null) {
String imagePath = portfolioService.addPosterImageForPage(fileUpload.getUploadFile(), fileUpload.getUploadFileName());
if (fileUpload.getUploadFile() != null) {
String imagePath = portfolioService.addPosterImageForPage(fileUpload.getUploadFile(),
fileUpload.getUploadFileName());
page.setImagePath(imagePath);
} else if(fileUpload.getInitialFile() == null) {
} else if (fileUpload.getInitialFile() == null) {
page.setImagePath(null);
portfolioService.removePosterImage(page);
}
page = portfolioService.updatePage(page);
}
fireEvent(ureq, Event.DONE_EVENT);
}
......@@ -252,6 +300,15 @@ public class PageMetadataEditController extends FormBasicController {
}
}
}
} else if (bindersEl == source) {
if (bindersEl.getSelectedKey().equals("none")) {
sectionsEl.setVisible(false);
currentBinder = null;
} else {
currentBinder = portfolioService.searchOwnedBinders(getIdentity()).get(bindersEl.getSelected());
sectionsEl.setVisible(true);
retrieveSections(flc, false);
}
}
}
}
}
\ No newline at end of file
#if($row.firstPageOfSection)
#if(${row.isSection()} && $row.firstPageOfSection)
<h3>$r.escapeHtml($row.sectionLongTitle)</h3>
<div class="o_portfolio_section_meta">
<div class="clearfix">
......
......@@ -103,7 +103,7 @@ public class PortfolioServiceTest extends OlatTestCase {
dbInstance.commit();
List<Section> sections = portfolioService.getSections(binder);
Section section = sections.get(0);
portfolioService.appendNewPage("Reviewed page", "", null, section);
portfolioService.appendNewPage(owner, "Reviewed page", "", null, section);
portfolioService.addAccessRights(section, coach, PortfolioRoles.coach);
dbInstance.commit();
......@@ -147,7 +147,7 @@ public class PortfolioServiceTest extends OlatTestCase {
dbInstance.commit();
List<Section> sections = portfolioService.getSections(binder);
Section section = sections.get(0);
portfolioService.appendNewPage("Reviewed page", "", null, section);
portfolioService.appendNewPage(owner, "Reviewed page", "", null, section);
portfolioService.addAccessRights(section, identity, PortfolioRoles.coach);
dbInstance.commit();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment