diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb index ae0383f..0052c24 100644 --- a/app/controllers/memberships_controller.rb +++ b/app/controllers/memberships_controller.rb @@ -19,7 +19,7 @@ class MembershipsController < ApplicationController # POST /memberships.json def create @membership = Membership.new(params[:membership]) - + @membership.fetprofile= Fetprofle.find(params[:fetprofile_id]) respond_to do |format| if @membership.save format.html { redirect_to @membership.fetprofile, notice: 'Membership was successfully created.' } diff --git a/app/controllers/neuigkeiten_controller.rb b/app/controllers/neuigkeiten_controller.rb index 280987e..70ad200 100755 --- a/app/controllers/neuigkeiten_controller.rb +++ b/app/controllers/neuigkeiten_controller.rb @@ -10,6 +10,9 @@ class NeuigkeitenController < ApplicationController @neuigkeit = Neuigkeit.find(params[:id]) if can? :edit, @neuigkeit @toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_neuigkeit_path(@neuigkeit),:icon=>:pencil} + @toolbar_elements << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => neuigkeit_path(@neuigkeit), :method=> :delete,:confirm=>"Sure?" } + @toolbar_elements << {:hicon=>'icon-plus', :text=> "publish",:path => neuigkeit_publish_path(@neuigkeit),:confirm=>"Sure?" } + end end @@ -19,14 +22,19 @@ class NeuigkeitenController < ApplicationController @neuigkeit.rubrik=@rubrik unless @rubrik.nil? end - + def publish + @neuigkeit = Neuigkeit.find(params[:id]) + @neuigkeit.publish + @neuigkeit.save + redirect_to @neuigkeit + end def edit @neuigkeit = Neuigkeit.find(params[:id]) end def create @neuigkeit = Neuigkeit.new(params[:neuigkeit]) - @rubrik = @neuigkeit.rubrik + respond_to do |format| if @neuigkeit.save diff --git a/app/controllers/rubriken_controller.rb b/app/controllers/rubriken_controller.rb index bbff5b5..b34ef46 100755 --- a/app/controllers/rubriken_controller.rb +++ b/app/controllers/rubriken_controller.rb @@ -3,7 +3,7 @@ class RubrikenController < ApplicationController load_and_authorize_resource def index @rubriken = Rubrik.all - + @neuigkeiten = Neuigkeit.recent end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 92e6c15..9f2826e 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -15,4 +15,5 @@ class Calendar < ActiveRecord::Base has_and_belongs_to_many :calentries mount_uploader :picture, PictureUploader resourcify + scope :public, -> { where(:public => :true) } end diff --git a/app/models/calentry.rb b/app/models/calentry.rb index 9dbc178..94561f3 100644 --- a/app/models/calentry.rb +++ b/app/models/calentry.rb @@ -16,14 +16,21 @@ class Calentry < ActiveRecord::Base has_and_belongs_to_many :calendars validates :start, :presence => true validates :typ, :presence => true + before_save :get_public + belongs_to :object, polymorphic: true + validate do |entry| if entry.ende.nil? errors.add(:ende, "Es muss ein Endzeitpunkt vorhanden sein") end end - belongs_to :object, polymorphic: true + resourcify + def get_public + self.public = (self.try(:object).nil?)? (self.calendars.public.count>0) : object.try(:public) + true + end def start_time start end @@ -33,5 +40,6 @@ class Calentry < ActiveRecord::Base def name summary end + scope :public, -> { where(:public => :true) } scope :upcoming, -> { where("start >= ?" , Time.now).where("start <= ?", 8.days.from_now) } end diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index 45bd7f8..e9d2242 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -14,14 +14,30 @@ class Neuigkeit < ActiveRecord::Base - attr_accessible :datum, :text, :title, :rubrik_id, :author_id + attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture belongs_to :author, :class_name =>'User' belongs_to :rubrik, :class_name =>'Rubrik', :foreign_key => "rubrik_id" validates :rubrik, :presence=>true validates :author, :presence=>true translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true - - scope :published, -> {where("datum >= ?", Time.now.to_date)} - scope :recent, -> { where("updated_at >= ? ",Time.now - 7.days)} - + has_one :calentry, :as => :object + mount_uploader :picture, PictureUploader + scope :published, -> {where("datum >= ? AND datum IS NOT NULL", Time.now.to_date)} + scope :recent, -> { published.where("updated_at >= ? ",Time.now - 7.days)} + def datum_nilsave + self.datum.nil? ? Time.now + 42.years : self.datum + end + def public + self.rubrik.public && self.datum >=Time.now.to_date + end + def publish + self.datum = Time.now + end + def reverse_publish + self.datum = nil + end + def text_first_words + md = /

(?[\w\s,\.!\?]*)/.match self.text + md[:text].split(" ")[1..100].join(" ")+ " ..." + end end diff --git a/app/models/rubrik.rb b/app/models/rubrik.rb index 99b150c..6087ef8 100755 --- a/app/models/rubrik.rb +++ b/app/models/rubrik.rb @@ -13,6 +13,7 @@ class Rubrik < ActiveRecord::Base attr_accessible :desc, :name, :prio has_many :neuigkeiten, :class_name => "Neuigkeit" + has_many :calentries, :through => :neuigkeiten, :as=>:object resourcify def moderator u=User.with_role(:newsmoderator).first diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index 58d233a..0d136c3 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -35,7 +35,10 @@ class PictureUploader < CarrierWave::Uploader::Base version :thumb do process :resize_to_fill => [64, 64] end - + version :big_thumb do + process :resize_to_fill => [200,200] + + end version :portrait do process :resize_to_fill => [128,192] end diff --git a/app/views/modulgruppen/_modulgruppe.html.erb b/app/views/modulgruppen/_modulgruppe.html.erb index 0e3f9d4..503dc7b 100755 --- a/app/views/modulgruppen/_modulgruppe.html.erb +++ b/app/views/modulgruppen/_modulgruppe.html.erb @@ -2,8 +2,9 @@

<%= link_to modulgruppe.name, modulgruppe_path(modulgruppe) %>

- <%= modulgruppe.desc%> + <%= modulgruppe.desc%>
<% link_to ''.html_safe+I18n.t("common.edit"), edit_modulgruppe_path(modulgruppe) %> diff --git a/app/views/moduls/_kurz.html.erb b/app/views/moduls/_kurz.html.erb index 2f70525..793dd3f 100755 --- a/app/views/moduls/_kurz.html.erb +++ b/app/views/moduls/_kurz.html.erb @@ -1,6 +1,6 @@ -

+

  • <% if !modul.name.nil? %><%= link_to "Modul "+ modul.name , modul_path(modul) %> <%end%>

    <% link_to ''.html_safe+I18n.t("common.edit"), edit_modul_path(modul) %> -
  • + diff --git a/app/views/moduls/_modul.html.erb b/app/views/moduls/_modul.html.erb index 0bf3d55..d448ba5 100755 --- a/app/views/moduls/_modul.html.erb +++ b/app/views/moduls/_modul.html.erb @@ -12,17 +12,24 @@
    +

    Modulgruppen

    +

    Lvas

    <% @modul.lvas.each_slice(3) do |row| %> + <% end %> - +
    diff --git a/app/views/neuigkeiten/_form.html.erb b/app/views/neuigkeiten/_form.html.erb index f04ce43..347cfdd 100755 --- a/app/views/neuigkeiten/_form.html.erb +++ b/app/views/neuigkeiten/_form.html.erb @@ -3,9 +3,10 @@ <%= f.inputs do %> <%= f.input :title, :placeholder=>"Titel" %> <%= f.input :text, :as=>:tinymce_text %> - <%= f.input :datum %> + <% f.input :datum %> <%= f.input :rubrik, :as=>:radio, :collection=>Rubrik.all %> <%= f.input :author, :as=>:radio %> + <%= f.input :picture, :as=>:file %> <% end %> <%= f.actions do %> diff --git a/app/views/neuigkeiten/_neuigkeit.html.erb b/app/views/neuigkeiten/_neuigkeit.html.erb index a7d812b..57efadc 100755 --- a/app/views/neuigkeiten/_neuigkeit.html.erb +++ b/app/views/neuigkeiten/_neuigkeit.html.erb @@ -1,6 +1,15 @@ -

    <%= link_to neuigkeit.title,neuigkeit_path(neuigkeit) %>

    -<%= if !neuigkeit.author.nil? - neuigkeit.author.email -end %> -

    <%= raw(neuigkeit.text) %>

    + +
    +
    +


    <%= image_tag neuigkeit.picture.thumb.url unless neuigkeit.picture.url.nil? %>

    +
    +
    <%= neuigkeit.rubrik.name %> + <%= "am "+ I18n.l(neuigkeit.try(:datum).try(:to_date)) unless neuigkeit.try(:datum).try(:to_date).nil? %>
    +

    <%= link_to neuigkeit.title,neuigkeit_path(neuigkeit) %>

    + <%= raw(neuigkeit.text_first_words) unless neuigkeit.text.nil?%> + <%= link_to "more" , neuigkeit_path(neuigkeit) %> +

    +
    +
    + diff --git a/app/views/neuigkeiten/show.html.erb b/app/views/neuigkeiten/show.html.erb index 47bb223..5ba4922 100755 --- a/app/views/neuigkeiten/show.html.erb +++ b/app/views/neuigkeiten/show.html.erb @@ -9,20 +9,22 @@
    <%= @neuigkeit.rubrik.name %>
    -

    - <%= @neuigkeit.try(:author).email.to_s %> am - <%= I18n.l @neuigkeit.datum.to_date %>

    +
    + + <%= @neuigkeit.author.email.to_s unless @neuigkeit.try(:author).try(:email).to_s %> + <%= "am " + I18n.l(@neuigkeit.try(:datum).try(:to_date)) unless @neuigkeit.try(:datum).try(:to_date).nil? %>
    -
    -


    <%= "FOTO" %>

    +
    +


    <%= link_to image_tag(@neuigkeit.picture.big_thumb.url),@neuigkeit.picture.url %>

    <%= link_to @neuigkeit.title,neuigkeit_path(@neuigkeit) %>

    <%= raw(@neuigkeit.text) %> +

    diff --git a/app/views/rubriken/index.html.erb b/app/views/rubriken/index.html.erb index 0403397..2b8ee82 100755 --- a/app/views/rubriken/index.html.erb +++ b/app/views/rubriken/index.html.erb @@ -1,12 +1,12 @@ <%= render 'tabs' %>

    <%= I18n.t("rubrik.title")%>

    -<% @rubriken.each do |rubrik| %> -<% rubrik.neuigkeiten.recent.each do |n| %> -
  • <%= link_to n.title+"("+rubrik.name+")" , n %>
  • -<% end %> -<%= link_to 'Weitere Artikel zu '+rubrik.name.to_s , rubrik %> + diff --git a/app/views/rubriken/show.html.erb b/app/views/rubriken/show.html.erb index 380d922..d1e3110 100755 --- a/app/views/rubriken/show.html.erb +++ b/app/views/rubriken/show.html.erb @@ -21,7 +21,7 @@ <% row.each do |neuigkeit| %>
    <%= render neuigkeit %> -<%= link_to "more" , neuigkeit_path(neuigkeit) %> +
    <% end %>
    diff --git a/app/views/studien/_studium.html.erb b/app/views/studien/_studium.html.erb index 68333a6..26b57c7 100644 --- a/app/views/studien/_studium.html.erb +++ b/app/views/studien/_studium.html.erb @@ -1,6 +1,6 @@

    <%= link_to studium.name + " " + studium.zahl.to_s, studium_path(studium, :ansicht=>'semesteransicht')%>

    <%= studium.typ%>

    -

    Beschreibung:
    +

    <%=I18n.t("studien.desc")%>:
    <%= !(studium.desc.to_s == "") ? studium.desc.html_safe : I18n.t("keine.beschreibung")%>

    diff --git a/app/views/studien/_tabs.html.erb b/app/views/studien/_tabs.html.erb index 12684ca..358baa7 100644 --- a/app/views/studien/_tabs.html.erb +++ b/app/views/studien/_tabs.html.erb @@ -4,7 +4,7 @@ <% else %>
  • <% end %> - <%= link_to "Alle Studien", studien_path %>
  • + <%= link_to I18n.t("studien.allestudien"), studien_path %> <% for s in Studium.all %> <% if !@studium.nil? && s == @studium %> @@ -20,6 +20,6 @@ <% else %>
  • <% end %> -<%= link_to "Verwaltung", studien_verwalten_path %> +<%= link_to I18n.t("studien.verwaltung.title"), studien_verwalten_path %>
  • diff --git a/app/views/studien/semesteransicht.html.erb b/app/views/studien/semesteransicht.html.erb index b5b3a85..c8048f1 100644 --- a/app/views/studien/semesteransicht.html.erb +++ b/app/views/studien/semesteransicht.html.erb @@ -18,7 +18,7 @@

    <%= sem.name %>

    -
    <%= link_to 'Lvas hinzufügen/entfernen', edit_semester_path(sem), :class=>"btn-small"%>
    +
    <%= link_to I18n.t("lva.addrem"), edit_semester_path(sem), :class=>"btn-small"%>
    <% sem.lvas.each do |lva| %>
    diff --git a/config/locales/studien.de.yml b/config/locales/studien.de.yml index 538d33f..ebce704 100644 --- a/config/locales/studien.de.yml +++ b/config/locales/studien.de.yml @@ -1,5 +1,6 @@ de: studien: + desc: "Beschreibung" studien: "Studien" list: "Studien der Fakultät Elektrotechnik" anzeigen: "Studium anzeigen" @@ -21,6 +22,7 @@ de: beschreibung: "Keine Beschreibung vorhanden" lva: add: "Lva hinzufügen" + addrem: "Lva hinzufügen/entfernen" list: "Alle Lvas" semester: ohne: "Ohne Semesterzuordnung" diff --git a/config/routes.rb b/config/routes.rb index d575bd8..097b915 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,7 +51,8 @@ resources :neuigkeiten resources :fragen get 'rubriken/verwalten', :controller=>:rubriken, :action=>:alle_verwalten, :as=>'alle_verwalten_rubrik' - + + get 'neuigkeiten/:id/publish', :controller=>:neuigkeiten, :action=>:publish, :as=>'neuigkeit_publish' resources :rubriken do resources :neuigkeiten, :only=>[:new, :show] end diff --git a/db/migrate/20130124000300_translate_lvas.rb b/db/migrate/20130124000300_translate_lvas.rb index a00ac43..1a8e479 100755 --- a/db/migrate/20130124000300_translate_lvas.rb +++ b/db/migrate/20130124000300_translate_lvas.rb @@ -3,13 +3,13 @@ class TranslateLvas < ActiveRecord::Migration Lva.create_translation_table!({ :desc => :text }, { - #:migrate_data => true + :migrate_data => true }) end def self.down - Lva.drop_translation_table! #:migrate_data => true + Lva.drop_translation_table! :migrate_data => true end -end \ No newline at end of file +end diff --git a/db/migrate/20130823084252_add_object_to_calentries.rb b/db/migrate/20130823084252_add_object_to_calentries.rb new file mode 100644 index 0000000..4770792 --- /dev/null +++ b/db/migrate/20130823084252_add_object_to_calentries.rb @@ -0,0 +1,14 @@ +class AddObjectToCalentries < ActiveRecord::Migration + def up + add_column :calentries,:object_id, :integer + add_column :calentries,:object_type, :string + add_column :calentries, :public, :boolean + Calentry.update_all(:public => :true) + end + + def down + remove_column :calentries, :object_id + remove_column :calentries,:object_type + remove_column :calentries,:public + end +end diff --git a/db/migrate/20130823094216_add_public_to_rubrikneuigkeiten.rb b/db/migrate/20130823094216_add_public_to_rubrikneuigkeiten.rb new file mode 100644 index 0000000..36a3b9f --- /dev/null +++ b/db/migrate/20130823094216_add_public_to_rubrikneuigkeiten.rb @@ -0,0 +1,9 @@ +class AddPublicToRubrikneuigkeiten < ActiveRecord::Migration + def up + add_column :rubriken, :public,:boolean + Rubrik.update_all(:public => :true) + end + def down + remove_column :rubriken, :public + end +end diff --git a/db/migrate/20130823114945_add_picture_to_neuigkeiten.rb b/db/migrate/20130823114945_add_picture_to_neuigkeiten.rb new file mode 100644 index 0000000..d75f61a --- /dev/null +++ b/db/migrate/20130823114945_add_picture_to_neuigkeiten.rb @@ -0,0 +1,5 @@ +class AddPictureToNeuigkeiten < ActiveRecord::Migration + def change + add_column :neuigkeiten,:picture,:string + end +end