added greenday event

This commit is contained in:
2017-11-12 13:27:10 +01:00
parent 299097e13f
commit 7bd9a0ab22
23 changed files with 401 additions and 1 deletions
+3
View File
@@ -14,6 +14,9 @@ gem 'coffee-rails', '~> 4.1.0'
# Integrate Paperclip into Mongoid.
gem 'mongoid-paperclip'
# Markdown rendering
gem 'redcarpet'
# Stripe integration
gem 'stripe'
+2
View File
@@ -260,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)
@@ -380,6 +381,7 @@ DEPENDENCIES
rails-i18n
rails_12factor
rails_admin
redcarpet
roadie-rails (~> 1.0)
route_translator
rspec-rails (~> 3.0)
+3
View File
@@ -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/
+11
View File
@@ -0,0 +1,11 @@
// 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
+5 -1
View File
@@ -23,8 +23,12 @@ nav#mainnav
li
font-size: 12pt
li.selected
background-color: $brand-success
a
color: white
#greendays
margin-bottom: 12px
border: 1px solid $brand-success
+30
View File
@@ -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;
}
}
+65
View File
@@ -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
+9
View File
@@ -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
+43
View File
@@ -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
+14
View File
@@ -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'
@@ -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)
+8
View File
@@ -0,0 +1,8 @@
h1 Editing greenday
== render 'form'
= link_to 'Show', @greenday
' |
= link_to 'Back', greendays_path
+68
View File
@@ -0,0 +1,68 @@
h1.sr-only = title 'Gründonnerstag'
#map
= link_to 'Neun Shop erfassen', new_greenday_path if admin?
.row
- @greendays.each do |greenday|
.col-xs-12.col-sm-6.col-lg-4
.well
h2 = greenday.title
- if greenday.logo
= 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)
| &nbsp;
= 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 = '<b>' + data.title + '</b>'
if(data.logo) {
content += '<img src="' + data.logo + ' alt="" width="100%"/>'
}
content += '<address>' + data.address.replace(/\n/g,"<br>")
if(data.homepage) {
content += '<br/><a href="' + data.homepage + '" target="_blank">' +data.homepage + '</a>'
}
content += '</address>'
if(data.description) {
content += '<p>' + data.description + '</p>'
}
infowindow.setContent(content);
});
});
});
}
script async="" defer="" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBbwMtGKDqf4i8x9-OVP1-H_QVAKp92h2M&callback=initMap&libraries=visualization"
+1
View File
@@ -0,0 +1 @@
json.array! @greendays, partial: 'greendays/greenday', as: :greenday
+5
View File
@@ -0,0 +1,5 @@
h1 New greenday
== render 'form'
= link_to 'Back', greendays_path
+4
View File
@@ -57,6 +57,8 @@ SimpleNavigation::Configuration.run do |navigation|
# against the current URI. You may also use a proc, or the symbol <tt>:subpath</tt>.
#
primary.item :greendays, 'Gründonnerstag', greendays_path
unless supporter_signed_in?
primary.item :home, I18n.t('.shared.topnavigation.support'), "/#{I18n.locale}"
end
@@ -79,5 +81,7 @@ SimpleNavigation::Configuration.run do |navigation|
else
primary.item :home, I18n.t('.shared.topnavigation.sign_in'), new_supporter_session_path
end
end
end
+1
View File
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :greendays
devise_for :supporters
root to: 'supporters#new'
+5
View File
@@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Greenday, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
+10
View File
@@ -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
+39
View File
@@ -0,0 +1,39 @@
require "rails_helper"
RSpec.describe GreendaysController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(:get => "/greendays").to route_to("greendays#index")
end
it "routes to #new" do
expect(:get => "/greendays/new").to route_to("greendays#new")
end
it "routes to #show" do
expect(:get => "/greendays/1").to route_to("greendays#show", :id => "1")
end
it "routes to #edit" do
expect(:get => "/greendays/1/edit").to route_to("greendays#edit", :id => "1")
end
it "routes to #create" do
expect(:post => "/greendays").to route_to("greendays#create")
end
it "routes to #update via PUT" do
expect(:put => "/greendays/1").to route_to("greendays#update", :id => "1")
end
it "routes to #update via PATCH" do
expect(:patch => "/greendays/1").to route_to("greendays#update", :id => "1")
end
it "routes to #destroy" do
expect(:delete => "/greendays/1").to route_to("greendays#destroy", :id => "1")
end
end
end
@@ -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
@@ -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
@@ -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