Skip to content

Commit 6ece894

Browse files
authored
Merge branch 'master' into registrations-list
2 parents 2f98631 + 452613e commit 6ece894

85 files changed

Lines changed: 693 additions & 2030 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/assets/javascripts/application.js

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//= require bootstrap-tab-history
1818
//= require cytoscape
1919
//= require cytoscape-panzoom
20-
//= require jscolor
2120
//= require jquery.simplecolorpicker.js
2221
//= require split
2322
//= require handlebars.runtime
@@ -41,36 +40,41 @@
4140
//= require ol
4241
//= require ol-geocoder
4342

44-
function redirect_to_sort_url(){
45-
url = new URL(window.location.href);
46-
url.searchParams.set(
47-
"sort",
48-
$("#sort").find(":selected").val()
49-
);
50-
window.location.replace(url.toString());
51-
}
52-
53-
function redirect_with_updated_search(param, paramVal) {
54-
url = new URL(window.location.href);
55-
// special case for empty range types
56-
if (param == 'start' && paramVal == '/') {
57-
url.searchParams.delete(param);
58-
} else {
59-
url.searchParams.set(param, paramVal);
60-
}
61-
window.location.replace(url.toString());
62-
}
43+
const Index = {
44+
applySorting: function () {
45+
Index.setParam("sort", $("#sort").val());
46+
},
6347

64-
function reposition_tiles(container, tileClass){
65-
var $container = $("." + container);
48+
applyPerPage: function () {
49+
Index.setParam("per_page", $("#per_page").val());
50+
},
6651

67-
$container.imagesLoaded(function () {
68-
$container.masonry({
69-
// options...
70-
itemSelector: "." + tileClass,
71-
columnWidth: 20
52+
applyDateParam: function (param, value) {
53+
const url = new URL(window.location.href);
54+
if (param === 'start' && value === '/') {
55+
url.searchParams.delete(param);
56+
} else {
57+
url.searchParams.set(param, value);
58+
}
59+
window.location.replace(url.toString());
60+
},
61+
62+
setParam: function (param, value) {
63+
const url = new URL(window.location.href);
64+
url.searchParams.set(param, value);
65+
window.location.replace(url.toString());
66+
},
67+
68+
repositionTiles(containerSelector, itemSelector) {
69+
const container = $(containerSelector);
70+
container.imagesLoaded(function () {
71+
container.masonry({
72+
// options...
73+
itemSelector: itemSelector,
74+
columnWidth: 20
75+
});
7276
});
73-
});
77+
}
7478
}
7579

7680
// Perform an ajax request to load the calendar and replace the contents
@@ -152,7 +156,7 @@ document.addEventListener("turbolinks:load", function(e) {
152156
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
153157
addTabToFilters(e.target.href.split('#').pop());
154158
// and reposition masonry tiles
155-
reposition_tiles('masonry', 'masonry-brick');
159+
Index.repositionTiles('.masonry', '.masonry-brick');
156160
});
157161

158162
// Manually trigger bootstrap tab history (we should probably remove the dependency and reimplement in a turbolink-compatible way)
@@ -168,12 +172,14 @@ document.addEventListener("turbolinks:load", function(e) {
168172

169173
// Masonry
170174
$(".nav-tabs a").on("shown.bs.tab", function(e) {
171-
reposition_tiles('masonry', 'masonry-brick');
175+
Index.repositionTiles('.masonry', '.masonry-brick');
172176
});
177+
173178
$(window).on("orientationchange", function() {
174-
reposition_tiles("masonry", "masonry-brick");
179+
Index.repositionTiles('.masonry', '.masonry-brick');
175180
});
176-
reposition_tiles("masonry", "masonry-brick");
181+
182+
Index.repositionTiles('.masonry', '.masonry-brick');
177183

178184
new Clipboard(".clipboard-btn");
179185

app/assets/javascripts/workflows.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ var Workflows = {
192192
$('#node-modal-form-title').val(data.name);
193193
$('#node-modal-form-description').val(data.description);
194194
if (data.color) {
195-
$('#node-modal-form-colour')[0].jscolor.fromString(data.color);
195+
$('#node-modal-form-colour').val(data.color);
196196
} else if (data.parent) {
197-
$('#node-modal-form-colour')[0].jscolor.fromString(cy.$('#' + data.parent).data('color'));
197+
$('#node-modal-form-colour').val(cy.$('#' + data.parent).data('color'));
198198
}
199199
$('#node-modal-form-parent-id').val(data.parent);
200200
$('#node-modal-form-x').val(position.x);
@@ -211,7 +211,7 @@ var Workflows = {
211211
description: $('#node-modal-form-description').val(),
212212
html_description: MarkdownIt.render($('#node-modal-form-description').val()),
213213
color: $('#node-modal-form-colour').val(),
214-
font_color: $('#node-modal-form-colour').css("color"),
214+
font_color: Workflows.getTextColor($('#node-modal-form-colour').val()),
215215
parent: $('#node-modal-form-parent-id').val(),
216216
associatedResources: Workflows.associatedResources.fetch(),
217217
ontologyTerms: Workflows.ontologyTerms.fetch()
@@ -470,6 +470,21 @@ var Workflows = {
470470
);
471471
}
472472
}
473+
},
474+
getTextColor: function (hex) {
475+
// Remove the leading '#', if present
476+
hex = hex.replace('#', '');
477+
478+
// Parse r, g, b values
479+
const r = parseInt(hex.substring(0, 2), 16);
480+
const g = parseInt(hex.substring(2, 4), 16);
481+
const b = parseInt(hex.substring(4, 6), 16);
482+
483+
// Calculate perceived brightness (luminance)
484+
const brightness = (0.299 * r) + (0.587 * g) + (0.114 * b);
485+
486+
// Threshold of ~186 is a common practical cutoff
487+
return brightness > 186 ? '#000000' : '#FFFFFF';
473488
}
474489
};
475490

@@ -621,7 +636,6 @@ document.addEventListener("turbolinks:load", function() {
621636
// Initialize
622637
Workflows.cancelState();
623638
Workflows.history.initialize();
624-
jscolor.installByClassName('jscolor');
625639
} else {
626640
// Hiding/revealing of child nodes
627641
if(hideChildNodes) {

app/assets/stylesheets/application.scss

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,21 @@ ul.unstyled {
418418
}
419419

420420
.search-results-count {
421-
margin-right: 5px;
421+
margin-right: 1em;
422422
display: inline-block
423423
}
424424

425+
.search-results-per-page {
426+
display: inline-block;
427+
428+
select {
429+
border: none;
430+
padding: 0;
431+
background: transparent;
432+
border-bottom: 1px dashed $text-color;
433+
}
434+
}
435+
425436
.index-display-options {
426437
margin: 5px 0;
427438
}

app/assets/stylesheets/showcase.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,11 @@
2424

2525
#main-container.showcase-container {
2626
max-width: 1720px;
27-
}
27+
}
28+
29+
.icon-grid {
30+
display: flex;
31+
gap: 10px;
32+
flex-wrap: wrap;
33+
margin-bottom: 1em;
34+
}

app/controllers/application_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ def job_status
9696

9797
private
9898

99-
def feature_enabled?(feature = controller_name)
99+
def feature_enabled?(feature)
100+
Space.current_space.feature_enabled?(feature)
101+
end
102+
103+
helper_method :feature_enabled?
104+
105+
def ensure_feature_enabled(feature = controller_name)
100106
if TeSS::Config.feature.key?(feature) && !TeSS::Config.feature[feature]
101107
raise ActionController::RoutingError.new('Feature not enabled')
102108
end

app/controllers/bioschemas_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class BioschemasController < ApplicationController
2-
before_action -> { feature_enabled?('bioschemas_testing') }
2+
before_action -> { ensure_feature_enabled('bioschemas_testing') }
33

44
def test
55

app/controllers/collections_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The controller for actions related to the Collection model
22
class CollectionsController < ApplicationController
3-
before_action :feature_enabled?
3+
before_action :ensure_feature_enabled
44
before_action :set_collection, only: %i[show edit curate update_curation add_item remove_item update destroy]
55
before_action :set_breadcrumbs
66

app/controllers/communities_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ def show
88
@resources = []
99
if TeSS::Config.solr_enabled
1010
enabled = []
11-
enabled.append(Event) if TeSS::Config.feature['events']
12-
enabled.append(Material) if TeSS::Config.feature['materials']
13-
enabled.append(Collection) if TeSS::Config.feature['collections']
11+
enabled.append(Event) if feature_enabled?('events')
12+
enabled.append(Material) if feature_enabled?('materials')
13+
enabled.append(Collection) if feature_enabled?('collections')
1414
enabled.each do |resource|
1515
@resources += resource.search_and_filter(nil, '', { 'max_age' => '1 month' },
1616
sort_by: 'new', per_page: 5).results

app/controllers/concerns/searchable_index.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# The concern for searchable index
22
module SearchableIndex
3+
DEFAULT_PAGE_SIZE = 10
4+
PER_PAGE_OPTIONS = [10, 20, 50, 100]
5+
36
extend ActiveSupport::Concern
47

58
included do
@@ -19,7 +22,7 @@ def count
1922
def fetch_resources
2023
if TeSS::Config.solr_enabled
2124
page = page_param.blank? ? 1 : page_param.to_i
22-
per_page = per_page_param.blank? ? 10 : per_page_param.to_i
25+
per_page = per_page_param.blank? ? DEFAULT_PAGE_SIZE : per_page_param.to_i
2326

2427
@search_results = @model.search_and_filter(current_user, @search_params, @facet_params,
2528
page: page, per_page: per_page, sort_by: @sort_by)

app/controllers/content_providers_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The controller for actions related to the Content Providers model
22
class ContentProvidersController < ApplicationController
3-
before_action -> { feature_enabled?('content_providers') }
3+
before_action :ensure_feature_enabled
44
before_action :set_content_provider, only: %i[show edit update destroy]
55
before_action :set_breadcrumbs
66

0 commit comments

Comments
 (0)