Skip to content

Commit

Permalink
Merge pull request #5 from digitaltom/email
Browse files Browse the repository at this point in the history
Implement sending picture sets by email
  • Loading branch information
digitaltom committed Jun 11, 2018
2 parents bfef5c4 + 9851f36 commit e6ab008
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 17 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![Build Status](https://travis-ci.org/digitaltom/photobooth.png?branch=master)](https://travis-ci.org/digitaltom/photobooth)
[![Dependency Status](https://gemnasium.com/digitaltom/photobooth.svg)](https://gemnasium.com/digitaltom/photobooth)
[![Code Climate](https://codeclimate.com/github/digitaltom/photobooth.png)](https://codeclimate.com/github/digitaltom/photobooth)
[![Coverage Status](https://coveralls.io/repos/github/digitaltom/photobooth/badge.svg?branch=master)](https://coveralls.io/github/digitaltom/photobooth?branch=master)

Expand Down
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('config/application', __dir__)

Rails.application.load_tasks
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ photoBoothApp.controller('PictureSetCtrl', [

$log.log('$routeParams.pictureSetId: ' + $routeParams.pictureSetId)
$scope.pictureSetId = $routeParams.pictureSetId;
$scope.emailFormData = {}

$scope.loadPictureSet = function () {
$http({
Expand All @@ -34,9 +35,21 @@ photoBoothApp.controller('PictureSetCtrl', [
});
};

$scope.send_email = function() {
$http({
method: 'POST',
data: $scope.emailFormData,
url: '/picture_sets/'+ $routeParams.pictureSetId + '/emails'
}).then(function successCallback(response) {
$scope.alerts.push({type: 'success', msg: 'Successfully sent email to ' + $scope.emailFormData.email});
$location.path( '/' );
}, function errorCallback(response) {
$rootScope.alerts.push({type: 'error', msg: response.data.error});
});
};

$scope.loadPictureSet()

$scope.rw = (location.search != '?rw/');

}]);

4 changes: 4 additions & 0 deletions app/assets/javascripts/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ photoBoothApp.config(['$routeProvider',
templateUrl: '<%= asset_path('picture_set_gallery.html') %>',
controller: 'PictureSetCtrl'
}).
when('/picture_set/:pictureSetId/email', {
templateUrl: '<%= asset_path('picture_set_email.html') %>',
controller: 'PictureSetCtrl'
}).
otherwise({
redirectTo: '/'
});
Expand Down
5 changes: 4 additions & 1 deletion app/assets/templates/picture_set.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
%b Last <

#button-all
%a.btn.btn-default.btn-lg{ 'ng-href' => "#/picture_set/{{picture_set.date}}/email" }
%b Send per email
%br
%a.btn.btn-default.btn-lg{ 'ng-href' => "#/picture_set/{{picture_set.date}}/gallery" }
%b All pictures
%b Single pictures

#button-delete{ 'ng-hide' => 'rw' }
%button.btn.btn-default.btn-sm{ 'ng-click' => 'destroy()'}
Expand Down
20 changes: 20 additions & 0 deletions app/assets/templates/picture_set_email.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.container.mail-container
.row
.col-sm-12
%p.lead.text-center
Get your picture send to you immediately:
.row
.col-sm-10
%form.center-block
.form-group
%input.input-lg.form-control#email{ 'ng-model' => 'emailFormData.email', 'type' => 'email', 'placeholder' => 'Email', 'size' => '20' }
.col-sm-2
%a.btn.btn-default.btn-lg{ 'ng-click' => "send_email()" }
%b Send email
.row
.col-sm-12
%img.img-responsive.center-block{'ng-src'=>'/{{picture_set.path}}/{{picture_set.animation}}'}

.row.text-center
%a.btn.btn-default.btn-lg{ 'ng-href' => "#/picture_set/{{picture_set.date}}" }
%b Back
8 changes: 5 additions & 3 deletions app/assets/templates/picture_set_gallery.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
.row
.col-lg-3.col-md-4.col-xs-6.thumb{ 'ng-repeat' => 'picture in picture_set.pictures'}
%a.thumbnail{ 'ng-href' => "{{picture_set.path}}/{{picture.full}}" }
%img.img-responsive{ style: 'width:400px;', src: "{{picture_set.path}}/{{picture.full}}", alt: "" }
%img.img-responsive{ style: 'width:400px;', src: "{{picture_set.path}}/{{picture.polaroid}}", alt: "" }
.col-lg-3.col-md-4.col-xs-6.thumb
%a.thumbnail{ 'ng-href' => "{{picture_set.path}}/{{picture_set.combined}}" }
%img.img-responsive{ style: 'width:400px;', 'ng-src' => "{{picture_set.path}}/{{picture_set.combined}}", alt: "" }
.row
.row.text-center
%a.btn.btn-default.btn-lg{ 'ng-href' => "#/picture_set/{{picture_set.date}}" }
%b Back
%b Back
%a.btn.btn-default.btn-lg{ 'ng-href' => "#/picture_set/{{picture_set.date}}/email" }
%b Send per email
12 changes: 12 additions & 0 deletions app/controllers/picture_sets/emails_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module PictureSets
class EmailsController < ApplicationController

def create
picture_set = PictureSet.find(params[:picture_set_id])
Thread.new do
::PictureSetMailer.image_email(params[:email], picture_set).deliver_now
end
render json: ''
end
end
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: OPTS.mail_settings['from']
layout 'mailer'
end
13 changes: 13 additions & 0 deletions app/mailers/picture_set_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class PictureSetMailer < ApplicationMailer

def image_email(email, picture_set)
image_path = Rails.root.join('public', picture_set[:path])
attachments.inline['animation.gif'] = File.read(File.join(image_path, picture_set[:animation]))
if File.exist?(File.join(image_path, picture_set[:combined]))
attachments.inline['combined.jpg'] = File.read(File.join(image_path, picture_set[:combined]))
end
I18n.with_locale(OPTS.locale) do
mail(to: email, subject: I18n.t('picture_set_mailer.image_email.subject', name: OPTS.image_caption))
end
end
end
4 changes: 2 additions & 2 deletions app/models/picture_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def destroy(date)

def combine_images(date, dir)
Thread.new do
Syscall.execute("time montage -geometry '25%x25%+25+25<' -background '#{OPTS.combined_image_bgcolor}' " \
"-title '#{OPTS.image_caption}' -font '#{OPTS.image_font}' -fill 'white' " \
Syscall.execute("time montage -geometry '25%x25%+25+25<' -background '#{OPTS.background_color}' " \
"-title '#{OPTS.image_caption}' -font '#{OPTS.font}' -fill '#{OPTS.font_color}' " \
"-pointsize #{OPTS.combined_image_fontsize} -gravity 'Center' #{date}_*.jpg #{date}#{COMBINED_SUFFIX}",
dir: dir)
end
Expand Down
6 changes: 6 additions & 0 deletions app/views/layouts/mailer.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
!!!
%html
%head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%body{ 'style' => "background-color: #{OPTS.background_color};" }
= yield
12 changes: 12 additions & 0 deletions app/views/picture_set_mailer/image_email.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%div{ 'style' => "text-align: center; color: #{OPTS.font_color};" }
%h1
= t('.header', name: OPTS.image_caption)
%p
= t('.content')
%p
= t('.greeting')
%p
= image_tag attachments['animation.gif'].url
- if attachments.inline['combined.jpg']
%p
= image_tag attachments['combined.jpg'].url
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Application < Rails::Application

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
I18n.config.available_locales = %i[en de]
end
end

Expand Down
18 changes: 15 additions & 3 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

Expand All @@ -38,4 +35,19 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.logger = nil
config.action_mailer.smtp_settings = {
address: OPTS.mail_settings['address'],
port: OPTS.mail_settings['port'],
user_name: OPTS.mail_settings['user_name'],
password: OPTS.mail_settings['password'],
authentication: OPTS.mail_settings['authentication'],
enable_starttls_auto: OPTS.mail_settings['enable_starttls_auto']
}

end
9 changes: 9 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: OPTS.mail_settings['address'],
port: OPTS.mail_settings['port'],
user_name: OPTS.mail_settings['user_name'],
password: OPTS.mail_settings['password'],
authentication: OPTS.mail_settings['authentication'],
enable_starttls_auto: OPTS.mail_settings['enable_starttls_auto']
}
end
28 changes: 28 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.

de:
picture_set_mailer:
image_email:
subject: "Deine Photobox Bilder von '%{name}'"
header: 'Viele Grüße von %{name}'
content: 'Wir hoffen du hattest eine ebenso unvergessliche Zeit wie wir. Vier dieser einmaligen Momente haben wir für dich festgehalten. Hier sind deine Erinnerungsstücke!'
greeting: 'Viel Spaß!'
7 changes: 6 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
# available at http://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
picture_set_mailer:
image_email:
subject: "Your Photobox picture from '%{name}'"
header: 'Kind regards from %{name}'
content: 'We hope you also had an amazing time. Four of these unforgettable memories are attached to this email.'
greeting: 'Have fun!'
16 changes: 13 additions & 3 deletions config/options.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
default:
image_caption: 'Photobooth'
image_font: 'LMMonoCaps10-Regular'
image_fontsize: 11
font: 'LMMonoCaps10-Regular'
font_color: '#1995AD'
background_color: '#f1f1f2'
combined_image_fontsize: 48
locale: :de # available :en, :de

combined_image_fontsize: 72
combined_image_bgcolor: 'LightCoral'
mail_settings:
from: ''
address: ''
port: 587
user_name: ''
password: ''
authentication: 'plain'
enable_starttls_auto: true

dropbox:
# raspi photobooth dropbox app:
Expand Down
7 changes: 5 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

root 'application#index'

resources :picture_sets, only: %i[index show create destroy]

resources :picture_sets, only: %i[index show create destroy] do
scope module: :picture_sets do
resources :emails, only: :create
end
end
end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e6ab008

Please sign in to comment.