Skip to content

Commit

Permalink
Merge pull request #96 from folded-ear/calendar-do-not-recog
Browse files Browse the repository at this point in the history
don't include leading ! on plan calendar items
  • Loading branch information
barneyb authored Aug 19, 2024
2 parents 505992d + 53c3d03 commit 635ccf4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/brennaswitzer/cookbook/domain/PlanItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public void setParent(PlanItem parent) {
this.parent = parent;
}

public boolean isRecognitionDisallowed() {
return getName().startsWith("!");
}

public void moveToTrash() {
this.trashBin = getPlan();
this.trashBin.getTrashBinItems().add(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ private Summary getEventSummary(PlanItem item) {
case COMPLETED -> sb.append("✔ ");
case DELETED -> sb.append("✘ ");
}
sb.append(item.getName());
if (item.isRecognitionDisallowed()) {
sb.append(item.getName().substring(1));
} else {
sb.append(item.getName());
}
PlanBucket bucket = item.getBucket();
if (bucket.isNamed()) {
sb.append(" - ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public PlanItem createItem(Long parentId, Long afterId, String name) {
PlanItem parent = getPlanItemById(parentId, AccessLevel.CHANGE);
PlanItem after = afterId == null ? null : getPlanItemById(afterId, AccessLevel.VIEW);
PlanItem item = itemRepo.save(new PlanItem(name).of(parent, after));
if (!isRecognitionDisallowed(item)) {
if (!item.isRecognitionDisallowed()) {
itemService.autoRecognize(item);
}
if (item.getId() == null) itemRepo.flush();
Expand Down Expand Up @@ -382,18 +382,14 @@ public PlanMessage deleteBucketForMessage(Long planId, Long id) {
public PlanItem renameItem(Long id, String name) {
PlanItem item = getPlanItemById(id, AccessLevel.CHANGE);
item.setName(name);
if (isRecognitionDisallowed(item)) {
if (item.isRecognitionDisallowed()) {
itemService.clearAutoRecognition(item);
} else if (!item.hasIngredient() || !(Hibernate.unproxy(item.getIngredient()) instanceof Recipe)) {
itemService.updateAutoRecognition(item);
}
return item;
}

private boolean isRecognitionDisallowed(PlanItem item) {
return item.getName().startsWith("!");
}

public PlanMessage renameItemForMessage(Long id, String name) {
return buildUpdateMessage(renameItem(id, name));
}
Expand Down

0 comments on commit 635ccf4

Please sign in to comment.