How to make the result card/list responsive? - reactivesearch

I am trying to make a filter based search using reactive search. However, I am stuck with the result card implementation. Currently, the result card only displays specific content from my elastic search database. However, I need the result card to be responsive in the sense that when a result card is clicked, a popup should be rendered on the screen displaying the additional details of the particular search result.
I have tried implementing a few CSS and Javascript popups, but am unable to render the contents of each search item.
<ResultCard
componentId="results"
dataField="original_title"
react={{
and: [
"mainSearch",
"RangeSlider",
"Brand-list",
"Segment-list",
"fuel-list"
]
}}
pagination={true}
className="Result_card"
paginationAt="bottom"
pages={5}
size={12}
Loader="Loading..."
noResults="No results were found..."
sortOptions={[
{
dataField: "Price__in_Lakhs_",
sortBy: "asc",
label: "Sort by Price (Low to High) \u00A0"
},
{
dataField: "Price__in_Lakhs_",
sortBy: "desc",
label: "Sort by Price (High to Low) \u00A0 \u00A0"
},
{
dataField: "Variants.keyword",
sortBy: "asc",
label: "Sort by Variant (A-Z) \u00A0"
}
]}
innerClass={{
title: "result-title",
listItem: "result-item",
list: "list-container",
sortOptions: "sort-options",
resultStats: "result-stats",
resultsInfo: "result-list-info"
}}
onData={function(res) {
return {
description: (
<div className="main-description">
<div className="ih-item square effect6 top_to_bottom">
<a target="#" href={"" + res.Index}>
<div className="img">
<img
src={"" + res.Index}
alt={""}
className="result-image"
/>
</div>
<div className="info colored">
<h3 className="overlay-title">
{res.Variants}
<div className="overlay-description">
{res.Model}
</div>
<div className="overlay-info">
<div className="rating-time-score-container">
<div className="sub-title Rating-data">
<b>
Price:
<span className="details">
{" "}
{res.Price__in_Lakhs_}
{" Lakhs"}
</span>
</b>
</div>
<div className="sub-title Score-data">
<b>
Segment:
<span className="details">
{" "}
{res.Segment}
</span>
</b>
</div>
</div>
<div className="revenue-lang-container">
<div className="revenue-data">
<b>
<span>Brand: </span>{" "}
<span className="details">
{" "}
{res.Brand}
</span>{" "}
</b>
</div>
<div className="sub-title language-data">
<b>
Mileage:
<span className="details">
{" "}
{res.Mileage__ARAI_} Kmpl
</span>
</b>
</div>
</div>
</div>
</div>
</a>
</div>
</div>
),
};
}}
/>

Maybe this thread might help you: https://stackoverflow.com/a/56685332/9119053 .
If this not what you are looking for can you, please give a proper context and also there seems to be some styling issue with the code as well.

Related

Updating the ranking based on jquery sortable

I'm trying to update the ranking of room prices with jquery-sortable. I'm following the approach of this example https://gorails.com/episodes/sortable-drag-and-drop.
goal
The room_prices can be dragged and dropped and the goal is to update the rank accordingly.
Issue
The controller action sort is triggered everytime I move a price, but the new order/ranking seems not to be transfered correctly to the controller.
=> The index in my controller action is still the index the page started with instead of the index after the drag and drop action.
index
<div id="room-price-index" data-url="<%= sort_room_category_room_prices_path(#room_category) %>">
<% #room_prices.each do |price| %>
<%= link_to edit_room_price_path(price), id: dom_id(price) do %>
<div class="item"><%= price.name %></div>
<% end %>
<% end %>
</div>
app/assets/javascripts/room_price.js
document.addEventListener("turbolinks:load", function() {
$("#room-price-index").sortable({
update: function(e, ui) {
console.log(e)
console.log(ui)
console.log(this)
console.log($(this).sortable('serialize'));
Rails.ajax({
url: $(this).data("url"),
type: "PATCH",
data: $(this).sortable('serialize'),
});
}
});
});
output console.log(e)
=>
jQuery.Event {originalEvent: j…y.Event, type: "sortupdate", timeStamp: 7277.559999958612, jQuery112403961329860286955: true, isDefaultPrevented: ƒ, …}
altKey: false
bubbles: true
button: 0
buttons: 0
cancelable: true
clientX: 783
clientY: 365
ctrlKey: false
currentTarget: document
data: null
delegateTarget: document
detail: 1
eventPhase: 3
fromElement: null
handleObj: {type: "mouseup", origType: "mouseup", data: null, guid: 30, handler: ƒ, …}
isDefaultPrevented: ƒ returnFalse()
isTrigger: 3
jQuery112403961329860286955: true
metaKey: false
namespace: ""
offsetX: 523
offsetY: 39
originalEvent: jQuery.Event {originalEvent: MouseEvent, type: "mouseup", timeStamp: 7277.559999958612, jQuery112403961329860286955: true, isDefaultPrevented: ƒ, …}
pageX: 783
pageY: 581
relatedTarget: null
result: undefined
rnamespace: null
screenX: 783
screenY: 444
shiftKey: false
target: div#acco-price-index.ui-sortable
timeStamp: 7277.559999958612
toElement: div.room-price-info
type: "sortupdate"
view: Window {parent: Window, postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, …}
which: 1
__proto__: Object
output console.log(ui)
=>
{helper: null, placeholder: jQuery.fn.init(1), position: {…}, originalPosition: {…}, offset: {…}, …}
helper: null
item: jQuery.fn.init [div.card-room-prices.ui-sortable-handle, context: div.card-room-prices.ui-sortable-handle]
offset: {top: 539.4375, left: 222}
originalPosition: {top: 533.4375, left: 15}
placeholder: jQuery.fn.init [div.card-room-prices.ui-sortable-handle.ui-sortable-placeholder, selector: "", context: undefined]
position: {top: 391.4375, left: 16.609375}
sender: null
__proto__: Object
output console.log(this)
<div id="acco-price-index" data-url="/room_categories/10/room_prices/sort" class="ui-sortable">
<a id="room_price_43" href="/room_prices/43/edit" class="ui-sortable-handle">
</a><div class="card-room-prices ui-sortable-handle"><a id="room_price_43" href="/room_prices/43/edit">
<div class="room-price-info">
<div class="room-price-info-item">ppppppp</div>
<div class="room-price-info-item">€3.00</div>
<div class="room-price-info-item"> 31-01-2020 </div>
<div class="room-price-info-item"> 6-03-2020 </div>
</div>
</a><div class="card-room-prices-actions"><a id="room_price_43" href="/room_prices/43/edit">
<!-- <div class="card-room-prices-actions-item">
<p><i class="fas fa-edit"></i> Price details </p>
</div> -->
</a><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/room_prices/43">
<div class="card-room-prices-actions-item">
<p><i class="fas fa-trash"></i> delete</p>
</div>
</a> </div>
</div>
<a id="room_price_41" href="/room_prices/41/edit" class="ui-sortable-handle">
</a><div class="card-room-prices ui-sortable-handle" style=""><a id="room_price_42" href="/room_prices/42/edit">
<div class="room-price-info">
<div class="room-price-info-item">fdsfsdfdsf</div>
<div class="room-price-info-item">€5.00</div>
<div class="room-price-info-item"> 15-12-2019 </div>
<div class="room-price-info-item"> 31-12-2019 </div>
</div>
</a><div class="card-room-prices-actions"><a id="room_price_42" href="/room_prices/42/edit">
<!-- <div class="card-room-prices-actions-item">
<p><i class="fas fa-edit"></i> Price details </p>
</div> -->
</a><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/room_prices/42">
<div class="card-room-prices-actions-item">
<p><i class="fas fa-trash"></i> delete</p>
</div>
</a> </div>
</div><div class="card-room-prices ui-sortable-handle"><a id="room_price_41" href="/room_prices/41/edit">
<div class="room-price-info">
<div class="room-price-info-item">Rob II</div>
<div class="room-price-info-item">€5.00</div>
<div class="room-price-info-item"> 15-12-2019 </div>
<div class="room-price-info-item"> 31-12-2019 </div>
</div>
</a><div class="card-room-prices-actions"><a id="room_price_41" href="/room_prices/41/edit">
<!-- <div class="card-room-prices-actions-item">
<p><i class="fas fa-edit"></i> Price details </p>
</div> -->
</a><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/room_prices/41">
<div class="card-room-prices-actions-item">
<p><i class="fas fa-trash"></i> delete</p>
</div>
</a> </div>
</div>
<a id="room_price_42" href="/room_prices/42/edit" class="ui-sortable-handle">
</a>
</div>
console.log($(this).sortable('serialize'));
room_price[]=43&room_price[]=41&room_price[]=42
controller
def sort
params[:room_price].each_with_index do |id, index|
binding.pry
# id => "43"
# index => "0"
# RoomPrice.where(id: id) => [#<RoomPrice:797987897 .....rank:1>]
RoomPrice.where(id: id).update_all(rank: index + 1)
binding.pry
# id => "43"
# index => "0"
# RoomPrice.where(id: id) => [#<RoomPrice:797987897 .....rank:1>]
end
skip_authorization
head :ok
end
Found the error, I thought I properly wrapped all my price items, but I accidentally also included some items that were not price items. Thanks all you guys for the help.

Using single-line looping to generate HTML classes in a Rails view

I have an hash in the format:
#meals = [
{
name: 'Roasted Chicken A La Ratatouille',
description: '',
tags: ['chicken'],
type: ['program'],
image_url: ''
},
{
name: 'Turkey Nuggets with Buffalo Cauliflower & Spinach',
description: '',
tags: ['turkey'],
type: ['program', 'veggies'],
image_url: ''
}
]
and I'd like to be able to unpack the meal type as class names for the element:
<% meals.shuffle.each do |meal| %>
<!-- Line in question -->
<div class="item col-3 p-2 a b <%= meal[:type].each {|t| t } %>">
<!-- End line in question -->
<div class="card">
<img class="card-img-top" src="<%= meal[:image_url] %>">
<div class="card-body">
<h5 class="card-title font-medium"><%= meal[:name] %></h5>
</div>
<div class="card-footer text-muted justify-content-center row">
<% meal[:tags].each do |tag| %>
<span style="margin: 2px;" class="badge bg-info-gradiant pointer"><%= tag %></span>
<% end -%>
</div>
</div>
</div>
<% end %>
But when the view renders, it displays as:
<div class="item col-3 p-2 a b ["program"]" style="position: absolute; left: 295px; top: 0px;">
<div class="card" style="height: 399px;">
...
</div>
</div>
Where program is displayed within the brackets. Is there a different way to accomplish this so that the values within the array are applied as class names?
You can use Array#join to explicitly convert the array of classes into a string of space-separated class names:
<div class="item col-3 p-2 a b <%= meal[:type].join(' ') %>">
How it works:
> meal[:type]
=> ["program", "veggies"]
> meal[:type].join(' ')
=> "program veggies"
Note that meal[:type].each does not do what you think it does. It calls the block for each element in the meal[:type] array with the expectation that the block performs a side effect (e.g. logging something or saving something), and then it returns the unmodified meal[:type] array. If you wanted to get a new array, you would have to use Array#map instead:
> meal[:type].each { |t| t.reverse }
=> ["program", "veggies"] # the block doesn’t affect the return value
> meal[:type].map { |t| t.reverse }
=> ["margorp", "seiggev"] # the block affects each returned element

render array in view with Ruby

I'm new to Ruby and I try to render an array which is in a separate file called database.rb:
Data = [
{
title: "First",
content: "Lorem ipsum...",
photo: "image1"
},
{
title: "Second",
content: "Eventually ...",
photo: "image2"
},
{
title: "Third",
content: "also to Kim’s ....",
photo: "image3"
}
]
I now want to render this array in a view.
In my app.rb I have this code:
require "sinatra"
require "sinatra/activerecord"
require_relative "database"
["/", "/articles"].each do |path|
get path do
#database = Data
erb :index
end
end
In my view index:
<% #database.each do |article| %>
<!-- Blog Post -->
<div class="card mb-4">
<img class="card-img-top" src="<%= article.photo %>" alt="">
<div class="card-body">
<h2 class="card-title oink"><%= article.title %></h2>
<p class="card-text oink"><%= article.content %></p>
</div>
<div class="card-footer text-muted">
</div>
</div>
<% end %>
How to get this to work? Because it seems that properties title, content and photo are not recognized.
What I should do? creating a model? but how?
Your array is made of hash items. If you want to stick with hashes, this is the way to access values (by key)
<!-- Blog Post -->
<div class="card mb-4">
<img class="card-img-top" src="<%= article[:photo] %>" alt="">
<div class="card-body">
<h2 class="card-title oink"><%= article[:title] %></h2>
<p class="card-text oink"><%= article[:content] %></p>
</div>
<div class="card-footer text-muted">
</div>
</div>
Otherwise, if you want to have methods, you might use Ruby Struct
Article = Struct.new(:title, :content, :photo)
Data = [
Article.new("First", "Lorem ipsum...", "image1"),
Article.new("Second", "Eventually ...", "image2"),
Article.new("Third", "also to Kim’s ....", "image3")
]
Now you can do it like in your snippet

Converting Haml code consisting anchor tag with class names to Html in Rails?

I am having haml page, I need to convert to html page. I am using https://haml2erb.org/ for converting. BUt I can't convert the below code, it is showing error at line: %a.button.dropdown-toggle.on-dark{data: { toggle: 'dropdown' }}
This is my code:
.list
.panel-title
.primary
%h2
{{ title }}
.wrapper
.secondary
.dropdown
%a.button.dropdown-toggle.on-dark{data: { toggle: 'dropdown' }}
%fa{name: 'ellipsis-v'}
%b.caret
It seems that haml2erb struggles with a nested hash for data attributes. This is what it should produce:
<div class="list">
<div class="panel-title">
<div class="primary">
<h2>
{{ title }}
</h2>
</div>
<div class="wrapper">
<div class="secondary">
<div class="dropdown">
<a class="button dropdown-toggle on-dark" data-toggle="dropdown">
<fa name="ellipsis-v"></fa>
<b class="caret"></b>
</a>
</div>
</div>
</div>
</div>
</div>

jQuery Ui-Autocomplete and popover in input tag

I want to use autocomplete and popover in one input tag.
But autocomplete can't display , I see google chrome developer tools, autocomplete is work, just can't display . I don't know how to do .
HTML code
<span class="form-labelTitle img-searchForm02">place</span>
<input class="auto-input" placeholder="city" data-toggle="popover" data-placement="bottom">
<div class="leave-btn"></div>
<div class="autocomplete-div auto1"></div>
<div id="popover-content" class="hide">
<div role="tabpanel">
<ul class="nav nav-tabs arrival-tabs" role="tablist" id="myTab">
<li class="active" role="presentation" ><a href='#JPN' role='tab' data-toggle='tab'>japan</a></li>
<li role="presentation" ><a href='#TPE' role='tab' data-toggle='tab'>taiwan</a></li>
</ul>
<div class="tab-content">
<div class='tab-pane active city' id='JPN'>
<span>Tokyo</span>
<span>okinawa</span>
</div>
<div class='tab-pane' id='TPE'>
<span>taipei</span>
</div>
JS code
$(function(){
$('.auto-input').popover({
'html': true,
'content': function () {
return $('#popover-content').html();
}
});
$('.auto-input').autocomplete({
open:function(event, ui){
$(this).popover('hide');
},
source: [
"tokyo",
"okinawa",
"taipei
],
appendTo:($('.auto1')),
});
});

Resources