Skip to content

Commit

Permalink
#37: Implement manually adding tag delta
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-sita committed Jul 19, 2024
1 parent 0224707 commit a88dc4b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<UUID> imageIds) {
dslContext.deleteFrom(TagDelta.TAG_DELTA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

}

Expand Down

0 comments on commit a88dc4b

Please sign in to comment.