@@ -32,23 +32,16 @@ export function apply() {
3232 { type : "empty" } ,
3333 ] ;
3434
35- function cycleSort ( ) {
36- if ( window . KanbanBro . cardComparatorSpecifiers . length == 0 ) {
37- setCardComparatorSpecifiers ( [ cyclerCardComparatorSpecifiers [ 0 ] ] ) ;
38- return ;
39- }
40- const oldIndex = cyclerCardComparatorSpecifiers . findIndex ( cardComparatorSpecifierEntry => {
41- if ( cardComparatorSpecifierEntry . type != window . KanbanBro . cardComparatorSpecifiers [ 0 ] . type ) return false ;
42- if ( cardComparatorSpecifierEntry . isDescending !== undefined ) {
43- if ( cardComparatorSpecifierEntry . isDescending != window . KanbanBro . cardComparatorSpecifiers [ 0 ] . isDescending ) return false ;
35+ function getNextCardComparatorSpecifier ( cardComparatorSpecifier ) {
36+ const oldIndex = cyclerCardComparatorSpecifiers . findIndex ( cyclerCardComparatorSpecifier => {
37+ if ( cyclerCardComparatorSpecifier . type != cardComparatorSpecifier . type ) return false ;
38+ if ( cyclerCardComparatorSpecifier . isDescending !== undefined ) {
39+ if ( cyclerCardComparatorSpecifier . isDescending != cardComparatorSpecifier . isDescending ) return false ;
4440 }
4541 return true ;
4642 } ) ;
47- if ( oldIndex == - 1 ) {
48- setCardComparatorSpecifiers ( [ cyclerCardComparatorSpecifiers [ 0 ] ] ) ;
49- return ;
50- }
51- setCardComparatorSpecifiers ( [ cyclerCardComparatorSpecifiers [ ( oldIndex + 1 ) % cyclerCardComparatorSpecifiers . length ] ] ) ;
43+ if ( oldIndex == - 1 ) return cyclerCardComparatorSpecifiers [ 0 ] ;
44+ return cyclerCardComparatorSpecifiers [ ( oldIndex + 1 ) % cyclerCardComparatorSpecifiers . length ] ;
5245 }
5346
5447 function openSortDialog ( ) {
@@ -58,23 +51,61 @@ export function apply() {
5851 titleDiv . textContent = "Sort" ;
5952 titleDiv . style . fontWeight = "700" ;
6053 } ) ,
61- also ( document . createElement ( "button" ) , toggleButton => {
62- toggleButton . type = "button" ;
63- toggleButton . classList . add ( "dialog-button" ) ;
64-
65- function updateButton ( ) {
66- if ( window . KanbanBro . cardComparatorSpecifiers . length == 0 ) {
67- toggleButton . textContent = "Unsorted" ;
68- } else if ( window . KanbanBro . cardComparatorSpecifiers . length == 1 ) {
69- toggleButton . textContent = getTitle ( window . KanbanBro . cardComparatorSpecifiers [ 0 ] ) ;
70- } else {
71- toggleButton . textContent = getTitle ( window . KanbanBro . cardComparatorSpecifiers [ 0 ] ) + "+" + ( window . KanbanBro . cardComparatorSpecifiers . length - 1 ) ;
72- }
54+ also ( document . createElement ( "div" ) , buttonsDiv => {
55+ buttonsDiv . className = "dialog-container" ;
56+ function updateButtons ( ) {
57+ buttonsDiv . innerHTML = "" ;
58+ window . KanbanBro . cardComparatorSpecifiers . forEach ( ( cardComparatorSpecifier , index ) => {
59+ buttonsDiv . append (
60+ also ( document . createElement ( "div" ) , buttonDiv => {
61+ buttonDiv . style . display = "flex" ;
62+ buttonDiv . style . gap = "12px" ;
63+ buttonDiv . style . alignItems = "center" ;
64+ buttonDiv . append (
65+ also ( document . createElement ( "div" ) , leftDiv => {
66+ leftDiv . append (
67+ also ( document . createElement ( "button" ) , toggleButton => {
68+ toggleButton . type = "button" ;
69+ toggleButton . classList . add ( "dialog-button" ) ;
70+ toggleButton . textContent = getTitle ( cardComparatorSpecifier ) ;
71+ toggleButton . addEventListener ( "click" , ( ) => {
72+ const newCardComparatorSpecifiers = [ ...window . KanbanBro . cardComparatorSpecifiers ] ;
73+ newCardComparatorSpecifiers [ index ] = getNextCardComparatorSpecifier ( newCardComparatorSpecifiers [ index ] ) ;
74+ setCardComparatorSpecifiers ( newCardComparatorSpecifiers ) ;
75+ } ) ;
76+ } ) ,
77+ ) ;
78+ } ) ,
79+ also ( document . createElement ( "div" ) , rightDiv => {
80+ rightDiv . style . marginLeft = "auto" ;
81+ rightDiv . append (
82+ also ( document . createElement ( "button" ) , removeButton => {
83+ removeButton . type = "button" ;
84+ removeButton . classList . add ( "dialog-button" ) ;
85+ removeButton . textContent = "🗑️" ;
86+ removeButton . addEventListener ( "click" , ( ) => {
87+ const newCardComparatorSpecifiers = [ ...window . KanbanBro . cardComparatorSpecifiers ] ;
88+ newCardComparatorSpecifiers . splice ( index , 1 ) ;
89+ setCardComparatorSpecifiers ( newCardComparatorSpecifiers ) ;
90+ } ) ;
91+ } ) ,
92+ ) ;
93+ } ) ,
94+ ) ;
95+ } ) ,
96+ ) ;
97+ } ) ;
7398 }
74- window . KanbanBro . event . addEventListener ( 'cardComparatorSpecifiersChanged' , ( ) => updateButton ( ) ) ;
75- updateButton ( ) ;
76-
77- toggleButton . addEventListener ( "click" , ( ) => cycleSort ( ) ) ;
99+ window . KanbanBro . event . addEventListener ( 'cardComparatorSpecifiersChanged' , ( ) => updateButtons ( ) ) ;
100+ updateButtons ( ) ;
101+ } ) ,
102+ also ( document . createElement ( "button" ) , addButton => {
103+ addButton . type = "button" ;
104+ addButton . classList . add ( "dialog-transparent-button" ) ;
105+ addButton . textContent = "+" ;
106+ addButton . addEventListener ( "click" , ( ) => {
107+ setCardComparatorSpecifiers ( [ ...window . KanbanBro . cardComparatorSpecifiers , { type : "empty" } ] ) ;
108+ } ) ;
78109 } ) ,
79110 also ( document . createElement ( "div" ) , actionsDiv => {
80111 actionsDiv . style . display = "flex" ;
0 commit comments