Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ <h1>Settings</h1>
Items can be assigned
</label>

<label class="micro-block">
<input
type="checkbox" name="features" value="addNewItemsToTop"
data-checked="includes lst.features 'addNewItemsToTop'"
/>
Items are added to the top
</label>

<label class="micro-block" data-class-micro-disabled="not assignFeature">
<input
type="checkbox" name="assign-by-default"
Expand Down
22 changes: 18 additions & 4 deletions client/listling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,24 @@ listling.ListPage = class extends micro.core.Page {
moveItemDrag: event => {
// NOTE: This may be better done by micro.OL itself if some reset attribute is set
this._itemsOL.insertBefore(event.detail.li, event.detail.from);
let from = event.detail.li.item;
let to = event.detail.to && event.detail.to.item;

if (to) {
let i = this._data.presentItems.findIndex(item => item.id === to.id);
to = this._data.presentItems[i - 1] || null;
} else {
to = this._data.presentItems[this._data.presentItems.length - 1];
let oldIdx = this._data.presentItems.findIndex(item => item.id === from.id);
let lastItemIdx = this._data.presentItems.length - 1;

if (oldIdx === lastItemIdx) {
// Move last item to head
to = null;
} else {
to = this._data.presentItems[lastItemIdx];
}
}
this._moveItem(event.detail.li.item, to);
this._moveItem(from, to);
},

moveItemKey: event => {
Expand Down Expand Up @@ -278,7 +288,7 @@ listling.ListPage = class extends micro.core.Page {
this.classList.toggle("listling-list-has-trashed-items", this._data.trashedItemsCount);
this.classList.toggle("listling-list-mode-view", !this._data.editMode);
this.classList.toggle("listling-list-mode-edit", this._data.editMode);
for (let feature of ["check", "assign", "vote", "value", "time", "location", "play"]) {
for (let feature of ["check", "assign", "vote", "value", "time", "location", "play", "addNewItemsToTop"]) {
this.classList.toggle(
`listling-list-feature-${feature}`,
this._data.lst && this._data.lst.features.includes(feature)
Expand Down Expand Up @@ -318,7 +328,11 @@ listling.ListPage = class extends micro.core.Page {

this.activity.events.addEventListener("list-create-item", event => {
if (!this._items.find(item => item.id === event.detail.event.detail.item.id)) {
this._items.push(event.detail.event.detail.item);
if (this.list.features.includes("addNewItemsToTop")) {
this._items.unshift(event.detail.event.detail.item);
} else {
this._items.push(event.detail.event.detail.item);
}
}
});

Expand Down
10 changes: 8 additions & 2 deletions listling/listling.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,13 @@ async def create(self, title: str, *, text: str = None, resource: str = None,

redis.call("SET", item.id, item_data)
redis.call("SADD", "items", item.id)
redis.call("RPUSH", list.id .. ".items", item.id)

if features.addNewItemsToTop then
redis.call("LPUSH", list.id .. ".items", item.id)
else
redis.call("RPUSH", list.id .. ".items", item.id)
end

redis.call("ZADD", list.id .. ".items.by_title", 0, id_by_title)
redis.call("HSET", list.id .. ".items.by_title.lexical", item.id, id_by_title)
if features.assign and list.assign_by_default then
Expand Down Expand Up @@ -561,7 +567,7 @@ def do_edit(self, **attrs: Any) -> None:
raise error.ValueError('title_empty')
if 'order' in attrs and attrs['order'] not in {None, 'title'}:
raise error.ValueError(f"Unknown order {attrs['order']}")
features = {'check', 'assign', 'vote', 'value', 'time', 'location', 'play'}
features = {'check', 'assign', 'vote', 'value', 'time', 'location', 'play', 'addNewItemsToTop'}
if 'features' in attrs and not set(attrs['features']) <= features:
raise error.ValueError('feature_unknown')
if 'mode' in attrs and attrs['mode'] not in {'collaborate', 'view'}:
Expand Down