Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Campaign show page #62

Merged
merged 7 commits into from
Nov 28, 2018
Merged

Campaign show page #62

merged 7 commits into from
Nov 28, 2018

Conversation

coderberry
Copy link
Contributor

codefund_ads

codefund_ads

codefund_ads

codefund_ads

codefund_ads

codefund_ads

codefund_ads

@coderberry coderberry added in progress This is actively being worked on review and removed in progress This is actively being worked on labels Nov 27, 2018
Copy link
Contributor

@hopsoft hopsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great. I have some change requests but love where this is headed.

before_action :set_campaign

def show
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed my thinking on having empty actions in controllers. While it does communicate some intent, the routes file is the true canonical source of what actions exist. I see these empty method defs as unnecessary noise... at least for experienced Rails developers. This practice could lead to cruft that we forget to clean up if/when the routes change.

No need to remove right now. I just wanted to communicate my thoughts on this pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand this better? How would you handle this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just omit the empty method. Rails will simply render view template if the route is defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In light of the fact that this is open source, do you think that it may be confusing to less experienced Rails developers?


def diff
render layout: false
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ We should adhere to a strict REST pattern with all controllers/actions. While this may seem pedantic, adhering to this strict policy will pay big dividends in the future.

Consider changing to:

# config/routes.rb
resource :diffs, only: [:show]

This controller/action now becomes polymorphic in nature and can show diffs on any model with a paper_trail.

campaign = @version.reify
campaign.save
redirect_to campaign_campaign_changelogs_path(campaign)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ We should adhere to a strict REST pattern with all controllers/actions. While this may seem pedantic, adhering to this strict policy will pay big dividends in the future.

Consider changing to:

# config/routes.rb
resource :rollbacks, only: [:create]

This controller/action now becomes polymorphic in nature and can support rollbacks for any model with a paper_trail.

def set_campaign
@campaign = Campaign.find(params[:campaign_id])
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could likely have a polymorphic comments controller and a single set of views that work for any model we give acts_as_commentable_with_threading behavior to.

# config/routes.rb
resources :campaigns do
  resources :comments
end

end

def remaining_days
return 0 unless start_date.present? && end_date.present?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could reuse total_days impl here.

return 0 if total_days.zero?

return 0 if start_date > Date.current
return 100 if end_date < Date.current

((remaining_days.to_f / total_days.to_f) * 100).to_i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above about divide by zero. Note the first guard could/should be replaced with the total_days impl.

@@ -37,6 +37,7 @@ class Impression < ApplicationRecord

# callbacks .................................................................
# scopes ....................................................................
scope :clicked, -> { where.not(clicked_at: nil) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't current have an index to optimize this query. How often will we ask for only clicks vs all impressions then determining clicks from that set? Is this something we should optimize for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably

<a data-controller="remote-modal"
data-action="click->remote-modal#displayModal"
data-url="<%= diff_campaign_campaign_changelog_path(@campaign, version) %>"
href="#">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird formatting.

@@ -0,0 +1,2 @@
PaperTrail.config.enabled = true
PaperTrail.config.version_limit = 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 3 enough for version_limit? I thought we wanted to target 25.

config/routes.rb Outdated
member do
get :diff, to: "campaign_changelogs#diff"
patch :rollback, to: "campaign_changelogs#rollback"
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Non-REST violation. See other comments about this.

Copy link
Contributor

@hopsoft hopsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome. Our minds are starting to meld.

resource :campaign_targeting, only: [:show], path: "/targeting"
resource :campaign_budget, only: [:show], path: "/budget"
resources :campaign_properties, only: [:index], path: "/properties"
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These routes are beautiful.

resources :versions, only: [:index], as: :property_versions
resources :comments, only: [:index], as: :property_comments
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it.

negative_keywords: negative_keywords,
status: ["active"],
}).apply(Property.order(name: :asc))
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might rename this method to matching_properties. What do you think?

def average_ctr
0.35
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods can be replaced with my branch when it lands.

# commentable class name and commentable id.
scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
where(commentable_type: commentable_str.to_s, commentable_id: commentable_id).order("created_at DESC")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love these scopes. I'd probably remove the prefix of find_comments_ as its somewhat redundant and I think the semantics will read better.

Consider this usage:

Comment.by_user(user)
# ~vs~
Comment.find_comments_by_user(user)

Also, switch to stabby lambda -> for scopes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are gem-generated files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update it

keywords
prohibited_advertisers
prohibit_fallback_campaigns
]
Copy link
Contributor

@hopsoft hopsoft Nov 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might consider sorting these types of lists. Sorting makes the semantics worse, but it also helps speed up scanning for a value and spotting dupes in the list.

Popper: 'popper.js',
Chartist: 'Chartist',
Typed: 'Typed',
SVGInjector: 'SVGInjector',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using SVGInjector or was that experimental?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do use this. It's part of the theme.

Eric Berry added 2 commits November 28, 2018 12:34
# Conflicts:
#	app/models/impression.rb
#	db/structure.sql
@coderberry coderberry merged commit 3ba6c4a into master Nov 28, 2018
@coderberry coderberry deleted the berry/61-campaign-show branch November 28, 2018 20:45
@coderberry coderberry removed the review label Nov 28, 2018
hopsoft pushed a commit that referenced this pull request Dec 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants