Search in sources :

Example 36 with SortKey

use of org.olat.core.commons.persistence.SortKey in project openolat by klemens.

the class FlexiTableElementImpl method loadCustomSettings.

private void loadCustomSettings(UserRequest ureq) {
    if (StringHelper.containsNonWhitespace(persistentId)) {
        Preferences prefs = ureq.getUserSession().getGuiPreferences();
        FlexiTablePreferences tablePrefs = (FlexiTablePreferences) prefs.get(FlexiTableElement.class, persistentId);
        if (tablePrefs != null) {
            if (tablePrefs.getPageSize() != getDefaultPageSize() && tablePrefs.getPageSize() != 0) {
                setPageSize(tablePrefs.getPageSize());
            }
            if (tablePrefs.getEnabledColumnKeys() != null) {
                enabledColumnIndex.clear();
                enabledColumnIndex.addAll(convertColumnKeysToIndex(tablePrefs.getEnabledColumnKeys()));
            }
            if (StringHelper.containsNonWhitespace(tablePrefs.getSortedColumnKey())) {
                String sortKey = null;
                String columnKey = tablePrefs.getSortedColumnKey();
                FlexiTableColumnModel colModel = dataModel.getTableColumnModel();
                for (int i = colModel.getColumnCount(); i-- > 0; ) {
                    FlexiColumnModel col = colModel.getColumnModel(i);
                    if (columnKey.equals(col.getColumnKey()) && col.isSortable()) {
                        sortKey = col.getSortKey();
                    }
                }
                if (sortKey == null && sortOptions != null && sortOptions.getSorts() != null) {
                    for (FlexiTableSort sortOption : sortOptions.getSorts()) {
                        if (sortOption.getSortKey().getKey().equals(columnKey)) {
                            sortKey = columnKey;
                        }
                    }
                }
                if (sortKey != null) {
                    orderBy = new SortKey[] { new SortKey(sortKey, tablePrefs.isSortDirection()) };
                    selectSortOption(sortKey, tablePrefs.isSortDirection());
                }
            }
            if (tablePrefs.getRendererType() != null) {
                setRendererType(tablePrefs.getRendererType());
            }
        }
    }
}
Also used : SortKey(org.olat.core.commons.persistence.SortKey) Preferences(org.olat.core.util.prefs.Preferences) FlexiTableSort(org.olat.core.gui.components.form.flexible.elements.FlexiTableSort) FlexiTableElement(org.olat.core.gui.components.form.flexible.elements.FlexiTableElement)

Example 37 with SortKey

use of org.olat.core.commons.persistence.SortKey in project openolat by klemens.

the class FlexiTableClassicRenderer method renderHeader.

private void renderHeader(StringOutput sb, FlexiTableComponent ftC, FlexiColumnModel fcm, Translator translator) {
    String header = getHeader(fcm, translator);
    sb.append("<th");
    // append sort key to make column width set via css
    if (fcm.getSortKey() != null) {
        sb.append(" class='o_col_").append(fcm.getSortKey()).append("'");
    }
    sb.append(">");
    // sort is not defined
    if (!fcm.isSortable() || fcm.getSortKey() == null) {
        sb.append(header);
    } else {
        FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
        Boolean asc = null;
        String sortKey = fcm.getSortKey();
        SortKey[] orderBy = ftE.getOrderBy();
        if (orderBy != null && orderBy.length > 0) {
            for (int i = orderBy.length; i-- > 0; ) {
                if (sortKey.equals(orderBy[i].getKey())) {
                    asc = new Boolean(orderBy[i].isAsc());
                }
            }
        }
        Form theForm = ftE.getRootForm();
        if (asc == null) {
            sb.append("<a class='o_orderby' href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, ftC.getFormDispatchId(), 1, true, true, true, new NameValuePair("sort", sortKey), new NameValuePair("asc", "asc"))).append("\">");
        } else if (asc.booleanValue()) {
            sb.append("<a class='o_orderby o_orderby_asc' href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, ftC.getFormDispatchId(), 1, true, true, true, new NameValuePair("sort", sortKey), new NameValuePair("asc", "desc"))).append("\">");
        } else {
            sb.append("<a class='o_orderby o_orderby_desc' href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, ftC.getFormDispatchId(), 1, true, true, true, new NameValuePair("sort", sortKey), new NameValuePair("asc", "asc"))).append("\">");
        }
        sb.append(header).append("</a>");
    }
    sb.append("</th>");
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) SortKey(org.olat.core.commons.persistence.SortKey)

Example 38 with SortKey

use of org.olat.core.commons.persistence.SortKey in project openolat by klemens.

the class IdentityListCourseNodeController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("courseNodeTitle", courseNode.getShortTitle());
        layoutCont.contextPut("courseNodeCssClass", CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(courseNode.getType()).getIconCSSClass());
        if (group != null) {
            layoutCont.contextPut("businessGroupName", group.getName());
        }
    }
    ICourse course = CourseFactory.loadCourse(courseEntry);
    String select = isSelectable() ? "select" : null;
    // add the table
    FlexiTableSortOptions options = new FlexiTableSortOptions();
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    if (isAdministrativeUser) {
        options.setDefaultOrderBy(new SortKey(IdentityCourseElementCols.username.sortKey(), true));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(IdentityCourseElementCols.username, select));
    }
    int colIndex = AssessmentToolConstants.USER_PROPS_OFFSET;
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
        boolean visible = UserManager.getInstance().isMandatoryUserProperty(AssessmentToolConstants.usageIdentifyer, userPropertyHandler);
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, select, true, "userProp-" + colIndex));
        if (!options.hasDefaultOrderBy()) {
            options.setDefaultOrderBy(new SortKey("userProp-" + colIndex, true));
        }
        colIndex++;
    }
    initAssessmentColumns(columnsModel);
    initStatusColumns(columnsModel);
    initModificationDatesColumns(columnsModel);
    initCalloutColumns(columnsModel);
    AssessableCourseNode assessableNode = courseNode instanceof AssessableCourseNode ? (AssessableCourseNode) courseNode : null;
    usersTableModel = new IdentityListCourseNodeTableModel(columnsModel, assessableNode, getLocale());
    tableEl = uifactory.addTableElement(getWindowControl(), "table", usersTableModel, 20, false, getTranslator(), formLayout);
    tableEl.setExportEnabled(true);
    tableEl.setSearchEnabled(new AssessedIdentityListProvider(getIdentity(), courseEntry, referenceEntry, courseNode.getIdent(), assessmentCallback), ureq.getUserSession());
    tableEl.setMultiSelect(!coachCourseEnv.isCourseReadOnly());
    tableEl.setSortSettings(options);
    tableEl.setSelectAllEnable(true);
    List<FlexiTableFilter> filters = new ArrayList<>();
    filters.add(new FlexiTableFilter(translate("filter.showAll"), "showAll", true));
    filters.add(FlexiTableFilter.SPACER);
    filters.add(new FlexiTableFilter(translate("filter.passed"), "passed"));
    filters.add(new FlexiTableFilter(translate("filter.failed"), "failed"));
    filters.add(new FlexiTableFilter(translate("filter.inProgress"), "inProgress"));
    filters.add(new FlexiTableFilter(translate("filter.inReview"), "inReview"));
    filters.add(new FlexiTableFilter(translate("filter.done"), "done"));
    tableEl.setFilters("", filters, false);
    if (assessmentCallback.canAssessBusinessGoupMembers() && group == null) {
        List<BusinessGroup> coachedGroups = null;
        if (assessmentCallback.isAdmin()) {
            coachedGroups = course.getCourseEnvironment().getCourseGroupManager().getAllBusinessGroups();
        } else {
            coachedGroups = assessmentCallback.getCoachedGroups();
        }
        if (coachedGroups.size() > 0) {
            List<FlexiTableFilter> groupFilters = new ArrayList<>();
            for (BusinessGroup coachedGroup : coachedGroups) {
                String groupName = StringHelper.escapeHtml(coachedGroup.getName());
                groupFilters.add(new FlexiTableFilter(groupName, coachedGroup.getKey().toString(), "o_icon o_icon_group"));
            }
            tableEl.setExtendedFilterButton(translate("filter.groups"), groupFilters);
        }
    }
    tableEl.setAndLoadPersistedPreferences(ureq, getTableId());
}
Also used : FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) SortKey(org.olat.core.commons.persistence.SortKey) CalculatedAssessableCourseNode(org.olat.course.nodes.CalculatedAssessableCourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) FlexiTableFilter(org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 39 with SortKey

use of org.olat.core.commons.persistence.SortKey in project openolat by klemens.

the class SelectThreadStepForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.type, new StatusTypeCellRenderer()));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.thread, "choose", new StaticFlexiCellRenderer("choose", new StickyCellRenderer())));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.creator));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.lastModified));
    if (!guestOnly) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.markedMessages, "marked", new StaticFlexiCellRenderer("marked", new TextFlexiCellRenderer())));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.unreadMessages, "unread", new StaticFlexiCellRenderer("unread", new TextFlexiCellRenderer())));
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.totalMessages));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.select, "select", new StaticFlexiCellRenderer(translate("select"), "select", "", "o_icon o_icon_select o_icon-fw")));
    threadTableModel = new ThreadListDataModel(columnsModel, getTranslator());
    threadTable = uifactory.addTableElement(getWindowControl(), "threads", threadTableModel, getTranslator(), formLayout);
    threadTable.setCustomizeColumns(false);
    threadTable.setElementCssClass("o_forum");
    threadTable.setEmtpyTableMessageKey("forum.emtpy");
    FlexiTableSortOptions sortOptions = new FlexiTableSortOptions();
    sortOptions.setDefaultOrderBy(new SortKey(ThreadListCols.lastModified.name(), false));
    threadTable.setSortSettings(sortOptions);
    loadModel();
    newThreadButton = uifactory.addFormLink("link.new.thread", formLayout, Link.BUTTON);
    newThreadButton.setIconLeftCSS("o_icon o_icon-fw o_forum_status_thread_icon");
    newThreadButton.setElementCssClass("o_sel_forum_thread_new");
}
Also used : FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) ThreadListDataModel(org.olat.modules.fo.ui.ThreadListDataModel) StatusTypeCellRenderer(org.olat.modules.fo.ui.StatusTypeCellRenderer) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) SortKey(org.olat.core.commons.persistence.SortKey) StickyCellRenderer(org.olat.modules.fo.ui.StickyCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)

Example 40 with SortKey

use of org.olat.core.commons.persistence.SortKey in project openolat by klemens.

the class ThreadListController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (foCallback.mayOpenNewThread()) {
        newThreadButton = uifactory.addFormLink("msg.create", formLayout, Link.BUTTON_SMALL);
        newThreadButton.setIconLeftCSS("o_icon o_icon-fw o_forum_status_thread_icon");
        newThreadButton.setElementCssClass("o_sel_forum_thread_new");
    }
    if (foCallback.mayArchiveForum()) {
        archiveForumButton = uifactory.addFormLink("archive.forum", formLayout, Link.BUTTON_SMALL);
        archiveForumButton.setIconLeftCSS("o_icon o_icon-fw o_icon_archive_tool");
        archiveForumButton.setElementCssClass("o_sel_forum_archive");
    }
    if (securityModule.isUserAllowedAutoComplete(ureq.getUserSession().getRoles()) && foCallback.mayFilterForUser()) {
        userListButton = uifactory.addFormLink("filter", formLayout, Link.BUTTON_SMALL);
        userListButton.setIconLeftCSS("o_icon o_icon-fw o_icon_user");
        userListButton.setElementCssClass("o_sel_forum_filter");
    }
    if (formLayout instanceof FormLayoutContainer) {
        SearchServiceUIFactory searchServiceUIFactory = (SearchServiceUIFactory) CoreSpringFactory.getBean(SearchServiceUIFactory.class);
        searchController = searchServiceUIFactory.createInputController(ureq, getWindowControl(), DisplayOption.STANDARD, mainForm);
        if (guestOnly && !searchModule.isGuestEnabled()) {
            searchController.setResourceContextEnable(false);
        }
        listenTo(searchController);
        ((FormLayoutContainer) formLayout).add("search_input", searchController.getFormItem());
    }
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.type, new StatusTypeCellRenderer()));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.thread, "select", new StaticFlexiCellRenderer("select", new StickyCellRenderer())));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.creator));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.lastModified));
    if (!guestOnly) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.markedMessages, "marked", new StaticFlexiCellRenderer("marked", new TextFlexiCellRenderer())));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.unreadMessages, "unread", new StaticFlexiCellRenderer("unread", new TextFlexiCellRenderer())));
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ThreadListCols.totalMessages));
    threadTableModel = new ThreadListDataModel(columnsModel, getTranslator());
    threadTable = uifactory.addTableElement(getWindowControl(), "threads", threadTableModel, getTranslator(), formLayout);
    threadTable.setCustomizeColumns(false);
    threadTable.setElementCssClass("o_forum");
    threadTable.setEmtpyTableMessageKey("forum.emtpy");
    FlexiTableSortOptions sortOptions = new FlexiTableSortOptions();
    sortOptions.setDefaultOrderBy(new SortKey(ThreadListCols.lastModified.name(), false));
    threadTable.setSortSettings(sortOptions);
}
Also used : FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) SearchServiceUIFactory(org.olat.search.SearchServiceUIFactory) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) SortKey(org.olat.core.commons.persistence.SortKey) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)

Aggregations

SortKey (org.olat.core.commons.persistence.SortKey)82 FlexiTableSortOptions (org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions)48 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)42 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)42 StaticFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer)30 ArrayList (java.util.ArrayList)20 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)18 Identity (org.olat.core.id.Identity)18 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)18 TextFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer)14 Test (org.junit.Test)12 FlexiTableFilter (org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter)12 FlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel)12 BooleanCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.BooleanCellRenderer)10 QuestionItem (org.olat.modules.qpool.QuestionItem)10 QuestionItemView (org.olat.modules.qpool.QuestionItemView)10 FlexiTableSort (org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)8 DateFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.DateFlexiCellRenderer)8 FlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiCellRenderer)6 BusinessGroup (org.olat.group.BusinessGroup)6