Skip to content

Commit

Permalink
[25910] Agenda Web: Implementation of color coding for areas (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksic28 authored and huthomas committed Dec 14, 2023
1 parent eb6cf82 commit 1bf857d
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 31 deletions.
62 changes: 45 additions & 17 deletions bundles/at.medevit.elexis.agenda.ui/rsc/html/switchParallel.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,61 @@

// https://fullcalendar.io/docs/v3/resourceOrder

var colorMapping = {};
function loadResources(callback) {
var _resources = loadResourcesFunction();
var resources = JSON.parse(_resources);
resources.forEach(function(resource) {
colorMapping[resource.id] = 'rgba(' + resource.color + ', 0.4)';
});
callback(resources);
}
}

function getColorForResource(resourceId) {
var color = colorMapping[resourceId] || 'rgba(255, 255, 255, 0.4)';
return color;
}
function loadEventsCallback(start, end, timezone, callback) {
var eventsJson = loadEventsFunction(start.format(), end.format(), timezone);
var jsonEvents = JSON.parse(eventsJson);

var events = [];
jsonEvents.forEach(function (event) {
events.push({
id: event.id,
title: event.title,
start: event.start,
end: event.end,
description: event.description,
icon: event.icon,
rendering: event.rendering,
borderColor: event.borderColor,
backgroundColor: event.backgroundColor,
textColor: event.textColor,
resourceId: event.resource,
allDay: event.allDay
var processedResources = new Set();
jsonEvents.forEach(function (event) {
var resourceId = event.resource || event.resourceId;
if (!processedResources.has(resourceId)) {
var color = getColorForResource(resourceId);
if (color && !color.includes("undefined")) {
var autoStartDate = new Date();
var autoEndDate = new Date();
autoStartDate.setFullYear(autoStartDate.getFullYear() - 1);
autoEndDate.setFullYear(autoEndDate.getFullYear() + 3);
var formattedStart = autoStartDate.toISOString().split('T')[0] + "T00:00";
var formattedEnd = autoEndDate.toISOString().split('T')[0] + "T23:59";
events.push({
resourceId: resourceId,
start: formattedStart,
end: formattedEnd,
rendering: 'background',
color: color
});
}
processedResources.add(resourceId);
}
events.push({
id: event.id,
title: event.title,
start: event.start,
end: event.end,
description: event.description,
icon: event.icon,
rendering: event.rendering,
borderColor: event.borderColor,
backgroundColor: event.backgroundColor,
textColor: event.textColor,
resourceId: event.resource,
allDay: event.allDay
});
});
});
callback(events);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.medevit.elexis.agenda.ui.function;

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

Expand All @@ -9,6 +11,8 @@
import com.google.gson.GsonBuilder;

import at.medevit.elexis.agenda.ui.composite.IAgendaComposite;
import ch.elexis.agenda.preferences.PreferenceConstants;
import ch.elexis.core.services.holder.ConfigServiceHolder;

public class LoadResourcesFunction extends AbstractBrowserFunction {

Expand All @@ -23,28 +27,39 @@ public LoadResourcesFunction(Browser browser, String name, IAgendaComposite agen

@Override
public Object function(Object[] arguments) {
Set<String> selectedResources = agendaComposite.getSelectedResources();
Set<Resource> _selectedResources = new LinkedHashSet<Resource>();
int order = 0;
for (String selectedResource : selectedResources) {
_selectedResources.add(new Resource(selectedResource, selectedResource, order));
order++;
}
String json = gson.toJson(_selectedResources);
return json;
Set<String> selectedResources = agendaComposite.getSelectedResources();
String colorPrefs = ConfigServiceHolder.get().get(PreferenceConstants.AG_BEREICH_FARBEN, null);
Map<String, String> resourceColors = new HashMap<>();
String[] colorAssignments = colorPrefs.split(";");
for (String assignment : colorAssignments) {
String[] parts = assignment.split(":");
if (parts.length == 2) {
resourceColors.put(parts[0], parts[1]);
}
}
Set<Resource> _selectedResources = new LinkedHashSet<Resource>();
int order = 0;
for (String selectedResource : selectedResources) {
String color = resourceColors.getOrDefault(selectedResource, null);
_selectedResources.add(new Resource(selectedResource, selectedResource, order, color));
order++;
}
String json = gson.toJson(_selectedResources);
return json;
}

private class Resource {

private String id;
private String title;
@SuppressWarnings("unused")
private int order;
private String color;

public Resource(String id, String title, int order) {
public Resource(String id, String title, int order, String color) {
this.id = id;
this.title = title;
this.order = order;
this.color = color;
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions bundles/ch.elexis.agenda/src/ch/elexis/agenda/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public final class Messages {
public static String TerminDialog_Mandator = ch.elexis.core.l10n.Messages.TerminDialog_Mandator;
public static String TerminDialog_past = ch.elexis.core.l10n.Messages.TerminDialog_past;
public static String TerminDialog_print = ch.elexis.core.l10n.Messages.Core_Print;
public static String Agenda_Bereiche_Title = ch.elexis.core.l10n.Messages.Core_Area_Bereiche;
public static String AgendaFarben_appstateTypes = ch.elexis.core.l10n.Messages.AgendaFarben_appstateTypes;
public static String AgendaFarben_appTypes = ch.elexis.core.l10n.Messages.AgendaFarben_appTypes;
public static String AgendaFarben_colorSettings = ch.elexis.core.l10n.Messages.AgendaFarben_colorSettings;
Expand Down Expand Up @@ -112,6 +113,7 @@ public final class Messages {
public static String Zeitvorgaben_terminTypes = ch.elexis.core.l10n.Messages.Zeitvorgaben_terminTypes;
public static String AgendaDefinitionen_shortCutsForBer = ch.elexis.core.l10n.Messages.AgendaDefinitionen_shortCutsForBer;
public static String AgendaDefinitionen_shortCutsForBerToUser = ch.elexis.core.l10n.Messages.AgendaDefinitionen_shortCutsForBerToUser;
public static String AgendaFarben_Title = ch.elexis.core.l10n.Messages.LeistungenView_defineColor;
public static String Tageseinteilung_no_past_Date = ch.elexis.core.l10n.Messages.Tageseinteilung_no_past_Date;
public static String AgendaAnzeige_options = ch.elexis.core.l10n.Messages.AgendaAnzeige_options;
public static String AgendaAnzeige_showReason = ch.elexis.core.l10n.Messages.AgendaAnzeige_showReason;
Expand Down Expand Up @@ -181,4 +183,9 @@ public final class Messages {
public static String Tageseinteilung_lblEditValuesFor_text = ch.elexis.core.l10n.Messages.Tageseinteilung_lblEditValuesFor_text;
public static String Tageseinteilung_lblChangedValuesAre_text = ch.elexis.core.l10n.Messages.Tageseinteilung_lblChangedValuesAre_text;
public static String Tageseinteilung_btnNewButton_text = ch.elexis.core.l10n.Messages.Tageseinteilung_btnNewButton_text;
public static String AgendaFarben_Bereich_Description = ch.elexis.core.l10n.Messages.AgendaFarben_Bereich_Description;
public static String AgendaFarben_Titel = ch.elexis.core.l10n.Messages.AgendaFarben_Titel;
public static String AgendaFarben_Link = ch.elexis.core.l10n.Messages.AgendaFarben_Link;
public static String Agenda_Mandator = ch.elexis.core.l10n.Messages.Agenda_Mandator;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
Expand Down Expand Up @@ -51,6 +53,7 @@
import ch.elexis.core.ui.util.SWTHelper;
import ch.elexis.data.Anwender;
import ch.elexis.data.Kontakt;
import ch.elexis.dialogs.FarbenSelektor;

public class AgendaDefinitionPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {

Expand Down Expand Up @@ -163,11 +166,15 @@ public Control createContents(Composite parent) {
comboViewerAreaType.setInput(AreaType.values());
comboViewerAreaType.setSelection(new StructuredSelection(AreaType.GENERIC));
comboViewerAreaType.addSelectionChangedListener(sc -> {
if (AreaType.CONTACT.equals(comboViewerAreaType.getStructuredSelection().getFirstElement())) {
if (linkAreaTypeValue.getText().length() == 0) {
AreaType selectedType = (AreaType) ((IStructuredSelection) sc.getSelection()).getFirstElement();
String area = (String) listViewerArea.getStructuredSelection().getFirstElement();

if (selectedType.equals(AreaType.CONTACT)) {
if (linkAreaTypeValue.getText().isEmpty()) {
linkAreaTypeValue.setText("<a>select</a>");
}
} else {
} else if (selectedType.equals(AreaType.GENERIC)) {
AppointmentServiceHolder.get().setAreaType(area, AreaType.GENERIC, null);
linkAreaTypeValue.setText(StringUtils.EMPTY);
}
});
Expand All @@ -189,6 +196,18 @@ public void mouseDown(MouseEvent e) {
}
};

Link farbenSelektorLink = new Link(compAreas, SWT.NONE);
farbenSelektorLink.setText("<a>" + Messages.AgendaFarben_Link + "</a>");
farbenSelektorLink.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FarbenSelektor farbenSelektor = new FarbenSelektor(UiDesk.getTopShell());
if (farbenSelektor.open() == Dialog.OK) {
listViewerArea.refresh();
}
}
});

linkAreaTypeValue = new Link(compositeAreaType, SWT.NONE);
linkAreaTypeValue.addMouseListener(contactSelectorMouseListener);
linkAreaTypeValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PreferenceConstants {
public static final String AG_DAYPREFERENCES = Preferences.AG_DAYPREFERENCES;
public static final String AG_SHOW_REASON = "agenda/show_reason"; //$NON-NLS-1$
public static final String AG_BEREICH = "agenda/bereich"; //$NON-NLS-1$
public static final String AG_BEREICH_FARBEN = "agenda/bereich/farben"; //$NON-NLS-1$
public static final String AG_BIG_SAVE_COLUMNWIDTH = "agenda/big/savecolumnwidth";
public static final String AG_BIG_COLUMNWIDTH = "agenda/big/columnwidth";

Expand Down Expand Up @@ -61,4 +62,6 @@ public class PreferenceConstants {
public static final String PREF_DEFAULT_MAIL_ACCOUNT_APPOINTMENT = "agenda/appointment";
public static final String PREF_DEFAULT_MAIL_ACCOUNT_APPOINTMENT_TEMPLATE = "agenda/appointmenttemplate";
public static final String PREF_DEFAULT_MAIL_ACCOUNT = "account";
public static final String AG_USE_MANDATOR_COLORS = "USE_MANDATOR_COLORS"; // $NON-NLS-1$

}
Loading

0 comments on commit 1bf857d

Please sign in to comment.