minor fixes and code cleanup
This commit is contained in:
parent
529e3a84f2
commit
76c08bb5c6
9 changed files with 53 additions and 83 deletions
|
@ -190,7 +190,7 @@ public class LmsSetupForm implements TemplateComposer {
|
||||||
.withEntityKey(entityKey)
|
.withEntityKey(entityKey)
|
||||||
.withExec(action -> this.testLmsSetup(action, formHandle))
|
.withExec(action -> this.testLmsSetup(action, formHandle))
|
||||||
.ignoreMoveAwayFromEdit()
|
.ignoreMoveAwayFromEdit()
|
||||||
.publishIf(() -> modifyGrant && isNotNew.getAsBoolean() && institutionActive)
|
.publishIf(() -> modifyGrant && isNotNew.getAsBoolean() && !readonly)
|
||||||
|
|
||||||
.newAction(ActionDefinition.LMS_SETUP_DEACTIVATE)
|
.newAction(ActionDefinition.LMS_SETUP_DEACTIVATE)
|
||||||
.withEntityKey(entityKey)
|
.withEntityKey(entityKey)
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class MainPage implements TemplateComposer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void compose(final PageContext pageContext) {
|
public void compose(final PageContext pageContext) {
|
||||||
this.pageStateService.clear();
|
this.pageStateService.clearState();
|
||||||
|
|
||||||
final Composite parent = pageContext.getParent();
|
final Composite parent = pageContext.getParent();
|
||||||
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||||
|
|
|
@ -148,7 +148,7 @@ public enum ActionDefinition {
|
||||||
LMS_SETUP_TEST(
|
LMS_SETUP_TEST(
|
||||||
new LocTextKey("sebserver.lmssetup.action.test"),
|
new LocTextKey("sebserver.lmssetup.action.test"),
|
||||||
ImageIcon.TEST,
|
ImageIcon.TEST,
|
||||||
PageStateDefinition.LMS_SETUP_VIEW,
|
PageStateDefinition.LMS_SETUP_EDIT,
|
||||||
ActionCategory.FORM),
|
ActionCategory.FORM),
|
||||||
LMS_SETUP_CANCEL_MODIFY(
|
LMS_SETUP_CANCEL_MODIFY(
|
||||||
new LocTextKey("sebserver.overall.action.modify.cancel"),
|
new LocTextKey("sebserver.overall.action.modify.cancel"),
|
||||||
|
|
|
@ -59,8 +59,9 @@ public interface PageService {
|
||||||
* @return the JSONMapper for parse, read and write JSON */
|
* @return the JSONMapper for parse, read and write JSON */
|
||||||
JSONMapper getJSONMapper();
|
JSONMapper getJSONMapper();
|
||||||
|
|
||||||
PageState initPageState(PageState initState);
|
/** Get the PageState of the current user.
|
||||||
|
*
|
||||||
|
* @return PageState of the current user. */
|
||||||
PageState getCurrentState();
|
PageState getCurrentState();
|
||||||
|
|
||||||
/** Publishes a given PageEvent to the current page tree
|
/** Publishes a given PageEvent to the current page tree
|
||||||
|
@ -70,25 +71,55 @@ public interface PageService {
|
||||||
* @param event the concrete PageEvent instance */
|
* @param event the concrete PageEvent instance */
|
||||||
<T extends PageEvent> void firePageEvent(T event, PageContext pageContext);
|
<T extends PageEvent> void firePageEvent(T event, PageContext pageContext);
|
||||||
|
|
||||||
|
/** Executes the given PageAction and if successful, propagate an ActionEvent to the current page.
|
||||||
|
*
|
||||||
|
* @param pageAction the PageAction to execute */
|
||||||
default void executePageAction(final PageAction pageAction) {
|
default void executePageAction(final PageAction pageAction) {
|
||||||
executePageAction(pageAction, result -> {
|
executePageAction(pageAction, result -> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Executes the given PageAction and if successful, propagate an ActionEvent to the current page.
|
||||||
|
*
|
||||||
|
* @param pageAction the PageAction to execute
|
||||||
|
* @param callback a callback to react on PageAction execution. The Callback gets a Result referencing to
|
||||||
|
* the executed PageAction or to an error if the PageAction has not been executed */
|
||||||
void executePageAction(PageAction pageAction, Consumer<Result<PageAction>> callback);
|
void executePageAction(PageAction pageAction, Consumer<Result<PageAction>> callback);
|
||||||
|
|
||||||
|
/** Publishes a PageAction to the current page. This uses the firePageEvent form
|
||||||
|
* PageContext of the given PageAction and fires a ActionPublishEvent for the given PageAction
|
||||||
|
*
|
||||||
|
* All ActionPublishEventListeners that are registered within the current page will
|
||||||
|
* receive the ActionPublishEvent sent by this.
|
||||||
|
*
|
||||||
|
* @param pageAction the PageAction to publish */
|
||||||
void publishAction(final PageAction pageAction);
|
void publishAction(final PageAction pageAction);
|
||||||
|
|
||||||
|
/** Get a new FormBuilder for the given PageContext and with number of rows.
|
||||||
|
*
|
||||||
|
* @param pageContext the PageContext on that the FormBuilder should work
|
||||||
|
* @param rows the number of rows of the from
|
||||||
|
* @return a FormBuilder instance for the given PageContext and with number of rows */
|
||||||
FormBuilder formBuilder(final PageContext pageContext, final int rows);
|
FormBuilder formBuilder(final PageContext pageContext, final int rows);
|
||||||
|
|
||||||
|
/** Get an new TableBuilder for specified page based RestCall.
|
||||||
|
*
|
||||||
|
* @param apiCall the SEB Server API RestCall that feeds the table with data
|
||||||
|
* @param <T> the type of the Entity of the table
|
||||||
|
* @return TableBuilder of specified type */
|
||||||
<T extends Entity> TableBuilder<T> entityTableBuilder(final RestCall<Page<T>> apiCall);
|
<T extends Entity> TableBuilder<T> entityTableBuilder(final RestCall<Page<T>> apiCall);
|
||||||
|
|
||||||
void clear();
|
/** Get a new PageActionBuilder for a given PageContext.
|
||||||
|
*
|
||||||
|
* @param pageContext the PageContext that is used by the new PageActionBuilder
|
||||||
|
* @return new PageActionBuilder to build PageAction */
|
||||||
default PageActionBuilder pageActionBuilder(final PageContext pageContext) {
|
default PageActionBuilder pageActionBuilder(final PageContext pageContext) {
|
||||||
return new PageActionBuilder(this, pageContext);
|
return new PageActionBuilder(this, pageContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Clears the PageState of the current users page */
|
||||||
|
void clearState();
|
||||||
|
|
||||||
default PageAction onEmptyEntityKeyGoTo(final PageAction action, final ActionDefinition gotoActionDef) {
|
default PageAction onEmptyEntityKeyGoTo(final PageAction action, final ActionDefinition gotoActionDef) {
|
||||||
if (action.getEntityKey() == null) {
|
if (action.getEntityKey() == null) {
|
||||||
final PageContext pageContext = action.pageContext();
|
final PageContext pageContext = action.pageContext();
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class DefaultPageLayout implements TemplateComposer {
|
||||||
// TODO error handling
|
// TODO error handling
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pageStateService.clear();
|
this.pageStateService.clearState();
|
||||||
|
|
||||||
// forward to login page with success message
|
// forward to login page with success message
|
||||||
pageContext.forwardToLoginPage();
|
pageContext.forwardToLoginPage();
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.ethz.seb.sebserver.gui.service.page.impl;
|
|
||||||
|
|
||||||
public final class MainPageState {
|
|
||||||
|
|
||||||
// private static final Logger log = LoggerFactory.getLogger(MainPageState.class);
|
|
||||||
//
|
|
||||||
// private PageAction action = null;
|
|
||||||
//
|
|
||||||
// private MainPageState() {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public action
|
|
||||||
//
|
|
||||||
// public boolean changeTo(final PageAction action) {
|
|
||||||
// if (this.action.definition != action.definition) {
|
|
||||||
// this.action = action;
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static MainPageState get() {
|
|
||||||
// try {
|
|
||||||
//
|
|
||||||
// final HttpSession httpSession = RWT
|
|
||||||
// .getUISession()
|
|
||||||
// .getHttpSession();
|
|
||||||
//
|
|
||||||
// MainPageState mainPageState = (MainPageState) httpSession.getAttribute(MainPage.ATTR_MAIN_PAGE_STATE);
|
|
||||||
// if (mainPageState == null) {
|
|
||||||
// mainPageState = new MainPageState();
|
|
||||||
// httpSession.setAttribute(MainPage.ATTR_MAIN_PAGE_STATE, mainPageState);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return mainPageState;
|
|
||||||
//
|
|
||||||
// } catch (final RuntimeException re) {
|
|
||||||
// throw re;
|
|
||||||
// } catch (final Exception e) {
|
|
||||||
// log.error("Unexpected error while trying to get MainPageState from user-session");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static void clear() {
|
|
||||||
// final MainPageState mainPageState = get();
|
|
||||||
// mainPageState.action = null;
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -91,12 +91,6 @@ public class PageServiceImpl implements PageService {
|
||||||
return this.jsonMapper;
|
return this.jsonMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageState initPageState(final PageState initState) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageState getCurrentState() {
|
public PageState getCurrentState() {
|
||||||
try {
|
try {
|
||||||
|
@ -206,7 +200,7 @@ public class PageServiceImpl implements PageService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clearState() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final HttpSession httpSession = RWT
|
final HttpSession httpSession = RWT
|
||||||
|
|
|
@ -67,11 +67,12 @@ public class EntityTable<ROW extends Entity> {
|
||||||
private final Table table;
|
private final Table table;
|
||||||
private final TableNavigator navigator;
|
private final TableNavigator navigator;
|
||||||
|
|
||||||
private int pageNumber = 1;
|
int pageNumber = 1;
|
||||||
private int pageSize;
|
int pageSize;
|
||||||
private String sortColumn = null;
|
String sortColumn = null;
|
||||||
private SortOrder sortOrder = SortOrder.ASCENDING;
|
SortOrder sortOrder = SortOrder.ASCENDING;
|
||||||
private boolean columnsWithSameWidth = true;
|
boolean columnsWithSameWidth = true;
|
||||||
|
boolean hideNavigation = false;
|
||||||
|
|
||||||
EntityTable(
|
EntityTable(
|
||||||
final int type,
|
final int type,
|
||||||
|
@ -93,6 +94,7 @@ public class EntityTable<ROW extends Entity> {
|
||||||
this.columns = Utils.immutableListOf(columns);
|
this.columns = Utils.immutableListOf(columns);
|
||||||
this.actions = Utils.immutableListOf(actions);
|
this.actions = Utils.immutableListOf(actions);
|
||||||
this.emptyMessage = emptyMessage;
|
this.emptyMessage = emptyMessage;
|
||||||
|
this.hideNavigation = hideNavigation;
|
||||||
|
|
||||||
final GridLayout layout = new GridLayout();
|
final GridLayout layout = new GridLayout();
|
||||||
layout.horizontalSpacing = 0;
|
layout.horizontalSpacing = 0;
|
||||||
|
@ -144,7 +146,7 @@ public class EntityTable<ROW extends Entity> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.navigator = (hideNavigation) ? null : new TableNavigator(this);
|
this.navigator = new TableNavigator(this);
|
||||||
|
|
||||||
createTableColumns();
|
createTableColumns();
|
||||||
updateTableRows(
|
updateTableRows(
|
||||||
|
@ -288,9 +290,7 @@ public class EntityTable<ROW extends Entity> {
|
||||||
.withQueryParams((this.filter != null) ? this.filter.getFilterParameter() : null)
|
.withQueryParams((this.filter != null) ? this.filter.getFilterParameter() : null)
|
||||||
.call()
|
.call()
|
||||||
.map(this::createTableRowsFromPage)
|
.map(this::createTableRowsFromPage)
|
||||||
.map(pageData -> (this.navigator != null)
|
.map(this.navigator::update)
|
||||||
? this.navigator.update(pageData)
|
|
||||||
: pageData)
|
|
||||||
.onErrorDo(t -> {
|
.onErrorDo(t -> {
|
||||||
// TODO error handling
|
// TODO error handling
|
||||||
});
|
});
|
||||||
|
|
|
@ -56,6 +56,10 @@ public class TableNavigator {
|
||||||
return pageData;
|
return pageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.entityTable.hideNavigation) {
|
||||||
|
return pageData;
|
||||||
|
}
|
||||||
|
|
||||||
final int pageNumber = pageData.getPageNumber();
|
final int pageNumber = pageData.getPageNumber();
|
||||||
final int numberOfPages = pageData.getNumberOfPages();
|
final int numberOfPages = pageData.getNumberOfPages();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue