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

Commit 9864c7e

Browse files
author
Eric Berry
authored
Campaigns CRUD (#53)
1 parent fa47003 commit 9864c7e

31 files changed

+488
-162
lines changed

app/controllers/campaign_searches_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def campaign_search_params
1818
:name,
1919
:us_hours_only,
2020
:user,
21+
:user_id,
2122
:weekdays_only,
2223
countries: [],
2324
keywords: [],

app/controllers/campaigns_controller.rb

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class CampaignsController < ApplicationController
2+
include Sortable
3+
24
before_action :authenticate_user!
35
before_action :set_campaign_search, only: [:index]
46
before_action :set_campaign, only: [:show, :edit, :update, :destroy]
@@ -7,7 +9,7 @@ class CampaignsController < ApplicationController
79
# GET /campaigns
810
# GET /campaigns.json
911
def index
10-
campaigns = Campaign.order(:name).includes(:user, :creative)
12+
campaigns = Campaign.order(order_by).includes(:user, :creative)
1113
campaigns = campaigns.where(user: @user) if @user
1214
campaigns = @campaign_search.apply(campaigns)
1315
@pagy, @campaigns = pagy(campaigns)
@@ -22,7 +24,7 @@ def show
2224

2325
# GET /campaigns/new
2426
def new
25-
@campaign = Campaign.new
27+
@campaign = current_user.campaigns.build(status: "pending")
2628
end
2729

2830
# GET /campaigns/1/edit
@@ -92,6 +94,32 @@ def set_user
9294

9395
# Never trust parameters from the scary internet, only allow the white list through.
9496
def campaign_params
95-
params.fetch(:campaign, {})
97+
params.require(:campaign).permit(
98+
:user_id,
99+
:status,
100+
:name,
101+
:date_range,
102+
:url,
103+
:creative_id,
104+
:us_hours_only,
105+
:weekdays_only,
106+
:ecpm,
107+
:daily_budget,
108+
:total_budget,
109+
countries: [],
110+
keywords: [],
111+
negative_keywords: []
112+
)
113+
end
114+
115+
def sortable_columns
116+
%w[
117+
name
118+
end_date
119+
total_budget_cents
120+
status
121+
created_at
122+
user.first_name
123+
]
96124
end
97125
end

app/helpers/campaigns_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def campaign_statuses_for_select
99
ENUMS::CAMPAIGN_STATUSES.values
1010
end
1111

12+
def campaign_status_color(status)
13+
ENUMS::CAMPAIGN_STATUS_COLORS[status]
14+
end
15+
1216
def campaign_status_html(status)
1317
case ENUMS::CAMPAIGN_STATUSES[status]
1418
when "active" then tag.span(class: "fas fa-circle text-success", title: "Active", data: tooltip_expando(placement: "left"))

app/inputs/currency_input.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class CurrencyInput < SimpleForm::Inputs::Base
2+
def input(wrapper_options)
3+
currency = options.delete(:currency) || default_currency
4+
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
5+
6+
content_tag(:div, input_group(currency, merged_input_options), class: "input-group")
7+
end
8+
9+
private
10+
11+
def input_group(currency, merged_input_options)
12+
"#{currency_addon(currency)} #{@builder.text_field(attribute_name, merged_input_options)}".html_safe
13+
end
14+
15+
def currency_addon(currency)
16+
content_tag(:span, content_tag(:span, currency, class: "input-group-text"), class: "input-group-prepend")
17+
end
18+
19+
def default_currency
20+
"$"
21+
end
22+
end

app/javascript/src/app/controllers/select_date_range_controller.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
// Our use of it here is simply because its already a dependency
33
// The verbose use of the `jQuery` variable instead of `$` is intentional so its use is easier to identify
44
import { Controller } from 'stimulus';
5+
import moment from 'moment';
56

67
export default class extends Controller {
78
connect() {
8-
jQuery(this.element).flatpickr({
9-
mode: 'range',
10-
dateFormat: 'M, d Y',
11-
minDate: this.defaultStartDate,
12-
defaultDate: [this.defaultStartDate, this.defaultEndDate],
9+
jQuery(this.element).daterangepicker({
10+
ranges: {
11+
'Next 30 Days': [moment(), moment().add(29, 'days')],
12+
'Next 60 Days': [moment(), moment().add(59, 'days')],
13+
'Next 90 Days': [moment(), moment().add(89, 'days')],
14+
'This Month': [moment().startOf('month'), moment().endOf('month')],
15+
'Next Month': [
16+
moment()
17+
.add(1, 'month')
18+
.startOf('month'),
19+
moment()
20+
.add(1, 'month')
21+
.endOf('month'),
22+
],
23+
},
1324
});
1425
}
15-
16-
get defaultStartDate() {
17-
return new Date();
18-
}
19-
20-
get defaultEndDate() {
21-
let d = new Date();
22-
d.setDate(d.getDate() + 30);
23-
return d;
24-
}
2526
}

app/javascript/src/app/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import './stylesheets/application.scss';
22
import './theme';
33
import 'select2';
4+
import 'moment';
5+
import 'bootstrap-daterangepicker';
6+
47
import { Application } from 'stimulus';
58
import { definitionsFromContext } from 'stimulus/webpack-helpers';
69

app/javascript/src/app/stylesheets/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import '~select2-bootstrap-theme/dist/select2-bootstrap';
33
@import "~noty/src/noty";
44
@import "~noty/src/themes/mint";
5+
@import "~bootstrap-daterangepicker/daterangepicker";
56
@import 'theme';
67
@import 'components';
78
@import 'utilities';

app/javascript/src/app/stylesheets/components.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,16 @@ th[scope=col] a {
122122
position: relative !important;
123123
display: inline-block !important;
124124
font-size: .875rem !important;
125-
color: #77838f !important;
126-
background: rgba(119, 131, 143, 0.1) !important;
125+
color: #ffffff !important;
126+
background: rgba(44, 127, 210, 0.66) !important;
127127
border-radius: 0.25rem !important;
128128
border: none !important;
129129
padding: .25rem .75rem !important;
130130
margin: 0 0 .25rem .25rem !important;
131131

132132
.select2-selection__choice__remove {
133133
margin-right: 6px !important;
134+
color: #ffffff !important;
134135
}
135136
}
136137
}

app/javascript/src/app/stylesheets/theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
@import '~theme/vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar';
44
@import '~theme/vendor/fancybox/jquery.fancybox';
55
@import '~theme/vendor/slick-carousel/slick/slick';
6+
@import '~theme/vendor/flatpickr/dist/flatpickr.min';
7+
@import '~theme/vendor/bootstrap-select/dist/css/bootstrap-select.min';
68
@import '~theme/include/scss/theme';

app/javascript/src/app/theme.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// theme vendored scripts
22
import 'theme/vendor/bootstrap/bootstrap.min';
33
import 'theme/vendor/appear';
4-
import 'theme/vendor/flatpickr/dist/flatpickr';
54
import 'theme/vendor/bootstrap-select/dist/js/bootstrap-select';
65
import 'theme/vendor/hs-megamenu/src/hs.megamenu';
76
import 'theme/vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min';
@@ -29,7 +28,6 @@ import 'theme/js/components/hs.show-animation';
2928
import 'theme/js/components/hs.go-to';
3029
import 'theme/js/components/hs.sticky-block';
3130
import 'theme/js/components/hs.scroll-nav';
32-
// import "theme/js/components/hs.summernote-editor";
3331
import 'theme/js/components/hs.chartist-area-chart';
3432
import 'theme/js/components/hs.chartist-bar-chart';
3533
import 'theme/js/components/hs.focus-state';
@@ -46,7 +44,6 @@ document.addEventListener('turbolinks:load', () => {
4644
jQuery.HSCore.components.HSFancyBox.init('.js-fancybox');
4745
jQuery.HSCore.components.HSSlickCarousel.init('.js-slick-carousel');
4846
jQuery.HSCore.components.HSValidation.init('.js-validate');
49-
// jQuery.HSCore.components.HSSummernoteEditor.init(".js-summernote-editor");
5047
jQuery.HSCore.components.HSFocusState.init();
5148

5249
// initialization of HSMegaMenu component

0 commit comments

Comments
 (0)