diff --git a/core/src/main/java/place/sita/labelle/core/repository/inrepository/delta/DeltaService.java b/core/src/main/java/place/sita/labelle/core/repository/inrepository/delta/DeltaService.java index d4914be..8617ffc 100644 --- a/core/src/main/java/place/sita/labelle/core/repository/inrepository/delta/DeltaService.java +++ b/core/src/main/java/place/sita/labelle/core/repository/inrepository/delta/DeltaService.java @@ -10,6 +10,7 @@ import java.util.UUID; import java.util.stream.Collectors; +import static place.sita.labelle.jooq.Tables.TAG_DELTA; import static place.sita.labelle.jooq.Tables.TAG_DELTA_CALC; @Service @@ -21,6 +22,23 @@ public DeltaService(DSLContext dslContext) { this.dslContext = dslContext; } + @Transactional + public void addTagDelta(UUID imageId, String tag, String category, TagDeltaType added) { + // does tag delta for this image id, tag and category already exist? + dslContext.deleteFrom(TAG_DELTA) + .where(TAG_DELTA.IMAGE_ID.eq(imageId) + .and(TAG_DELTA.TAG.eq(tag)) + .and(TAG_DELTA.CATEGORY.eq(category)) + ).execute(); + + dslContext.insertInto(TagDelta.TAG_DELTA) + .set(TagDelta.TAG_DELTA.IMAGE_ID, imageId) + .set(TagDelta.TAG_DELTA.TAG, tag) + .set(TagDelta.TAG_DELTA.CATEGORY, category) + .set(TagDelta.TAG_DELTA.ADDS, added == TagDeltaType.ADD) + .execute(); + } + @Transactional public void recalculateTagDeltas(Set imageIds) { dslContext.deleteFrom(TagDelta.TAG_DELTA) diff --git a/gui-local/src/main/java/place/sita/labelle/gui/local/repositoryfx/TagDeltasComponentController.java b/gui-local/src/main/java/place/sita/labelle/gui/local/repositoryfx/TagDeltasComponentController.java index 31d4459..5dd7b5c 100644 --- a/gui-local/src/main/java/place/sita/labelle/gui/local/repositoryfx/TagDeltasComponentController.java +++ b/gui-local/src/main/java/place/sita/labelle/gui/local/repositoryfx/TagDeltasComponentController.java @@ -143,12 +143,23 @@ public String toString() { } @FXML - void addDeltaButtonPress(ActionEvent event) { - + public void addDeltaButtonPress(ActionEvent event) { + addDelta(DeltaType.ADD, deltaCategoryTextField.getText(), deltaEntryTextField.getText()); } @FXML - void removeDeltaButtonPress(ActionEvent event) { + public void removeDeltaButtonPress(ActionEvent event) { + addDelta(DeltaType.REMOVE, deltaCategoryTextField.getText(), deltaEntryTextField.getText()); + } + + private void addDelta(DeltaType deltaType, String category, String tag) { + Threading.onSeparateThread(toolkit -> { + deltaService.addTagDelta(selected.id(), tag, category, map(deltaType)); + toolkit.onFxThread(() -> { + // adding deltas has side effects that are too bothersome to calculate in view context + reloadDeltas(); + }); + }); }