Skip to content

Commit

Permalink
implemented admin auction page, refactor the logic, update ordeable s…
Browse files Browse the repository at this point in the history
…timulus controller
  • Loading branch information
OlegPhenomenon committed Aug 18, 2023
1 parent 41ca969 commit a4b87c7
Show file tree
Hide file tree
Showing 27 changed files with 551 additions and 303 deletions.
45 changes: 38 additions & 7 deletions app/assets/builds/application.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/assets/builds/application.js.map

Large diffs are not rendered by default.

16 changes: 1 addition & 15 deletions app/components/common/header/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,7 @@
<span class="o-arrow js-submenu-toggle"></span>

<ul class="submenu">
<li>
<%= link_to 'OKSJONID', root_path %>
</li>
<li>
<a href="#">KASUTAJA KONTO</a>
</li>
<li>
<%= link_to 'MINU ARVED', invoices_path %>
</li>
<li>
<%= link_to 'MINU PAKKUMISED', offers_path %>
</li>
<li>
<a href="#">Minu SOOVIDE NIMEKIRI</a>
</li>
<%= regular_menu_list %>
<li class="c-toolbar__search js-search-toolbar">
<%= link_to notifications_path, class: 'c-toolbar__notice' do %>
<svg width="12" height="16" viewBox="0 0 12 16" fill="white"
Expand Down
40 changes: 40 additions & 0 deletions app/components/common/header/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,46 @@ def languages

safe_join(l)
end

def regular_menu_list
menu = current_user&.roles&.include?(User::ADMINISTATOR_ROLE) ? admin_menu_list_items : regular_menu_list_items

m = menu.map do |item|
content_tag('li') do
content_tag('a', item[:name], href: item[:path])
end
end

safe_join(m)
end

private

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def admin_menu_list_items
[{ name: t(:auctions_name), path: admin_auctions_path },
{ name: t(:results_name), path: admin_results_path },
{ name: t(:finished_auctions), path: admin_finished_auctions_index_path },
{ name: t(:billing_profiles_name), path: admin_billing_profiles_path },
{ name: t(:users_name), path: admin_users_path },
{ name: t(:bans_name), path: admin_bans_path },
{ name: t(:invoices_name), path: admin_invoices_path },
{ name: t(:jobs_name), path: admin_jobs_path },
{ name: t(:settings_name), path: admin_settings_path },
{ name: t(:paid_deposits_name), path: admin_paid_deposits_path },
{ name: t(:statistics_name), path: admin_statistics_path }]
end

def regular_menu_list_items
items = [{ name: t(:auctions_name), path: auctions_path },
{ name: t(:my_invoices), path: invoices_path },
{ name: t(:my_offers), path: offers_path },
{ name: t(:my_wishlist), path: wishlist_items_path }]

items.insert(1, { name: t(:profile), path: user_path(current_user&.uuid) }) if user_signed_in?
items
end
end
end
end
5 changes: 5 additions & 0 deletions app/components/common/table/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def sortable_column(column, caption, option)
action: "click->#{stimulus_controller_name_dirty}#resortTable",
"#{stimulus_controller_name_dirty}-direction-value": next_direction(column),
"#{stimulus_controller_name_dirty}-column-value": column,
"#{stimulus_controller_name_dirty}-frame-name-value": frame_name,
"#{stimulus_controller_name_dirty}-asc-class": sorting_asc_class,
"#{stimulus_controller_name_dirty}-desc-class": sorting_desc_class,
"#{stimulus_controller_name_dirty}-target": target_element_name }
Expand All @@ -46,6 +47,10 @@ def target_element_name
'th'
end

def frame_name
'results'
end

def currently_sorted?(column)
params[:sort] == column.to_s
end
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/admin/auctions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def destroy
end
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def bulk_starts_at
results = AdminBulkActionService.apply_for_english_auction(auction_elements: params[:auction_elements])
skipped_auctions = results[0]
Expand Down Expand Up @@ -89,12 +91,10 @@ def apply_auction_participants
def validate_enable_and_disable_option_in_same_action
auction_elements = params[:auction_elements]

if auction_elements[:enable_deposit] == 'true' &&
auction_elements[:disable_deposit] == 'true'
return unless auction_elements[:enable_deposit] == 'true' && auction_elements[:disable_deposit] == 'true'

flash[:alert] = 'it cannot be enable and disable deposit in same action'
redirect_to admin_auctions_path and return
end
flash[:alert] = 'it cannot be enable and disable deposit in same action'
redirect_to admin_auctions_path and return
end

def create_params
Expand Down
20 changes: 20 additions & 0 deletions app/javascript/controllers/form/bundle_checkbox_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// app/javascript/controllers/debounce_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["hiddenField", "checkboxes"];

collect_ids() {
if(this.hasCheckboxesTarget == false) return;

const regx = /\d+/;
this.hiddenFieldTarget.value = '';

this.checkboxesTargets.forEach((el) => {
if (el.checked == false) return;

const element_id = el.id;
this.hiddenFieldTarget.value += ` ${element_id.match(regx)}`
});
}
}
16 changes: 16 additions & 0 deletions app/javascript/controllers/form/checkbox_toggle_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// app/javascript/controllers/check_controller.js
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["enableDeposit", "disableDeposit"];

connect() {
this.enableDepositTarget.addEventListener('click', (source) => {
this.disableDepositTarget.checked = false;
});

this.disableDepositTarget.addEventListener('click', (source) => {
this.enableDepositTarget.checked = false;
});
}
}
6 changes: 6 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ application.register("form--filter", Form__FilterController);
import Form__AutobiderSubmitController from "./form/autobider_submit_controller";
application.register("form--autobider-submit", Form__AutobiderSubmitController);

import Form__BundleCheckboxController from "./form/bundle_checkbox_controller";
application.register("form--bundle-checkbox", Form__BundleCheckboxController);

import Form__CheckboxToggleController from "./form/checkbox_toggle_controller";
application.register("form--checkbox-toggle", Form__CheckboxToggleController);

import Table__OrdeableController from "./table/ordeable_controller";
application.register("table--ordeable", Table__OrdeableController);

Expand Down
4 changes: 2 additions & 2 deletions app/javascript/controllers/table/ordeable_controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static values = { direction: String, column: String, }
static values = { direction: String, column: String, frameName: String }
static targets = ['th']
static classes = ['asc', 'desc']

Expand All @@ -10,7 +10,7 @@ export default class extends Controller {
}

resortTable(_event) {
Turbo.visit('?sort=' + this.columnValue + '&direction=' + this.directionValue, {});
Turbo.visit('?sort=' + this.columnValue + '&direction=' + this.directionValue, { frame: this.frameNameValue });
}

directionValueChanged() {
Expand Down
16 changes: 8 additions & 8 deletions app/models/auction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class Auction < ApplicationRecord
end)

scope :with_type, (lambda do |type|
if type.present?
if type == BLIND
return where(platform: [type, nil])
elsif type == 'english'
return where(platform: type)
else
self
end
return unless type.present?

if type == BLIND
return where(platform: [type, nil])
elsif type == 'english'
return where(platform: type)
else
self
end
end)

Expand Down
23 changes: 0 additions & 23 deletions app/packs/entrypoints/controllers/checker_controller.js

This file was deleted.

5 changes: 5 additions & 0 deletions app/services/admin_bulk_action_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def initialize(auction_elements:)

def self.apply_for_english_auction(auction_elements:)
admin_handler = new(auction_elements: auction_elements)

puts '---- DD --- CC --- SS'
puts auction_elements
puts '--- DD -- ZZ -- ERE -'

admin_handler.apply_english_auction
end

Expand Down
10 changes: 8 additions & 2 deletions app/views/admin/auctions/_auction.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

<%# name_frame_id = dom_id(auction) %>
<%# locals: (form:,) -%>

<tr class="auctions-table-row" data-turbo-frame="auction_<%= auction.id %>">
<td class="text-center">
<%= f.check_box :auction_ids, { multiple: true }, auction.id, nil %>

<%= form.label "auction_ids_#{auction.id}", class: 'o-checkbox' do %>
<%= form.check_box :auction_ids, { multiple: true, data: { form__bundle_checkbox_target: 'checkboxes' } }, auction.id, nil %>
<div class="o-checkbox__slider round"></div>
<% end %>

</td>
<td class="auction-domain-name monospace">
<%= link_to(admin_auction_path(auction.id), target: '_top') do %>
Expand Down
22 changes: 22 additions & 0 deletions app/views/admin/auctions/deprecated/_auction.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<%# name_frame_id = dom_id(auction) %>
<tr class="auctions-table-row" data-turbo-frame="auction_<%= auction.id %>">
<td class="text-center">
<%= f.check_box :auction_ids, { multiple: true }, auction.id, nil %>
</td>
<td class="auction-domain-name monospace">
<%= link_to(admin_auction_path(auction.id), target: '_top') do %>
<%= domain_name_with_embedded_colors(auction.domain_name) %>
<% end %>
</td>
<td><%= auction.starts_at %></td>
<td><%= auction.ends_at %></td>
<td class="auction-highest-offer"><%= auction.highest_offer_id.present? ? auction.highest_price : t('.no_price')%></td>
<td class="auction-offers-count"><%= auction.number_of_offers %></td>
<td class="auction-turns-count"><%= auction.turns_count %></td>
<td class="auction-turns-count"><%= auction.starting_price %></td>
<td class="auction-turns-count"><%= auction.slipping_end %></td>
<td class="auction-platform"><%= auction.platform %></td>
<td class="auction-platform"><%= auction.deposit %></td>
<td class="auction-platform"><%= auction.enable_deposit %></td>
</tr>
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a4b87c7

Please sign in to comment.