how can i match html tags with no id with deface - spree

Trying to add a column to a table in the configuration menu, the table has a empty <th> </th> just for looks, but when i add the column, it adds it after this so looks ugly, adding it with this
Deface::Override.new(:virtual_path => "spree/admin/user_groups/index",
:name => "minimum_order_column",
:insert_after => "code[erb-loud]:contains('description')",
:partial => "spree/admin/user_groups/minimum_order_column")
first weird thing is that it adds it after that empty th, but seems like a easy fix if I could just remove it
admin/user_groups is from spree_user_groups

Deface uses CSS selectors in general to do it's dirty work.
You should be able to do th[3] or th:last to find that <th>
http://deface.heroku.com/ is a great tool to help in testing selectors.

Related

Table ant d expand able row icon

Here is the sand box link:
Ant d expandable icon
Is this possible to set width, height of expandable icon column (+ sign) or is it possible to render custom icon? Basically I want to control the spacing between expandable column and "Name" column.
You can now add
expandIcon={record => <i>expand</i>}
below the expandedRowRender line in the props. So it will look like :
<Table
columns={columns}
expandedRowRender={record => <p style={{ margin: 0 }}>{record.description}</p>}
expandIcon={record => <i>expand</i>}
dataSource={data}
/>
P.S. This only customizes the expand icon as you have asked, you'll have to write some more lines of code to make the new icon clickable and pass the record to show data in the expanded area.
Please give it a try and let me know if you need help with the onClick() part of it!
I know it's too late, but it might help some new comer.
<Table
size="small"
dataSource={getDataSource()}
locale={{ emptyText: "No Data found" }}
expandedRowRender={expandedRowRender}
expandIcon={record => showExpandIcon(record)}
columns={getColumn()}
/>
Now inside your showExpandIcon custom function you can return whatever custom Icon you want.
showExpandIcon(record){
const { expanded, onExpand } = record;
if(expanded){
return <CustomIcon onClick={e=>{onExpand(record, e)}}/>
}
else{
return <SomeOtherCustomIcon onClick={e=>{onExpand(record, e)}}
}
onExpand is an event, which you need to pass on onClick of your custom Icon to expand the row.
try adding
expandIcon={record => <i>expand</i>}
below the expandedRowRender line in the props. So it will look like :
// like this we can add inside table props
<Table
...props
**expandedRowRender={record => <p style={{ margin: 0 }}>}**
/>

ActiveAdmin formtastic link_to on a collection leading to the show view

Just wondering about how to have this link to this to the appropriate supplier_company_view with clickable names. The .to_sentence is optional.
column :supply_companies do |pt|
pt.supply_companies.collect {|c| c.company_name.capitalize }.to_sentence
end
can do it this way but not sure if it is the best way.
column :supply_companies do |pt|
pt.supply_companies.map { |cn| link_to cn.company_name,
admin_supply_companies_path + "\/" + cn.id.to_s }.join(", ").html_safe
end

How to display a youtube embed link that is called from database

I have an application I want to use for my teaching studio where I create lessons that students can view. the lessons are specific to each student so they are linked via a :user_id (user has_many lessons, lesson belongs_to user). I can bring up specific lessons based on which user it is but the one part I cannot figure out is how to get a video (youtube) link to display correctly. What I want is to save the link along with the text for the lesson. The text and title and all that comes up fine right now, but the video will not display with embed code and throws a routing error in the iframe window.
Here is my code for the _lesson partial. "video_url" is the name of the column in the database.
_lesson.html.erb
<li>
<span class="content">
<%= lesson.title %><br />
<%= lesson.lesson_notes %>
<iframe width="490" height="275" src="<%= lesson.video_url %>" frameborder="0" allowfullscreen></iframe>
</span>
</li>
this is the code in my show view.
show.html.erb
<% if #user.lessons.any? %>
<h3> Lessons (<%= #user.lessons.count %>)</h3>
<ol class="lessons">
<%= render #lessons %>
</ol>
<%= will_paginate #lessons %>
<% end %>
the error I get is below
No route matches [GET] "/users/www.youtube.com/embed/CFF0mV24WCY"
I kind of understand what is happening, but not really. I guess I am unsure why it is looking for that route instead of just embedding the code and then displaying the video. It brings up all the other text and stuff from the lesson so that is working fine. Is there not an easy way just to display the link so it embeds the video along with it? I have searched quite a bit but everything I find just deals with embedding the code into the html which I can do, but this needs to change based on the user so has to be pulled out of the database along with the rest of the lesson info. Any help would be greatly appreciated.
src needs to know the protocol, so if you don't include http://, the explorer assumes that the given src is next to your actual path.
A shitty solution could be add the protocol with a raw string:
src="http://<%= lesson.video_url %>"
But a way better solution is adding a filter to check if the protocol is included when you save the field.

Rails 4: tell simple_form to use input type "date" instead of showing different select boxes like Rails 4's f.date_field?

When I use Simple Form it shows three different select boxes for column type date. Instead of this I want Simple Form to show date attributes as HTML5 does. Specifically I want Simple Form to do the following:
<input type="date" name="org[established_at]" id="org_established_at">
For this I tried:
<%= f.input :established_at, as: :date %>
But this produces three different select boxes for date picking.
How do I tell Simple Form and Rails 4 to use input type "date"?
Recently I've done it like this:
f.input :established_at, as: :string, input_html: { class: :datepicker }
and used http://xdsoft.net/jqplugins/datetimepicker/ to show the calendar
In my project I used next:
= f.input_field :year, as: :datepicker, class: "string form-control teacher_kpk_year", readonly: true
Gemfile:
gem 'bootstrap-datepicker-rails'
applications.js
//= require bootstrap-datepicker
If you have a field defined as date, you only need add the parameter html5 like this:
f.input :established_at, html5: true
But, if you haven't defined your field like date or something like that, you only need to add the alias to the previous declaration, like this form:
f.input :established_at, as: :date, html5: true
And both forms will render a date or datetime picker like bootstrap-datepicker
best regards,

Editable Sitecore text field within a Sitecore Glass link field renderer

Using standard sitecore controls (Link and Text), you can embed a text field within a link in the following way:
<sc:Link runat="server" Field="LinkUrl" >
<sc:Text runat="server" Field="LinkText" />
</sc:Link>
That will give you the ability to edit the text of one field and link of another field.
I have tried to replicate this using Glass, but have been unsuccessful. Something like this would be good (It doesn't work):
<%= Editable( x => x.LinkUrl,new { Text = Editable(Model,q => q.LinkText,null)}) %>
Is there another way of sorting this out?
There are two options I see if I cannot do this using standard glass functionality:
Change the GlassHtml code
Use Two Fields
If you are using Razor use this:
#using (BeginRenderLink(x => x.Link, isEditable: true))
{
#Editable(x => x.Title);
}
If you are using WebForms:
<%using(BeginRenderLink(x=>x.Link){ %>
<%=Editable(x=>x.Title) %>
<% } %>
Mike
If you are using Glass version 3, then you can't use Editable on Link and Image fields.
Use RenderLink and RenderImage instead.
See here: http://glass.lu/docs/tutorial/sitecore/tutorial22/tutorial22.html
The Editable method is the most basic method to use to make a field
editable and should be used with most fields that are page editable
except the Image field and General Link field