Calendar Klasse überarbeitet Views,gefixt, Pictures hinzugefügt

This commit is contained in:
Andreas Stephanides
2013-08-11 01:17:37 +02:00
parent 116446ff63
commit a5a02e065a
17 changed files with 238 additions and 67 deletions

View File

@@ -12,9 +12,9 @@ gem 'rails', '3.2.9'
# Gems used only for assets and not required # Gems used only for assets and not required
# in production environments by default. # in production environments by default.
group :assets do group :assets do
gem 'sass-rails', '~> 3.2.3' gem 'sass-rails', '~> 3.2'
gem 'coffee-rails', '~> 3.2.1' 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 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3' gem 'uglifier', '>= 1.0.3'
@@ -77,3 +77,4 @@ gem 'rspec-rails'
end end
gem "simple_calendar", "~> 0.1.9" gem "simple_calendar", "~> 0.1.9"
gem 'rmagick'

View File

@@ -10,7 +10,7 @@
* *
*= require_self *= require_self
*= require_tree . *= require_tree .
* require 'bootstrap' *= require 'bootstrap'
*/ */
$linkColor: #03006E; $linkColor: #03006E;
@import 'bootstrap'; @import 'bootstrap';

View File

@@ -3,7 +3,6 @@ class CalendarsController < ApplicationController
# GET /calendars.json # GET /calendars.json
def index def index
@calendars = Calendar.all @calendars = Calendar.all
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
format.json { render json: @calendars } format.json { render json: @calendars }
@@ -18,6 +17,7 @@ class CalendarsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.json { render json: @calendar } format.json { render json: @calendar }
format.ics { render 'show.ics.erb'}
end end
end end

View File

@@ -1,6 +1,7 @@
class DateStringInput < FormtasticBootstrap::Inputs::StringInput class DateStringInput < FormtasticBootstrap::Inputs::StringInput
def input_html_options 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
end end

View File

@@ -1,4 +1,5 @@
class Calendar < ActiveRecord::Base class Calendar < ActiveRecord::Base
attr_accessible :name, :public attr_accessible :name, :public, :picture
has_and_belongs_to_many :calentries has_and_belongs_to_many :calentries
mount_uploader :picture, PictureUploader
end end

View File

@@ -1,6 +1,13 @@
class Calentry < ActiveRecord::Base class Calentry < ActiveRecord::Base
attr_accessible :ende, :start, :summary, :typ,:calendar_ids 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 def start_time
start start
end end

View 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

View File

@@ -2,6 +2,7 @@
<%= f.inputs do %> <%= f.inputs do %>
<%= f.input :name %> <%= f.input :name %>
<%= f.input :public %> <%= f.input :public %>
<%= f.input :picture, :as => :file %>
<% end %> <% end %>
<%= f.actions do %> <%= f.actions do %>

View File

@@ -1,25 +1,14 @@
<h1>Listing calendars</h1> <h1>Listing calendars</h1>
<table>
<tr>
<th>Name</th>
<th>Public</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @calendars.each do |calendar| %> <% @calendars.each do |calendar| %>
<tr> <div class="media">
<td><%= calendar.name %></td> <a class="pull-left" href="#">
<td><%= calendar.public %></td> <img class="media-object img-circle" src="<%= calendar.picture.thumb.url %>"/>
<td><%= link_to 'Show', calendar %></td> </a>
<td><%= link_to 'Edit', edit_calendar_path(calendar) %></td> <div class="media-body">
<td><%= link_to 'Destroy', calendar, method: :delete, data: { confirm: 'Are you sure?' } %></td> <h4><%= link_to calendar.name, calendar %></h4>
</tr> </div>
</div>
<% end %> <% end %>
</table>
<br />
<%= link_to 'New Calendar', new_calendar_path %> <%= link_to 'New Calendar', new_calendar_path %>

View File

@@ -1,24 +1,30 @@
<div class="container-fluid">
<div class="row-fluid">
<p id="notice"><%= notice %></p> <p id="notice"><%= notice %></p>
<p> <h1>
<b>Name:</b> <%= '<i class="icon-globe"></i>'.html_safe unless !@calendar.public%>
<%= @calendar.name %> <%= @calendar.name %>
</p> </h1>
<div class="row-fluid">
<p> <ul class="list-group">
<b>Public:</b>
<%= @calendar.public %>
</p>
<p>
<ul>
<% @calendar.calentries.each do |entry| %> <% @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 %> <% end %>
</ul>
</div>
<div class="row-fluid">
<%= calendar @calendar.calentries do |entry| %> <%= calendar @calendar.calentries do |entry| %>
<div><%= link_to entry.name, entry %></div> <div><%= link_to entry.name, entry %></div>
<% end %> <% end %>
</div>
<%= link_to 'New Entry', new_calentry_path %> <div class="row-fluid">
<%= link_to 'Edit', edit_calendar_path(@calendar) %> | <div class="btn-group">
<%= link_to 'Back', calendars_path %> <%= 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>

View File

@@ -0,0 +1,3 @@
<% @calendar.calentries.each do |entry| %>
<%= render entry %>
<% end %>

View File

@@ -0,0 +1,5 @@
<%= calentry.start %>
<%= calentry.ende %>
<%= calentry.summary %>
<%= calentry.typ %>

View File

@@ -1,13 +1,34 @@
<div class="container-fluid">
<%= semantic_form_for @calentry do |f| %> <%= semantic_form_for @calentry do |f| %>
<%= f.inputs do %> <%= f.inputs do %>
<div class="row-fluid">
<div class="span6">
<%= f.input :start , :as => :date_string %> <%= 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 :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 %> <%= f.input :typ %>
</div>
</div>
<% end %> <% end %>
<div class="row-fluid">
<div class="span12">
<%= f.actions do %> <%= f.actions do %>
<%= f.action :submit, :as => :input %> <%= f.action :submit, :as => :input %>
<% end %> <% end %>
</div>
</div>
<% end %> <% end %>
</div>

View File

@@ -1,25 +1,25 @@
<p id="notice"><%= notice %></p> <p id="notice"><%= notice %></p>
<div class="container-fluid">
<p> <div class="row-fluid">
<b>Start:</b> <div class="span12">
<%= @calentry.start %> <b>
</p>
<p>
<b>Ende:</b>
<%= @calentry.ende %>
</p>
<p>
<b>Summary:</b>
<%= @calentry.summary %> <%= @calentry.summary %>
</p> </b>
<p> </div>
<b>Typ:</b> </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 %> <%= @calentry.typ %>
</p> </div></div>
<div class="row-fluid">
<div class="span12">
<%= link_to 'Edit', edit_calentry_path(@calentry) %> | <%= link_to 'Edit', edit_calentry_path(@calentry) %> |
<%= link_to 'Back', calentries_path %> <%= link_to 'Back', calentries_path %>
</div></div></div>

View File

@@ -0,0 +1,5 @@
class AddPictureToCalendars < ActiveRecord::Migration
def change
add_column :calendars, :picture, :string
end
end

View File

@@ -11,7 +11,23 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "beispiele", :force => true do |t|
t.string "name" t.string "name"
@@ -22,6 +38,38 @@ ActiveRecord::Schema.define(:version => 20130729085446) do
t.string "beispieldatei" t.string "beispieldatei"
end 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| create_table "lva_translations", :force => true do |t|
t.integer "lva_id" t.integer "lva_id"
t.string "locale" t.string "locale"
@@ -50,11 +98,14 @@ ActiveRecord::Schema.define(:version => 20130729085446) do
t.integer "modul_id" t.integer "modul_id"
end 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 "lva_id"
t.integer "semester_id" t.integer "semester_id"
end 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| create_table "modul_translations", :force => true do |t|
t.integer "modul_id" t.integer "modul_id"
t.string "locale" t.string "locale"
@@ -161,6 +212,20 @@ ActiveRecord::Schema.define(:version => 20130729085446) do
add_index "studium_translations", ["locale"], :name => "index_studium_translations_on_locale" 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| create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false t.string "encrypted_password", :default => "", :null => false

View File

@@ -1,5 +1,20 @@
require 'spec_helper' require 'spec_helper'
describe Calentry do 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 end