diff --git a/Gemfile b/Gemfile index 872327f..807cce6 100644 --- a/Gemfile +++ b/Gemfile @@ -14,9 +14,15 @@ gem 'coffee-rails', '~> 4.1.0' # Integrate Paperclip into Mongoid. gem 'mongoid-paperclip' +# Markdown rendering +gem 'redcarpet' + # Stripe integration gem 'stripe' +# Render your navigation as HTML list, link list or breadcrumbs. +gem 'simple-navigation' + # To extend paperclip with locales gem 'paperclip-i18n' @@ -37,9 +43,6 @@ gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc -# Easily generate a Twitter Bootstrap navbar in your Rails app -gem 'rails_bootstrap_navbar' - # Kaminari Mongoid adapter. gem 'kaminari-mongoid' gem 'kaminari-actionview' diff --git a/Gemfile.lock b/Gemfile.lock index 0e548cc..194156d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,8 +52,6 @@ GEM benchmark-ips (2.7.2) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) - bootstrap-navbar (2.5.0) - gem_config (~> 0.3) bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) @@ -114,7 +112,6 @@ GEM ffi (1.9.18) font-awesome-rails (4.7.0.2) railties (>= 3.2, < 5.2) - gem_config (0.3.1) geocoder (1.4.4) get_process_mem (0.2.1) globalid (0.4.0) @@ -251,9 +248,6 @@ GEM rails (>= 4.0, < 6) remotipart (~> 1.3) sass-rails (>= 4.0, < 6) - rails_bootstrap_navbar (2.0.1) - bootstrap-navbar (~> 2.0) - rails (>= 3.0.0) rails_serve_static_assets (0.0.5) rails_stdout_logging (0.0.5) railties (4.2.10) @@ -266,6 +260,7 @@ GEM rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) rdoc (4.3.0) + redcarpet (3.4.0) remotipart (1.3.1) responders (2.4.0) actionpack (>= 4.2.0, < 5.3) @@ -314,6 +309,8 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simple-navigation (4.0.5) + activesupport (>= 2.3.2) simple_form (3.5.0) actionpack (> 4, < 5.2) activemodel (> 4, < 5.2) @@ -384,12 +381,13 @@ DEPENDENCIES rails-i18n rails_12factor rails_admin - rails_bootstrap_navbar + redcarpet roadie-rails (~> 1.0) route_translator rspec-rails (~> 3.0) sass-rails (~> 5.0) sdoc (~> 0.4.0) + simple-navigation simple_form slim slim-rails @@ -402,4 +400,4 @@ RUBY VERSION ruby 2.3.1p112 BUNDLED WITH - 1.14.6 + 1.16.0 diff --git a/app/assets/javascripts/greendays.coffee b/app/assets/javascripts/greendays.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/greendays.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/application.sass b/app/assets/stylesheets/application.sass index a227ef1..424b669 100644 --- a/app/assets/stylesheets/application.sass +++ b/app/assets/stylesheets/application.sass @@ -20,6 +20,17 @@ @import "footnotes" @import "statements" @import "donations" +@import "nav" + +*:focus + outline: 0 + -webkit-box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px red + box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px red + +.form-control:focus, input:focus + outline: 0 + -webkit-box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px $brand-success + box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.075), 0 0 8px $brand-success .alert-alert @extend .alert-danger @@ -58,6 +69,12 @@ body .container padding-left: 0px + header > .row + margin-bottom: 12px + + main > h1 + margin-top: 0px + ul#topnav font-size: 1.2em @@ -135,4 +152,7 @@ body a color: #FFF - \ No newline at end of file +.row.fix + display: flex + flex-wrap: wrap + width: 100% diff --git a/app/assets/stylesheets/greendays.sass b/app/assets/stylesheets/greendays.sass new file mode 100644 index 0000000..38a26c0 --- /dev/null +++ b/app/assets/stylesheets/greendays.sass @@ -0,0 +1,14 @@ +// Place all the styles related to the Greendays controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.well > h2 + margin-top: 0px + +#map + width: 100% + height: 300px + margin-bottom: 12px + +.col-lg-4 + width: 32% !important \ No newline at end of file diff --git a/app/assets/stylesheets/nav.sass b/app/assets/stylesheets/nav.sass new file mode 100644 index 0000000..a2549fe --- /dev/null +++ b/app/assets/stylesheets/nav.sass @@ -0,0 +1,34 @@ +@import "variables" + +nav#mainnav + marign-top: 12px + font-size: 16pt + + a + color: $brand-success + + a.selected + font-weight: bold + + + ul + list-style: none + padding: 0px + + li + padding: 5px 5px 5px 10px + + ul + padding-left: 20px + + li + font-size: 12pt + + li.selected + background-color: $brand-success + a + color: white + + #greendays + margin-bottom: 12px + border: 1px solid $brand-success \ No newline at end of file diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..4932c1f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,30 @@ +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/app/assets/stylesheets/variables.sass b/app/assets/stylesheets/variables.sass index f7edb05..4552e82 100644 --- a/app/assets/stylesheets/variables.sass +++ b/app/assets/stylesheets/variables.sass @@ -1,4 +1,4 @@ -$brand-success: #66903F +$brand-success: #4b7d1c $navbar-default-bg: #FFF $navbar-default-border: none $font-size-base: 14px diff --git a/app/controllers/greendays_controller.rb b/app/controllers/greendays_controller.rb new file mode 100644 index 0000000..b49e929 --- /dev/null +++ b/app/controllers/greendays_controller.rb @@ -0,0 +1,65 @@ +class GreendaysController < ApplicationController + before_action :only_admin, except: [:index, :show] + before_action :set_greenday, only: [:show, :edit, :update, :destroy] + + def index + @greendays = Greenday.all.sort(title: 1) + end + + def new + @greenday = Greenday.new + end + + def edit; end + + def create + @greenday = Greenday.new(greenday_params) + + respond_to do |format| + if @greenday.save + format.html { redirect_to greendays_path, success: 'Greenday was successfully created.' } + format.json { render :show, status: :created, location: @greenday } + else + format.html { render :new } + format.json { render json: @greenday.errors, status: :unprocessable_entity } + end + end + end + + def update + respond_to do |format| + if @greenday.update(greenday_params) + format.html { redirect_to greendays_path, notice: 'Greenday was successfully updated.' } + format.json { render :show, status: :ok, location: @greenday } + else + format.html { render :edit } + format.json { render json: @greenday.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @greenday.destroy + respond_to do |format| + format.html { redirect_to greendays_path, notice: 'Greenday was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_greenday + @greenday = Greenday.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def greenday_params + params.require(:greenday).permit(:title, :address, :homepage, :description, :logo, :delete_logo) + end + + def only_admin + return true if current_supporter && current_supporter.admin? + raise ActionController::RoutingError, 'Not Found' + end +end diff --git a/app/controllers/supporters_controller.rb b/app/controllers/supporters_controller.rb index 3ebdbee..2cbb11c 100644 --- a/app/controllers/supporters_controller.rb +++ b/app/controllers/supporters_controller.rb @@ -21,7 +21,7 @@ class SupportersController < ApplicationController private def supporter_form_params - params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments) + params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments, :tel) end # We use sendy for newsletters atm diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 63f80ea..1c47532 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,4 +3,13 @@ module ApplicationHelper content_for :title, strip_tags(page_title.to_s) page_title end + + def markdown(content) + @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true) + @markdown.render(content) + end + + def admin? + current_supporter && current_supporter.admin? + end end diff --git a/app/models/greenday.rb b/app/models/greenday.rb new file mode 100644 index 0000000..197616e --- /dev/null +++ b/app/models/greenday.rb @@ -0,0 +1,43 @@ +class Greenday + include Mongoid::Document + include Mongoid::Timestamps + include Geocoder::Model::Mongoid + include Mongoid::Paperclip + + before_save :delete_logo? + + has_mongoid_attached_file :logo, + path: ':attachment/:id/:style.:extension', + styles: { + original: ['1920x1680>', :jpg], + small: ['100x100#', :jpg], + medium: ['250x250', :jpg], + large: ['500x500>', :jpg] + }, + convert_options: { all: '-background white -flatten +matte' } + + field :title, type: String + field :address, type: String + field :homepage, type: String + field :description, type: String + field :coordinates, type: Array + + geocoded_by :address + after_validation :geocode # auto-fetch coordinates + + validates :title, presence: true + validates :address, presence: true + validates_attachment_content_type :logo, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'] + + def delete_logo + @delete_logo ||= '0' + end + + attr_writer :delete_logo + + private + + def delete_logo? + logo.clear if @delete_logo == '1' + end +end diff --git a/app/models/supporter.rb b/app/models/supporter.rb index 34abd97..141f4f5 100644 --- a/app/models/supporter.rb +++ b/app/models/supporter.rb @@ -45,6 +45,7 @@ class Supporter field :comments, type: String field :language, type: String field :duplicate, type: Boolean, default: false + field :tel, type: String validates :first_name, presence: true validates :last_name, presence: true diff --git a/app/views/greendays/_description.de.slim b/app/views/greendays/_description.de.slim new file mode 100644 index 0000000..c14b047 --- /dev/null +++ b/app/views/greendays/_description.de.slim @@ -0,0 +1,4 @@ +b Am 23. November ist Nationaler CBD-Tag! +p Um die #{link_to 'Finanzierung der Sammlung und Beglaubigung', donation_path} der eidgenössischen #{link_to 'Volksinitiative zur Cannabislegalisierung', initiative_text_path} in der Schweiz voranzutreiben, lanciert der Verein Legalize it! in Zusammenarbeit mit dem #{link_to 'Branchenverband IG Hanf', 'https://www.ighanf.ch/D_about.html', target: '_blank'} am 23. November 2017 den ersten nationalen CBD-Tag. +p An diesem Tag gibt es in zahlreichen CBD-Läden 10 Prozent Rabatt auf ausgewählte CBD-Produkte. In jedem Laden steht eine Spendenbox, welche für Spenden für die Initiative benutzt werden kann und die dem Verein Legalize it! zugute kommt. +p Welche Läden mitmachen, seht ihr auf der Karte: \ No newline at end of file diff --git a/app/views/greendays/_form.html.slim b/app/views/greendays/_form.html.slim new file mode 100644 index 0000000..a070085 --- /dev/null +++ b/app/views/greendays/_form.html.slim @@ -0,0 +1,14 @@ += simple_form_for(@greenday) do |f| + = f.error_notification + + .form-inputs + = f.input :title + = f.input :address, as: :text + = f.input :homepage + = f.input :description, as: :text + = f.input :logo, as: :file, required: false + = image_tag f.object.logo.url(:original), alt: '', class: 'img-responsive' + = f.input :delete_logo, as: :boolean + + .form-actions + = f.button :submit, 'Shop speichern' diff --git a/app/views/greendays/_greenday.json.jbuilder b/app/views/greendays/_greenday.json.jbuilder new file mode 100644 index 0000000..d741703 --- /dev/null +++ b/app/views/greendays/_greenday.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! greenday, :id, :title, :address, :coordinates, :homepage, :logo, :description, :created_at, :updated_at +json.url greenday_url(greenday, format: :json) diff --git a/app/views/greendays/edit.html.slim b/app/views/greendays/edit.html.slim new file mode 100644 index 0000000..007d026 --- /dev/null +++ b/app/views/greendays/edit.html.slim @@ -0,0 +1,8 @@ +h1 Editing greenday + +== render 'form' + += link_to 'Show', @greenday +' | += link_to 'Back', greendays_path + diff --git a/app/views/greendays/index.html.slim b/app/views/greendays/index.html.slim new file mode 100644 index 0000000..d39b420 --- /dev/null +++ b/app/views/greendays/index.html.slim @@ -0,0 +1,69 @@ + +h1.sr-only = title 'Gründonnerstag' += render 'description' +#map += link_to 'Neuen Shop erfassen', new_greenday_path if admin? + +.row.fix + - @greendays.each do |greenday| + .col-xs-12.col-sm-6.col-lg-4 + .well + h2 = greenday.title + - if greenday.logo.url(:original) != '/logos/original/missing.png' + = image_tag greenday.logo.url(:original), alt: '', class: 'img-responsive' + address = simple_format(greenday.address) + - if greenday.homepage + = link_to(greenday.homepage, greenday.homepage, target: "_blank") + p = markdown(greenday.description).html_safe + + - if admin? + = link_to 'Bearbeiten', edit_greenday_path(greenday) + |   + = link_to 'Löschen', greenday, data: { confirm: 'Are you sure?' }, method: :delete + +javascript: + function initMap() { + + var map = new google.maps.Map(document.getElementById('map'), { + zoom: 8, center: {lat: 47.242, lng: 8.133}, + }); + + var greendays_url = "#{greendays_url(format: :json)}" + + var infowindow = new google.maps.InfoWindow({ + content: '', + maxWidth: 200 + }); + + + $.getJSON(greendays_url, function(json) { + $.each(json, function(key, data) { + var marker = new google.maps.Marker({ + position: {lat: data.coordinates[1], lng: data.coordinates[0] }, + map: map, + title: data.title + }); + + marker.addListener('click', function() { + infowindow.open(map, marker); + + var content = '' + data.title + '' + if(data.logo) { + content += '' + } + content += '
' + data.address.replace(/\n/g,"
") + if(data.homepage) { + content += '
' +data.homepage + '' + } + content += '
' + + if(data.description) { + content += '

' + data.description + '

' + } + infowindow.setContent(content); + }); + }); + }); + } + +script async="" defer="" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBbwMtGKDqf4i8x9-OVP1-H_QVAKp92h2M&callback=initMap&libraries=visualization" \ No newline at end of file diff --git a/app/views/greendays/index.json.jbuilder b/app/views/greendays/index.json.jbuilder new file mode 100644 index 0000000..30d440e --- /dev/null +++ b/app/views/greendays/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @greendays, partial: 'greendays/greenday', as: :greenday diff --git a/app/views/greendays/new.html.slim b/app/views/greendays/new.html.slim new file mode 100644 index 0000000..7e340d3 --- /dev/null +++ b/app/views/greendays/new.html.slim @@ -0,0 +1,5 @@ +h1 New greenday + +== render 'form' + += link_to 'Back', greendays_path diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 12620e2..9bf2df7 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -65,8 +65,11 @@ html lang="#{I18n.locale}" .container.content = render 'shared/flashes' = render 'shared/header' - = render 'shared/topnavigation' - = yield + .row + .col-xs-12.col-sm-3 + nav#mainnav = render_navigation + .col-xs-12.col-sm-9 + main= yield hr footer.row .col-xs-12.col-sm-6 diff --git a/app/views/shared/_topnavigation.slim b/app/views/shared/_topnavigation.slim deleted file mode 100644 index d9268dc..0000000 --- a/app/views/shared/_topnavigation.slim +++ /dev/null @@ -1,19 +0,0 @@ -= navbar do - = navbar_header - = navbar_collapse do - = navbar_group id: 'topnav' do - = navbar_item "Home", "/#{I18n.locale}" - = navbar_dropdown t('.initiative') do - = navbar_item t('.initiative_text'), initiative_text_path - = navbar_item t('.arguments'), arguments_path - = navbar_item t('.faq'), faq_path - = navbar_item t('.numbers'), numbers_path - = navbar_item t('.collection_concept'), collection_concept_path - = navbar_item t('.statements'), statements_path - = navbar_item t('donation'), donation_path - = navbar_item 'Blog', 'http://blog.cannabis-initiative.ch' - = navbar_item t('.sign_in'), new_supporter_session_path unless supporter_signed_in? - = navbar_item t('.sign_out'), destroy_supporter_session_path, nil, 'data-method' => :delete if supporter_signed_in? - - if supporter_signed_in? && current_supporter.admin? - = navbar_dropdown t('admin.title') do - = navbar_item t('admin.publicities.index.title'), admin_publicities_path diff --git a/app/views/supporters/_form.slim b/app/views/supporters/_form.slim index 5171f5b..ad4e8ad 100644 --- a/app/views/supporters/_form.slim +++ b/app/views/supporters/_form.slim @@ -9,6 +9,7 @@ = f.input :city, placeholder: t('.placeholders.city') = f.input :zip, placeholder: t('.placeholders.zip') = f.input :email, placeholder: t('.placeholders.email') + = f.input :tel, placeholder: '+41 (0) xxxx' = f.input :support, as: :radio_buttons, collection: t('support_type').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first = f.input :li_membership, as: :boolean = f.input :age_category, as: :radio_buttons, collection: t('age_category'), label_method: :last, value_method: :first diff --git a/app/views/supporters/new.slim b/app/views/supporters/new.slim index dbf173e..d98336f 100644 --- a/app/views/supporters/new.slim +++ b/app/views/supporters/new.slim @@ -23,6 +23,8 @@ dd == t("age_category.#{current_supporter.age_category}") dt = Supporter.human_attribute_name(:language) dd = t("languages.#{current_supporter.language}") + dt = Supporter.human_attribute_name(:tel) + dd = current_supporter.tel p = link_to t('.edit'), edit_supporter_registration_path(), class: 'pull-right' diff --git a/app/views/supporters/registrations/edit.html.slim b/app/views/supporters/registrations/edit.html.slim index d85ef28..75a3fa5 100644 --- a/app/views/supporters/registrations/edit.html.slim +++ b/app/views/supporters/registrations/edit.html.slim @@ -21,7 +21,6 @@ = f.input :language, as: :radio_buttons, collection: t('languages').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first .form-actions = f.button :submit, t("devise.registrations.edit.update"), class: 'btn btn-primary' - p = link_to t("devise.shared.links.back"), :back hr p = link_to t("devise.registrations.edit.cancel_my_account"), registration_path(resource_name), data: { confirm: t("devise.registrations.edit.are_you_sure") }, method: :delete, class: 'btn btn-danger btn-sm pull-right' diff --git a/config/environments/staging.rb b/config/environments/staging.rb new file mode 100644 index 0000000..48d165c --- /dev/null +++ b/config/environments/staging.rb @@ -0,0 +1,107 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + config.middleware.insert_before(::Rack::Runtime, "::Rack::Auth::Basic", "Staging") do |_u, p| + p == ENV['STAGING_PASSWORD'] + end + + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :warn + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + config.action_mailer.default_url_options = { host: 'ch420-staging.herokuapp.com' } + config.action_mailer.asset_host = 'https://ch420-staging.herokuapp.com' + + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + port: '587', + address: ENV['SMTP_HOST'], + user_name: ENV['SMTP_USER'], + password: ENV['SMTP_PASSWORD'], + domain: 'hanflegal.ch', + authentication: :plain, + enable_starttls_auto: true + } + + config.paperclip_defaults = { + storage: :s3, + s3_protocol: :https, + s3_region: ENV["S3_REGION"], + s3_host_name: ENV["S3_HOST_NAME"], + s3_credentials: { + bucket: "cannabis-initiative-staging", + access_key_id: ENV["S3_ACCESS_KEY"], + secret_access_key: ENV["S3_ACCESS_SECRET"] + } + } +end diff --git a/config/initializers/rails-bootstrap-navbar.rb b/config/initializers/rails-bootstrap-navbar.rb deleted file mode 100644 index b0816f5..0000000 --- a/config/initializers/rails-bootstrap-navbar.rb +++ /dev/null @@ -1,4 +0,0 @@ -BootstrapNavbar.configure do |config| - config.bootstrap_version = '3.3.6' - config.root_paths = ['/', '/de', '/fr', '/it'] # default: ['/'] -end \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index f5d5ce4..46c2332 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -7,6 +7,8 @@ de: logo: Logo der Initiative title_html: Ja, ich will Cannabis in der Schweiz legalisieren topnavigation: + support: Unterstützen + my_account: Mein Konto sign_in: Anmelden sign_out: Abmelden initiative_text: Der Initiativtext im Wortlaut @@ -15,7 +17,7 @@ de: faq: Fragen und Antworten sponsoring: Sponsoren numbers: Zahlen - statementes: Statements + statements: Statements collection_concept: Wie macht man eine Volksinitiative? lang: Sprache @@ -80,7 +82,7 @@ de: new: title: Hallo %{name} - edit: Meine Daten bearbeiten... + edit: Meine Daten bearbeiten my_data: Meine Daten publicities: @@ -117,6 +119,7 @@ de: numbers: zahlen statementes: statements collection_concept: Sammelkonzept + greendays: gründonnerstag mongoid: models: @@ -138,6 +141,7 @@ de: language: Sprache password_confirmation: Passwort bestätigen current_password: Aktuelles Passwort + tel: Telefon (optional) publicity: state: Status organisation: Organisation diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 6732aca..00c3997 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -12,6 +12,7 @@ fr: logo: Logo de l'initiative title_html: Oui, je veux légaliser le cannabis en Suisse. topnavigation: + support: Soutenez-nous sign_out: déconnecter sign_in: Connexion initiative: l' initiative @@ -22,6 +23,7 @@ fr: numbers: Chiffres (en allemand) statements: Déclarations collection_concept: Comment faire une initiative populaire? (en allemand) + my_account: Mon compte lang: Langue are_you_sure: Tu es sûre? @@ -77,7 +79,7 @@ fr: new: title: Salut %{name} - edit: Modifier mes données ... + edit: Modifier mes données my_data: Mes données publicities: @@ -114,6 +116,7 @@ fr: numbers: chiffres statements: declarations collection_concept: plan_de_collecte + greendays: jeudi_vert mongoid: models: @@ -135,7 +138,8 @@ fr: language: Langue password_confirmation: confirmer le mot de passe current_password: Mot de passe actuel - + tel: Téléphone (facultatif) + publicity: status: Statu organisation: Organisation diff --git a/config/locales/it.yml b/config/locales/it.yml index 63cdf1d..071fce8 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -9,6 +9,7 @@ it: logo: Logo dell'iniziativa title_html: Si, voglio legalizzare la cannabis in Svizzera topnavigation: + support: Sostenici sign_out: Disconnettersi sign_in: Registro initiative_text: Il testo dell’iniziativa (in tedesco) @@ -19,6 +20,7 @@ it: numbers: Numeri (in tedesco) statements: Dichiarazioni collection_concept: Come fare un iniziativa popolare? (in tedesco) + my_account: Il mio account counter: supporters: "Sostenitore:" @@ -81,7 +83,7 @@ it: new: title: Ciao %{name} - edit: Modifica i miei dati ... + edit: Modifica i miei dati my_data: Miei dati publicities: @@ -118,6 +120,7 @@ it: numbers: numeri statements: dichiarazioni collection_concept: sistema_di_raccolta + greendays: giovedi_verdi mongoid: attributes: @@ -137,6 +140,7 @@ it: language: Lingua password_confirmation: conferma password current_password: Password corrente + tel: Telefono (opzionale) publicity: status: Statu organisation: Organizzazione diff --git a/config/mongoid.yml b/config/mongoid.yml index 755128a..2c086bc 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -12,6 +12,11 @@ test: database: ch420_test hosts: - localhost:27017 + +staging: + clients: + default: + uri: <%= ENV['MONGODB_URI'] %> production: clients: diff --git a/config/navigation.rb b/config/navigation.rb new file mode 100644 index 0000000..93b7e02 --- /dev/null +++ b/config/navigation.rb @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +# Configures your navigation +SimpleNavigation::Configuration.run do |navigation| + # Specify a custom renderer if needed. + # The default renderer is SimpleNavigation::Renderer::List which renders HTML lists. + # The renderer can also be specified as option in the render_navigation call. + # navigation.renderer = Your::Custom::Renderer + + # Specify the class that will be applied to active navigation items. Defaults to 'selected' + #navigation.selected_class = 'selected' + + # Specify the class that will be applied to the current leaf of + # active navigation items. Defaults to 'simple-navigation-active-leaf' + #navigation.active_leaf_class = 'simple-navigation-active-leaf' + + # Specify if item keys are added to navigation items as id. Defaults to true + #navigation.autogenerate_item_ids = true + + # You can override the default logic that is used to autogenerate the item ids. + # To do this, define a Proc which takes the key of the current item as argument. + # The example below would add a prefix to each key. + #navigation.id_generator = Proc.new {|key| "my-prefix-#{key}"} + + # If you need to add custom html around item names, you can define a proc that + # will be called with the name you pass in to the navigation. + # The example below shows how to wrap items spans. + #navigation.name_generator = Proc.new {|name, item| "#{name}"} + + # Specify if the auto highlight feature is turned on (globally, for the whole navigation). Defaults to true + #navigation.auto_highlight = true + + # Specifies whether auto highlight should ignore query params and/or anchors when + # comparing the navigation items with the current URL. Defaults to true + #navigation.ignore_query_params_on_auto_highlight = true + #navigation.ignore_anchors_on_auto_highlight = true + + # If this option is set to true, all item names will be considered as safe (passed through html_safe). Defaults to false. + #navigation.consider_item_names_as_safe = false + + # Define the primary navigation + navigation.items do |primary| + # Add an item to the primary navigation. The following params apply: + # key - a symbol which uniquely defines your navigation item in the scope of the primary_navigation + # name - will be displayed in the rendered navigation. This can also be a call to your I18n-framework. + # url - the address that the generated item links to. You can also use url_helpers (named routes, restful routes helper, url_for etc.) + # options - can be used to specify attributes that will be included in the rendered navigation item (e.g. id, class etc.) + # some special options that can be set: + # :if - Specifies a proc to call to determine if the item should + # be rendered (e.g. if: -> { current_user.admin? }). The + # proc should evaluate to a true or false value and is evaluated in the context of the view. + # :unless - Specifies a proc to call to determine if the item should not + # be rendered (e.g. unless: -> { current_user.admin? }). The + # proc should evaluate to a true or false value and is evaluated in the context of the view. + # :method - Specifies the http-method for the generated link - default is :get. + # :highlights_on - if autohighlighting is turned off and/or you want to explicitly specify + # when the item should be highlighted, you can set a regexp which is matched + # against the current URI. You may also use a proc, or the symbol :subpath. + # + + primary.item :greendays, 'Gründonnerstag', greendays_path + + unless supporter_signed_in? + primary.item :home, I18n.t('.shared.topnavigation.support'), "/#{I18n.locale}" + end + primary.item :initiative, I18n.t('.shared.topnavigation.initiative'), initiative_text_path do | initiative | + initiative.item :arguments, I18n.t('.shared.topnavigation.arguments'), arguments_path + initiative.item :faq, I18n.t('.shared.topnavigation.faq'), faq_path + initiative.item :numbers, I18n.t('.shared.topnavigation.numbers'), numbers_path + initiative.item :collection_concept, I18n.t('.shared.topnavigation.collection_concept'), collection_concept_path + end + primary.item :statements, I18n.t('.shared.topnavigation.statements'), statements_path do |statements| + statements.item :new_statement, I18n.t('.supporters.publicity.renew'), new_publicity_path + end + primary.item :donation, I18n.t('donation'), donation_path + primary.item :blog, 'Blog', 'http://blog.cannabis-initiative.ch/', link_html: { target: '_blank'} + if supporter_signed_in? + primary.item :home, I18n.t('.shared.topnavigation.my_account'), "/#{I18n.locale}" do |my_account| + my_account.item :edit_account, I18n.t('.supporters.new.edit'), edit_supporter_registration_path() + my_account.item :sign_out, I18n.t('.shared.topnavigation.sign_out'), destroy_supporter_session_path, link_html: { 'data-method' => :delete } + end + else + primary.item :home, I18n.t('.shared.topnavigation.sign_in'), new_supporter_session_path + end + + + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5281711..b1845b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,7 @@ Rails.application.routes.draw do end localized do + resources :greendays get '/initiative_text', to: 'pages#show', as: :initiative_text, page: 'initiative_text' get '/arguments', to: 'pages#show', as: :arguments, page: 'arguments' get '/faq', to: 'pages#show', as: :faq, page: 'faq' diff --git a/config/secrets.yml b/config/secrets.yml index 1807f9b..ab42a5d 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -16,6 +16,10 @@ development: test: secret_key_base: f9c7c3d851c4c3c44390cb50e69491b241ae26d0e3b9d488579590963d30ff8e7e5d91b0930ec9b282661a59b24ef6abe4fc5615607e787f9e0ac76cb81f42fd +staging: + secret_key_base: 88f843073f09ab3f825b53df5d179d8818abea1848cd4717a4f6f0e3c8b4cb11c719d2fe5cb867755cab5d3aaf7feab62c6f9df7d56a270ebeaf7e0ab9be6ba8 + + # Do not keep production secrets in the repository, # instead read values from the environment. production: diff --git a/spec/features/support_spec.rb b/spec/features/support_spec.rb index b46f952..d5867e3 100644 --- a/spec/features/support_spec.rb +++ b/spec/features/support_spec.rb @@ -10,6 +10,7 @@ feature 'Support' do fill_in 'Postleitzahl', with: '8704' fill_in 'Ort', with: 'Herrliberg' fill_in 'E-Mail', with: 'blocher@blocher.ch' + fill_in 'Telefon', with: '12345' fill_in 'Kommentar / Feedback', with: 'Test text' choose 'Ich würde eine Volksinitiative für die Legalisierung von Cannabis unterschreiben und helfe aktiv Unterschriften in meiner Umgebung zu sammeln.' @@ -30,6 +31,7 @@ feature 'Support' do expect(supporter.comments).to eq 'Test text' expect(supporter.language).to eq 'de' expect(supporter.li_membership).to eq true + expect(supporter.tel).to eq '12345' end scenario 'A bot tries to enter data' do diff --git a/spec/models/greenday_spec.rb b/spec/models/greenday_spec.rb new file mode 100644 index 0000000..d8ba7a7 --- /dev/null +++ b/spec/models/greenday_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Greenday, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/greendays_spec.rb b/spec/requests/greendays_spec.rb new file mode 100644 index 0000000..282b151 --- /dev/null +++ b/spec/requests/greendays_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Greendays", type: :request do + describe "GET /greendays" do + it "works! (now write some real specs)" do + get greendays_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/views/greendays/edit.html.slim_spec.rb b/spec/views/greendays/edit.html.slim_spec.rb new file mode 100644 index 0000000..f5dc9d7 --- /dev/null +++ b/spec/views/greendays/edit.html.slim_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "greendays/edit", type: :view do + before(:each) do + @greenday = assign(:greenday, Greenday.create!( + :title => "MyString", + :address => "MyText", + :description => "MyText" + )) + end + + it "renders the edit greenday form" do + render + + assert_select "form[action=?][method=?]", greenday_path(@greenday), "post" do + + assert_select "input#greenday_title[name=?]", "greenday[title]" + + assert_select "textarea#greenday_address[name=?]", "greenday[address]" + + assert_select "textarea#greenday_description[name=?]", "greenday[description]" + end + end +end diff --git a/spec/views/greendays/index.html.slim_spec.rb b/spec/views/greendays/index.html.slim_spec.rb new file mode 100644 index 0000000..75e7e18 --- /dev/null +++ b/spec/views/greendays/index.html.slim_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe 'greendays/index' do + before(:each) do + assign(:greendays, [ + Greenday.create!( + title: 'Title', + address: 'Address', + description: 'MyText' + ), + Greenday.create!( + title: 'Title', + address: 'Address', + description: 'MyText' + ) + ]) + end + + it 'renders a list of greendays' do + render + assert_select 'h2', text: 'Title'.to_s, count: 2 + assert_select "address", :text => "Address".to_s, count: 2 + assert_select "p", :text => "MyText".to_s, count: 2 + end +end diff --git a/spec/views/greendays/new.html.slim_spec.rb b/spec/views/greendays/new.html.slim_spec.rb new file mode 100644 index 0000000..6c6130e --- /dev/null +++ b/spec/views/greendays/new.html.slim_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe "greendays/new", type: :view do + before(:each) do + assign(:greenday, Greenday.new( + :title => "MyString", + :address => "MyText", + :description => "MyText" + )) + end + + it "renders new greenday form" do + render + + assert_select "form[action=?][method=?]", greendays_path, "post" do + + assert_select "input#greenday_title[name=?]", "greenday[title]" + + assert_select "textarea#greenday_address[name=?]", "greenday[address]" + + assert_select "textarea#greenday_description[name=?]", "greenday[description]" + end + end +end