Ordering fixes

This commit is contained in:
crschnick 2024-05-30 10:08:27 +00:00
parent ae02fb3791
commit bc9b962be9
14 changed files with 85 additions and 34 deletions

View file

@ -428,7 +428,7 @@ public abstract class StoreEntryComp extends SimpleComp {
} }
var order = new Menu(AppI18n.get("order"), new FontIcon("mdal-bookmarks")); var order = new Menu(AppI18n.get("order"), new FontIcon("mdal-bookmarks"));
var noOrder = new MenuItem("None"); var noOrder = new MenuItem(AppI18n.get("none"), new FontIcon("mdi2r-reorder-horizontal"));
noOrder.setOnAction(event -> { noOrder.setOnAction(event -> {
DataStorage.get().orderBefore(wrapper.getEntry(), null); DataStorage.get().orderBefore(wrapper.getEntry(), null);
event.consume(); event.consume();
@ -437,7 +437,8 @@ public abstract class StoreEntryComp extends SimpleComp {
noOrder.setDisable(true); noOrder.setDisable(true);
} }
order.getItems().add(noOrder); order.getItems().add(noOrder);
var stick = new MenuItem(AppI18n.get("stickToTop")); order.getItems().add(new SeparatorMenuItem());
var stick = new MenuItem(AppI18n.get("stickToTop"), new FontIcon("mdi2o-order-bool-descending"));
stick.setOnAction(event -> { stick.setOnAction(event -> {
DataStorage.get().orderBefore(wrapper.getEntry(), wrapper.getEntry()); DataStorage.get().orderBefore(wrapper.getEntry(), wrapper.getEntry());
event.consume(); event.consume();
@ -447,14 +448,18 @@ public abstract class StoreEntryComp extends SimpleComp {
} }
order.getItems().add(stick); order.getItems().add(stick);
order.getItems().add(new SeparatorMenuItem()); order.getItems().add(new SeparatorMenuItem());
var desc = new MenuItem(AppI18n.get("orderAheadOf"), new FontIcon("mdi2o-order-bool-descending-variant"));
desc.setDisable(true);
order.getItems().add(desc);
var section = StoreViewState.get().getParentSectionForWrapper(wrapper); var section = StoreViewState.get().getParentSectionForWrapper(wrapper);
if (section.isPresent()) {
section.get().getAllChildren().getList().forEach(other -> { section.get().getAllChildren().getList().forEach(other -> {
var ow = other.getWrapper(); var ow = other.getWrapper();
var op = ow.getEntry().getProvider(); var op = ow.getEntry().getProvider();
MenuItem m = new MenuItem(ow.getName().getValue(), MenuItem m = new MenuItem(ow.getName().getValue(),
op != null ? PrettyImageHelper.ofFixedSizeSquare(op.getDisplayIconFileName(ow.getEntry().getStore()), op != null ? PrettyImageHelper.ofFixedSizeSquare(op.getDisplayIconFileName(ow.getEntry().getStore()),
16).createRegion() : null); 16).createRegion() : null);
if (ow.getEntry().getUuid().equals(wrapper.getEntry().getOrderBefore())) { if (other.getWrapper().equals(wrapper) || ow.getEntry().getUuid().equals(wrapper.getEntry().getOrderBefore())) {
m.setDisable(true); m.setDisable(true);
} }
m.setOnAction(event -> { m.setOnAction(event -> {
@ -463,6 +468,7 @@ public abstract class StoreEntryComp extends SimpleComp {
}); });
order.getItems().add(m); order.getItems().add(m);
}); });
}
contextMenu.getItems().add(order); contextMenu.getItems().add(order);
contextMenu.getItems().add(new SeparatorMenuItem()); contextMenu.getItems().add(new SeparatorMenuItem());

View file

@ -15,7 +15,10 @@ import javafx.collections.FXCollections;
import lombok.Value; import lombok.Value;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.ToIntFunction;
@Value @Value
public class StoreSection { public class StoreSection {
@ -62,29 +65,36 @@ public class StoreSection {
return list; return list;
} }
var explicitOrderComp = new Comparator<StoreSection>() { var explicitOrderComp = Comparator.<StoreSection>comparingInt(new ToIntFunction<>() {
@Override @Override
public int compare(StoreSection o1, StoreSection o2) { public int applyAsInt(StoreSection value) {
var explicit1 = o1.getWrapper().getEntry().getOrderBefore(); var explicit = value.getWrapper().getEntry().getOrderBefore();
var explicit2 = o2.getWrapper().getEntry().getOrderBefore(); if (explicit == null) {
if (explicit1 == null && explicit2 == null) {
return 0;
}
if (explicit1 != null && explicit2 == null) {
return -1;
}
if (explicit2 != null && explicit1 == null) {
return 1; return 1;
} }
if (explicit1.equals(o2.getWrapper().getEntry().getUuid())) {
return -1; if (explicit.equals(value.getWrapper().getEntry().getUuid())) {
return Integer.MIN_VALUE;
} }
if (explicit2.equals(o1.getWrapper().getEntry().getUuid())) {
return -1; return -count(value.getWrapper(), new HashSet<>());
} }
private int count(StoreEntryWrapper wrapper, Set<StoreEntryWrapper> seen) {
if (seen.contains(wrapper)) {
// Loop!
return 0; return 0;
} }
}; seen.add(wrapper);
var found = list.getList().stream().filter(section -> wrapper.getEntry().getOrderBefore().equals(section.getWrapper().getEntry().getUuid())).findFirst();
if (found.isPresent()) {
return count(found.get().getWrapper(), seen);
} else {
return seen.size();
}
}
});
var usableComp = Comparator.<StoreSection>comparingInt( var usableComp = Comparator.<StoreSection>comparingInt(
value -> value.getWrapper().getEntry().getValidity().isUsable() ? -1 : 1); value -> value.getWrapper().getEntry().getValidity().isUsable() ? -1 : 1);
var comp = explicitOrderComp.thenComparing(usableComp); var comp = explicitOrderComp.thenComparing(usableComp);

View file

@ -457,3 +457,6 @@ history=Browsing-historik
skipAll=Spring alle over skipAll=Spring alle over
notes=Bemærkninger notes=Bemærkninger
addNotes=Tilføj noter addNotes=Tilføj noter
order=Bestille ...
stickToTop=Hold dig på toppen
orderAheadOf=Bestil på forhånd ...

View file

@ -451,3 +451,6 @@ history=Browsing-Verlauf
skipAll=Alles überspringen skipAll=Alles überspringen
notes=Anmerkungen notes=Anmerkungen
addNotes=Notizen hinzufügen addNotes=Notizen hinzufügen
order=Bestellen ...
stickToTop=Oben bleiben
orderAheadOf=Vorbestellen ...

View file

@ -456,3 +456,5 @@ notes=Notes
addNotes=Add notes addNotes=Add notes
#context: verb #context: verb
order=Order ... order=Order ...
stickToTop=Keep on top
orderAheadOf=Order ahead of ...

View file

@ -438,3 +438,6 @@ history=Historial de navegación
skipAll=Saltar todo skipAll=Saltar todo
notes=Notas notes=Notas
addNotes=Añadir notas addNotes=Añadir notas
order=Ordenar ...
stickToTop=Mantener arriba
orderAheadOf=Haz tu pedido antes de ...

View file

@ -438,3 +438,6 @@ history=Historique de navigation
skipAll=Sauter tout skipAll=Sauter tout
notes=Notes notes=Notes
addNotes=Ajouter des notes addNotes=Ajouter des notes
order=Commander...
stickToTop=Garde le dessus
orderAheadOf=Commande en avance...

View file

@ -438,3 +438,6 @@ history=Cronologia di navigazione
skipAll=Salta tutto skipAll=Salta tutto
notes=Note notes=Note
addNotes=Aggiungi note addNotes=Aggiungi note
order=Ordinare ...
stickToTop=Continua a essere in cima
orderAheadOf=Ordina prima di ...

View file

@ -438,3 +438,6 @@ history=閲覧履歴
skipAll=すべてスキップする skipAll=すべてスキップする
notes=備考 notes=備考
addNotes=メモを追加する addNotes=メモを追加する
order=注文する
stickToTop=トップをキープする
orderAheadOf=先に注文する

View file

@ -438,3 +438,6 @@ history=Browsegeschiedenis
skipAll=Alles overslaan skipAll=Alles overslaan
notes=Opmerkingen notes=Opmerkingen
addNotes=Opmerkingen toevoegen addNotes=Opmerkingen toevoegen
order=Bestellen ...
stickToTop=Bovenaan houden
orderAheadOf=Vooruitbestellen ...

View file

@ -438,3 +438,6 @@ history=Histórico de navegação
skipAll=Salta tudo skipAll=Salta tudo
notes=Nota notes=Nota
addNotes=Adiciona notas addNotes=Adiciona notas
order=Encomenda ...
stickToTop=Mantém-te no topo
orderAheadOf=Encomenda antes de ...

View file

@ -438,3 +438,6 @@ history=История просмотров
skipAll=Пропустить все skipAll=Пропустить все
notes=Заметки notes=Заметки
addNotes=Добавляй заметки addNotes=Добавляй заметки
order=Заказать ...
stickToTop=Держись на высоте
orderAheadOf=Заказать заранее ...

View file

@ -439,3 +439,6 @@ history=Tarama geçmişi
skipAll=Tümünü atla skipAll=Tümünü atla
notes=Notlar notes=Notlar
addNotes=Notlar ekleyin addNotes=Notlar ekleyin
order=Sipariş ...
stickToTop=Zirvede kal
orderAheadOf=Önceden sipariş verin ...

View file

@ -438,3 +438,6 @@ history=浏览历史
skipAll=全部跳过 skipAll=全部跳过
notes=说明 notes=说明
addNotes=添加注释 addNotes=添加注释
order=订购 ...
stickToTop=保持在顶部
orderAheadOf=提前订购...