Search in sources :

Example 41 with SortKey

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

the class ThreadListController method loadModel.

public void loadModel() {
    Identity identity = guestOnly ? null : getIdentity();
    List<ForumThread> threads = forumManager.getForumThreads(forum, identity);
    if (!foCallback.mayEditMessageAsModerator()) {
        for (Iterator<ForumThread> threadIt = threads.iterator(); threadIt.hasNext(); ) {
            if (Status.getStatus(threadIt.next().getStatusCode()).isHidden()) {
                threadIt.remove();
            }
        }
    }
    threadTableModel.setObjects(threads);
    threadTableModel.sort(new SortKey(ThreadListCols.thread.name(), true));
    threadTable.reloadData();
    threadTable.reset();
    if (archiveForumButton != null) {
        archiveForumButton.setVisible(threads.size() > 0);
    }
    if (userListButton != null) {
        userListButton.setVisible(threads.size() > 0);
    }
}
Also used : ForumThread(org.olat.modules.fo.model.ForumThread) SortKey(org.olat.core.commons.persistence.SortKey) Identity(org.olat.core.id.Identity)

Example 42 with SortKey

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

the class SharedPagesController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(SharePageCols.bookmark));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(SharePageCols.userInfosStatus, new SharedPageStatusCellRenderer(getTranslator())));
    FlexiCellRenderer titleRenderer = new BooleanCellRenderer(new StaticFlexiCellRenderer("select", new PageTitleCellRenderer()), new PageTitleCellRenderer());
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(true, true, "select", SharePageCols.pageName.ordinal(), "select", true, SharePageCols.pageName.sortKey(), FlexiColumnModel.ALIGNMENT_LEFT, titleRenderer));
    SortKey defaultSortKey = null;
    if (isAdministrativeUser) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(ShareItemCols.username));
        defaultSortKey = new SortKey(Cols.username.name(), true);
    }
    // followed by the users fields
    int colPos = USER_PROPS_OFFSET;
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
        String propName = userPropertyHandler.getName();
        if (defaultSortKey == null && i == 0) {
            defaultSortKey = new SortKey(propName, true);
        } else if (UserConstants.LASTNAME.equals(propName) && !isAdministrativeUser) {
            defaultSortKey = new SortKey(propName, true);
        }
        boolean visible = userManager.isMandatoryUserProperty(USER_PROPS_ID, userPropertyHandler);
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, true, propName));
        colPos++;
    }
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(SharePageCols.lastChanges));
    columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(SharePageCols.pageStatus, new StatusCellRenderer(getTranslator())));
    model = new SharedPagesDataModel(columnsModel, getLocale());
    tableEl = uifactory.addTableElement(getWindowControl(), "table", model, 20, false, getTranslator(), formLayout);
    tableEl.setSearchEnabled(true);
    tableEl.setCustomizeColumns(true);
    tableEl.setElementCssClass("o_binder_shared_bookmark_pages_listing");
    tableEl.setEmtpyTableMessageKey("table.sEmptyTable");
    tableEl.setPageSize(24);
    tableEl.setAndLoadPersistedPreferences(ureq, "shared-bookmark-pages");
    if (filters != null && !filters.isEmpty()) {
        List<FlexiTableFilter> tableFilters = new ArrayList<>(filters.size());
        for (PageStatus status : filters) {
            String label = translate(status.i18nKey());
            tableFilters.add(new FlexiTableFilter(label, status.name(), "o_icon ".concat(status.cssClass())));
        }
        tableFilters.add(FlexiTableFilter.SPACER);
        tableFilters.add(new FlexiTableFilter(translate("filter.show.all"), "all", true));
        tableEl.setFilters("Filters", tableFilters, true);
        if (defaultFilter != null) {
            tableEl.setSelectedFilterKey(defaultFilter.name());
        }
    }
}
Also used : PageStatus(org.olat.modules.portfolio.PageStatus) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) FlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiCellRenderer) PageTitleCellRenderer(org.olat.modules.portfolio.ui.renderer.PageTitleCellRenderer) ArrayList(java.util.ArrayList) StatusCellRenderer(org.olat.modules.portfolio.ui.renderer.StatusCellRenderer) SharedPageStatusCellRenderer(org.olat.modules.portfolio.ui.renderer.SharedPageStatusCellRenderer) SortKey(org.olat.core.commons.persistence.SortKey) StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) SharedPageStatusCellRenderer(org.olat.modules.portfolio.ui.renderer.SharedPageStatusCellRenderer) BooleanCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.BooleanCellRenderer) 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 43 with SortKey

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

the class MembersTableController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
    SortKey defaultSortKey = initColumns(columnsModel);
    membersModel = new MemberListTableModel(columnsModel, imModule.isOnlineStatusEnabled());
    membersModel.setObjects(membersList);
    membersTable = uifactory.addTableElement(getWindowControl(), "table", membersModel, pageSize, false, getTranslator(), formLayout);
    membersTable.setEmtpyTableMessageKey("nomembers");
    membersTable.setAndLoadPersistedPreferences(ureq, this.getClass().getSimpleName());
    membersTable.setExportEnabled(false);
    membersTable.setElementCssClass("o_sel_member_list");
    if (defaultSortKey != null) {
        FlexiTableSortOptions options = new FlexiTableSortOptions();
        options.setDefaultOrderBy(defaultSortKey);
        membersTable.setSortSettings(options);
    }
}
Also used : FlexiTableSortOptions(org.olat.core.gui.components.form.flexible.elements.FlexiTableSortOptions) MemberListTableModel(org.olat.group.ui.main.MemberListTableModel) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) SortKey(org.olat.core.commons.persistence.SortKey)

Example 44 with SortKey

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

the class MembersTableController method initColumns.

private SortKey initColumns(FlexiTableColumnModel columnsModel) {
    int colPos = AbstractMemberListController.USER_PROPS_OFFSET;
    SortKey defaultSortKey = null;
    String rowAction = "vcard";
    if (chatEnabled && editable) {
        DefaultFlexiColumnModel chatCol = new DefaultFlexiColumnModel(Cols.online.i18n(), Cols.online.ordinal());
        chatCol.setExportable(false);
        columnsModel.addFlexiColumnModel(chatCol);
    }
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        String propName = userPropertyHandler.getName();
        boolean visible = userManager.isMandatoryUserProperty(MembersDisplayRunController.USER_PROPS_LIST_ID, userPropertyHandler);
        String emailRowAction = rowAction;
        FlexiColumnModel col;
        if (UserConstants.FIRSTNAME.equals(propName) || UserConstants.LASTNAME.equals(propName) || UserConstants.EMAIL.equals(propName)) {
            // when email is enabled, the action will trigger email workflow
            if (UserConstants.EMAIL.equals(propName) && canEmail) {
                emailRowAction = "email";
            }
            col = new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, emailRowAction, true, propName, new StaticFlexiCellRenderer(emailRowAction, new TextFlexiCellRenderer()));
        } else {
            col = new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos, true, propName);
        }
        columnsModel.addFlexiColumnModel(col);
        colPos++;
        if (defaultSortKey == null) {
            defaultSortKey = new SortKey(propName, true);
        }
    }
    if (userLastTimeVisible) {
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.firstTime.i18n(), Cols.firstTime.ordinal(), true, Cols.firstTime.name()));
        columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.lastTime.i18n(), Cols.lastTime.ordinal(), true, Cols.lastTime.name()));
    }
    return defaultSortKey;
}
Also used : StaticFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) FlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel) SortKey(org.olat.core.commons.persistence.SortKey) TextFlexiCellRenderer(org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 45 with SortKey

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

the class QItemQueriesDAOTest method getItemsByAuthor_orderBy.

@Test
public void getItemsByAuthor_orderBy() {
    // create an author with 2 items
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-2-" + UUID.randomUUID().toString());
    QuestionItem item1 = questionDao.createAndPersist(id, "NGC 2171", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    QuestionItem item2 = questionDao.createAndPersist(id, "NGC 2172", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(item1);
    Assert.assertNotNull(item2);
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    params.setAuthor(id);
    // test order by
    for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
        SortKey sortAsc = new SortKey(order.name(), true);
        List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getItemsByAuthor(params, null, 0, -1, sortAsc);
        Assert.assertNotNull(ascOrderedItems);
        SortKey sortDesc = new SortKey(order.name(), false);
        List<QuestionItemView> descOrderedItems = qItemQueriesDao.getItemsByAuthor(params, null, 0, -1, sortDesc);
        Assert.assertNotNull(descOrderedItems);
    }
}
Also used : SortKey(org.olat.core.commons.persistence.SortKey) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

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