Skip to content

Commit

Permalink
Add tag assignments. Centralize model updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Sep 10, 2024
1 parent 36fb543 commit ca16bb0
Show file tree
Hide file tree
Showing 11 changed files with 846 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.io7m.laurel.filemodel;

import com.io7m.jattribute.core.AttributeReadableType;
import com.io7m.laurel.filemodel.internal.LCategoryAndTags;
import com.io7m.laurel.model.LCategory;
import com.io7m.laurel.model.LException;
import com.io7m.laurel.model.LImage;
Expand All @@ -28,6 +29,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Flow;

Expand Down Expand Up @@ -115,6 +117,28 @@ CompletableFuture<?> imageAdd(
CompletableFuture<?> imageSelect(
Optional<String> name);

/**
* Assign the given tags to the given categories.
*
* @param categories The categories/tags
*
* @return The operation in progress
*/

CompletableFuture<?> categoryTagsAssign(
List<LCategoryAndTags> categories);

/**
* Unassign the given tags from the given categories.
*
* @param categories The categories/tags
*
* @return The operation in progress
*/

CompletableFuture<?> categoryTagsUnassign(
List<LCategoryAndTags> categories);

@Override
void close()
throws LException;
Expand Down Expand Up @@ -191,4 +215,10 @@ void close()
*/

AttributeReadableType<List<LCategory>> categoryList();

/**
* @return The tags for every available category
*/

AttributeReadableType<SortedMap<LCategory, List<LTag>>> categoryTags();
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ private static LCommandCategoriesAdd fromProperties(
return c;
}

private static List<LCategory> listCategories(
final LDatabaseTransactionType transaction)
{
final var context =
transaction.get(DSLContext.class);

return context.select(CATEGORIES.CATEGORY_TEXT)
.from(CATEGORIES)
.orderBy(CATEGORIES.CATEGORY_TEXT.asc())
.stream()
.map(r -> new LCategory(r.get(CATEGORIES.CATEGORY_TEXT)))
.toList();
}

@Override
protected LCommandUndoable onExecute(
final LFileModel model,
Expand Down Expand Up @@ -148,7 +134,7 @@ protected LCommandUndoable onExecute(
);
}

model.setCategoriesAll(listCategories(transaction));
LCommandModelUpdates.updateTagsAndCategories(context, model);
model.eventWithoutProgress("Added %d categories.", this.savedData.size());

if (!this.savedData.isEmpty()) {
Expand Down Expand Up @@ -180,7 +166,7 @@ protected void onUndo(
.execute();
}

model.setCategoriesAll(listCategories(transaction));
LCommandModelUpdates.updateTagsAndCategories(context, model);
model.eventWithoutProgress("Removed %d categories.", Integer.valueOf(max));
}

Expand Down Expand Up @@ -210,7 +196,7 @@ protected void onRedo(
.execute();
}

model.setCategoriesAll(listCategories(transaction));
LCommandModelUpdates.updateTagsAndCategories(context, model);
model.eventWithoutProgress("Added %d categories.", Integer.valueOf(max));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected LCommandUndoable onExecute(
}

model.eventWithoutProgress("Updated %d categories.", this.savedData.size());
model.setCategoriesRequired(listRequired(transaction));
LCommandModelUpdates.updateTagsAndCategories(context, model);

if (!this.savedData.isEmpty()) {
return LCommandUndoable.COMMAND_UNDOABLE;
Expand Down Expand Up @@ -172,7 +172,7 @@ protected void onUndo(
}

model.eventWithoutProgress("Updated %d categories.", Integer.valueOf(max));
model.setCategoriesRequired(listRequired(transaction));
LCommandModelUpdates.updateTagsAndCategories(context, model);
}

@Override
Expand All @@ -199,22 +199,7 @@ protected void onRedo(
}

model.eventWithoutProgress("Updated %d categories.", Integer.valueOf(max));
model.setCategoriesRequired(listRequired(transaction));
}

private static List<LCategory> listRequired(
final LDatabaseTransactionType transaction)
{
final var context =
transaction.get(DSLContext.class);

return context.select(CATEGORIES.CATEGORY_TEXT)
.from(CATEGORIES)
.where(CATEGORIES.CATEGORY_REQUIRED.eq(1L))
.orderBy(CATEGORIES.CATEGORY_TEXT.asc())
.stream()
.map(r -> new LCategory(r.get(CATEGORIES.CATEGORY_TEXT)))
.toList();
LCommandModelUpdates.updateTagsAndCategories(context, model);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ protected LCommandUndoable onExecute(
}

model.eventWithoutProgress("Updated %d categories.", this.savedData.size());
model.setCategoriesRequired(listRequired(transaction));

LCommandModelUpdates.updateTagsAndCategories(context, model);

if (!this.savedData.isEmpty()) {
return LCommandUndoable.COMMAND_UNDOABLE;
Expand Down Expand Up @@ -173,8 +172,7 @@ protected void onUndo(
}

model.eventWithoutProgress("Updated %d categories.", Integer.valueOf(max));
model.setCategoriesRequired(listRequired(transaction));

LCommandModelUpdates.updateTagsAndCategories(context, model);
}

@Override
Expand All @@ -201,22 +199,7 @@ protected void onRedo(
}

model.eventWithoutProgress("Updated %d categories.", Integer.valueOf(max));
model.setCategoriesRequired(listRequired(transaction));
}

private static List<LCategory> listRequired(
final LDatabaseTransactionType transaction)
{
final var context =
transaction.get(DSLContext.class);

return context.select(CATEGORIES.CATEGORY_TEXT)
.from(CATEGORIES)
.where(CATEGORIES.CATEGORY_REQUIRED.eq(1L))
.orderBy(CATEGORIES.CATEGORY_TEXT.asc())
.stream()
.map(r -> new LCategory(r.get(CATEGORIES.CATEGORY_TEXT)))
.toList();
LCommandModelUpdates.updateTagsAndCategories(context, model);
}

@Override
Expand Down
Loading

0 comments on commit ca16bb0

Please sign in to comment.