Search in sources :

Example 1 with BinderPageUsage

use of org.olat.modules.portfolio.model.BinderPageUsage in project OpenOLAT by OpenOLAT.

the class MediaDetailsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("title", StringHelper.escapeHtml(media.getTitle()));
        layoutCont.contextPut("description", StringHelper.xssScan(media.getDescription()));
        layoutCont.contextPut("iconCssClass", handler.getIconCssClass(media));
        mediaCtrl = handler.getMediaController(ureq, getWindowControl(), media, new StandardMediaRenderingHints());
        if (mediaCtrl != null) {
            listenTo(mediaCtrl);
            layoutCont.put("media", mediaCtrl.getInitialComponent());
        }
        String metaPage = velocity_root + "/media_details_metadata.html";
        FormLayoutContainer metaCont = FormLayoutContainer.createCustomFormLayout("meta", getTranslator(), metaPage);
        layoutCont.add("meta", metaCont);
        metaCont.setRootForm(mainForm);
        metaCont.contextPut("media", media);
        String author = userManager.getUserDisplayName(media.getAuthor());
        metaCont.contextPut("author", author);
        if (media.getCollectionDate() != null) {
            String collectionDate = Formatter.getInstance(getLocale()).formatDate(media.getCollectionDate());
            metaCont.contextPut("collectionDate", collectionDate);
        }
        if (media.getBusinessPath() != null) {
            gotoOriginalLink = LinkFactory.createLink("goto.original", metaCont.getFormItemComponent(), this);
        }
        if (StringHelper.containsNonWhitespace(media.getMetadataXml())) {
            Object metadata = MetadataXStream.get().fromXML(media.getMetadataXml());
            metaCont.contextPut("metadata", metadata);
        }
        List<Category> categories = portfolioService.getCategories(media);
        if (categories != null && categories.size() > 0) {
            Map<String, String> categoriesMap = categories.stream().collect(Collectors.toMap(c -> c.getName(), c -> c.getName()));
            TextBoxListElement categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categoriesMap, metaCont, getTranslator());
            categoriesEl.setHelpText(translate("categories.hint"));
            categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
            categoriesEl.setEnabled(false);
        }
        List<FormLink> binderLinks = new ArrayList<>(usedInList.size());
        Set<Long> binderUniqueKeys = new HashSet<>();
        for (BinderPageUsage binder : usedInList) {
            if (binderUniqueKeys.contains(binder.getBinderKey()))
                continue;
            FormLink link;
            if (binder.getBinderKey() == null) {
                link = uifactory.addFormLink("binder_" + (++counter), "page", binder.getPageTitle(), null, metaCont, Link.LINK | Link.NONTRANSLATED);
                binderUniqueKeys.add(binder.getPageKey());
            } else {
                link = uifactory.addFormLink("binder_" + (++counter), "binder", binder.getBinderTitle(), null, metaCont, Link.LINK | Link.NONTRANSLATED);
                binderUniqueKeys.add(binder.getBinderKey());
            }
            link.setUserObject(binder);
            binderLinks.add(link);
        }
        metaCont.contextPut("binderLinks", binderLinks);
    }
}
Also used : BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) FormItem(org.olat.core.gui.components.form.flexible.FormItem) TextBoxListElement(org.olat.core.gui.components.form.flexible.elements.TextBoxListElement) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) Category(org.olat.modules.portfolio.Category) ContextEntry(org.olat.core.id.context.ContextEntry) Media(org.olat.modules.portfolio.Media) Map(java.util.Map) MediaHandler(org.olat.modules.portfolio.MediaHandler) StringHelper(org.olat.core.util.StringHelper) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) StateEntry(org.olat.core.id.context.StateEntry) Formatter(org.olat.core.util.Formatter) PortfolioService(org.olat.modules.portfolio.PortfolioService) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) Link(org.olat.core.gui.components.link.Link) WindowControl(org.olat.core.gui.control.WindowControl) Set(java.util.Set) MediaEvent(org.olat.modules.portfolio.ui.event.MediaEvent) Component(org.olat.core.gui.components.Component) LinkFactory(org.olat.core.gui.components.link.LinkFactory) Collectors(java.util.stream.Collectors) Controller(org.olat.core.gui.control.Controller) UserManager(org.olat.user.UserManager) List(java.util.List) MetadataXStream(org.olat.modules.portfolio.manager.MetadataXStream) NewControllerFactory(org.olat.NewControllerFactory) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Align(org.olat.core.gui.components.stack.TooledStackedPanel.Align) TooledController(org.olat.core.gui.components.stack.TooledController) DialogBoxUIFactory(org.olat.core.gui.control.generic.modal.DialogBoxUIFactory) UserRequest(org.olat.core.gui.UserRequest) PageStatus(org.olat.modules.portfolio.PageStatus) StandardMediaRenderingHints(org.olat.modules.portfolio.model.StandardMediaRenderingHints) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Category(org.olat.modules.portfolio.Category) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) StandardMediaRenderingHints(org.olat.modules.portfolio.model.StandardMediaRenderingHints) BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) TextBoxListElement(org.olat.core.gui.components.form.flexible.elements.TextBoxListElement) HashSet(java.util.HashSet)

Example 2 with BinderPageUsage

use of org.olat.modules.portfolio.model.BinderPageUsage in project OpenOLAT by OpenOLAT.

the class MediaDAOTest method usedInBinders.

@Test
public void usedInBinders() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
    Binder binder = portfolioService.createNewBinder("Binder p2", "A binder with 2 page", null, author);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
    Media media = mediaDao.createMedia("Media", "Binder", "Une citation sur les classeurs", TextHandler.TEXT_MEDIA, "[Media:0]", null, 10, author);
    dbInstance.commitAndCloseSession();
    MediaPart mediaPart = new MediaPart();
    mediaPart.setMedia(media);
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, mediaPart);
    dbInstance.commitAndCloseSession();
    // reload
    List<BinderPageUsage> binders = mediaDao.usedInBinders(media);
    Assert.assertNotNull(binders);
    Assert.assertEquals(1, binders.size());
    Assert.assertTrue(binders.get(0).getBinderKey().equals(binder.getKey()));
}
Also used : Binder(org.olat.modules.portfolio.Binder) MediaPart(org.olat.modules.portfolio.model.MediaPart) BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) Media(org.olat.modules.portfolio.Media) Page(org.olat.modules.portfolio.Page) Identity(org.olat.core.id.Identity) Section(org.olat.modules.portfolio.Section) PageBody(org.olat.modules.portfolio.PageBody) Test(org.junit.Test)

Example 3 with BinderPageUsage

use of org.olat.modules.portfolio.model.BinderPageUsage in project openolat by klemens.

the class MediaDetailsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("title", StringHelper.escapeHtml(media.getTitle()));
        layoutCont.contextPut("description", StringHelper.xssScan(media.getDescription()));
        layoutCont.contextPut("iconCssClass", handler.getIconCssClass(media));
        mediaCtrl = handler.getMediaController(ureq, getWindowControl(), media, new StandardMediaRenderingHints());
        if (mediaCtrl != null) {
            listenTo(mediaCtrl);
            layoutCont.put("media", mediaCtrl.getInitialComponent());
        }
        String metaPage = velocity_root + "/media_details_metadata.html";
        FormLayoutContainer metaCont = FormLayoutContainer.createCustomFormLayout("meta", getTranslator(), metaPage);
        layoutCont.add("meta", metaCont);
        metaCont.setRootForm(mainForm);
        metaCont.contextPut("media", media);
        String author = userManager.getUserDisplayName(media.getAuthor());
        metaCont.contextPut("author", author);
        if (media.getCollectionDate() != null) {
            String collectionDate = Formatter.getInstance(getLocale()).formatDate(media.getCollectionDate());
            metaCont.contextPut("collectionDate", collectionDate);
        }
        if (media.getBusinessPath() != null) {
            gotoOriginalLink = LinkFactory.createLink("goto.original", metaCont.getFormItemComponent(), this);
        }
        if (StringHelper.containsNonWhitespace(media.getMetadataXml())) {
            Object metadata = MetadataXStream.get().fromXML(media.getMetadataXml());
            metaCont.contextPut("metadata", metadata);
        }
        List<Category> categories = portfolioService.getCategories(media);
        if (categories != null && categories.size() > 0) {
            Map<String, String> categoriesMap = categories.stream().collect(Collectors.toMap(c -> c.getName(), c -> c.getName()));
            TextBoxListElement categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categoriesMap, metaCont, getTranslator());
            categoriesEl.setHelpText(translate("categories.hint"));
            categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
            categoriesEl.setEnabled(false);
        }
        List<FormLink> binderLinks = new ArrayList<>(usedInList.size());
        Set<Long> binderUniqueKeys = new HashSet<>();
        for (BinderPageUsage binder : usedInList) {
            if (binderUniqueKeys.contains(binder.getBinderKey()))
                continue;
            FormLink link;
            if (binder.getBinderKey() == null) {
                link = uifactory.addFormLink("binder_" + (++counter), "page", binder.getPageTitle(), null, metaCont, Link.LINK | Link.NONTRANSLATED);
                binderUniqueKeys.add(binder.getPageKey());
            } else {
                link = uifactory.addFormLink("binder_" + (++counter), "binder", binder.getBinderTitle(), null, metaCont, Link.LINK | Link.NONTRANSLATED);
                binderUniqueKeys.add(binder.getBinderKey());
            }
            link.setUserObject(binder);
            binderLinks.add(link);
        }
        metaCont.contextPut("binderLinks", binderLinks);
    }
}
Also used : BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) FormEvent(org.olat.core.gui.components.form.flexible.impl.FormEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) FormItem(org.olat.core.gui.components.form.flexible.FormItem) TextBoxListElement(org.olat.core.gui.components.form.flexible.elements.TextBoxListElement) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Event(org.olat.core.gui.control.Event) FormBasicController(org.olat.core.gui.components.form.flexible.impl.FormBasicController) FormItemContainer(org.olat.core.gui.components.form.flexible.FormItemContainer) Category(org.olat.modules.portfolio.Category) ContextEntry(org.olat.core.id.context.ContextEntry) Media(org.olat.modules.portfolio.Media) Map(java.util.Map) MediaHandler(org.olat.modules.portfolio.MediaHandler) StringHelper(org.olat.core.util.StringHelper) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) StateEntry(org.olat.core.id.context.StateEntry) Formatter(org.olat.core.util.Formatter) PortfolioService(org.olat.modules.portfolio.PortfolioService) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) Link(org.olat.core.gui.components.link.Link) WindowControl(org.olat.core.gui.control.WindowControl) Set(java.util.Set) MediaEvent(org.olat.modules.portfolio.ui.event.MediaEvent) Component(org.olat.core.gui.components.Component) LinkFactory(org.olat.core.gui.components.link.LinkFactory) Collectors(java.util.stream.Collectors) Controller(org.olat.core.gui.control.Controller) UserManager(org.olat.user.UserManager) List(java.util.List) MetadataXStream(org.olat.modules.portfolio.manager.MetadataXStream) NewControllerFactory(org.olat.NewControllerFactory) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Align(org.olat.core.gui.components.stack.TooledStackedPanel.Align) TooledController(org.olat.core.gui.components.stack.TooledController) DialogBoxUIFactory(org.olat.core.gui.control.generic.modal.DialogBoxUIFactory) UserRequest(org.olat.core.gui.UserRequest) PageStatus(org.olat.modules.portfolio.PageStatus) StandardMediaRenderingHints(org.olat.modules.portfolio.model.StandardMediaRenderingHints) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Category(org.olat.modules.portfolio.Category) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) StandardMediaRenderingHints(org.olat.modules.portfolio.model.StandardMediaRenderingHints) BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) TextBoxListElement(org.olat.core.gui.components.form.flexible.elements.TextBoxListElement) HashSet(java.util.HashSet)

Example 4 with BinderPageUsage

use of org.olat.modules.portfolio.model.BinderPageUsage in project openolat by klemens.

the class MediaDAOTest method usedInBinders.

@Test
public void usedInBinders() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-2");
    Binder binder = portfolioService.createNewBinder("Binder p2", "A binder with 2 page", null, author);
    Section section = binderDao.createSection("Section", "First section", null, null, binder);
    dbInstance.commitAndCloseSession();
    Section reloadedSection = binderDao.loadSectionByKey(section.getKey());
    Page page = pageDao.createAndPersist("Page 1", "A page with content.", null, null, true, reloadedSection, null);
    Media media = mediaDao.createMedia("Media", "Binder", "Une citation sur les classeurs", TextHandler.TEXT_MEDIA, "[Media:0]", null, 10, author);
    dbInstance.commitAndCloseSession();
    MediaPart mediaPart = new MediaPart();
    mediaPart.setMedia(media);
    PageBody reloadedBody = pageDao.loadPageBodyByKey(page.getBody().getKey());
    pageDao.persistPart(reloadedBody, mediaPart);
    dbInstance.commitAndCloseSession();
    // reload
    List<BinderPageUsage> binders = mediaDao.usedInBinders(media);
    Assert.assertNotNull(binders);
    Assert.assertEquals(1, binders.size());
    Assert.assertTrue(binders.get(0).getBinderKey().equals(binder.getKey()));
}
Also used : Binder(org.olat.modules.portfolio.Binder) MediaPart(org.olat.modules.portfolio.model.MediaPart) BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) Media(org.olat.modules.portfolio.Media) Page(org.olat.modules.portfolio.Page) Identity(org.olat.core.id.Identity) Section(org.olat.modules.portfolio.Section) PageBody(org.olat.modules.portfolio.PageBody) Test(org.junit.Test)

Example 5 with BinderPageUsage

use of org.olat.modules.portfolio.model.BinderPageUsage in project OpenOLAT by OpenOLAT.

the class MediaDetailsController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source instanceof FormLink) {
        FormLink link = (FormLink) source;
        String cmd = link.getCmd();
        Object uobject = link.getUserObject();
        if ("binder".equals(cmd)) {
            if (uobject instanceof BinderPageUsage) {
                String businessPath = "[Binder:" + ((BinderPageUsage) uobject).getBinderKey() + "]";
                NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
            }
        } else if ("page".equals(cmd)) {
            if (uobject instanceof BinderPageUsage) {
                // http://localhost:8081/auth/HomeSite/720898/PortfolioV2/0/MyPages/0/Entry/89
                String businessPath = "[HomeSite:" + getIdentity().getKey() + "][PortfolioV2:0][MyPages:0][Entry:" + ((BinderPageUsage) uobject).getPageKey() + "]";
                NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
            }
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : BinderPageUsage(org.olat.modules.portfolio.model.BinderPageUsage) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Aggregations

BinderPageUsage (org.olat.modules.portfolio.model.BinderPageUsage)8 ArrayList (java.util.ArrayList)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 Media (org.olat.modules.portfolio.Media)4 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 NewControllerFactory (org.olat.NewControllerFactory)2 PersistenceHelper.makeFuzzyQueryString (org.olat.core.commons.persistence.PersistenceHelper.makeFuzzyQueryString)2 UserRequest (org.olat.core.gui.UserRequest)2 Component (org.olat.core.gui.components.Component)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 FormItemContainer (org.olat.core.gui.components.form.flexible.FormItemContainer)2 TextBoxListElement (org.olat.core.gui.components.form.flexible.elements.TextBoxListElement)2 FormBasicController (org.olat.core.gui.components.form.flexible.impl.FormBasicController)2 FormEvent (org.olat.core.gui.components.form.flexible.impl.FormEvent)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2