Skip to content

Commit 85eb0ba

Browse files
committed
#178: add option to add unmapped tasks to sync
1 parent 692983d commit 85eb0ba

File tree

2 files changed

+75
-15
lines changed

2 files changed

+75
-15
lines changed

src/main/java/de/doubleslash/keeptime/view/ExternalProjectsSyncController.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import de.doubleslash.keeptime.controller.HeimatController;
88
import de.doubleslash.keeptime.model.Project;
99
import de.doubleslash.keeptime.model.Work;
10+
import de.doubleslash.keeptime.rest.integration.heimat.model.HeimatTask;
1011
import javafx.animation.Animation;
1112
import javafx.animation.PauseTransition;
1213
import javafx.animation.RotateTransition;
@@ -17,7 +18,9 @@
1718
import javafx.beans.property.*;
1819
import javafx.beans.value.ChangeListener;
1920
import javafx.collections.FXCollections;
21+
import javafx.collections.ListChangeListener;
2022
import javafx.collections.ObservableList;
23+
import javafx.collections.transformation.FilteredList;
2124
import javafx.concurrent.Task;
2225
import javafx.fxml.FXML;
2326
import javafx.scene.Node;
@@ -43,6 +46,7 @@
4346
import java.util.Collections;
4447
import java.util.List;
4548
import java.util.function.Consumer;
49+
import java.util.function.Predicate;
4650

4751
import static de.doubleslash.keeptime.view.ReportController.copyToClipboard;
4852

@@ -82,6 +86,11 @@ public class ExternalProjectsSyncController {
8286
@FXML
8387
private Label loadingMessage;
8488

89+
@FXML
90+
private ComboBox<HeimatTask> heimatTaskComboBox;
91+
@FXML
92+
private Button addHeimatTaskButton;
93+
8594
private final SVGPath loadingSpinner = SvgNodeProvider.getSvgNodeWithScale(Resources.RESOURCE.SVG_SPINNER_SOLID, 0.1,
8695
0.1);
8796
private final SVGPath loadingSuccess = SvgNodeProvider.getSvgNodeWithScale(Resources.RESOURCE.SVG_THUMBS_UP_SOLID,
@@ -148,12 +157,54 @@ public void initForDate(LocalDate currentReportDate, List<Work> currentWorkItems
148157
}), items2);
149158

150159
saveButton.disableProperty().bind(projectsValidProperty);
151-
152160
externalSystemLink.setOnAction(ae -> BrowserHelper.openURL(heimatController.getUrlForDay(currentReportDate)));
161+
162+
final List<HeimatTask> tasksForDay = heimatController.getTasks(currentReportDate);
163+
final FilteredList<HeimatTask> tasksNotInList = new FilteredList<>(FXCollections.observableArrayList(tasksForDay),
164+
(task) -> items.stream().noneMatch(tr -> task.id() == tr.mapping.heimatTaskId()));
165+
items.addListener(
166+
(ListChangeListener<? super TableRow>) c -> {
167+
final Predicate<? super HeimatTask> predicate = tasksNotInList.getPredicate();
168+
tasksNotInList.setPredicate(null);
169+
tasksNotInList.setPredicate(predicate);
170+
});
171+
heimatTaskComboBox.setItems(tasksNotInList);
172+
addHeimatTaskButton.disableProperty()
173+
.bind(heimatTaskComboBox.getSelectionModel().selectedItemProperty().isNull());
174+
addHeimatTaskButton.setOnAction(ae -> {
175+
final HeimatTask task = heimatTaskComboBox.getValue();
176+
items.add(new TableRow(new HeimatController.Mapping(task.id(), true,
177+
"Manually added\n\n" + task.name() + "\n(" + task.taskHolderName() + ")", List.of(), List.of(), "", "",
178+
0, 0), "", 0));
179+
heimatTaskComboBox.getSelectionModel().clearSelection();
180+
});
181+
153182
}
154183

155184
@FXML
156185
private void initialize() {
186+
heimatTaskComboBox.setCellFactory(param -> new ListCell<>() {
187+
@Override
188+
protected void updateItem(HeimatTask item, boolean empty) {
189+
super.updateItem(item, empty);
190+
if (empty || item == null) {
191+
setText(null);
192+
} else {
193+
setText(item.taskHolderName() + " - " + item.name());
194+
}
195+
}
196+
});
197+
heimatTaskComboBox.setButtonCell(new ListCell<>() {
198+
@Override
199+
protected void updateItem(HeimatTask item, boolean empty) {
200+
super.updateItem(item, empty);
201+
if (empty || item == null) {
202+
setText(null);
203+
} else {
204+
setText(item.name() + " - " + item.taskHolderName());
205+
}
206+
}
207+
});
157208
initializeLoadingScreen();
158209

159210
TableColumn<TableRow, TableRow> shouldSyncColumn = new TableColumn<>("Sync");
@@ -397,8 +448,6 @@ protected List<HeimatController.HeimatErrors> call() {
397448
});
398449

399450
cancelButton.setOnAction(ae -> thisStage.close());
400-
401-
// TODO offer some way to book time to an additional project?
402451
}
403452

404453
private static void markNodeValidOrNot(final Node textArea, final boolean isValid) {

src/main/resources/layouts/externalProjectSync.fxml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<?import javafx.scene.control.Button?>
4+
<?import javafx.scene.control.ComboBox?>
45
<?import javafx.scene.control.Hyperlink?>
56
<?import javafx.scene.control.Label?>
67
<?import javafx.scene.control.TableView?>
@@ -14,46 +15,56 @@
1415
<children>
1516
<AnchorPane fx:id="pane" prefHeight="600.0" prefWidth="1000.0">
1617
<children>
17-
<TableView fx:id="mappingTableView" layoutY="50.0" prefHeight="603.0" prefWidth="1112.0" AnchorPane.bottomAnchor="55.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="35.0" />
18-
<HBox layoutX="987.0" layoutY="722.0" spacing="5.0" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="5.0">
19-
<children>
20-
<Button fx:id="saveButton" mnemonicParsing="false" text="Save" />
21-
<Button fx:id="cancelButton" mnemonicParsing="false" text="Cancel" />
22-
</children>
23-
</HBox>
18+
<TableView fx:id="mappingTableView" layoutY="50.0" prefHeight="603.0" prefWidth="1112.0" AnchorPane.bottomAnchor="80.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="35.0" />
19+
<Hyperlink fx:id="externalSystemLink" layoutX="29.0" layoutY="723.0" text="Open day in HEIMAT" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0" />
2420
<HBox spacing="5.0" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0">
2521
<children>
2622
<Label text="Syncing day" />
2723
<Label fx:id="dayOfSyncLabel" text="01.01.2025" />
2824
</children>
2925
</HBox>
30-
<HBox layoutX="37.0" layoutY="665.0" spacing="50.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="5.0">
26+
<HBox layoutX="37.0" layoutY="665.0" spacing="50.0" AnchorPane.bottomAnchor="35.0" AnchorPane.leftAnchor="5.0">
3127
<children>
3228
<VBox spacing="5.0">
3329
<children>
3430
<HBox spacing="5.0">
3531
<children>
3632
<Label text="New Heimat time:" />
37-
<Label fx:id="sumTimeLabel" alignment="CENTER_RIGHT" contentDisplay="RIGHT" text="08:45" />
33+
<Label fx:id="sumTimeLabel" alignment="CENTER_RIGHT" contentDisplay="RIGHT" text="00:00" />
3834
</children>
3935
</HBox>
4036
<HBox spacing="5.0">
4137
<children>
4238
<Label text="Current Heimat time:" />
43-
<Label fx:id="heimatTimeLabel" text="08:45" />
39+
<Label fx:id="heimatTimeLabel" text="00:00" />
4440
</children>
4541
</HBox>
4642
</children>
4743
</VBox>
4844
<HBox spacing="5.0">
4945
<children>
5046
<Label text="KeepTime work time:" />
51-
<Label fx:id="keepTimeTimeLabel" text="08:45" />
47+
<Label fx:id="keepTimeTimeLabel" text="00:00" />
5248
</children>
5349
</HBox>
5450
</children>
5551
</HBox>
56-
<Hyperlink fx:id="externalSystemLink" layoutX="29.0" layoutY="723.0" text="Open day in HEIMAT" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0" />
52+
<VBox spacing="15.0" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="5.0">
53+
<children>
54+
<HBox spacing="5.0">
55+
<children>
56+
<ComboBox fx:id="heimatTaskComboBox" prefHeight="25.0" prefWidth="254.0" />
57+
<Button fx:id="addHeimatTaskButton" mnemonicParsing="false" prefHeight="25.0" text="Add" />
58+
</children>
59+
</HBox>
60+
<HBox alignment="TOP_RIGHT" spacing="5.0">
61+
<children>
62+
<Button fx:id="saveButton" mnemonicParsing="false" text="Save" />
63+
<Button fx:id="cancelButton" mnemonicParsing="false" text="Cancel" />
64+
</children>
65+
</HBox>
66+
</children>
67+
</VBox>
5768
</children>
5869
</AnchorPane>
5970
<VBox fx:id="loadingScreen" alignment="CENTER" spacing="10.0" visible="false">

0 commit comments

Comments
 (0)