Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rescheduled 🗓️
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3lingo
rescheduled 🗓️
Commits
963472ea
Commit
963472ea
authored
2 months ago
by
Teal Bauer
Browse files
Options
Downloads
Patches
Plain Diff
feat: persist UI state in my assignments better
parent
a62d1e64
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#39553
passed
2 months ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/views/assignments/by_user.html.erb
+78
-60
78 additions, 60 deletions
app/views/assignments/by_user.html.erb
with
78 additions
and
60 deletions
app/views/assignments/by_user.html.erb
+
78
−
60
View file @
963472ea
...
...
@@ -193,103 +193,121 @@
const
tabContents
=
document
.
querySelectorAll
(
'
[role="tabpanel"]
'
);
const
showCandidatesCheckbox
=
document
.
getElementById
(
'
showCandidates
'
);
// Helper function to parse URL hash into an object
function
getHashParams
()
{
const
hash
=
window
.
location
.
hash
.
substring
(
1
);
const
params
=
{};
if
(
hash
)
{
hash
.
split
(
'
&
'
).
forEach
(
part
=>
{
const
[
key
,
value
]
=
part
.
split
(
'
=
'
);
if
(
key
)
{
params
[
key
]
=
value
===
undefined
?
true
:
decodeURIComponent
(
value
);
}
});
}
return
params
;
}
// Helper function to update URL hash from an object
function
updateUrlHash
(
newParams
)
{
const
currentParams
=
getHashParams
();
const
updatedParams
=
{
...
currentParams
,
...
newParams
};
const
hashParts
=
[];
for
(
const
key
in
updatedParams
)
{
if
(
updatedParams
[
key
]
!==
undefined
&&
updatedParams
[
key
]
!==
null
)
{
hashParts
.
push
(
`
${
encodeURIComponent
(
key
)}
=
${
encodeURIComponent
(
updatedParams
[
key
])}
`
);
}
}
const
newHash
=
hashParts
.
join
(
'
&
'
);
window
.
history
.
replaceState
(
null
,
null
,
newHash
?
`#
${
newHash
}
`
:
window
.
location
.
pathname
+
window
.
location
.
search
);
}
// Function to switch tabs
function
switchTab
(
targetId
)
{
function
switchTab
(
targetId
,
preserveHash
=
false
)
{
const
target
=
document
.
querySelector
(
targetId
);
const
button
=
document
.
querySelector
(
`[data-tabs-target="
${
targetId
}
"]`
);
if
(
!
target
||
!
button
)
return
;
// Hide all tabs
tabContents
.
forEach
(
content
=>
{
content
.
classList
.
add
(
'
hidden
'
);
content
.
classList
.
remove
(
'
block
'
);
});
// Remove active state from all buttons
tabButtons
.
forEach
(
btn
=>
{
btn
.
classList
.
remove
(
'
text-blue-600
'
,
'
dark:text-blue-500
'
,
'
border-blue-600
'
,
'
dark:border-blue-500
'
,
'
active
'
);
btn
.
classList
.
add
(
'
text-gray-500
'
,
'
dark:text-gray-400
'
,
'
border-transparent
'
);
btn
.
setAttribute
(
'
aria-selected
'
,
'
false
'
);
});
// Show the selected tab
target
.
classList
.
remove
(
'
hidden
'
);
target
.
classList
.
add
(
'
block
'
);
// Set active state on clicked button
button
.
classList
.
remove
(
'
text-gray-500
'
,
'
dark:text-gray-400
'
,
'
border-transparent
'
);
button
.
classList
.
add
(
'
text-blue-600
'
,
'
dark:text-blue-500
'
,
'
border-blue-600
'
,
'
dark:border-blue-500
'
,
'
active
'
);
button
.
setAttribute
(
'
aria-selected
'
,
'
true
'
);
// Update URL hash
if
(
!
preserveHash
)
{
const
viewName
=
targetId
===
'
#listViewTab
'
?
'
list
'
:
'
table
'
;
window
.
history
.
replaceState
(
null
,
null
,
`#
${
viewName
}
`
);
updateUrlHash
({
view
:
viewName
});
}
// Handle tab clicks
tabButtons
.
forEach
(
button
=>
{
button
.
addEventListener
(
'
click
'
,
()
=>
{
switchTab
(
button
.
dataset
.
tabsTarget
);
});
});
// Handle initial load based on URL hash
const
hash
=
window
.
location
.
hash
;
if
(
hash
===
'
#table
'
)
{
switchTab
(
'
#tableViewTab
'
);
}
else
if
(
hash
===
'
#list
'
||
!
hash
)
{
switchTab
(
'
#listViewTab
'
);
}
// Handle candidate filter
if
(
showCandidatesCheckbox
)
{
// Function to toggle candidate visibility
function
toggleCandidates
(
show
)
{
// For table view - find rows with yellow background
function
toggleCandidatesVisibility
(
show
)
{
const
candidateTableRows
=
document
.
querySelectorAll
(
'
tr.bg-yellow-50
'
);
candidateTableRows
.
forEach
(
row
=>
{
if
(
show
)
{
row
.
style
.
display
=
''
;
}
else
{
row
.
style
.
display
=
'
none
'
;
}
row
.
style
.
display
=
show
?
''
:
'
none
'
;
});
// For list view - find list items that contain the CANDIDATE badge
const
listItems
=
document
.
querySelectorAll
(
'
#listViewTab li
'
);
listItems
.
forEach
(
item
=>
{
const
hasCandidate
=
item
.
querySelector
(
'
.bg-yellow-100
'
);
if
(
hasCandidate
)
{
if
(
show
)
{
item
.
style
.
display
=
''
;
}
else
{
item
.
style
.
display
=
'
none
'
;
}
item
.
style
.
display
=
show
?
''
:
'
none
'
;
}
});
// Also hide/show date headers if all items in that date are hidden
document
.
querySelectorAll
(
'
#listViewTab .mb-6
'
).
forEach
(
dateGroup
=>
{
const
listItems
=
dateGroup
.
querySelectorAll
(
'
li
'
);
if
(
listItems
.
length
>
0
)
{
const
visibleItems
=
Array
.
from
(
listItems
).
filter
(
item
=>
item
.
style
.
display
!==
'
none
'
);
if
(
visibleItems
.
length
===
0
)
{
dateGroup
.
style
.
display
=
'
none
'
;
}
else
{
dateGroup
.
style
.
display
=
''
;
}
const
groupListItems
=
dateGroup
.
querySelectorAll
(
'
li
'
);
if
(
groupListItems
.
length
>
0
)
{
const
visibleItems
=
Array
.
from
(
groupListItems
).
filter
(
item
=>
item
.
style
.
display
!==
'
none
'
);
dateGroup
.
style
.
display
=
visibleItems
.
length
===
0
?
'
none
'
:
''
;
}
});
}
// Initial state
toggleCandidates
(
showCandidatesCheckbox
.
checked
);
// Handle tab clicks
tabButtons
.
forEach
(
button
=>
{
button
.
addEventListener
(
'
click
'
,
()
=>
{
switchTab
(
button
.
dataset
.
tabsTarget
);
});
});
// Handle checkbox changes
// Handle candidate filter
if
(
showCandidatesCheckbox
)
{
showCandidatesCheckbox
.
addEventListener
(
'
change
'
,
function
()
{
toggleCandidates
(
this
.
checked
);
toggleCandidatesVisibility
(
this
.
checked
);
updateUrlHash
({
candidates
:
this
.
checked
.
toString
()
});
});
}
// Initial load based on URL hash
const
initialParams
=
getHashParams
();
// Set initial tab view
if
(
initialParams
.
view
===
'
table
'
)
{
switchTab
(
'
#tableViewTab
'
,
true
);
// true to preserve other hash parts
}
else
{
// Default to list view
switchTab
(
'
#listViewTab
'
,
true
);
}
// Set initial candidate visibility
if
(
showCandidatesCheckbox
)
{
const
showCandidates
=
initialParams
.
candidates
===
'
true
'
;
showCandidatesCheckbox
.
checked
=
showCandidates
;
toggleCandidatesVisibility
(
showCandidates
);
}
});
</script>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment