-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On off switch for din kurs events table#158297012 #542
On off switch for din kurs events table#158297012 #542
Conversation
…8297012 adds on/off switch for Dinkurs Events
@tmszrbn - yes, those tests started failing very recently (I saw them yesterday). We're using a test Dinkurs account to fetch events, and I had thought that the fetched events would not change - that was a bad assumption, evidently. I am working on a PR right now that would include a fix (short-term) for that problem. Longer-term, we probably need to use VCR for those tests. |
…8297012 failing cucumber tests
…tps://github.com/tmszrbn/shf-project into on-off-switch-for-DinKurs-events-table#158297012
That flex display was the final commit. In retrospect I'm not sure if writing placeholder in swedish translation was the right thing to do. |
The "rebuild" button is only visible to admins. You'll have to continue to close/reopen the PR in the meantime. |
The PT story as written was incomplete. This feature should prevent this section of the company However, if the user is an admin, or a member associated with this company, and there is a Dinkurs key defined for the company, we could show something like:
That would serve as a reminder to the member that their events are not visible to a visitor (which they might tend to forget otherwise). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments.
@@ -0,0 +1,5 @@ | |||
class AddShowDinkursEventsColumnToCompany < ActiveRecord::Migration[5.1] | |||
def change | |||
add_column :companies, :show_dinkurs_events, :boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a field which defaults to nil
, which is OK for companies that do not use this feature yet. However, we have 5 companies in production who are already using this feature.
Here is the dinkurs-fetch log from today:
[SHF_TASK] [Load Dinkurs Events] [info] Started at 2018-06-27 01:30:07 UTC
[SHF_TASK] [Load Dinkurs Events] [info] Company 24: 80 events.
[SHF_TASK] [Load Dinkurs Events] [info] Company 61: 3 events.
[SHF_TASK] [Load Dinkurs Events] [info] Company 89: 36 events.
[SHF_TASK] [Load Dinkurs Events] [info] Company 108: 2 events.
[SHF_TASK] [Load Dinkurs Events] [info] Company 116: 8 events.
[SHF_TASK] [Load Dinkurs Events] [info] Company 165: 0 events.
[SHF_TASK] [Load Dinkurs Events] [info] Company 214: 0 events.
[SHF_TASK] [Load Dinkurs Events] [info] Finished at 2018-06-27 01:30:12 UTC.
[SHF_TASK] [Load Dinkurs Events] [info] Duration: 4.94 seconds.
So, this migration has to set this value to true
for any company for which dinkurs_company_id.blank?
is not true (this will prevent setting the attribute to true
for the two companies that have a blank string for that attribute).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did it with after_initialize
, will it be ok, to set show_dinkurs_events
on true when somebody sets dinkurs_company_id
?
Edit: On the second thought it doesn't seem right since they won't see that it's on while setting an id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer doing this in the migration - it would be a one-time action and associated with the schema change, so it should be done there. Doing it in after_initialize
would add unnecessary overhead at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re your edit comment: yes, very true. And if they set a dinkurs key it does not neccessarily mean that they also want to immediately start showing events on the company page - they need to explicitly control that.
app/views/companies/_form.html.haml
Outdated
= f.text_field :dinkurs_company_id, class: 'wpcf7-form-control' | ||
|
||
.dinkurs_company_show | ||
= f.label :show_dinkurs_events, "#{t('companies.show_dinkurs_events')}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a tooltip for the switch - so that a user knows what it does and how to set it to on (show events) and off (hide events). In English it could be something like this:
Set this switch to on (toggle to the right) to show upcoming Dinkurs events on your company page.
Please note that we will also need cucumber test(s) for this (add test(s) or augment existing ones). |
Almost forgot - you'll also have to add a test for the added DB column to |
align-items: center; | ||
} | ||
|
||
label, .glyphicon { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each selector in a comma sequence should be on its own single line
width: 50%; | ||
} | ||
.dinkurs_company_show { | ||
display: flex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties should be ordered align-items, display, flex-direction
.dinkurs_company_id, .dinkurs_company_show { | ||
width: 50%; | ||
} | ||
.dinkurs_company_show { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selector dinkurs_company_show
should be written in lowercase with hyphens
|
||
.dinkurs_company_id, .dinkurs_company_show { | ||
width: 50%; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule declaration should be followed by an empty line
} | ||
} | ||
|
||
.dinkurs_company_id, .dinkurs_company_show { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selector dinkurs_company_id
should be written in lowercase with hyphens
Selector dinkurs_company_show
should be written in lowercase with hyphens
Each selector in a comma sequence should be on its own single line
left: 4px; | ||
bottom: 4px; | ||
background-color: white; | ||
-webkit-transition: .4s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid vendor prefixes..4
should be written with a leading zero as 0.4
width: 26px; | ||
left: 4px; | ||
bottom: 4px; | ||
background-color: white; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Color white
should be written in hexadecimal form as #ffffff
Color literals like white
should only be used in variable declarations; they should be referred to via variable everywhere else.
transition: .4s; | ||
|
||
&:before { | ||
position: absolute; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties should be ordered background-color, bottom, content, height, left, position, -webkit-transition, transition, width
-webkit-transition: .4s; | ||
transition: .4s; | ||
|
||
&:before { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Begin pseudo elements with double colons: ::
bottom: 0; | ||
background-color: #f4f4f8; | ||
-webkit-transition: .4s; | ||
transition: .4s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.4
should be written with a leading zero as 0.4
…-events-table#158297012 [TEST] Tomek :on off switch for din kurs events table#158297012
@@ -86,7 +86,9 @@ | |||
end | |||
|
|||
When "I {action} the checkbox with id {capture_string}" do |action, element_id| | |||
send action, element_id | |||
send action, id: element_id | |||
rescue Capybara::ElementNotFound |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/Syntax: unexpected token kRESCUE
app/views/companies/show.html.haml
Outdated
@@ -47,7 +47,7 @@ | |||
= render 'company_addresses', company: @company, user_can_edit: user_can_edit | |||
|
|||
.col-md-12 | |||
- unless @company.dinkurs_company_id.blank? | |||
- unless @company.dinkurs_company_id.blank? || !(current_user.member_or_admin? || @company.show_dinkurs_events) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For an admin or a member of this company, if there is a dinkurs_company_if defined, and show_dinkurs_events
is false, then the view should not show anything regarding an events table.
That is, instead of seeing this:
We should just see this:
(Showing Dinkurs events on this page has been disabled. Edit the company to enable that.)
(include the parentheses).
This particular statement could be replaced with:
if ! @company.dinkurs_company_id.blank? && ! @company.show_dinkurs_events && user_can_edit
which is somewhat easier to read. (this will also prevent a member who is not associated with this company from seeing this message).
%td.event-start-date.text-align-center | ||
= event.start_date | ||
- else | ||
= render 'events/empty_with_message', message: t('events.show.no_events') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the changes recommended for company show
view, we can remove this logic (that is, we don't need or want to check show_dinkurs_events
in this file).
About the Swedish translation - should I use some translator, set dummy translation or...? |
@tmszrbn - for initial translations, I use google translate - then @thesuss corrects those as needed when she reviews the PR. |
flex-direction: column; | ||
} | ||
|
||
label, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains trailing whitespace
width: 50%; | ||
} | ||
|
||
.dinkurs_company_show { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selector dinkurs_company_show
should be written in lowercase with hyphens
} | ||
} | ||
|
||
.dinkurs_company_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selector dinkurs_company_id
should be written in lowercase with hyphens
Selector dinkurs_company_show
should be written in lowercase with hyphens
Line contains trailing whitespace
box-shadow: 0 0 1px #2196f3; | ||
} | ||
|
||
input::checked + &::before { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Begin pseudo classes with a single colon: :
} | ||
|
||
input::focus + & { | ||
box-shadow: 0 0 1px #2196f3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Color literals like #2196f3
should only be used in variable declarations; they should be referred to via variable everywhere else.
|
||
/* The slider */ | ||
.slider { | ||
position: absolute; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties should be ordered background-color, bottom, cursor, height, left, position, right, top, transition
& input {display:none;} | ||
} | ||
|
||
/* The slider */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use //
comments everywhere
height: 34px; | ||
|
||
/* Hide default HTML checkbox */ | ||
& input {display:none;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary parent selector (&)
Colon after property should be followed by one space
width: 60px; | ||
height: 34px; | ||
|
||
/* Hide default HTML checkbox */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use //
comments everywhere
|
||
/* The switch - the box around the slider */ | ||
.switch { | ||
position: relative; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties should be ordered display, height, position, width
} | ||
} | ||
|
||
.dinkurs-company-id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains trailing whitespace
|
||
// Hide default HTML checkbox | ||
input { | ||
display:none; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
@@ -59,7 +72,7 @@ $btn-hover-color: #7EDD8B; | |||
color: black; | |||
text-transform: none; | |||
|
|||
&:hover { | |||
&::hover { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Begin pseudo classes with a single colon: :
justify-content: center; | ||
} | ||
|
||
.new_company { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selector new_company
should be written in lowercase with hyphens
config/locales/sv.yml
Outdated
@@ -630,6 +633,8 @@ sv: | |||
location: Plats | |||
fee: Pris | |||
no_events: (Inga planerade händelser) | |||
show_not: (Visar Dinkurs-händelser på den här sidan har inaktiverats. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visning av Dinkurs-händelser på den här sidan har inaktiverats.
config/locales/sv.yml
Outdated
@@ -630,6 +633,8 @@ sv: | |||
location: Plats | |||
fee: Pris | |||
no_events: (Inga planerade händelser) | |||
show_not: (Visar Dinkurs-händelser på den här sidan har inaktiverats. | |||
Redigera företaget för att aktivera det.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redigera företaget för att aktivera visning av händelser.)
config/locales/sv.yml
Outdated
@@ -581,6 +581,8 @@ sv: | |||
flera län, eller "Online" om det (i huvudsak) finns på nätet | |||
visibility_tooltip: Hur detaljerat din adress visas för besökare (inkl kartor). Välj 'Ingen' för att inte visa din adress för besökare alls. | |||
org_nr_tooltip: Endast siffror (ej bindestreck) | |||
dinkurs_show_tooltip: Sätt den här knappen på (växla till höger) | |||
för att visa kommande dinkurs händelser på din företagsida. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Växla den här knappen till på (till höger)
för att visa kommande dinkurs händelser på din företagsida.
app/views/companies/edit.html.haml
Outdated
@@ -9,7 +9,7 @@ | |||
= render 'business_categories/as_list', | |||
categories_names: @company.categories_names | |||
.entry-content.wpcf7 | |||
= render 'form' | |||
= render 'form', class_name: 'edit-company' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains trailing whitespace
def change | ||
add_column :companies, :show_dinkurs_events, :boolean | ||
Company.find_each do |company| | ||
company.show_dinkurs_events = !company.dinkurs_company_id.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry - I should have caught this before .... you're not saving the updated company record here.
So, you could just add the statement company.save
to the block.
It's interesting as to whether the find_each
method is faster than a more direct approach, such as:
Company.where.not(dinkurs_company_id: [nil, '']).each { |c| c.update_attribute(:show_dinkurs_events, true) }
find_each
will pass every company to the block. The alternative above only passes the companies with a non-blank dinkurs key, but involves more SQL.
Our DB is small enough that it really doesn't matter ... just wondering about this (your logic is fine - no change needed except for the save
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I'd recommend changing to the SQL-select approach - that is a better approach overall and would make a significant performance difference on a large DB.
PT Story: https://www.pivotaltracker.com/story/show/158297012
Changes proposed in this pull request:
show_dinkurs_events
attribute to the Company model._form.html.haml
, at least in case of editting.Screenshots (Optional):
Ready for review:
@AgileVentures/shf-project-team