Search in sources :

Example 81 with VelocityContainer

use of org.olat.core.gui.components.velocity.VelocityContainer in project openolat by klemens.

the class ExportBinderAsCPResource method exportSection.

private void exportSection(Section section, ZipOutputStream zout) throws IOException {
    String pagePath = Util.getPackageVelocityRoot(AbstractPageListController.class) + "/portfolio_element_row.html";
    VelocityContainer rowVC = new VelocityContainer("html", pagePath, translator, null);
    AssessmentSection assessmentSection = null;
    PortfolioElementRow row = new PortfolioElementRow(section, assessmentSection, false, false);
    rowVC.contextPut("row", row);
    rowVC.contextPut("rowIndex", 0);
    String html = createResultHTML(null, rowVC, null, "o_section_export");
    convertToZipEntry(zout, sectionFilename(section), html);
}
Also used : PortfolioElementRow(org.olat.modules.portfolio.ui.model.PortfolioElementRow) AbstractPageListController(org.olat.modules.portfolio.ui.AbstractPageListController) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 82 with VelocityContainer

use of org.olat.core.gui.components.velocity.VelocityContainer in project openolat by klemens.

the class ExportBinderAsPDFResource method createResultHTML.

private String createResultHTML(Component content) {
    String pagePath = Util.getPackageVelocityRoot(this.getClass()) + "/export.html";
    VelocityContainer mainVC = new VelocityContainer("html", pagePath, translator, null);
    mainVC.put("cmp", content);
    mainVC.contextPut("bodyCssClass", "o_portfolio_export");
    StringOutput sb = new StringOutput(32000);
    URLBuilder ubu = new URLBuilder("auth", "1", "0");
    Renderer renderer = Renderer.getInstance(mainVC, translator, ubu, new RenderResult(), new EmptyGlobalSettings());
    VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, mainVC, sb);
    mainVC.contextPut("r", vrdec);
    renderer.render(sb, mainVC, null);
    return sb.toString();
}
Also used : Renderer(org.olat.core.gui.render.Renderer) RenderResult(org.olat.core.gui.render.RenderResult) StringOutput(org.olat.core.gui.render.StringOutput) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) URLBuilder(org.olat.core.gui.render.URLBuilder) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator)

Example 83 with VelocityContainer

use of org.olat.core.gui.components.velocity.VelocityContainer in project openolat by klemens.

the class HTMLEditorController method initEditorForm.

private void initEditorForm(VFSContainer bContainer, String relFilePath, CustomLinkTreeModel linkTreeModel, String mPath, boolean editorCheck, boolean versions, boolean withButtons) {
    this.baseContainer = bContainer;
    this.fileRelPath = relFilePath;
    this.mediaPath = mPath;
    this.versionsEnabled = versions;
    this.buttonsEnabled = withButtons;
    this.customLinkTreeModel = linkTreeModel;
    this.editorCheckEnabled = editorCheck;
    // make sure the filename doesn't start with a slash
    this.fileName = ((relFilePath.charAt(0) == '/') ? relFilePath.substring(1) : relFilePath);
    this.fileLeaf = (VFSLeaf) bContainer.resolve(fileName);
    if (fileLeaf == null)
        throw new AssertException("file::" + getFileDebuggingPath(bContainer, relFilePath) + " does not exist!");
    long size = fileLeaf.getSize();
    if (size > FolderConfig.getMaxEditSizeLimit()) {
        // limit to reasonable size, see OO-57
        fileToLargeError = translate("plaintext.error.tolarge", new String[] { (size / 1000) + "", (FolderConfig.getMaxEditSizeLimit() / 1000) + "" });
        this.body = "";
        this.editable = false;
        return;
    }
    // check if someone else is already editing the file
    if (fileLeaf instanceof LocalFileImpl) {
        // Cast to LocalFile necessary because the VFSItem is missing some
        // ID mechanism that identifies an item within the system
        OLATResourceable lockResourceable = createLockResourceable(fileLeaf);
        // OLAT-5066: the use of "fileName" gives users the (false) impression that the file they wish to access
        // is already locked by someone else. Since the lock token must be smaller than 50 characters we us an
        // MD5 hash of the absolute file path which will always be 32 characters long and virtually unique.
        String lockToken = createLockToken(bContainer, relFilePath);
        lock = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(lockResourceable, getIdentity(), lockToken);
        VelocityContainer vc = (VelocityContainer) flc.getComponent();
        if (!lock.isSuccess()) {
            vc.contextPut("locked", Boolean.TRUE);
            String fullname = UserManager.getInstance().getUserDisplayName(lock.getOwner());
            vc.contextPut("lockOwner", fullname);
            editable = false;
            return;
        } else {
            vc.contextPut("locked", Boolean.FALSE);
        }
    }
    // Parse the content of the page
    this.body = parsePage(fileLeaf);
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 84 with VelocityContainer

use of org.olat.core.gui.components.velocity.VelocityContainer in project openolat by klemens.

the class HighScoreRunController method event.

@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source == links[0] || source == links[1] || source == links[2]) {
        List<String> persons = new ArrayList<>();
        Link link;
        if (source == links[0]) {
            link = links[0];
            buildMemberList(persons, 0);
        } else if (source == links[1]) {
            link = links[1];
            buildMemberList(persons, 1);
        } else {
            link = links[2];
            buildMemberList(persons, 2);
        }
        if (calloutCtr == null) {
            VelocityContainer podiumcalloutVC = createVelocityContainer("podiumcallout");
            podiumcalloutVC.contextPut("persons", persons);
            calloutCtr = new CloseableCalloutWindowController(ureq, getWindowControl(), podiumcalloutVC, link, "This is a title in a callout window", false, null);
            calloutCtr.activate();
            listenTo(calloutCtr);
        } else {
            removeAsListenerAndDispose(calloutCtr);
            calloutCtr = null;
        }
    } else if (source == this.flc.getFormItemComponent()) {
        if ("show".equals(event.getCommand())) {
            doUpdateShowConfig(ureq, true);
        } else if ("hide".equals(event.getCommand())) {
            doUpdateShowConfig(ureq, false);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CloseableCalloutWindowController(org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController) Link(org.olat.core.gui.components.link.Link) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 85 with VelocityContainer

use of org.olat.core.gui.components.velocity.VelocityContainer in project openolat by klemens.

the class HighScoreRunController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    VelocityContainer mainVC = this.flc.getFormItemComponent();
    mainVC.put("loadd3js", new StatisticsComponent("d3loader"));
    if (viewHistogram) {
        VelocityContainer scoreHistogramVC = createVelocityContainer("histogram_score");
        // transfer all scores to velocity container as base data for histogram
        HighScoreRankingResults modifiedData = highScoreManager.processHistogramData(allScores, lowerBorder, upperBorder);
        allScores = modifiedData.getModifiedScores();
        scoreHistogramVC.contextPut("datas", BarSeries.datasToString(allScores));
        // histogram marker for own position
        scoreHistogramVC.contextPut("cutValue", ownIdIndices.size() > 0 ? highScoreManager.calculateHistogramCutvalue(allMembers.get(ownIdIndices.get(0)).getScore(), modifiedData.getClasswidth(), modifiedData.getMin()) : -1000);
        // classwidth to correctly display the histogram
        long classwidth = modifiedData.getClasswidth();
        scoreHistogramVC.contextPut("step", classwidth);
        // find path for ownID image to display in histogram
        UserAvatarMapper mapper = new UserAvatarMapper(false);
        String mapperPath = registerMapper(ureq, mapper);
        String identityMapperPath = mapper.createPathFor(mapperPath, ownIdentity);
        scoreHistogramVC.contextPut("mapperUrl", identityMapperPath);
        mainVC.put("scoreHistogram", scoreHistogramVC);
    }
    if (viewPodium) {
        String[] localizer = { "first", "second", "third" };
        // for clarity and space reasons do not show any portraits if one position has more than 6 persons
        int maxPerson = 6;
        boolean showPortraits = !anonymous && allPodium.get(0).size() <= maxPerson && allPodium.get(1).size() <= maxPerson && allPodium.get(2).size() <= maxPerson;
        for (int i = 0; i < localizer.length; i++) {
            int sizePerPos = allPodium.get(i).size();
            StringBuilder sb = new StringBuilder();
            if (sizePerPos > 2) {
                int reduce = 0;
                // create link if podium has more than 2 entries per rank, entries can be displayed as anonymous
                if (allPodium.get(i).get(0).getIdentity().equals(ownIdentity)) {
                    sb.append(userManager.getUserDisplayName(ownIdentity));
                    ++reduce;
                }
                if (sizePerPos > 6 || anonymous) {
                    mainVC.contextPut("further" + (i + 1), (sizePerPos - reduce) + " " + (reduce == 1 ? translate("highscore.further") : translate("highscore.total")));
                } else {
                    links[i] = LinkFactory.createLink(null, "link" + (i + 1), "cmd", (sizePerPos - reduce) + " " + (reduce == 1 ? translate("highscore.further") : translate("highscore.total")), getTranslator(), mainVC, this, 16);
                }
            } else {
                for (HighScoreTableEntry te : allPodium.get(i)) {
                    if (!anonymous || te.getIdentity().equals(ownIdentity)) {
                        sb.append(userManager.getUserDisplayName(te.getIdentity()));
                        sb.append("<br/>");
                    }
                }
            }
            mainVC.contextPut(localizer[i], sizePerPos > 0 ? sb.toString() : translate("highscore.unavail"));
            mainVC.contextPut("score" + (i + 1), sizePerPos > 0 ? allPodium.get(i).get(0).getScore() : null);
            if (sizePerPos > 0 && showPortraits) {
                // decide whether or not to display id portrait
                mainVC.contextPut("number" + (i + 1), sizePerPos);
                for (int j = 0; j < sizePerPos; j++) {
                    Identity currentID = allPodium.get(i).get(j).getIdentity();
                    boolean choosePortrait = !anonymous || ownIdentity.equals(currentID);
                    DisplayPortraitController portrait = new DisplayPortraitController(ureq, getWindowControl(), currentID, false, choosePortrait, !choosePortrait);
                    listenTo(portrait);
                    Component portraitComponent = portrait.getInitialComponent();
                    mainVC.put("portrait" + (i + 1) + "-" + (j + 1), portraitComponent);
                }
            } else {
                // if amount of people per rank is too large, own id portrait can still be displayed
                for (int j = 0; j < sizePerPos; j++) {
                    Identity currentID = allPodium.get(i).get(j).getIdentity();
                    if (ownIdentity.equals(currentID)) {
                        DisplayPortraitController portrait = new DisplayPortraitController(ureq, getWindowControl(), currentID, true, true, false);
                        listenTo(portrait);
                        mainVC.put("portrait" + (i + 1), portrait.getInitialComponent());
                    }
                }
            }
        }
    }
    if (viewTable) {
        FlexiTableColumnModel tableColumnModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
        tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("highscore.table.header1", HighScoreTableEntry.RANK));
        tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("highscore.table.header2", HighScoreTableEntry.SCORE));
        tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("highscore.table.header3", HighScoreTableEntry.NAME));
        // trim to tableSize
        if (tableSize < allMembers.size()) {
            allMembers.subList(tableSize, allMembers.size()).clear();
        }
        tableDataModel = new FlexiTableDataModelImpl<HighScoreTableEntry>(new HighScoreFlexiTableModel(allMembers, anonymous, translate("highscore.anonymous"), ownIdentity), tableColumnModel);
        FlexiTableElement topTenTable = uifactory.addTableElement(getWindowControl(), "table", tableDataModel, getTranslator(), formLayout);
        topTenTable.setNumOfRowsEnabled(false);
        topTenTable.setCustomizeColumns(false);
        topTenTable.setCssDelegate(new MarkedMemberCssDelegate(false));
        // establish a 2nd table if ownID position is greater than first table's size setting
        if (!ownIdMembers.isEmpty()) {
            tableDataModel2 = new FlexiTableDataModelImpl<HighScoreTableEntry>(new HighScoreFlexiTableModel(ownIdMembers, anonymous, translate("highscore.anonymous"), ownIdentity), tableColumnModel);
            FlexiTableElement tableElement = uifactory.addTableElement(getWindowControl(), "table2", tableDataModel2, getTranslator(), formLayout);
            tableElement.setNumOfRowsEnabled(false);
            tableElement.setCustomizeColumns(false);
            tableElement.setCssDelegate(new MarkedMemberCssDelegate(true));
        }
    }
    if (viewPosition && ownIdIndices.size() > 0) {
        int amountWorse = allScores.length - ownIdIndices.get(0) - 1;
        if (amountWorse > 0) {
            mainVC.contextPut("relposition", translate("highscore.position.inrelation", new String[] { String.valueOf(amountWorse) }));
        }
        int ownRank = highscoreDataModel.getOwnTableEntry().getRank();
        mainVC.contextPut("position", translate("highscore.position.yourposition", new String[] { String.valueOf(ownRank) }));
    }
}
Also used : DisplayPortraitController(org.olat.user.DisplayPortraitController) StatisticsComponent(org.olat.core.gui.components.chart.StatisticsComponent) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) UserAvatarMapper(org.olat.user.UserAvatarMapper) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) HighScoreRankingResults(org.olat.course.highscore.model.HighScoreRankingResults) Identity(org.olat.core.id.Identity) StatisticsComponent(org.olat.core.gui.components.chart.StatisticsComponent) Component(org.olat.core.gui.components.Component) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) FlexiTableElement(org.olat.core.gui.components.form.flexible.elements.FlexiTableElement)

Aggregations

VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)162 Component (org.olat.core.gui.components.Component)22 ArrayList (java.util.ArrayList)16 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)14 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)14 CloseableCalloutWindowController (org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController)14 Link (org.olat.core.gui.components.link.Link)12 Panel (org.olat.core.gui.components.panel.Panel)12 UserRequest (org.olat.core.gui.UserRequest)10 JSAndCSSComponent (org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent)10 List (java.util.List)8 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)8 WindowControl (org.olat.core.gui.control.WindowControl)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 Translator (org.olat.core.gui.translator.Translator)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 HashMap (java.util.HashMap)6 Collectors (java.util.stream.Collectors)6 Mapper (org.olat.core.dispatcher.mapper.Mapper)6 BarSeries (org.olat.core.gui.components.chart.BarSeries)6