ish_manager 0.1.8.327 → 0.1.8.329

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/ish_manager/application.js +2 -0
  3. data/app/assets/javascripts/ish_manager/email_contexts.js +32 -0
  4. data/app/assets/javascripts/ish_manager/{application_materialize.js → trash/application_materialize.js} +0 -0
  5. data/app/assets/javascripts/ish_manager/{materialize.js → trash/materialize.js} +0 -0
  6. data/app/assets/stylesheets/ish_manager/email_templates.scss +24 -1
  7. data/app/controllers/ish_manager/email_campaigns_controller.rb +6 -6
  8. data/app/controllers/ish_manager/email_contexts_controller.rb +28 -5
  9. data/app/controllers/ish_manager/email_templates_controller.rb +17 -0
  10. data/app/mailers/ish_manager/office_mailer.rb +82 -7
  11. data/app/views/ish_manager/application/_main_header_admin.haml +2 -3
  12. data/app/views/ish_manager/email_contexts/_form.haml +36 -11
  13. data/app/views/ish_manager/email_contexts/index.haml +4 -1
  14. data/app/views/ish_manager/email_contexts/show.haml +14 -3
  15. data/app/views/ish_manager/email_templates/_form.haml +12 -1
  16. data/app/views/ish_manager/email_templates/_form_mini.haml +9 -0
  17. data/app/views/ish_manager/email_templates/_index.haml +2 -1
  18. data/app/views/ish_manager/email_templates/{_marketing_ror_2.html → _marketing_react_1.html} +0 -0
  19. data/app/views/ish_manager/email_templates/_marketing_ror_2.html.erb +753 -0
  20. data/app/views/ish_manager/email_templates/edit.haml +2 -0
  21. data/app/views/ish_manager/email_templates/plain.html.erb +4 -0
  22. data/app/views/ish_manager/trash/email_campaigns-trash/_form.haml +46 -0
  23. data/app/views/ish_manager/trash/email_campaigns-trash/edit.haml +0 -0
  24. data/app/views/ish_manager/trash/email_campaigns-trash/index.haml +4 -0
  25. data/app/views/ish_manager/trash/email_campaigns-trash/new.haml +2 -0
  26. data/config/routes.rb +10 -8
  27. metadata +14 -6
  28. data/app/views/ish_manager/email_campaigns/index.haml +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4352bd842e1cdc92ad63259bde55833704e7366d06728a19cb40c8f3ba37e81
4
- data.tar.gz: 16b80cef890656d55899269d7f0501a963e250d504132c4c60cb49c6279a5507
3
+ metadata.gz: 168e3b80f936578509b925a3724a24455bded5f8ec0a340a9db76a02b827a11e
4
+ data.tar.gz: fafe8c1ae99e9677a8b3066410e263d8bfd762fdbf982e2216c83d652eee22cf
5
5
  SHA512:
6
- metadata.gz: 18d9fa469444b421b46d8a7f7a8fac0a48e3e7880f87c18f51b36e33ce8000b9f60301ef0f53491d7713cad2d432e3424bddca4a92614686e7d136df805790bd
7
- data.tar.gz: 1564a872717ec4fdd6076eb7697a0ed6882f566abecec082bf5e8b322fb1cf11688ed79dc590470cef1cf096db62ad6d4dce11c6e28e175cdb12cc4aaf2a0d53
6
+ metadata.gz: df33c3dc00fc249314ffeaf0c52ed075e3011ef2b0b939221f9820de50a588c5459c1fe4e3b22c4add4d8078e8ea636e010f5bffe4123e9a0411fdadf57725e1
7
+ data.tar.gz: f59723fe434089ae4e777f546514000c3b6b4fa9730710c535ff4979fe2dbbdb9c65cd6fa54314e67fc5f91959c5f4028fcfa3be42e375c73f425e5a8cd4a45d
@@ -17,7 +17,9 @@
17
17
  //= require ish_manager/vendor/jquery.fileupload
18
18
  //= require ish_manager/vendor/jquery-ui.min
19
19
  //= require ish_manager/shared
20
+ //
20
21
  //= require ish_manager/maps
22
+ //= require ish_manager/email_contexts
21
23
 
22
24
  $(function () {
23
25
 
@@ -0,0 +1,32 @@
1
+
2
+ AppRouter = {
3
+ new_email_context_with: (slug) => `/manager/email_contexts/new_with/${slug}`
4
+ }
5
+
6
+ $(document).ready(() => {
7
+
8
+ if ($(".email-contexts--form").length) {
9
+ $("#ish_email_context_email_template_id").on('change', (ev) => {
10
+ const val = ev.target.value
11
+ window.location.href = AppRouter.new_email_context_with(val)
12
+ })
13
+
14
+ $("#ish_email_context_type").on('change', (ev) => {
15
+ const val = ev.target.value
16
+ if (val == 'TYPE_CAMPAIGN') {
17
+ $(".email-contexts--form .TYPE_SINGLE").css('display', 'none')
18
+ } else {
19
+ $(".email-contexts--form .TYPE_SINGLE").css('display', 'block')
20
+ }
21
+ })
22
+ // on page load:
23
+ if ($("#ish_email_context_type").val() == 'TYPE_CAMPAIGN') {
24
+ $(".email-contexts--form .TYPE_SINGLE").css('display', 'none')
25
+ } else {
26
+ $(".email-contexts--form .TYPE_SINGLE").css('display', 'block')
27
+ }
28
+
29
+ }
30
+
31
+ })
32
+
@@ -35,7 +35,7 @@
35
35
  }
36
36
 
37
37
 
38
- .email-templates--form {
38
+ .email-templates--form-mini {
39
39
  border: 1px solid red;
40
40
  padding: 1em;
41
41
 
@@ -48,3 +48,26 @@
48
48
  }
49
49
 
50
50
  }
51
+
52
+ .email-contexts--form,
53
+ .email-templates--form {
54
+
55
+ .field-subject {
56
+ display: flex;
57
+ width: calc( 100% - 20px );
58
+
59
+ input[name='ish_email_context[subject]'],
60
+ input[name='ish_email_template[subject]'] {
61
+ margin-left: 5px;
62
+ flex-grow: 1;
63
+ }
64
+ }
65
+
66
+
67
+
68
+ .body {
69
+ border: 1px solid red;
70
+ padding: 10px;
71
+ margin: 10px;
72
+ }
73
+ }
@@ -2,8 +2,8 @@
2
2
  class ::IshManager::EmailCampaignsController < IshManager::ApplicationController
3
3
 
4
4
  def index
5
- authorize! :index, Ish::Campaign
6
- @campaigns = Ish::Campaign.where( :profile => @current_profile, :is_trash => false )
5
+ authorize! :index, Ish::EmailCampaign
6
+ @campaigns = Ish::EmailCampaign.where( :profile => @current_profile, :is_trash => false )
7
7
  if params[:is_done]
8
8
  @campaigns = @campaigns.where( :is_done => true )
9
9
  else
@@ -12,12 +12,12 @@ class ::IshManager::EmailCampaignsController < IshManager::ApplicationController
12
12
  end
13
13
 
14
14
  def new
15
- @new_campaign = Ish::Campaign.new
15
+ @new_campaign = Ish::EmailCampaign.new
16
16
  authorize! :new, @new_campaign
17
17
  end
18
18
 
19
19
  def create
20
- @campaign = Ish::Campaign.new params[:campaign].permit!
20
+ @campaign = Ish::EmailCampaign.new params[:campaign].permit!
21
21
  @campaign.profile = @current_profile
22
22
  authorize! :create, @campaign
23
23
  if @campaign.save
@@ -34,12 +34,12 @@ class ::IshManager::EmailCampaignsController < IshManager::ApplicationController
34
34
  end
35
35
 
36
36
  def edit
37
- @campaign = Ish::Campaign.find params[:id]
37
+ @campaign = Ish::EmailCampaign.find params[:id]
38
38
  authorize! :edit, @campaign
39
39
  end
40
40
 
41
41
  def update
42
- @campaign = Ish::Campaign.find params[:id]
42
+ @campaign = Ish::EmailCampaign.find params[:id]
43
43
  authorize! :update, @campaign
44
44
  if @campaign.update_attributes params[:campaign].permit!
45
45
  flash[:notice] = 'Successfully updated campaign.'
@@ -32,9 +32,17 @@ class ::IshManager::EmailContextsController < ::IshManager::ApplicationControlle
32
32
  end
33
33
 
34
34
  def do_send
35
- authorize! :send, ::Ish::EmailContext
36
- IshManager::OfficeMailer.send_context_email(params[:id]).deliver_later
37
- flash[:notice] = 'Scheduled send'
35
+ @ctx = ::Ish::EmailContext.find params[:id]
36
+ authorize! :send, @ctx
37
+ case @ctx.type
38
+ when ::Ish::EmailContext::TYPE_SINGLE
39
+ flash[:notice] = 'Scheduled a single send'
40
+ IshManager::OfficeMailer.send_context_email(params[:id]).deliver_later
41
+ when ::Ish::EmailContext::TYPE_CAMPAIGN
42
+ flash[:notice] = 'Scheduled campaign send'
43
+ IshManager::OfficeMailer.send_campaign(params[:id]).deliver_later
44
+ end
45
+
38
46
  redirect_to action: 'index'
39
47
  end
40
48
 
@@ -47,7 +55,16 @@ class ::IshManager::EmailContextsController < ::IshManager::ApplicationControlle
47
55
  @email_ctx = EmailContext.find params[:id]
48
56
  authorize! :iframe_src, @email_ctx
49
57
  @email_template = @email_ctx.email_template
50
- render 'ish_manager/email_templates/iframe_src', layout: false
58
+ case @email_template.type
59
+ when 'partial'
60
+ render 'ish_manager/email_templates/iframe_src', layout: false
61
+ return
62
+ when 'plain'
63
+ @body = @email_template.body
64
+ @body.gsub!('{name}', @email_ctx.tmpl_name)
65
+ render 'ish_manager/email_templates/plain', layout: false
66
+ return
67
+ end
51
68
  end
52
69
 
53
70
  def index
@@ -61,7 +78,13 @@ class ::IshManager::EmailContextsController < ::IshManager::ApplicationControlle
61
78
 
62
79
  def new
63
80
  authorize! :new, ::Ish::EmailContext
64
- @email_ctx = ::Ish::EmailContext.new email_template: @template
81
+ @template = Ish::EmailTemplate.where( slug: params[:template_slug] ).first
82
+ @template ||= Ish::EmailTemplate.where( id: params[:template_slug] ).first
83
+ attrs = {}
84
+ if @template
85
+ attrs = @template.attributes.slice( :subject, :body, :from_email )
86
+ end
87
+ @email_ctx = ::Ish::EmailContext.new( { email_template: @template }.merge(attrs) )
65
88
  end
66
89
 
67
90
  def show
@@ -23,6 +23,11 @@ class ::IshManager::EmailTemplatesController < ::IshManager::ApplicationControll
23
23
  redirect_to action: :index
24
24
  end
25
25
 
26
+ def edit
27
+ @template = Ish::EmailTemplate.where({ id: params[:id] }).first
28
+ authorize! :edit, @template
29
+ end
30
+
26
31
  def iframe_src
27
32
  authorize! :iframe_src, Ish::EmailTemplate
28
33
  @email_template = Ish::EmailTemplate.where({ id: params[:id] }).first ||
@@ -45,5 +50,17 @@ class ::IshManager::EmailTemplatesController < ::IshManager::ApplicationControll
45
50
  @email_ctx = EmailContext.new({ body: Ish::LoremIpsum.html })
46
51
  end
47
52
 
53
+ def update
54
+ @template = Ish::EmailTemplate.where({ id: params[:id] }).first
55
+ authorize! :update, @template
56
+ flag = @template.update_attributes( params[:ish_email_template].permit! )
57
+ if flag
58
+ flash[:notice] = 'Success.'
59
+ redirect_to action: 'index'
60
+ else
61
+ flash[:alert] = "No luck. #{@template.errors.full_messages.join(', ')}"
62
+ render :edit
63
+ end
64
+ end
48
65
 
49
66
  end
@@ -1,22 +1,97 @@
1
1
 
2
2
  class IshManager::OfficeMailer < IshManager::ApplicationMailer
3
- default from: 'piousbox@gmail.com'
4
- # layout 'mailer'
3
+
4
+ def send_campaign campaign_id
5
+ @ctx = ::Ish::EmailContext.find campaign_id
6
+ actl = ActionController::Base.new
7
+ actl.instance_variable_set( :@ctx, @ctx )
8
+
9
+ if @ctx.email_template.type != 'partial'
10
+ raise "only `partial` template type is supported for campaigns."
11
+ end
12
+
13
+ puts! @ctx.leads, '@ctx.leads'
14
+
15
+ @ctx.leads.each do |clead| # a campaign lead
16
+ @lead = clead
17
+
18
+ @pixel_tracking = {
19
+ 'v' => 1,
20
+ 'tid' => 'UA-53077236-2',
21
+ 'cid' => @lead[:cid],
22
+ 't' => 'event',
23
+ 'ec' => 'email',
24
+ 'ea' => 'open',
25
+ 'utm_source' => 'eror1',
26
+ 'utm_medium' => 'email',
27
+ 'utm_campaign' => 'eror1',
28
+ }.map { |k, v| "#{k}=#{v}" }.join("&")
29
+ actl.instance_variable_set( :@pixel_tracking, @pixel_tracking )
30
+
31
+ @click_tracking = {
32
+ 'cid' => @lead[:cid],
33
+ 't' => 'event',
34
+ 'ec' => 'email',
35
+ 'ea' => 'clk-ctct', # clicked contact us
36
+ 'utm_source' => 'eror1',
37
+ 'utm_medium' => 'email',
38
+ 'utm_campaign' => 'eror1',
39
+ }.map { |k, v| "#{k}=#{v}" }.join("&")
40
+ actl.instance_variable_set( :@click_tracking, @click_tracking )
41
+
42
+
43
+ actl.instance_variable_set( :@lead, @lead )
44
+
45
+ template = "render/_#{@ctx.email_template.slug}"
46
+ # rendered_str = actl.render_to_string("ish_manager/email_templates/_#{@ctx.email_template.slug}")
47
+ # @lead.update( rendered_str: rendered_str, sent_at: Time.now )
48
+
49
+ mail( from: @ctx.from_email,
50
+ to: @lead.email,
51
+ bcc: 'piousbox@gmail.com',
52
+ subject: @ctx.subject,
53
+ template_name: template )
54
+ end
55
+ end
5
56
 
6
57
  def send_context_email ctx_id
7
58
  @email_ctx = ::Ish::EmailContext.find ctx_id
8
- template = "render/_#{@email_ctx.email_template.slug}"
9
-
10
59
  ac = ActionController::Base.new
11
60
  ac.instance_variable_set( :@email_ctx, @email_ctx )
12
- rendered_str = ac.render_to_string("ish_manager/email_templates/_#{@email_ctx.email_template.slug}")
61
+
62
+ case @email_ctx.email_template.type
63
+ when 'partial'
64
+ template = "render/_#{@email_ctx.email_template.slug}"
65
+ rendered_str = ac.render_to_string("ish_manager/email_templates/_#{@email_ctx.email_template.slug}")
66
+ when 'plain'
67
+ @body = @email_ctx.email_template.body
68
+ @body.gsub!('{name}', @email_ctx.name)
69
+ template = "render/plain"
70
+ rendered_str = ac.render_to_string("ish_manager/email_templates/plain")
71
+ end
72
+
13
73
  @email_ctx.update( rendered_str: rendered_str, sent_at: Time.now )
14
74
 
15
- mail( to: @email_ctx.to_email,
75
+ mail( from: @email_ctx.from_email,
76
+ to: @email_ctx.to_email,
16
77
  bcc: 'piousbox@gmail.com',
17
78
  subject: @email_ctx.subject,
18
79
  template_name: template )
19
-
20
80
  end
21
81
 
22
82
  end
83
+
84
+
85
+ ## 2022-11-10 backup
86
+ # def send_context_email ctx_id
87
+ # @email_ctx = ::Ish::EmailContext.find ctx_id
88
+ # template = "render/_#{@email_ctx.email_template.slug}"
89
+ # ac = ActionController::Base.new
90
+ # ac.instance_variable_set( :@email_ctx, @email_ctx )
91
+ # rendered_str = ac.render_to_string("ish_manager/email_templates/_#{@email_ctx.email_template.slug}")
92
+ # @email_ctx.update( rendered_str: rendered_str, sent_at: Time.now )
93
+ # mail( to: @email_ctx.to_email,
94
+ # bcc: 'piousbox@gmail.com',
95
+ # subject: @email_ctx.subject,
96
+ # template_name: template )
97
+ # end
@@ -53,7 +53,7 @@
53
53
  Office
54
54
  .namespace
55
55
  %ul
56
- %li= link_to 'Leads', leads_path
56
+ %li= link_to 'Leads', '/admin/leads'
57
57
  %li
58
58
  = link_to 'Meetings', meetings_path
59
59
  = link_to '[+]', new_meeting_path
@@ -62,7 +62,6 @@
62
62
  = link_to 'Email Templates', email_templates_path
63
63
  %li
64
64
  = link_to 'Email Contexts', email_contexts_path
65
- %li
66
- = link_to 'Email Campaigns', email_campaigns_path
65
+ -# %li= link_to 'Email Campaigns', email_campaigns_path
67
66
  %hr
68
67
 
@@ -2,23 +2,48 @@
2
2
  .email-contexts--form
3
3
  %h2
4
4
  New Email Context
5
- -# with template `#{email_ctx.email_template&.slug}`
5
+ - if email_ctx.email_template
6
+ with template `#{email_ctx.email_template.slug}` type:#{email_ctx.email_template.type}.
6
7
 
7
8
  - url = %w| index new create |.include?( params[:action] ) ? email_contexts_path : email_context_path(email_ctx)
8
9
  = form_for email_ctx, url: url do |f|
9
- .field
10
- = f.label :email_template_id
11
- = f.select :email_template_id, options_for_select(@email_templates_list, selected: params[:email_template_id] || email_ctx.email_template&.id )
10
+ .row
12
11
 
13
- .field
14
- = f.label :to_email
15
- = f.text_field :to_email
16
- .field
12
+ .col.s6
13
+ .field
14
+ = f.label :email_template_id
15
+ = f.select :email_template_id, options_for_select(@email_templates_list, selected: params[:email_template_id] || email_ctx.email_template&.id )
16
+ .field
17
+ = f.label :title
18
+ = f.text_field :title
19
+
20
+ .field
21
+ = f.label :from_email
22
+ = f.select :from_email, options_for_select(Ish::EmailContext.from_email_list, selected: email_ctx.from_email)
23
+
24
+ .col.s6
25
+ .field
26
+ = f.label :type
27
+ = f.select :type, options_for_select(Ish::EmailContext.types_list, selected: email_ctx.type)
28
+ .TYPE_SINGLE
29
+ .field
30
+ = f.label :to_email
31
+ = f.text_field :to_email
32
+ %h5 Templating
33
+ .field
34
+ = f.label :tmpl_name
35
+ = f.text_field :tmpl_name
36
+
37
+ .field.field-subject
17
38
  = f.label :subject
18
39
  = f.text_field :subject
19
- .field
20
- = f.label :body
21
- = f.text_area :body, class: 'tinymce'
40
+ - if 'plain' == email_ctx.email_template&.type
41
+ .body
42
+ = raw email_ctx.email_template.body
43
+ - else
44
+ .field
45
+ = f.label :body
46
+ = f.text_area :body, class: 'tinymce'
22
47
  .actions
23
48
  .left
24
49
  = f.submit 'Preview'
@@ -19,7 +19,10 @@
19
19
  = link_to '~', edit_email_context_path(ctx)
20
20
  = link_to email_context_path(ctx) do
21
21
  view
22
+ = ctx.title
22
23
  = button_to '[x]', email_context_path(ctx), method: :delete, form_class: :inline, data: { confirm: 'Are you sure?' }
23
24
  -# = link_to 'iframe', email_context_iframe_path(ctx), target: :_blank do
24
25
 
25
- To #{ctx.to_email}: #{ctx.subject}
26
+ [ <b>tmpl:</b> #{ctx.email_template.slug} ]
27
+ [ <b>To:</b> #{ctx.to_email} ]
28
+ <u>#{ctx.subject}</u>
@@ -2,9 +2,20 @@
2
2
  .email-contexts-show
3
3
 
4
4
  %ul
5
- %li <b>To:</b> #{@email_ctx.to_email}
6
- %li <b>Subject:</b> #{@email_ctx.subject}
5
+
6
+ %li <b>Type:</b> #{@email_ctx.type}
7
+ %li <b>Title:</b> #{@email_ctx.title}
7
8
  %li <b>Template:</b> #{@email_ctx.email_template.slug}
9
+ %li <b>From:</b> #{@email_ctx.from_email}
10
+
11
+ %li <b>Subject:</b> #{@email_ctx.subject}
12
+
13
+ - if @email_ctx.type == Ish::EmailContext::TYPE_SINGLE
14
+ %li <b>To:</b> #{@email_ctx.to_email}
15
+ %li <b>Template:</b> #{@email_ctx.email_template.slug} <b>Type:</b> #{@email_ctx.email_template.type}
16
+ - if @email_ctx.type == Ish::EmailContext::TYPE_CAMPAIGN
17
+ %li <b>Leads (#{@email_ctx.leads.length}):</b> #{@email_ctx.leads.map { |p| p&.email }.join(", ") }
18
+
8
19
  - if @email_ctx.sent_at
9
20
  %li <b>Sent at:</b> #{@email_ctx.sent_at.strftime('%Y-%m-%d %l:%M%P')}
10
21
  - else
@@ -13,6 +24,6 @@
13
24
  = link_to '[~]', edit_email_context_path(@email_ctx)
14
25
 
15
26
  - if @email_ctx.sent_at
16
- =raw @email_ctx.rendered_str
27
+ = raw @email_ctx.rendered_str
17
28
  - else
18
29
  %iframe{ src: email_context_iframe_path(@email_ctx), width: '100%', height: '100%' }
@@ -3,9 +3,20 @@
3
3
 
4
4
  .email-templates--form
5
5
  = form_for email_template, url: url do |f|
6
- %h3 New Email Template
6
+ .field
7
+ = f.label :type
8
+ = f.select :type, options_for_select(Ish::EmailTemplate.type_list, selected: email_template.type)
7
9
  .field
8
10
  = f.label :slug
9
11
  = f.text_field :slug
12
+ .field
13
+ = f.label :from_email
14
+ = f.select :from_email, options_for_select(Ish::EmailContext.from_email_list, selected: email_template.from_email)
15
+ .field.field-subject
16
+ = f.label :subject
17
+ = f.text_field :subject
18
+ .field
19
+ = f.label :body
20
+ = f.text_area :body, class: 'tinymce'
10
21
  .actions
11
22
  = f.submit 'Submit'
@@ -0,0 +1,9 @@
1
+
2
+ .email-templates--form-mini
3
+ = form_for ::Ish::EmailTemplate.new, url: email_templates_path do |f|
4
+ %h3 New Email Template
5
+ .field
6
+ = f.label :slug
7
+ = f.text_field :slug
8
+ .actions
9
+ = f.submit 'Create'
@@ -3,11 +3,12 @@
3
3
  Email Templates
4
4
  .email-templates-index
5
5
 
6
- = render 'ish_manager/email_templates/form', email_template: ::Ish::EmailTemplate.new
6
+ = render 'ish_manager/email_templates/form_mini'
7
7
  %ul
8
8
  - @templates.each do |tmpl|
9
9
  %li
10
10
  = link_to 'Use', new_email_context_path({ email_template_id: tmpl.id })
11
+ = link_to 'Edit', edit_email_template_path({ id: tmpl })
11
12
  = link_to 'View', email_template_path({ id: tmpl })
12
13
  = link_to 'iFrame', email_template_iframe_path({ id: tmpl }), target: :_blank
13
14
  = tmpl.slug