mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Sorting: Renamed sort set to sort rule
Renamed based on feedback from Tim and Script on Discord. Also fixed flaky test
This commit is contained in:
41
resources/js/components/sort-rule-manager.ts
Normal file
41
resources/js/components/sort-rule-manager.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import {Component} from "./component.js";
|
||||
import Sortable from "sortablejs";
|
||||
import {buildListActions, sortActionClickListener} from "../services/dual-lists";
|
||||
|
||||
|
||||
export class SortRuleManager extends Component {
|
||||
|
||||
protected input!: HTMLInputElement;
|
||||
protected configuredList!: HTMLElement;
|
||||
protected availableList!: HTMLElement;
|
||||
|
||||
setup() {
|
||||
this.input = this.$refs.input as HTMLInputElement;
|
||||
this.configuredList = this.$refs.configuredOperationsList;
|
||||
this.availableList = this.$refs.availableOperationsList;
|
||||
|
||||
this.initSortable();
|
||||
|
||||
const listActions = buildListActions(this.availableList, this.configuredList);
|
||||
const sortActionListener = sortActionClickListener(listActions, this.onChange.bind(this));
|
||||
this.$el.addEventListener('click', sortActionListener);
|
||||
}
|
||||
|
||||
initSortable() {
|
||||
const scrollBoxes = [this.configuredList, this.availableList];
|
||||
for (const scrollBox of scrollBoxes) {
|
||||
new Sortable(scrollBox, {
|
||||
group: 'sort-rule-operations',
|
||||
ghostClass: 'primary-background-light',
|
||||
handle: '.handle',
|
||||
animation: 150,
|
||||
onSort: this.onChange.bind(this),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onChange() {
|
||||
const configuredOpEls = Array.from(this.configuredList.querySelectorAll('[data-id]'));
|
||||
this.input.value = configuredOpEls.map(elem => elem.getAttribute('data-id')).join(',');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user