Search in sources :

Example 6 with Category

use of org.olat.modules.portfolio.Category 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 7 with Category

use of org.olat.modules.portfolio.Category in project OpenOLAT by OpenOLAT.

the class PageMetadataController method initMetadata.

private void initMetadata(UserRequest ureq) {
    Set<Identity> owners = new HashSet<>();
    if (page.getSection() != null && page.getSection().getBinder() != null) {
        owners.addAll(portfolioService.getMembers(page.getSection().getBinder(), PortfolioRoles.owner.name()));
    }
    owners.addAll(portfolioService.getMembers(page, PortfolioRoles.owner.name()));
    StringBuilder ownerSb = new StringBuilder();
    for (Identity owner : owners) {
        if (ownerSb.length() > 0)
            ownerSb.append(", ");
        ownerSb.append(userManager.getUserDisplayName(owner));
    }
    mainVC.contextPut("owners", ownerSb.toString());
    mainVC.contextPut("pageTitle", page.getTitle());
    mainVC.contextPut("pageSummary", page.getSummary());
    mainVC.contextPut("status", page.getPageStatus());
    mainVC.contextPut("statusCss", page.getPageStatus() == null ? PageStatus.draft.cssClass() : page.getPageStatus().cssClass());
    mainVC.contextPut("lastPublicationDate", page.getLastPublicationDate());
    List<Category> categories = portfolioService.getCategories(page);
    if (secCallback.canEditCategories(page)) {
        // editable categories
        categoriesEditCtr = new CategoriesEditController(ureq, getWindowControl(), categories);
        listenTo(categoriesEditCtr);
        mainVC.put("pageCategoriesCtr", categoriesEditCtr.getInitialComponent());
    } else {
        // read-only categories
        List<String> categoryNames = new ArrayList<>(categories.size());
        for (Category category : categories) {
            categoryNames.add(category.getName());
        }
        mainVC.contextPut("pageCategories", categoryNames);
    }
    mainVC.contextPut("lastModified", page.getLastModified());
    if (StringHelper.containsNonWhitespace(page.getImagePath())) {
        File posterImage = portfolioService.getPosterImage(page);
        if (page.getImageAlignment() == PageImageAlign.background) {
            mapperThumbnailUrl = registerCacheableMapper(ureq, "page-meta", new PageImageMapper(posterImage));
            mainVC.contextPut("mapperThumbnailUrl", mapperThumbnailUrl);
            mainVC.contextPut("imageAlign", PageImageAlign.background.name());
            mainVC.contextPut("imageName", posterImage.getName());
        } else {
            // alignment is right
            imageCmp = new ImageComponent(ureq.getUserSession(), "poster");
            imageCmp.setMedia(posterImage);
            imageCmp.setMaxWithAndHeightToFitWithin(PICTURE_WIDTH, PICTURE_HEIGHT);
            mainVC.put("poster", imageCmp);
            mainVC.contextPut("imageAlign", page.getImageAlignment() == null ? PageImageAlign.right.name() : page.getImageAlignment().name());
        }
    } else {
        mainVC.contextPut("imageAlign", "none");
    }
}
Also used : Category(org.olat.modules.portfolio.Category) ArrayList(java.util.ArrayList) ImageComponent(org.olat.core.gui.components.image.ImageComponent) Identity(org.olat.core.id.Identity) File(java.io.File) HashSet(java.util.HashSet)

Example 8 with Category

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

the class AbstractPageListController method getCategories.

private List<String> getCategories(OLATResourceable ores, Map<OLATResourceable, List<Category>> categorizedElementMap) {
    List<String> strings = null;
    List<Category> categories = categorizedElementMap.get(ores);
    if (categories != null && categories.size() > 0) {
        strings = new ArrayList<>(categories.size());
        for (Category category : categories) {
            strings.add(category.getName());
        }
    }
    return strings;
}
Also used : Category(org.olat.modules.portfolio.Category)

Example 9 with Category

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

the class DeletedPageListController method loadModel.

@Override
protected void loadModel(UserRequest ureq, String searchString) {
    Map<Long, Long> numberOfCommentsMap = portfolioService.getNumberOfCommentsOnOwnedPage(getIdentity());
    List<CategoryToElement> categorizedElements = portfolioService.getCategorizedOwnedPages(getIdentity());
    Map<OLATResourceable, List<Category>> categorizedElementMap = new HashMap<>();
    for (CategoryToElement categorizedElement : categorizedElements) {
        List<Category> categories = categorizedElementMap.get(categorizedElement.getCategorizedResource());
        if (categories == null) {
            categories = new ArrayList<>();
            categorizedElementMap.put(categorizedElement.getCategorizedResource(), categories);
        }
        categories.add(categorizedElement.getCategory());
    }
    List<Page> pages = portfolioService.searchDeletedPages(getIdentity(), searchString);
    List<PortfolioElementRow> rows = new ArrayList<>(pages.size());
    for (Page page : pages) {
        rows.add(forgePageRow(ureq, page, null, null, categorizedElementMap, numberOfCommentsMap, true));
    }
    // clean up the posters
    disposeRows();
    model.setObjects(rows);
    tableEl.reset();
    tableEl.reloadData();
    deleteButton.setVisible(tableEl.getRendererType() == FlexiTableRendererType.classic && model.getRowCount() > 0);
}
Also used : PortfolioElementRow(org.olat.modules.portfolio.ui.model.PortfolioElementRow) Category(org.olat.modules.portfolio.Category) OLATResourceable(org.olat.core.id.OLATResourceable) HashMap(java.util.HashMap) CategoryToElement(org.olat.modules.portfolio.CategoryToElement) ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with Category

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

the class PortfolioServiceImpl method updateCategories.

private void updateCategories(OLATResourceable oresource, List<String> categories) {
    List<Category> currentCategories = categoryDao.getCategories(oresource);
    Map<String, Category> currentCategoryMap = new HashMap<>();
    for (Category category : currentCategories) {
        currentCategoryMap.put(category.getName(), category);
    }
    List<String> newCategories = new ArrayList<>(categories);
    for (String newCategory : newCategories) {
        if (!currentCategoryMap.containsKey(newCategory)) {
            Category category = categoryDao.createAndPersistCategory(newCategory);
            categoryDao.appendRelation(oresource, category);
        }
    }
    for (Category currentCategory : currentCategories) {
        String name = currentCategory.getName();
        if (!newCategories.contains(name)) {
            categoryDao.removeRelation(oresource, currentCategory);
        }
    }
}
Also used : Category(org.olat.modules.portfolio.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

Category (org.olat.modules.portfolio.Category)26 ArrayList (java.util.ArrayList)14 OLATResourceable (org.olat.core.id.OLATResourceable)14 List (java.util.List)12 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 Test (org.junit.Test)8 UserRequest (org.olat.core.gui.UserRequest)8 Component (org.olat.core.gui.components.Component)8 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)8 Event (org.olat.core.gui.control.Event)8 WindowControl (org.olat.core.gui.control.WindowControl)8 Identity (org.olat.core.id.Identity)8 StringHelper (org.olat.core.util.StringHelper)8 Media (org.olat.modules.portfolio.Media)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Map (java.util.Map)6 Set (java.util.Set)6 FormItem (org.olat.core.gui.components.form.flexible.FormItem)6 FormItemContainer (org.olat.core.gui.components.form.flexible.FormItemContainer)6