Skip to content

Commit

Permalink
perf(registrar): load only open applications on apps view
Browse files Browse the repository at this point in the history
* for loading all applications is getting too slow, load only open applications until chosen otherwise
  • Loading branch information
Johaney-s committed Sep 26, 2022
1 parent 3c97e42 commit 5a89bd9
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ public static Request getApplicationsForUser(int userId, JsonEvents events) {

}

/**
* Retrieve open applications for User.
*
* @param userId ID of user to get applications for or 0 if user unknown (search by authorization)
* @param events Events done on callback
*
* @return Request unique request
*/
public static Request getOpenApplicationsForUser(int userId, JsonEvents events) {

JsonClient client = new JsonClient(events);
if (userId > 0) {
client.put("id", userId);
}
return client.call(REGISTRAR_MANAGER + "getOpenApplicationsForUser");

}

/**
* Retrieve applications for Member.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ public interface PerunRegistrarTranslation extends PerunTranslation {
@DefaultMessage("Submitted registrations")
public String submittedTitle();

@DefaultMessage("Open applications")
public String openAppsOnly();

@DefaultMessage("All applications")
public String allApps();

@DefaultMessage("This operation may take a while.")
public String slowOperation();

@DefaultMessage("Submitted")
public String submittedOn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import cz.metacentrum.perun.wui.registrar.model.ApplicationColumnProvider;
import cz.metacentrum.perun.wui.widgets.PerunButton;
import cz.metacentrum.perun.wui.widgets.PerunDataGrid;
import org.gwtbootstrap3.client.ui.AnchorListItem;
import org.gwtbootstrap3.client.ui.html.Text;

/**
Expand All @@ -40,6 +41,15 @@ interface AppsViewUiBinder extends UiBinder<Widget, AppsView> {
@UiField
PerunButton refresh;

@UiField
AnchorListItem openAppsOnly;

@UiField
AnchorListItem allApps;

@UiField
PerunButton filterButton;

private PerunRegistrarTranslation translation = GWT.create(PerunRegistrarTranslation.class);

@Inject
Expand All @@ -48,6 +58,10 @@ public AppsView(AppsViewUiBinder binder) {
initWidget(binder.createAndBindUi(this));
text.setText(translation.submittedTitle());
refresh.setTooltipText(translation.refresh());
openAppsOnly.setText(translation.openAppsOnly());
allApps.setText(translation.allApps());
allApps.setTitle(translation.slowOperation());
filterButton.setText(translation.filter());
grid.setHeight("100%");

}
Expand All @@ -57,34 +71,83 @@ public void refresh(ClickEvent event) {
draw();
}

@UiHandler(value = "filterButton")
public void filterButton(ClickEvent event) {
draw();
}

@UiHandler(value = "allApps")
public void allApps(ClickEvent event) {
allApps.setActive(true);
openAppsOnly.setActive(false);
draw();
}

@UiHandler(value = "openAppsOnly")
public void openAppsOnly(ClickEvent event) {
openAppsOnly.setActive(true);
allApps.setActive(false);
draw();
}

public void draw() {

// make sure we search by identity and user session info
RegistrarManager.getApplicationsForUser(0, new JsonEvents() {

JsonEvents retry = this;

@Override
public void onFinished(JavaScriptObject jso) {
grid.setList(JsUtils.<Application>jsoAsList(jso));
}

@Override
public void onError(PerunException error) {
grid.getLoaderWidget().onError(error, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
RegistrarManager.getApplicationsForUser(0, retry);
}
});
}

@Override
public void onLoadingStart() {
grid.clearTable();
grid.getLoaderWidget().onLoading(translation.loadingApplications());
}
});

if (openAppsOnly.isActive()) {
// make sure we search by identity and user session info
RegistrarManager.getOpenApplicationsForUser(0, new JsonEvents() {

JsonEvents retry = this;

@Override
public void onFinished(JavaScriptObject jso) {
grid.setList(JsUtils.<Application>jsoAsList(jso));
}

@Override
public void onError(PerunException error) {
grid.getLoaderWidget().onError(error, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
RegistrarManager.getOpenApplicationsForUser(0, retry);
}
});
}

@Override
public void onLoadingStart() {
grid.clearTable();
grid.getLoaderWidget().onLoading(translation.loadingApplications());
}
});
} else {
// make sure we search by identity and user session info
RegistrarManager.getApplicationsForUser(0, new JsonEvents() {

JsonEvents retry = this;

@Override
public void onFinished(JavaScriptObject jso) {
grid.setList(JsUtils.<Application>jsoAsList(jso));
}

@Override
public void onError(PerunException error) {
grid.getLoaderWidget().onError(error, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
RegistrarManager.getApplicationsForUser(0, retry);
}
});
}

@Override
public void onLoadingStart() {
grid.clearTable();
grid.getLoaderWidget().onLoading(translation.loadingApplications());
}
});
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
<b:Heading size="H2" ui:field="pageTitle">
<b:Icon ui:field="icon" type="ARCHIVE" fixedWidth="true" />
<b.html:Text text="My registrations" ui:field="text"/>
<b.html:Small text=""/>
<b.html:Small text="" marginRight="20"/>
<b:ButtonGroup>
<p:PerunButton icon="FILTER" ui:field="filterButton">Filter</p:PerunButton>
<b:Button dataToggle="DROPDOWN" ui:field="dropdown"/>
<b:DropDownMenu>
<b:AnchorListItem ui:field="openAppsOnly" active="true">Open applications</b:AnchorListItem>
<b:AnchorListItem ui:field="allApps">All applications</b:AnchorListItem>
</b:DropDownMenu>
</b:ButtonGroup>
<p:PerunButton tooltipText="Refresh" icon="REFRESH" ui:field="refresh" marginLeft="20" />
</b:Heading>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ submittedOn=Podáno
state=Stav
type=Typ
virtualOrganization=Virtuální organizace
openAppsOnly=Otevřené přihlášky
allApps=Všechny přihlášky
slowOperation=Tato operace může chvíli trvat.
group=Skupina
showDetail=Zobrazit
mailVerificationText=Zkontrolujte si prosím doručenou poštu pro <b>{0}</b>. Pokud jste neobdrželi zprávu pro ověření mailové adresy, zkontrolujte si složku pro SPAM nebo použijte tlačítko pro opětovné odeslání.
Expand Down

0 comments on commit 5a89bd9

Please sign in to comment.