Skip to content
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

Merged
merged 18 commits into from
Jul 3, 2018
Merged

On off switch for din kurs events table#158297012 #542

merged 18 commits into from
Jul 3, 2018

Conversation

tomurb
Copy link

@tomurb tomurb commented Jun 25, 2018

PT Story: https://www.pivotaltracker.com/story/show/158297012

Changes proposed in this pull request:

  1. Added show_dinkurs_events attribute to the Company model.
  2. Added switch for new attribute for the company views' _form.html.haml, at least in case of editting.

Screenshots (Optional):
obraz
obraz

Ready for review:
@AgileVentures/shf-project-team

@patmbolger
Copy link
Collaborator

@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.

@tomurb
Copy link
Author

tomurb commented Jun 25, 2018

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.
Where is the rebuild button on semaphore?

@patmbolger
Copy link
Collaborator

The "rebuild" button is only visible to admins. You'll have to continue to close/reopen the PR in the meantime.

@tomurb tomurb closed this Jun 25, 2018
@tomurb tomurb reopened this Jun 25, 2018
@patmbolger
Copy link
Collaborator

The PT story as written was incomplete. This feature should prevent this section of the company show view from appearing, if the switch is set to off:


screen shot 2018-06-27 at 7 44 49 am


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:

Showing Dinkurs events on this page has been disabled.  Edit the company to enable that.

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).

Copy link
Collaborator

@patmbolger patmbolger left a 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
Copy link
Collaborator

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).

Copy link
Author

@tomurb tomurb Jun 27, 2018

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

= f.text_field :dinkurs_company_id, class: 'wpcf7-form-control'

.dinkurs_company_show
= f.label :show_dinkurs_events, "#{t('companies.show_dinkurs_events')}"
Copy link
Collaborator

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.

@patmbolger
Copy link
Collaborator

Please note that we will also need cucumber test(s) for this (add test(s) or augment existing ones).

@patmbolger
Copy link
Collaborator

Almost forgot - you'll also have to add a test for the added DB column to company_spec.rb.

align-items: center;
}

label, .glyphicon {

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;

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 {

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%;
}

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 {

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;

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;

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;

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 {

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;

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

patmbolger and others added 3 commits June 29, 2018 18:16
@@ -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

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

@patmbolger
Copy link
Collaborator

  1. You have some errors with i18N. You can see the errors by running the suggested command i18n-tasks missing. This shows me:

screen shot 2018-07-01 at 2 28 00 pm

  1. Please try to address all (or most) of the "hound-ci" issues.

  2. See other code comments.

@@ -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)
Copy link
Collaborator

@patmbolger patmbolger Jul 1, 2018

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:


screen shot 2018-07-01 at 2 18 30 pm


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')
Copy link
Collaborator

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).

@tomurb
Copy link
Author

tomurb commented Jul 2, 2018

About the Swedish translation - should I use some translator, set dummy translation or...?

@patmbolger
Copy link
Collaborator

@tmszrbn - for initial translations, I use google translate - then @thesuss corrects those as needed when she reviews the PR.

flex-direction: column;
}

label,

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 {

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,

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 {

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;

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;

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 */

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;}

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 */

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;

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,

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;

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 {

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 {

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

@tomurb
Copy link
Author

tomurb commented Jul 2, 2018

Sorry for spamming with fixes.
That is final, I think.
obraz

@@ -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.
Copy link
Collaborator

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.

@@ -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.)
Copy link
Collaborator

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.)

@@ -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.
Copy link
Collaborator

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.

@@ -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'

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?
Copy link
Collaborator

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).

Copy link
Collaborator

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.

@patmbolger patmbolger merged commit 24eb704 into AgileVentures:develop Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants