Calendar Klasse überarbeitet Views,gefixt, Pictures hinzugefügt
This commit is contained in:
5
Gemfile
5
Gemfile
@@ -12,9 +12,9 @@ gem 'rails', '3.2.9'
|
||||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
group :assets do
|
||||
gem 'sass-rails', '~> 3.2.3'
|
||||
gem 'sass-rails', '~> 3.2'
|
||||
gem 'coffee-rails', '~> 3.2.1'
|
||||
gem 'bootstrap-sass','~> 2.2.0'
|
||||
gem 'bootstrap-sass','~> 2.3.2.1'
|
||||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||
gem 'therubyracer', :platforms => :ruby
|
||||
gem 'uglifier', '>= 1.0.3'
|
||||
@@ -77,3 +77,4 @@ gem 'rspec-rails'
|
||||
end
|
||||
|
||||
gem "simple_calendar", "~> 0.1.9"
|
||||
gem 'rmagick'
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*= require_self
|
||||
*= require_tree .
|
||||
* require 'bootstrap'
|
||||
*= require 'bootstrap'
|
||||
*/
|
||||
$linkColor: #03006E;
|
||||
@import 'bootstrap';
|
||||
|
||||
@@ -3,7 +3,6 @@ class CalendarsController < ApplicationController
|
||||
# GET /calendars.json
|
||||
def index
|
||||
@calendars = Calendar.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @calendars }
|
||||
@@ -18,6 +17,7 @@ class CalendarsController < ApplicationController
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @calendar }
|
||||
format.ics { render 'show.ics.erb'}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class DateStringInput < FormtasticBootstrap::Inputs::StringInput
|
||||
def input_html_options
|
||||
super.merge(:class => "datetext", :onclick =>"beep", :value=>I18n.l(@object.send(method.to_sym)))
|
||||
value = (@object.send(method.to_sym))
|
||||
super.merge(:class => "datetext", :onclick =>"beep", :value=>I18n.l((value.is_a?(Time)||value.is_a?(Date)||value.is_a?(DateTime)) ? value : Time.now))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Calendar < ActiveRecord::Base
|
||||
attr_accessible :name, :public
|
||||
attr_accessible :name, :public, :picture
|
||||
has_and_belongs_to_many :calentries
|
||||
mount_uploader :picture, PictureUploader
|
||||
end
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
class Calentry < ActiveRecord::Base
|
||||
attr_accessible :ende, :start, :summary, :typ,:calendar_ids
|
||||
has_and_belongs_to_many :calendar
|
||||
has_and_belongs_to_many :calendars
|
||||
validates :start, :presence => true
|
||||
validates :typ, :presence => true
|
||||
validate do |entry|
|
||||
if entry.ende.nil?
|
||||
errors.add(:ende, "Es muss ein Endzeitpunkt vorhanden sein")
|
||||
end
|
||||
end
|
||||
def start_time
|
||||
start
|
||||
end
|
||||
|
||||
51
app/uploaders/picture_uploader.rb
Normal file
51
app/uploaders/picture_uploader.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
# encoding: utf-8
|
||||
|
||||
class PictureUploader < CarrierWave::Uploader::Base
|
||||
|
||||
# Include RMagick or MiniMagick support:
|
||||
include CarrierWave::RMagick
|
||||
# include CarrierWave::MiniMagick
|
||||
|
||||
# Choose what kind of storage to use for this uploader:
|
||||
storage :file
|
||||
# storage :fog
|
||||
|
||||
# Override the directory where uploaded files will be stored.
|
||||
# This is a sensible default for uploaders that are meant to be mounted:
|
||||
def store_dir
|
||||
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
||||
end
|
||||
|
||||
# Provide a default URL as a default if there hasn't been a file uploaded:
|
||||
# def default_url
|
||||
# # For Rails 3.1+ asset pipeline compatibility:
|
||||
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
||||
#
|
||||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
||||
# end
|
||||
|
||||
# Process files as they are uploaded:
|
||||
# process :scale => [200, 300]
|
||||
#
|
||||
# def scale(width, height)
|
||||
# # do something
|
||||
# end
|
||||
|
||||
# Create different versions of your uploaded files:
|
||||
version :thumb do
|
||||
process :resize_to_fill => [64, 64]
|
||||
end
|
||||
|
||||
# Add a white list of extensions which are allowed to be uploaded.
|
||||
# For images you might use something like this:
|
||||
def extension_white_list
|
||||
%w(jpg jpeg gif png)
|
||||
end
|
||||
|
||||
# Override the filename of the uploaded files:
|
||||
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
||||
# def filename
|
||||
# "something.jpg" if original_filename
|
||||
# end
|
||||
|
||||
end
|
||||
@@ -2,6 +2,7 @@
|
||||
<%= f.inputs do %>
|
||||
<%= f.input :name %>
|
||||
<%= f.input :public %>
|
||||
<%= f.input :picture, :as => :file %>
|
||||
<% end %>
|
||||
|
||||
<%= f.actions do %>
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
<h1>Listing calendars</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Public</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @calendars.each do |calendar| %>
|
||||
<tr>
|
||||
<td><%= calendar.name %></td>
|
||||
<td><%= calendar.public %></td>
|
||||
<td><%= link_to 'Show', calendar %></td>
|
||||
<td><%= link_to 'Edit', edit_calendar_path(calendar) %></td>
|
||||
<td><%= link_to 'Destroy', calendar, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<div class="media">
|
||||
<a class="pull-left" href="#">
|
||||
<img class="media-object img-circle" src="<%= calendar.picture.thumb.url %>"/>
|
||||
</a>
|
||||
<div class="media-body">
|
||||
<h4><%= link_to calendar.name, calendar %></h4>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New Calendar', new_calendar_path %>
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row-fluid">
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Name:</b>
|
||||
<h1>
|
||||
<%= '<i class="icon-globe"></i>'.html_safe unless !@calendar.public%>
|
||||
<%= @calendar.name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Public:</b>
|
||||
<%= @calendar.public %>
|
||||
</p>
|
||||
<p>
|
||||
<ul>
|
||||
</h1>
|
||||
<div class="row-fluid">
|
||||
<ul class="list-group">
|
||||
<% @calendar.calentries.each do |entry| %>
|
||||
<%= entry.summary+ "- " + entry.start.to_s %>
|
||||
<li class="list-group-item">
|
||||
<%= link_to entry.summary+ " - " + I18n.l(entry.start), entry %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<%= calendar @calendar.calentries do |entry| %>
|
||||
<div><%= link_to entry.name, entry %></div>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'New Entry', new_calentry_path %>
|
||||
<%= link_to 'Edit', edit_calendar_path(@calendar) %> |
|
||||
<%= link_to 'Back', calendars_path %>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="btn-group">
|
||||
<%= link_to 'New Entry', new_calentry_path, {:class=>"btn"} %>
|
||||
<%= link_to 'Edit', edit_calendar_path(@calendar), {:class=>"btn"} %>
|
||||
<%= link_to 'Back', calendars_path, {:class=>"btn"} %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
3
app/views/calendars/show.ics.erb
Normal file
3
app/views/calendars/show.ics.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<% @calendar.calentries.each do |entry| %>
|
||||
<%= render entry %>
|
||||
<% end %>
|
||||
5
app/views/calentries/_calentry.ics.erb
Normal file
5
app/views/calentries/_calentry.ics.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<%= calentry.start %>
|
||||
<%= calentry.ende %>
|
||||
<%= calentry.summary %>
|
||||
<%= calentry.typ %>
|
||||
|
||||
@@ -1,13 +1,34 @@
|
||||
<div class="container-fluid">
|
||||
<%= semantic_form_for @calentry do |f| %>
|
||||
<%= f.inputs do %>
|
||||
<div class="row-fluid">
|
||||
<div class="span6">
|
||||
<%= f.input :start , :as => :date_string %>
|
||||
<%= f.input :ende %>
|
||||
</div>
|
||||
<div class="span6">
|
||||
<%= f.input :ende , :as => :date_string %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<%= f.input :summary %>
|
||||
<%= f.input :calendar, :as=> :radio %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span6">
|
||||
<%= f.input :calendars, :as=> :radio %>
|
||||
</div>
|
||||
<div class="span6">
|
||||
<%= f.input :typ %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<%= f.actions do %>
|
||||
<%= f.action :submit, :as => :input %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<b>Start:</b>
|
||||
<%= @calentry.start %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Ende:</b>
|
||||
<%= @calentry.ende %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Summary:</b>
|
||||
<div class="container-fluid">
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<b>
|
||||
<%= @calentry.summary %>
|
||||
</p>
|
||||
</b>
|
||||
|
||||
<p>
|
||||
<b>Typ:</b>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span9">
|
||||
<%= I18n.l @calentry.start %>
|
||||
<%= " bis " unless @calentry.ende.nil? %>
|
||||
<%= I18n.l @calentry.ende %>
|
||||
</div>
|
||||
<div class="span3">
|
||||
<%= @calentry.typ %>
|
||||
</p>
|
||||
|
||||
</div></div>
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<%= link_to 'Edit', edit_calentry_path(@calentry) %> |
|
||||
<%= link_to 'Back', calentries_path %>
|
||||
</div></div></div>
|
||||
|
||||
5
db/migrate/20130810214456_add_picture_to_calendars.rb
Normal file
5
db/migrate/20130810214456_add_picture_to_calendars.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddPictureToCalendars < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :calendars, :picture, :string
|
||||
end
|
||||
end
|
||||
69
db/schema.rb
69
db/schema.rb
@@ -11,7 +11,23 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130729085446) do
|
||||
ActiveRecord::Schema.define(:version => 20130810214456) do
|
||||
|
||||
create_table "attachments", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "beispiel_translations", :force => true do |t|
|
||||
t.string "locale"
|
||||
t.text "desc"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "beispiele_id"
|
||||
end
|
||||
|
||||
add_index "beispiel_translations", ["locale"], :name => "index_beispiel_translations_on_locale"
|
||||
|
||||
create_table "beispiele", :force => true do |t|
|
||||
t.string "name"
|
||||
@@ -22,6 +38,38 @@ ActiveRecord::Schema.define(:version => 20130729085446) do
|
||||
t.string "beispieldatei"
|
||||
end
|
||||
|
||||
create_table "calendars", :force => true do |t|
|
||||
t.string "name"
|
||||
t.boolean "public"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "picture"
|
||||
end
|
||||
|
||||
create_table "calendars_calentries", :id => false, :force => true do |t|
|
||||
t.integer "calentry_id"
|
||||
t.integer "calendar_id"
|
||||
end
|
||||
|
||||
add_index "calendars_calentries", ["calendar_id"], :name => "index_calendars_calentries_on_calendar_id"
|
||||
add_index "calendars_calentries", ["calentry_id", "calendar_id"], :name => "index_calendars_calentries_on_calentry_id_and_calendar_id"
|
||||
|
||||
create_table "calentries", :force => true do |t|
|
||||
t.datetime "start"
|
||||
t.datetime "ende"
|
||||
t.string "summary"
|
||||
t.integer "typ"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "fragen", :force => true do |t|
|
||||
t.string "title"
|
||||
t.text "text"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "lva_translations", :force => true do |t|
|
||||
t.integer "lva_id"
|
||||
t.string "locale"
|
||||
@@ -50,11 +98,14 @@ ActiveRecord::Schema.define(:version => 20130729085446) do
|
||||
t.integer "modul_id"
|
||||
end
|
||||
|
||||
create_table "lvas_semesters", :force => true do |t|
|
||||
create_table "lvas_semesters", :id => false, :force => true do |t|
|
||||
t.integer "lva_id"
|
||||
t.integer "semester_id"
|
||||
end
|
||||
|
||||
add_index "lvas_semesters", ["lva_id", "semester_id"], :name => "index_lvas_semesters_on_lva_id_and_semester_id"
|
||||
add_index "lvas_semesters", ["semester_id"], :name => "index_lvas_semesters_on_semester_id"
|
||||
|
||||
create_table "modul_translations", :force => true do |t|
|
||||
t.integer "modul_id"
|
||||
t.string "locale"
|
||||
@@ -161,6 +212,20 @@ ActiveRecord::Schema.define(:version => 20130729085446) do
|
||||
|
||||
add_index "studium_translations", ["locale"], :name => "index_studium_translations_on_locale"
|
||||
|
||||
create_table "themen", :force => true do |t|
|
||||
t.string "title"
|
||||
t.text "text"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "themengruppen", :force => true do |t|
|
||||
t.string "title"
|
||||
t.text "text"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :default => "", :null => false
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Calentry do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
it "should be valid with full data" do
|
||||
e = FactoryGirl.build(:calentry)
|
||||
c = FactoryGirl.create(:calendar)
|
||||
e.calendars<<c
|
||||
e.should be_valid
|
||||
end
|
||||
[:ende,:start,:typ].each do |attr|
|
||||
it "should not be valid without #{attr}" do
|
||||
e= FactoryGirl.build(:calentry, attr => nil)
|
||||
c=FactoryGirl.create(:calendar)
|
||||
e.calendars<<c
|
||||
e.should_not be_valid
|
||||
e.should have_at_least(1).errors_on(attr)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user