Skip to content

Commit

Permalink
updated admins templates
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Aug 23, 2023
1 parent 34d559c commit 7c73208
Show file tree
Hide file tree
Showing 47 changed files with 1,654 additions and 1,015 deletions.
6 changes: 1 addition & 5 deletions app/assets/builds/application.js

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

4 changes: 2 additions & 2 deletions app/assets/builds/application.js.map

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions app/components/common/notifications/icon/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

<%- if @readed %>
<%- if @notification_type == 'AuctionWinnerNotification' %>
<span class="c-notification__header__icon o-trophy-icon"></span>
<h5 class="c-notification__header__title">Oled võitnud! <span class="o-new"></span></h5>
<%- elsif @notification_type == 'OfferNotification' %>
<span class="c-notification__header__icon o-hammer-icon"></span>
<h5 class="c-notification__header__title">OfferNotification <span class="o-new"></span></h5>
<%- elsif @notification_type == 'AuctionLooserNotification' %>
<span class="c-notification__header__icon o-hammer-icon"></span>
<h5 class="c-notification__header__title">You losed! <span class="o-new"></span></h5>
<%- end %>
<%- else %>
<%- if @notification_type == 'AuctionWinnerNotification' %>
<span class="o-trophy-icon"></span>
<h5 class="c-notification__header__title">Oled võitnud! <span class="o-new"></span></h5>
<%- elsif @notification_type == 'OfferNotification' %>
<span class="o-hammer-icon"></span>
<h5 class="c-notification__header__title">OfferNotification <span class="o-new"></span></h5>
<%- elsif @notification_type == 'AuctionLooserNotification' %>
<span class="o-hammer-icon"></span>
<h5 class="c-notification__header__title">You losed! <span class="o-new"></span></h5>
<%- end %>
<%- end %>
16 changes: 16 additions & 0 deletions app/components/common/notifications/icon/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Common
module Notifications
module Icon
class Component < ViewComponent::Base
attr_reader :notification_type, :readed

def initialize(notification:, readed:)
@notification_type = notification.type
@readed = readed

super
end
end
end
end
end
4 changes: 2 additions & 2 deletions app/components/common/table/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def frame_name
end

def currently_sorted?(column)
params[:sort] == column.to_s
params[:sort_by] == column.to_s
end

def next_direction(column)
return unless currently_sorted?(column)

params[:direction] == 'asc' ? 'desc' : 'asc'
params[:sort_direction] == 'asc' ? 'desc' : 'asc'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def update
# GET /invoices/aa450f1a-45e2-4f22-b2c3-f5f46b5f906b
def show; end

# GET /invoices
# rubocop:disable Metrics/AbcSize
def index
@issued_invoices = invoices_list_by_status(Invoice.statuses[:issued])
@cancelled_payable_invoices = invoices_list_by_status(Invoice.statuses[:cancelled]).with_ban
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ def create

# GET /offers
def index
offers = Offer.includes(:auction)
.includes(:result)
.where(user_id: current_user)
.order('auctions.ends_at DESC')

offers = current_user.offers.search(params)
@pagy, @offers = pagy(offers, items: params[:per_page] ||= 15)
end

Expand Down
2 changes: 1 addition & 1 deletion app/javascript/controllers/table/ordeable_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class extends Controller {
}

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

directionValueChanged() {
Expand Down
6 changes: 3 additions & 3 deletions app/models/auction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def deposit=(value)

def self.search(params = {})
param_list = %w[domain_name starts_at ends_at platform users_price]
sort_column = params[:sort].presence_in(param_list) || 'domain_name'
sort_admin_column = params[:sort].presence_in(%w[domain name
sort_column = params[:sort_by].presence_in(param_list) || 'domain_name'
sort_admin_column = params[:sort_by].presence_in(%w[domain name
starts_at
ends_at
highest_offer_cents
Expand All @@ -119,7 +119,7 @@ def self.search(params = {})
min_bids_step
slipping_end
platform]) || 'id'
sort_direction = params[:direction].presence_in(%w[asc desc]) || 'desc'
sort_direction = params[:sort_direction].presence_in(%w[asc desc]) || 'desc'
is_from_admin = params[:admin] == 'true'

with_highest_offers
Expand Down
11 changes: 2 additions & 9 deletions app/models/offer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Offer < ApplicationRecord
include ActionView::RecordIdentifier
include Broadcast
include Filter

belongs_to :user, optional: true
belongs_to :auction, optional: false
Expand All @@ -17,17 +19,8 @@ class Offer < ApplicationRecord

DEFAULT_PRICE_VALUE = 1

after_create_commit :broadcast_replace_auction
after_update_commit :broadcast_replace_auction

attr_accessor :skip_autobider, :skip_if_wishlist_case, :skip_validation

def broadcast_replace_auction
return if auction.platform == 'blind' || auction.platform.nil?

Offers::ReplaceBroadcastService.call({ offer: self })
end

def validate_accessebly_to_set_bid
return if auction.nil?
return if auction.allow_to_set_bid?(user)
Expand Down
14 changes: 14 additions & 0 deletions app/models/offer/broadcast.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Offer::Broadcast
extend ActiveSupport::Concern

included do
after_create_commit :broadcast_replace_auction
after_update_commit :broadcast_replace_auction
end

def broadcast_replace_auction
return if auction.platform == 'blind' || auction.platform.nil?

Offers::ReplaceBroadcastService.call({ offer: self })
end
end
18 changes: 18 additions & 0 deletions app/models/offer/filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Offer::Filter
extend ActiveSupport::Concern

included do
scope :filter_by_domain_name, -> {
includes(:auction).where("auctions.domain_name LIKE ?", "%#{params[:domain_name]}%")
}
end

class_methods do
def search(params = {})
sort_by = params[:sort_by] || 'created_at'
sort_direction = params[:sort_direction] || 'desc'

includes(:auction).order("#{sort_by} #{sort_direction}")
end
end
end
49 changes: 14 additions & 35 deletions app/views/admin/auctions/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
<%= component 'common/hero', title: t('.title') %>
<div class="o-container">

<!-- This stumulus controller `form--bundle-checkbox` is used to determine which checkboxes the user has clicked in order for the server side to process exactly the selected auction options -->
<div class="c-table c-table--sortable" data-controller='form--bundle-checkbox' }>
<div class="c-table c-table--sortable" data-controller='form--bundle-checkbox'>
<h2><%= t('.auctions.filter_panel') %></h2>

<%= form_with url: admin_auctions_path, method: :get,
data: { controller: 'form--debounce', form__debounce_target: 'form', turbo_action: "advance",
turbo_frame: "results", action: 'input->form--debounce#search' } do |form| %>
<div class="c-table__filters">
<%= form.search_field :domain_name, value: params[:domain_name], placeholder: t('search_by_domain_name') %>
</div>

<div class="c-table__filters" >
<div class="c-table__filters__btns" style='display: flex !important; align-items: center !important; justify-content: space-between !important; width: 100%;'>
<div>
<%= form.label :type, 'Select type of auction' %>
<%= form.select :type, options_for_select(Auction.platforms.map { |platform| [platform[0].capitalize, platform[0]] }, params[:type]), {include_blank: 'All'} %>
</div>
<div>
<%= form.label :starts_at, t('auctions.starts_at') %>
<%= form.datetime_field :starts_at %>
<%= form.label :starts_at, t('auctions.starts_at') %>
<%= form.datetime_field :starts_at %>
</div>
<div>
<%= form.label :ends_at, t('auctions.ends_at') %>
<%= form.datetime_field :ends_at %>
<%= form.label :ends_at, t('auctions.ends_at') %>
<%= form.datetime_field :ends_at %>
</div>
<div>
<label>Show auctions with no start date</label>
Expand All @@ -39,73 +36,61 @@
</div>
</div>
<% end %>

<h2><%= t('.auctions.values_panel') %></h2>

<!-- Some table elements have built-in features, such as a checkbox to select an element. Item selection is bound to a form, but the page layout does not allow (actually it can, but it will not look clean) to pass directly to form values, because the auction table is not in the scope of the form builder. That's why I use this trick, to declare a variable that is above the builder scope, make the variable global in the current scope, pass the form values after building, and pass this value to a separate partial. -->
<% @form_auction_table = nil %>

<%= form_for :auction_elements, url: bulk_starts_at_admin_auctions_path do |form| %>
<% @form_auction_table = form %>

<%= form.hidden_field :elements_id, data: { form__bundle_checkbox_target: 'hiddenField' } %>

<div class="c-table__filters">
<div>
<%= form.label :set_starts_at, t('auctions.starts_at') %>
<%= form.datetime_field :set_starts_at, class: "form-control", min: Time.zone.today %>
<%= form.label :set_starts_at, t('auctions.starts_at') %>
<%= form.datetime_field :set_starts_at, class: "form-control", min: Time.zone.today %>
</div>
<div>
<%= form.label :set_ends_at, t('auctions.ends_at') %>
<%= form.datetime_field :set_ends_at, class: "form-control", min: Time.zone.today %>
<%= form.label :set_ends_at, t('auctions.ends_at') %>
<%= form.datetime_field :set_ends_at, class: "form-control", min: Time.zone.today %>
</div>
<div>
<%= form.label :starting_price, t('auctions.starting_price') %>
<%= form.number_field :starting_price, class: "form-control", step: :any, value: 5.0 %>
<%= form.label :starting_price, t('auctions.starting_price') %>
<%= form.number_field :starting_price, class: "form-control", step: :any, value: 5.0 %>
</div>
<div>
<%= form.label :slipping_end, t('auctions.slipping_end') %>
<%= form.number_field :slipping_end, class: "form-control", step: 1, value: 5 %>
<%= form.label :slipping_end, t('auctions.slipping_end') %>
<%= form.number_field :slipping_end, class: "form-control", step: 1, value: 5 %>
</div>
</div>

<div class="c-table__filters" data-controller="form--checkbox-toggle" style='display: flex !important; align-items: center !important; justify-content: space-between !important; width: 100%;'>
<div>
<%= form.label :deposit, t('auctions.deposit') %>
<%= form.number_field :deposit, class: "form-control", step: :any, value: 0.0 %>
</div>

<div>
<label><%= t('auctions.index.enable_deposit') %></label>
<label class="o-checkbox">
<%= form.check_box :enable_deposit, { data: { form__checkbox_toggle_target: 'enableDeposit' } }, true, nil %>
<div class="o-checkbox__slider round"></div>
</label>
</div>

<div>
<label><%= t('auctions.index.disable_deposit') %></label>
<label class="o-checkbox">
<%= form.check_box :disable_deposit, { data: { form__checkbox_toggle_target: 'disableDeposit' } }, true, nil %>
<div class="o-checkbox__slider round"></div>
</label>
</div>

<div>
<label><%= t('auctions.index.check_all') %></label>
<label class="o-checkbox" for="check_all">
<%= form.check_box :check_all %>
<div class="o-checkbox__slider round"></div>
</label>
</div>

<div>
<%= form.submit 'Run bulk operation', id: 'bulk-operation', class: 'c-btn c-btn--blue', data: { action: 'click->form--bundle-checkbox#collect_ids' }, style: 'cursor: pointer;' %>
</div>

</div>
<% end %>

<!--
These parameters are passed to the Common::Table::Component. These parameters are used to generate headers in the table component. The name "column_name" indicates the name of the column. This is necessary for sorting, so the name of this column should correspond to the name of the column in the database table. If you want to make it so that the data is not sorted by the column, then you should add a nil value. "Caption" is the table header, and "options" are additional parameters that are passed into the tags.
-->
Expand All @@ -121,22 +106,16 @@
{ column: 'platform', caption: t('auctions.auction_type'), options: { class: 'sorting' } },
{ column: 'requirement_deposit_in_cents', caption: t('auctions.auctions'), options: { class: 'sorting' } },
{ column: 'enable_deposit', caption: t('auctions.enable_deposit'), options: { class: 'sorting' } }] %>


<!-- In the Stimulus controller, I use the Turbo class with frame parameters named 'results' for table sorting. This means that rendering the table with the new sort order should occur within the scope of the turbo_frame_tag with the name "results". For it to work correctly, it's necessary to wrap the table content within this turbo_frame_tag with "results" name. The name "results" is assigned as a value for the orderable Stimulus controller in the table component. -->
<%= turbo_frame_tag "results" do %>

<!-- Options attributes are used as table attributes -->
<%= component 'common/table', header_collection:, options: { class: 'js-table-dt dataTable no-footer' } do %>

<!-- "The body of the table also needs to be in the component block, so the component wraps it with the necessary tags." -->

<%= tag.tbody id: "auctions-table-body", class: 'contents' do %>
<%#= render partial: 'auctions', locals: { auctions: @auctions, form: @form_auction_table } %>
<%= render @auctions, form: @form_auction_table %>
<% end %>
<% end %>
<% end %>

</div>
</div>
</div>
Loading

0 comments on commit 7c73208

Please sign in to comment.