Skip to content

Commit

Permalink
Merge pull request #1820 from datadryad/admin-dashboard
Browse files Browse the repository at this point in the history
Admin dashboard improvements
  • Loading branch information
alinvetian authored Sep 5, 2024
2 parents f2c13af + 9ecf62b commit 68f194d
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 120 deletions.
16 changes: 12 additions & 4 deletions app/assets/javascripts/stash_engine/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,28 @@ class ComboboxAutocomplete {
}
break
case 'ArrowDown':
case 'ArrowRight':
e.preventDefault()
if (e.target.id === this.textbox.id) {
if (this.list.hasAttribute('hidden')) this.open()
this.list.firstChild.focus()
e.preventDefault()
} else if (e.target.nextSibling) {
e.target.nextSibling.focus()
}
break
case 'ArrowRight':
if (e.target.id !== this.textbox.id) {
e.preventDefault()
if (e.target.nextSibling) {
e.target.nextSibling.focus()
}
}
break
case 'ArrowUp':
if (e.target.id !== this.textbox.id && e.target.previousSibling) {
e.target.previousSibling.focus()
if (e.target.id !== this.textbox.id) {
e.preventDefault()
if (e.target.previousSibling) {
e.target.previousSibling.focus()
}
}
break
case 'Home':
Expand Down
93 changes: 93 additions & 0 deletions app/assets/javascripts/stash_engine/multibox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'use strict';

class MultipleSelect {
constructor(combobox, textbox, list) {
this.combobox = combobox
this.textbox = textbox
this.list = list

this.textbox.addEventListener('click', this.open.bind(this))

this.textbox.addEventListener('blur', this.unFocus.bind(this), true)
this.list.addEventListener('blur', this.unFocus.bind(this), true)
this.combobox.addEventListener('blur', this.unFocus.bind(this), true)

this.textbox.addEventListener('keydown', this.keyPressed.bind(this))
this.list.addEventListener('keydown', this.listPressed.bind(this), true)

this.list.addEventListener('click', this.selectOption.bind(this), true)
}
open() {
this.list.removeAttribute('hidden')
this.textbox.setAttribute('aria-expanded', true)
}
close(){
this.list.setAttribute('hidden', true)
this.textbox.setAttribute('aria-expanded', false)
}
unFocus(e) {
if (!this.combobox.contains(e.relatedTarget)) {
this.close()
}
}
selectOption(e) {
const checked = this.list.querySelectorAll('input[type="checkbox"]:checked')
const selected = Array.from(checked)
if (selected.length > 0) {
this.textbox.value = selected.map(x => x.parentElement.textContent.trim()).join(', ')
this.textbox.classList.add('selected')
} else {
this.textbox.value = ''
this.textbox.classList.remove('selected')
}
}
listPressed(e) {
this.keyPressed(e)
}
keyPressed(e, option) {
switch (e.key) {
case 'Enter':
if (e.target.type === 'checkbox') {
e.preventDefault()
e.stopPropagation()
e.target.checked = !e.target.checked
this.selectOption(e)
}
else if (e.target.id === this.textbox.id) {
this.open()
}
break
case 'ArrowDown':
case 'ArrowRight':
e.preventDefault()
if (e.target.id === this.textbox.id) {
if (this.list.hasAttribute('hidden')) this.open()
this.list.firstElementChild.firstElementChild.focus()
} else if (e.target.parentElement.nextElementSibling) {
e.target.parentElement.nextElementSibling.firstElementChild.focus()
}
break
case 'ArrowUp':
e.preventDefault()
if (e.target.id !== this.textbox.id && e.target.parentElement.previousElementSibling) {
e.target.parentElement.previousElementSibling.firstElementChild.focus()
}
break
case 'Home':
e.preventDefault()
if (e.target.id !== this.textbox.id) {
this.list.firstElementChild.firstElementChild.focus()
}
break
case 'End':
e.preventDefault()
if (e.target.id !== this.textbox.id) {
this.list.lastElementChild.firstElementChild.focus()
}
break
default:
break
}
}

}
14 changes: 5 additions & 9 deletions app/assets/stylesheets/scss/_admin-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,10 @@
}

#edit_fields-form {
columns: 7;
&.drop-column {
columns: 6;
}
&, &.drop-column {
@media (max-width: 1070px) { columns: 5 }
@media (max-width: 920px) { columns: 3 }
@media (max-width: 480px) { columns: 2 }
}
columns: 6;
@media (max-width: 1070px) { columns: 5 }
@media (max-width: 920px) { columns: 3 }
@media (max-width: 480px) { columns: 2 }

div {
margin-bottom: 4px;
Expand Down Expand Up @@ -209,6 +204,7 @@
input[type='text'].selected,
input[type='search'].selected,
input[type='date'].selected,
input[type='button'].selected,
select.selected {
border: thin solid $light-green;
&:not(:focus) {
Expand Down
71 changes: 65 additions & 6 deletions app/assets/stylesheets/scss/_select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,65 @@ select {
margin: 0 0 20px;
}

.multiselect {
position: relative;
flex-grow: 2;
min-width: 0;

&:focus {
outline: 0;
}

& > input {
width: 100%;
overflow-x: hidden;
text-overflow: ellipsis;
text-align: left;
}

&:focus-within > input {
outline: 2px solid $medium-blue !important;
}

fieldset {
display: block;
min-width: 0;
margin: 0;
padding: 0;
border: none;
position: absolute;
top: 32px;
right: -2px;
left: -2px;
z-index: 10;
width: calc(100% + 4px);
max-height: 50vh;
overflow-y: auto;
overflow-x: hidden;
background-color: $lighter-gray;

label {
display: block;
width: 100%;
height: 100%;
padding: 6px 10px;
cursor: default;
white-space: nowrap;
overflow-x: hidden;
text-overflow: ellipsis;

&:hover, &:focus-within {
color: white;
background-color: $dark-blue;
}

input:focus {
outline: none;
}
}
}
}

.searchselect {
position: relative;
flex-grow: 2;
Expand All @@ -17,7 +76,7 @@ select {
}

&:focus-within input {
outline: 2px solid $medium-blue;
outline: 2px solid $medium-blue !important;
}

ul {
Expand Down Expand Up @@ -51,11 +110,11 @@ select {
&.selected-option:before {
content: '\f00c';
}
&:hover,
&:focus {
color: white;
background-color: $dark-blue;
}
&:hover,
&:focus {
color: white;
background-color: $dark-blue;
}
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions app/controllers/stash_engine/admin_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module StashEngine
# rubocop:disable Metrics/ClassLength
class AdminDashboardController < ApplicationController
helper SortableTableHelper
helper AdminDashboardHelper
before_action :require_admin
protect_from_forgery except: :results
before_action :setup_paging, only: %i[results]
Expand All @@ -25,24 +26,25 @@ def results
if params[:sort].present? || @search_string.present?
order_string = 'relevance desc'
if params[:sort].present?
order_list = %w[title author_string status total_file_size view_count curator_name
order_list = %w[title author_string status total_file_size view_count curator_name created_at
updated_at submit_date publication_date first_sub_date first_pub_date queue_date]
order_string = helpers.sortable_table_order(whitelist: order_list)
order_string = "stash_engine_curation_activities.#{order_string}" if @sort == 'updated_at'
order_string = "stash_engine_identifiers.#{order_string}" if @sort == 'created_at'
order_string += ', relevance desc' if @search_string.present?
end
@datasets = @datasets.order(order_string)
end

@datasets = @datasets.page(@page).per(@page_size)

respond_to do |format|
format.js do
@datasets = @datasets.page(@page).per(@page_size)
add_subqueries
collect_properties
end
format.csv do
headers['Content-Disposition'] = "attachment; filename=#{Time.new.strftime('%F')}_report.csv"
helpers.csv_headers
self.response_body = helpers.csv_enumerator
end
end
end
Expand Down Expand Up @@ -87,11 +89,6 @@ def collect_properties
end

def setup_paging
if request.format.csv?
@page = 1
@page_size = 10_000
return
end
@page = params[:page] || 1
@page_size = 10 if params[:page_size].blank? || params[:page_size].to_i == 0
@page_size ||= params[:page_size].to_i
Expand All @@ -113,11 +110,11 @@ def setup_limits
@journal_limit = journal_limit || []
end

# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def setup_search
@sort = params[:sort]
@search = params[:search].to_i
session[:admin_search_count] = nil if @page == 1
session[:admin_search_count] = nil if @page == 1 || params[:clear]
session[:admin_search_filters] = nil if params[:clear]
session[:admin_search_fields] = nil if params[:clear]
session[:admin_search_string] = nil if params[:clear]
Expand Down Expand Up @@ -170,6 +167,7 @@ def add_fields
date_fields
@datasets = @datasets.select('stash_engine_curation_activities.status') if @sort == 'status'
@datasets = @datasets.select('stash_engine_curation_activities.updated_at') if @sort == 'updated_at'
@datasets = @datasets.select('stash_engine_identifiers.created_at') if @sort == 'created_at'
return unless @search_string.present?

search_string = %r{^10.[\S]+/[\S]+$}.match(@search_string) ? "\"#{@search_string}\"" : @search_string
Expand Down Expand Up @@ -241,7 +239,7 @@ def date_filters
"stash_engine_identifiers.publication_date #{date_string(@filters[:first_pub_date])}"
) unless @filters[:first_pub_date].nil? || @filters[:first_pub_date].values.all?(&:blank?)
end
# rubocop:enable Style/MultilineIfModifier, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize
# rubocop:enable Metrics/MethodLength, Style/MultilineIfModifier, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize

def tenant_filter
return unless @role_object.is_a?(StashEngine::Tenant) || @filters[:member].present?
Expand Down
Loading

0 comments on commit 68f194d

Please sign in to comment.