Skip to content

Commit

Permalink
Merge pull request #1551 from seek4science/unify-asset-selection-views
Browse files Browse the repository at this point in the history
Unify asset selection views
  • Loading branch information
fbacall authored Sep 27, 2023
2 parents bccf7b0 + 8376120 commit b3192ed
Show file tree
Hide file tree
Showing 36 changed files with 901 additions and 1,219 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
//= require calendar
//= require inplace
//= require strain
//= require checkbox
//= require batch_asset_selection
//= require cytoscape.js-2.5.0/cytoscape
//= require cytoscape_isa_graph
//= require bives
Expand Down
121 changes: 121 additions & 0 deletions app/assets/javascripts/batch_asset_selection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
$j(document).ready(function () {
$j('.batch-selection-select-children').click(BatchAssetSelection.selectChildren);
$j('.batch-selection-deselect-children').click(BatchAssetSelection.deselectChildren);
$j('.batch-selection-collapse-children').click(BatchAssetSelection.collapseRecursively);
$j('.batch-selection-expand-children').click(BatchAssetSelection.expandRecursively);
$j('.batch-selection-show-permissions').click(function (event) {
event.preventDefault();
$j('.batch-selection-permission-list', $j(this).closest('.batch-selection-scope')).show();
})
$j('.batch-selection-hide-permissions').click(function (event) {
event.preventDefault();
$j('.batch-selection-permission-list', $j(this).closest('.batch-selection-scope')).hide();
})
$j('.batch-selection-hide-blocked').click(BatchAssetSelection.hideBlocked).click(); // Trigger on page load
$j('.batch-selection-show-blocked').click(BatchAssetSelection.showBlocked);
$j('.batch-selection-collapse-toggle').click(function () {
BatchAssetSelection.toggleCollapse(this);
return false;
});
$j('.batch-selection-check-btn').click(function (event) {
if (event.target.nodeName.includes('BUTTON')) {
$j(this).find(':checkbox').click();
}
});
$j('.batch-selection-check-btn :checkbox').click(function () {
BatchAssetSelection.checkRepeatedItems(this.className, this.checked);
});
$j('.batch-selection-managed-by-toggle').click(function (event) {
event.preventDefault();
$j('.batch-selection-managed-by-list:first', $j(this).closest('.batch-selection-scope')).toggle();
});
$j('.batch-selection-permissions-toggle').click(function (event) {
event.preventDefault();
$j('.batch-selection-permission-list:first', $j(this).closest('.batch-selection-scope')).toggle();
});
});

const BatchAssetSelection = {
blockedSelectors: '.not-visible, .not-manageable, .already-published',
selectChildren: function (event) {
event.preventDefault();
BatchAssetSelection.setChildren($j(this).closest('.batch-selection-scope'), true);
},

deselectChildren: function (event) {
event.preventDefault();
BatchAssetSelection.setChildren($j(this).closest('.batch-selection-scope'), false);
},

setChildren: function (scope, value) {
const children = $j(':checkbox', scope);
const classes = new Set();
for (let child of children) {
classes.add(child.className);
}

classes.forEach(c => BatchAssetSelection.checkRepeatedItems(c, value));
},

checkRepeatedItems: function (className, check) {
document.getElementById('batch-asset-selection')
.querySelectorAll('.' + className).forEach(e => e.checked = check);
},

toggleManagers: function () {
$j('.batch-selection-managed-by-list', $j(this).closest('.batch-selection-asset')).toggle();

return false;
},

toggleCollapse: function (element, state) {
if (state === undefined) {
state = !element.classList.contains('open');
}
element.classList.toggle('open', state);
$j(element).closest('.batch-selection-scope').children('.batch-selection-collapse').toggle(state);
},

collapseRecursively: function () {
const scope = $j(this).closest('.batch-selection-scope').children('.batch-selection-collapse');
const toggles = $j('.batch-selection-collapse-toggle', scope);
for (let toggle of toggles) {
BatchAssetSelection.toggleCollapse(toggle, false);
}

return false;
},

expandRecursively: function () {
const scope = $j(this).closest('.batch-selection-scope').children('.batch-selection-collapse');
const toggles = $j('.batch-selection-collapse-toggle', scope);
for (let toggle of toggles) {
BatchAssetSelection.toggleCollapse(toggle, true);
}

return false;
},

hideBlocked: function () {
const children = $j(this).closest('.batch-selection-scope')
.find(BatchAssetSelection.blockedSelectors)
.closest('.batch-selection-asset');
for (let child of children) {
const element = $j(child);
// Don't hide if any non-blocked children
if (!$j(':checkbox', element).length) {
element.hide();
}
}

return false;
},

showBlocked: function () {
$j(this).closest('.batch-selection-scope')
.find(BatchAssetSelection.blockedSelectors)
.closest('.batch-selection-asset').show();

return false;
}
}
42 changes: 0 additions & 42 deletions app/assets/javascripts/checkbox.js

This file was deleted.

69 changes: 44 additions & 25 deletions app/assets/stylesheets/publishing.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ ul.publishing_options li.secondary {

}

.published {
color: limegreen;
}

span.published {
color: green;
}

span.approve {
color: limegreen;
font-weight: bolder;
Expand Down Expand Up @@ -64,32 +56,19 @@ ul.item_for_decision {
.publishing_options {
padding: 0.5em 1em;

&.publishable {
background-color: #fafaff;
border-left-color: $btn-success-bg;
&.not-manageable {
border-left-color: $btn-warning-bg;
}

&.not-publishable {
border-left-color: $btn-warning-bg;
&.not-visible {
border-left-color: $btn-danger-bg;
}

&.already-published {
border-left-color: $gray-light;
}
}

.publish-colour {
color: $btn-success-bg;
}

.publish-checkbox {
background-color: $btn-success-bg;
color: $btn-success-color;
padding: 0px 10px;
border-radius: 5px;
display: inline-block;
}

ul.decided_item {
padding-left: 1em;
}
Expand All @@ -108,3 +87,43 @@ ul.decided_item li.type_and_title {
padding: 0.5em 15px;
margin: 0.3em 0em;
}

.batch-selection-buttons {
margin-bottom: 1em;
display: flex;
gap: 1em;
}

.batch-selection-asset-row {
display: flex;
gap: 1em;
align-items: center;
.visibility_icon {
margin: 0;
}
}

.batch-selection-permission-list,
.batch-selection-managed-by-list,
.batch-selection-children {
margin-left: 3em;
}

.batch-selection-check-btn {
input {
margin: 0;
vertical-align: middle;
}
}

.batch-selection-collapse-toggle {
cursor: pointer;

.glyphicon-menu-down { display: none; };
.glyphicon-menu-right { display: inline; };

&.open {
.glyphicon-menu-down { display: inline; };
.glyphicon-menu-right { display: none; };
}
}
14 changes: 0 additions & 14 deletions app/assets/stylesheets/sharing.scss
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,3 @@
padding-left: 16px;
}
}

.parent-btn-checkbox {
padding: 1px 6px 0px 6px;
border-radius: 5px;
display: inline-block;
height: 25px;
}
.parent-btn-dropdown {
padding: 2px 6px 10px 0px;
border-radius: 5px;
display: inline-block;
height: 25px;
}

1 change: 1 addition & 0 deletions app/controllers/single_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class SinglePagesController < ApplicationController
include Seek::AssetsCommon
include Seek::Sharing::SharingCommon
include Seek::Publishing::PublishingCommon
include Seek::Data::SpreadsheetExplorerRepresentation

before_action :set_up_instance_variable
Expand Down
18 changes: 6 additions & 12 deletions app/helpers/assets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,6 @@ def publishing_item_param(item)
"publish[#{item.class.name}][#{item.id}]"
end

def sharing_item_param(item)
if item.try(:is_isa?)
"share_isa[#{item.class.name}][#{item.id}]"
elsif (item.respond_to? (:investigations)) && (!item.investigations.any?)
"share_not_isa[#{item.class.name}][#{item.id}]"
elsif !item.respond_to? (:investigations)
"share_not_isa[#{item.class.name}][#{item.id}]"
else
"share_isa[#{item.class.name}][#{item.id}]"
end
end

def include_downloadable_item?(items)
has_downloadable_item = false
items.each do |item|
Expand Down Expand Up @@ -346,4 +334,10 @@ def controlled_vocab_annotation_items(controlled_vocab_terms)
end.join(', ').html_safe
end

def batch_selection_collapse_toggle
content_tag(:span, class: 'batch-selection-collapse-toggle open') do
concat content_tag(:span, '', class: 'glyphicon glyphicon-menu-down', 'aria-hidden' => 'true')
concat content_tag(:span, '', class: 'glyphicon glyphicon-menu-right', 'aria-hidden' => 'true')
end
end
end
25 changes: 19 additions & 6 deletions app/helpers/policy_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def project_policy_json(project)
hash.to_json.html_safe
end

def permission_title(permission, member_prefix: false, icon: false)
def permission_title(permission, member_prefix: false, icon: false, link: false)
if permission.is_a?(Permission)
type = permission.contributor_type
contributor = permission.contributor
Expand All @@ -168,18 +168,31 @@ def permission_title(permission, member_prefix: false, icon: false)
contributor = permission
end

if type == 'Person'
option = { target: :_blank }
case type
when 'Person'
text = "#{contributor.first_name} #{contributor.last_name}"
elsif type == 'WorkGroup'
text = "#{member_prefix ? 'Members of ' : ''}#{contributor.project.title} @ #{contributor.institution.title}"
text = link_to(h(text), contributor, option).html_safe if link
when 'WorkGroup'
institution = contributor.institution
project = contributor.project
if link
text = "#{member_prefix ? 'Members of ' : ''}#{link_to(h(project.title), project, option)} @ #{link_to(h(institution.title), institution, option)}".html_safe
else
text = "#{member_prefix ? 'Members of ' : ''}#{project.title} @ #{institution.title}"
end
else
text = "#{member_prefix ? 'Members of ' : ''}#{contributor.title}"
if link
text = "#{member_prefix ? 'Members of ' : ''}#{link_to(h(contributor.title), contributor, option)}".html_safe
else
text = "#{member_prefix ? 'Members of ' : ''}#{contributor.title}"
end
end

if icon
content_tag(:span, class: 'type-icon-wrapper') do
image_tag(asset_path(icon_filename_for_key(type.underscore)), class: 'type-icon')
end.html_safe + " #{text}"
end.html_safe + " #{text}".html_safe
else
text
end
Expand Down
Loading

0 comments on commit b3192ed

Please sign in to comment.