-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from penguineer/accounting
Add an Accounting area
- Loading branch information
Showing
10 changed files
with
164 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/com/penguineering/gartenplus/ui/appframe/TabbedLayoutBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.penguineering.gartenplus.ui.appframe; | ||
|
||
import com.penguineering.gartenplus.auth.SecurityUtils; | ||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.HasElement; | ||
import com.vaadin.flow.component.UI; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout; | ||
import com.vaadin.flow.component.tabs.Tab; | ||
import com.vaadin.flow.component.tabs.Tabs; | ||
import com.vaadin.flow.router.BeforeEnterEvent; | ||
import com.vaadin.flow.router.BeforeEnterObserver; | ||
import com.vaadin.flow.router.Route; | ||
import com.vaadin.flow.router.RouterLayout; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
public abstract class TabbedLayoutBase extends VerticalLayout implements RouterLayout, BeforeEnterObserver { | ||
private final Map<String, Class<? extends Component>> targets; | ||
|
||
private final Div content; | ||
private final Tabs menu; | ||
|
||
public TabbedLayoutBase(Map<String, Class<? extends Component>> targets) { | ||
super(); | ||
this.targets = targets; | ||
|
||
Set<String> userRoles = SecurityUtils.getCurrentUserRoles(); | ||
|
||
menu = new Tabs(); | ||
targets.entrySet().stream() | ||
.filter(e -> SecurityUtils.isUserAuthorizedForComponent(e.getValue(), userRoles)) | ||
.map(Map.Entry::getKey) | ||
.map(Tab::new) | ||
.forEach(menu::add); | ||
menu.addSelectedChangeListener(this::navigateToTab); | ||
add(menu); | ||
|
||
content = new Div(); | ||
content.setSizeFull(); | ||
content.getStyle() | ||
.set("margin", "0") | ||
.set("padding", "0"); | ||
add(content); | ||
} | ||
|
||
private void navigateToTab(Tabs.SelectedChangeEvent event) { | ||
Optional.of(event.getSelectedTab()) | ||
.map(Tab::getLabel) | ||
.map(targets::get) | ||
.ifPresent(target -> UI.getCurrent().navigate(target)); | ||
} | ||
|
||
@Override | ||
public void beforeEnter(BeforeEnterEvent event) { | ||
String currentPath = event.getLocation().getPath(); | ||
targets.forEach((label, target) -> { | ||
Route route = target.getAnnotation(Route.class); | ||
if (route != null && currentPath.contains(route.value())) { | ||
menu.setSelectedTab(menu.getChildren() | ||
.filter(component -> component instanceof Tab) | ||
.map(component -> (Tab) component) | ||
.filter(tab -> tab.getLabel().equals(label)) | ||
.findFirst() | ||
.orElse(null)); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void showRouterLayoutContent(HasElement newContent) { | ||
// Previous content is automatically removed | ||
|
||
newContent.getElement() | ||
.getComponent() | ||
.ifPresent(content::add); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.penguineering.gartenplus.ui.content.accounting; | ||
|
||
|
||
import com.penguineering.gartenplus.ui.appframe.AppFrameLayout; | ||
import com.penguineering.gartenplus.ui.appframe.TabbedLayoutBase; | ||
import com.penguineering.gartenplus.ui.content.accounting.ledgers.LedgersSettingsPage; | ||
import com.penguineering.gartenplus.ui.content.accounting.myfinances.MyFinancesPage; | ||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.router.ParentLayout; | ||
import com.vaadin.flow.router.RoutePrefix; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
@ParentLayout(AppFrameLayout.class) | ||
@RoutePrefix(value = "accounting") | ||
public class AccountingLayout extends TabbedLayoutBase { | ||
private static final Map<String, Class<? extends Component>> targets = new LinkedHashMap<>(); | ||
|
||
static { | ||
targets.put("Meine Finanzen", MyFinancesPage.class); | ||
targets.put("Hauptbücher", LedgersSettingsPage.class); | ||
} | ||
|
||
public AccountingLayout() { | ||
super(targets); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/penguineering/gartenplus/ui/content/accounting/AccountingPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.penguineering.gartenplus.ui.content.accounting; | ||
|
||
import com.penguineering.gartenplus.ui.appframe.GartenplusPage; | ||
import com.penguineering.gartenplus.ui.content.accounting.myfinances.MyFinancesPage; | ||
import com.vaadin.flow.router.BeforeEnterEvent; | ||
import com.vaadin.flow.router.BeforeEnterObserver; | ||
import com.vaadin.flow.router.PageTitle; | ||
import com.vaadin.flow.router.Route; | ||
import jakarta.annotation.security.PermitAll; | ||
|
||
@Route(value = "", layout = AccountingLayout.class) | ||
@PermitAll | ||
@PageTitle("GartenPlus | Buchhaltung") | ||
public class AccountingPage extends GartenplusPage implements BeforeEnterObserver { | ||
@Override | ||
public void beforeEnter(BeforeEnterEvent event) { | ||
|
||
event.getUI().navigate(MyFinancesPage.class); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../admin/settings/ledgers/LedgerEditor.java → ...tent/accounting/ledgers/LedgerEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...t/admin/settings/ledgers/LedgersGrid.java → ...ntent/accounting/ledgers/LedgersGrid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...in/java/com/penguineering/gartenplus/ui/content/accounting/myfinances/MyFinancesPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.penguineering.gartenplus.ui.content.accounting.myfinances; | ||
|
||
import com.penguineering.gartenplus.ui.appframe.GartenplusPage; | ||
import com.penguineering.gartenplus.ui.content.accounting.AccountingLayout; | ||
import com.vaadin.flow.component.html.Paragraph; | ||
import com.vaadin.flow.router.PageTitle; | ||
import com.vaadin.flow.router.Route; | ||
import jakarta.annotation.security.PermitAll; | ||
import jakarta.annotation.security.RolesAllowed; | ||
|
||
@Route(value = "myfinances", layout = AccountingLayout.class) | ||
@PermitAll | ||
@PageTitle("GartenPlus | Buchhaltung | Meine Finanzen") | ||
public class MyFinancesPage extends GartenplusPage { | ||
public MyFinancesPage() { | ||
add(new Paragraph("Diese Seite wächst noch.")); | ||
} | ||
} |
73 changes: 6 additions & 67 deletions
73
src/main/java/com/penguineering/gartenplus/ui/content/admin/settings/SettingsLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,28 @@ | ||
package com.penguineering.gartenplus.ui.content.admin.settings; | ||
|
||
import com.penguineering.gartenplus.auth.SecurityUtils; | ||
import com.penguineering.gartenplus.ui.appframe.TabbedLayoutBase; | ||
import com.penguineering.gartenplus.ui.content.accounting.ledgers.LedgersSettingsPage; | ||
import com.penguineering.gartenplus.ui.content.admin.AdminLayout; | ||
import com.penguineering.gartenplus.ui.content.admin.settings.groups.GroupSettingsPage; | ||
import com.penguineering.gartenplus.ui.content.admin.settings.ledgers.LedgersSettingsPage; | ||
import com.penguineering.gartenplus.ui.content.admin.settings.users.UsersSettingsPage; | ||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.HasElement; | ||
import com.vaadin.flow.component.UI; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout; | ||
import com.vaadin.flow.component.tabs.Tab; | ||
import com.vaadin.flow.component.tabs.Tabs; | ||
import com.vaadin.flow.router.*; | ||
import com.vaadin.flow.router.ParentLayout; | ||
import com.vaadin.flow.router.RoutePrefix; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
@ParentLayout(AdminLayout.class) | ||
@RoutePrefix(value = "settings") | ||
public class SettingsLayout extends VerticalLayout implements RouterLayout, BeforeEnterObserver { | ||
public class SettingsLayout extends TabbedLayoutBase { | ||
private static final Map<String, Class<? extends Component>> targets = new LinkedHashMap<>(); | ||
|
||
static { | ||
targets.put("Benutzer", UsersSettingsPage.class); | ||
targets.put("Gruppen", GroupSettingsPage.class); | ||
targets.put("Hauptbücher", LedgersSettingsPage.class); | ||
} | ||
|
||
private final Div content; | ||
private final Tabs menu; | ||
|
||
public SettingsLayout() { | ||
super(); | ||
|
||
Set<String> userRoles = SecurityUtils.getCurrentUserRoles(); | ||
|
||
menu = new Tabs(); | ||
targets.entrySet().stream() | ||
.filter(e -> SecurityUtils.isUserAuthorizedForComponent(e.getValue(), userRoles)) | ||
.map(Map.Entry::getKey) | ||
.map(Tab::new) | ||
.forEach(menu::add); | ||
menu.addSelectedChangeListener(this::navigateToTab); | ||
add(menu); | ||
|
||
content = new Div(); | ||
content.setSizeFull(); | ||
content.getStyle() | ||
.set("margin", "0") | ||
.set("padding", "0"); | ||
add(content); | ||
} | ||
|
||
private void navigateToTab(Tabs.SelectedChangeEvent event) { | ||
Optional.of(event.getSelectedTab()) | ||
.map(Tab::getLabel) | ||
.map(targets::get) | ||
.ifPresent(target -> UI.getCurrent().navigate(target)); | ||
} | ||
|
||
@Override | ||
public void beforeEnter(BeforeEnterEvent event) { | ||
String currentPath = event.getLocation().getPath(); | ||
targets.forEach((label, target) -> { | ||
Route route = target.getAnnotation(Route.class); | ||
if (route != null && currentPath.contains(route.value())) { | ||
menu.setSelectedTab(menu.getChildren() | ||
.filter(component -> component instanceof Tab) | ||
.map(component -> (Tab) component) | ||
.filter(tab -> tab.getLabel().equals(label)) | ||
.findFirst() | ||
.orElse(null)); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void showRouterLayoutContent(HasElement newContent) { | ||
// Previous content is automatically removed | ||
|
||
newContent.getElement() | ||
.getComponent() | ||
.ifPresent(content::add); | ||
super(targets); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters