Skip to content

Commit 97b8ff1

Browse files
authored
Merge branch 'main' into improve-reader-ui-part-2
2 parents ce9c77d + a0aeecc commit 97b8ff1

29 files changed

+506
-26
lines changed

.erb_lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ exclude:
44
- app/views/ach_transfers/_form.html.erb # erb-lint _really_ doesn't like Alpine
55
- app/views/wires/new_v2.html.erb # erb-lint _really_ doesn't like Alpine
66
- app/views/increase_checks/new_v2.html.erb # erb-lint _really_ doesn't like Alpine
7+
- app/views/events/sub_organizations.html.erb # erb-lint _really_ doesn't like Alpine
8+
- app/views/events/scoped_tags/_scoped_tag_option.html.erb # erb-lint _really_ doesn't like Alpine
79
- app/views/doorkeeper/authorizations/new.html.erb
810
linters:
911
ErbSafety:

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source "https://rubygems.org"
44

5-
ruby File.read(File.join(File.dirname(__FILE__), ".ruby-version")).strip
5+
ruby file: ".ruby-version"
66

77
gem "dotenv-rails", groups: [:development, :test]
88

app/controllers/api/v4/stripe_cards_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def transactions
2727
@hcb_codes = @hcb_codes.select(&:missing_receipt?) if params[:missing_receipts] == "true"
2828

2929
@total_count = @hcb_codes.size
30-
@has_more = false # TODO: implement pagination
30+
@hcb_codes = paginate_hcb_codes(@hcb_codes)
3131
end
3232

3333
def create

app/controllers/api/v4/transactions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def missing_receipt
2727
@hcb_codes = HcbCode.where(id: hcb_codes_missing_ids).order(created_at: :desc)
2828

2929
@total_count = @hcb_codes.size
30-
@has_more = false # TODO: implement pagination
30+
@hcb_codes = paginate_hcb_codes(@hcb_codes)
3131
end
3232

3333
def update
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# frozen_string_literal: true
2+
3+
class Event
4+
class ScopedTagsController < ApplicationController
5+
include SetEvent
6+
7+
before_action :set_scoped_tag, except: :create
8+
before_action :set_event
9+
10+
def create
11+
@scoped_tag = @event.subevent_scoped_tags.build(name: params[:name])
12+
13+
authorize @scoped_tag
14+
15+
if @scoped_tag.save
16+
if params[:subevent_id]
17+
subevent = Event.find(params[:subevent_id])
18+
19+
if @scoped_tag.parent_event.subevents.include?(subevent)
20+
subevent.scoped_tags << @scoped_tag
21+
end
22+
end
23+
24+
respond_to do |format|
25+
format.turbo_stream { render turbo_stream: turbo_stream.append_all(".scoped_tag_results", partial: "events/scoped_tags/scoped_tag_option", locals: { scoped_tag: @scoped_tag }) }
26+
format.any do
27+
flash[:success] = "Successfully created new sub-organization tag"
28+
redirect_back fallback_location: event_sub_organizations_path(@event)
29+
end
30+
end
31+
else
32+
flash[:error] = "Failed to create new sub-organization tag"
33+
redirect_to event_sub_organizations_path(@event)
34+
end
35+
end
36+
37+
def destroy
38+
authorize @scoped_tag
39+
40+
@scoped_tag.destroy!
41+
42+
respond_to do |format|
43+
format.turbo_stream do
44+
streams = [turbo_stream.remove_all("[data-scoped-tag='#{@scoped_tag.id}']")]
45+
streams << turbo_stream.remove_all(".scoped-tags__divider") if @event.subevent_scoped_tags.none?
46+
render turbo_stream: streams
47+
end
48+
format.any { redirect_back fallback_location: event_sub_organizations_path(@scoped_tag.parent_event) }
49+
end
50+
end
51+
52+
def toggle_tag
53+
authorize @scoped_tag
54+
55+
unless @scoped_tag.parent_event.subevents.include?(@event)
56+
flash[:error] = "Cannot add tag of a different parent organization to this organization"
57+
return redirect_to event_sub_organizations_path(@scoped_tag.parent_event)
58+
end
59+
60+
if @event.scoped_tags.exists?(@scoped_tag.id)
61+
removed = true
62+
@event.scoped_tags.destroy(@scoped_tag)
63+
else
64+
@event.scoped_tags << @scoped_tag
65+
end
66+
67+
respond_to do |format|
68+
format.turbo_stream do
69+
if removed
70+
render partial: "events/scoped_tags/destroy", locals: { scoped_tag: @scoped_tag, subevent: @event }
71+
else
72+
render partial: "events/scoped_tags/create", locals: { scoped_tag: @scoped_tag, subevent: @event }
73+
end
74+
end
75+
format.any { redirect_back fallback_location: event_sub_organizations_path(@scoped_tag.parent_event) }
76+
end
77+
end
78+
79+
private
80+
81+
def set_scoped_tag
82+
@scoped_tag = Event::ScopedTag.find(params[:id])
83+
end
84+
85+
end
86+
87+
end

app/controllers/events_controller.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,11 +837,18 @@ def sub_organizations
837837
respond_to do |format|
838838
format.html do
839839
search = params[:q] || params[:search]
840+
scoped_tag = Event::ScopedTag.find_by(name: params[:tag])
840841

841842
relation = @event.subevents
842843
relation = relation.where("name ILIKE ?", "%#{search}%") if search.present?
844+
relation = relation.joins(:scoped_tags).where("event_scoped_tags.id = #{scoped_tag.id}") if scoped_tag.present?
843845
relation = relation.order(created_at: :desc)
844846

847+
@filter_options = [
848+
{ key: "tag", label: "Tag", type: "select", options: @event.subevent_scoped_tags.map(&:name) }
849+
]
850+
@has_filter = helpers.check_filters?(@filter_options, params)
851+
845852
@sub_organizations = relation
846853
end
847854

@@ -883,7 +890,8 @@ def create_sub_organization
883890
is_public: @event.is_public,
884891
plan: @event.config.subevent_plan.presence,
885892
risk_level: @event.risk_level,
886-
parent_event: @event
893+
parent_event: @event,
894+
scoped_tags: params[:scoped_tags]
887895
).run
888896

889897
redirect_to subevent

app/controllers/hcb_codes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def invoice_as_personal_transaction
246246

247247
authorize hcb_code
248248

249-
if hcb_code.amount_cents >= -100
249+
if hcb_code.amount_cents > -100
250250
flash[:error] = "Invoices can only be generated for charges of $1.00 or more."
251251
return redirect_to hcb_code
252252
end

app/helpers/api/v4/application_helper.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ def pagination_metadata(json)
1313
json.has_more @has_more
1414
end
1515

16+
def paginate_hcb_codes(hcb_codes)
17+
limit = params[:limit]&.to_i || 25
18+
return render json: { error: "invalid_operation", messages: "Limit is capped at 100. '#{params[:limit]}' is invalid." }, status: :bad_request if limit > 100
19+
20+
start_index = if params[:after]
21+
index = hcb_codes.index { |hcb_code| hcb_code.public_id == params[:after] }
22+
return render json: { error: "invalid_operation", messages: "After parameter '#{params[:after]}' not found" }, status: :bad_request if index.nil?
23+
24+
index + 1
25+
else
26+
0
27+
end
28+
@has_more = hcb_codes.length > start_index + limit
29+
30+
hcb_codes.slice(start_index, limit)
31+
end
32+
1633
def transaction_amount(tx, event: nil)
1734
return tx.amount.cents if !tx.is_a?(HcbCode)
1835

app/javascript/controllers/menu_controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class extends Controller {
1616
appendTo: String,
1717
placement: { type: String, default: 'bottom-start' },
1818
contentId: String,
19+
updateOnResize: { type: Boolean, default: false }, // See https://github.com/hackclub/hcb/issues/8588
1920
}
2021

2122
initialize() {
@@ -60,7 +61,7 @@ export default class extends Controller {
6061
this.content,
6162
this.computePosition.bind(this, false),
6263
{
63-
elementResize: false, // See https://github.com/hackclub/hcb/issues/8588
64+
elementResize: this.updateOnResizeValue,
6465
}
6566
)
6667
}

app/javascript/controllers/text_filter_controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class extends Controller {
6262
get listboxElement() {
6363
const listbox = this.comboboxElement.getAttribute('aria-controls')
6464

65-
return document.getElementById(listbox)
65+
return document.querySelector(listbox)
6666
}
6767

6868
get optionElements() {

0 commit comments

Comments
 (0)