Skip to content

Commit

Permalink
Added config to include unassigned category in pie charts on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
buchen committed Dec 18, 2022
1 parent c6c881f commit bb14d7b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package name.abuchen.portfolio.ui.views.dashboard.charts;

import org.eclipse.jface.action.IMenuManager;

import name.abuchen.portfolio.model.Dashboard;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.util.SimpleAction;
import name.abuchen.portfolio.ui.views.dashboard.WidgetConfig;
import name.abuchen.portfolio.ui.views.dashboard.WidgetDelegate;

public class IncludeUnassignedCategoryConfig implements WidgetConfig
{
private final WidgetDelegate<?> delegate;
private boolean isUnassignedIncluded = false;

public IncludeUnassignedCategoryConfig(WidgetDelegate<?> delegate, boolean defaultValue)
{
this.delegate = delegate;

String code = delegate.getWidget().getConfiguration().get(Dashboard.Config.FLAG_INCLUDE_UNASSIGNED.name());
this.isUnassignedIncluded = code != null ? Boolean.parseBoolean(code) : defaultValue;
}

@Override
public void menuAboutToShow(IMenuManager manager)
{
SimpleAction action = new SimpleAction(Messages.LabelIncludeUnassignedCategoryInCharts, a -> {
this.isUnassignedIncluded = !this.isUnassignedIncluded;

delegate.getWidget().getConfiguration().put(Dashboard.Config.FLAG_INCLUDE_UNASSIGNED.name(),
String.valueOf(this.isUnassignedIncluded));

delegate.update();
delegate.getClient().touch();
});

action.setChecked(this.isUnassignedIncluded);
manager.add(action);
}

@Override
public String getLabel()
{
return Messages.LabelIncludeUnassignedCategoryInCharts + ": " //$NON-NLS-1$
+ (this.isUnassignedIncluded ? Messages.LabelYes : Messages.LabelNo);
}

public boolean isUnassignedCategoryIncluded()
{
return this.isUnassignedIncluded;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public TaxonomyChartWidget(Widget widget, DashboardData data)
super(widget, data);

addConfigAfter(ReportingPeriodConfig.class, new TaxonomyConfig(this));
addConfigAfter(ClientFilterConfig.class, new IncludeUnassignedCategoryConfig(this, true));
}

@Override
Expand All @@ -44,7 +45,10 @@ public Supplier<TaxonomyModel> getUpdateTask()
if (taxonomy != null)
{
Client filteredClient = get(ClientFilterConfig.class).getSelectedFilter().filter(getClient());
return new TaxonomyModel(getDashboardData().getExchangeRateProviderFactory(), filteredClient, taxonomy);
TaxonomyModel model = new TaxonomyModel(getDashboardData().getExchangeRateProviderFactory(),
filteredClient, taxonomy);
model.setExcludeUnassignedCategoryInCharts(!get(IncludeUnassignedCategoryConfig.class).isUnassignedCategoryIncluded());
return model;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum Config
{
REPORTING_PERIOD, DATA_SERIES, SECONDARY_DATA_SERIES, CONFIG_UUID, AGGREGATION, EXCHANGE_RATE_SERIES, //
COLOR_SCHEMA, LAYOUT, HEIGHT, EARNING_TYPE, NET_GROSS, CLIENT_FILTER, CALCULATION_METHOD, METRIC, //
ATTRIBUTE_UUID, URL, SHOW_Y_AXIS, TAXONOMY;
ATTRIBUTE_UUID, URL, SHOW_Y_AXIS, TAXONOMY, FLAG_INCLUDE_UNASSIGNED;
}

public static final class Column
Expand Down

0 comments on commit bb14d7b

Please sign in to comment.