Neuigkeiten Link
Querverweise für Neuigkeiten
This commit is contained in:
@@ -1,28 +1,16 @@
|
||||
class NeuigkeitenController < ApplicationController
|
||||
before_filter {@toolbar_elements=[]}
|
||||
before_filter :load_toolbar_elements, :only=>[:show,:find_link]
|
||||
load_and_authorize_resource
|
||||
|
||||
def show
|
||||
@neuigkeit = Neuigkeit.find(params[:id])
|
||||
@rubrik=@neuigkeit.rubrik
|
||||
|
||||
if !params[:version].nil?
|
||||
@neuigkeit.assign_attributes(@neuigkeit.translation.versions.reverse[params[:version].to_i].reify.attributes.select{|k,v| @neuigkeit.translated_attribute_names.include? k.to_sym })
|
||||
|
||||
# @neuigkeit=Neuigkeit.find(params[:id])
|
||||
end
|
||||
@calentries1=@neuigkeit.calentries
|
||||
|
||||
@toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('neuigkeit.publish'),:path => publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>"Sure?" } if can? :publish, @neuigkeit
|
||||
@toolbar_elements << {:hicon=>'icon-minus', :text=> I18n.t('neuigkeit.unpublish'),:path => unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>"Sure?" } if can?(:unpublish, @neuigkeit) && !@neuigkeit.published?
|
||||
|
||||
@toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:icon=>:pencil} if can? :edit, @neuigkeit.rubrik
|
||||
@versions= @neuigkeit.translation.versions.select([:created_at]).reverse
|
||||
@toolbar_elements <<{:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:method=>:versions,:versions=>@versions}
|
||||
|
||||
@toolbar_elements << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :method=> :delete,:confirm=>'Sure?' } if can? :delete, @neuigkeit
|
||||
# @toolbar_elements << {:path=> add_calentry_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :text=>"Add Calentry", :icon=>:plus}
|
||||
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -74,6 +62,24 @@ class NeuigkeitenController < ApplicationController
|
||||
@calentries<< Calentry.new
|
||||
|
||||
end
|
||||
def find_link
|
||||
@rubrik=@neuigkeit.rubrik
|
||||
@calentries1=@neuigkeit.calentries
|
||||
@nlink_search = Neuigkeit::LINKTYPES.clone
|
||||
|
||||
@nlink_search.collect!{|t| t.constantize}
|
||||
@nlink_search.collect!{|t| t.search(params[:query]).limit(2)}
|
||||
|
||||
|
||||
@nlink_search.flatten!
|
||||
|
||||
render action:"show"
|
||||
end
|
||||
def create_link
|
||||
Nlink.create(:link=>params[:link_type].constantize.find(params[:link_id]),:neuigkeit=>Neuigkeit.find(params[:id]))
|
||||
|
||||
redirect_to action:"show"
|
||||
end
|
||||
|
||||
def create
|
||||
@neuigkeit = Neuigkeit.new(params[:neuigkeit])
|
||||
@@ -111,4 +117,24 @@ class NeuigkeitenController < ApplicationController
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_toolbar_elements
|
||||
@neuigkeit=Neuigkeit.find(params[:id])
|
||||
@toolbar_elements=[]
|
||||
@toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('neuigkeit.publish'),:path => publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>'Sure?' } if can?(:publish, @neuigkeit) && @neuigkeit.published?
|
||||
@toolbar_elements << {:hicon=>'icon-minus', :text=> I18n.t('neuigkeit.unpublish'),:path => unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>'Sure?' } if can?(:unpublish, @neuigkeit) && !@neuigkeit.published?
|
||||
@toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:icon=>:pencil} if can? :edit, @neuigkeit.rubrik
|
||||
@versions= @neuigkeit.translation.versions.select([:created_at]).reverse
|
||||
|
||||
@toolbar_elements <<{:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:method=>:versions,:versions=>@versions}
|
||||
|
||||
@toolbar_elements << {:hicon=>'icon-remove-circle', :text=> I18n.t('common.delete'),:path => rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit), :method=> :delete,:confirm=>'Sure?' } if can? :delete, @neuigkeit
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -29,7 +29,6 @@ class ThemengruppenController < ApplicationController
|
||||
@toolbar_elements << {:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t("themengruppe.manage"), :path=>themengruppe_verwalten_path(@themengruppe)} if can? :edit, @themengruppe
|
||||
@toolbar_elements << {:hicon=>'icon-remove-circle',:text=>I18n.t('themengruppe.remove'), :path=>themengruppe_path(@themengruppe), :method=>:delete,:confirm=>I18n.t('themengruppe.sure')} if can? :delete, @themengruppe
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @themengruppe }
|
||||
|
||||
@@ -14,4 +14,11 @@ class Gallery < ActiveRecord::Base
|
||||
WORD_COUNT = 20
|
||||
attr_accessible :datum, :desc, :name
|
||||
has_many :fotos
|
||||
has_many :nlinks, as: :link
|
||||
scope :search, ->(query) {where("name like ? or desc like ?", "%#{query}%", "%#{query}%")}
|
||||
|
||||
def title
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ class Gremium < ActiveRecord::Base
|
||||
|
||||
belongs_to :thema # Gehört zu einem Thema
|
||||
scope :tabs, -> { where(:typ => [1,3]).order(:typ).order(:name) } # Gremien die in Tabs angezeigt werden (Alle Anderen nur in der Liste
|
||||
scope :search, ->(query) {where("name like ? or desc like ?", "%#{query}%", "%#{query}%")}
|
||||
|
||||
# Gremium im 2. Fall für die Konstruktion "Mitglied des ... / der ... "
|
||||
accepts_nested_attributes_for :memberships, :reject_if=>lambda{|a| a[:typ].blank?|| a[:start].blank? ||a[:fetprofile_id].blank?}
|
||||
def fall2
|
||||
|
||||
@@ -44,6 +44,7 @@ class Lva < ActiveRecord::Base
|
||||
has_many :beispiele , :class_name => "Beispiel"
|
||||
has_and_belongs_to_many :lecturers
|
||||
translates :desc,:pruefungsinformation, :fallbacks_for_empty_translations => true, :versioning=>true
|
||||
scope :search, ->(query) {where("name like ? or desc like ?", "%#{query}%", "%#{query}%")}
|
||||
|
||||
validates :lvanr,:format=>{ :with => /^[0-9][0-9][0-9]\.[0-9A][0-9][0-9]$/}, :presence=>true, :uniqueness=>true # , :uniqueness=>true # LVA-Nummer muss das Format 000.000 besitzen (uniqueness?) oder 000 für nicht
|
||||
validates_presence_of :ects # ECTS vorhanden?
|
||||
@@ -52,6 +53,11 @@ class Lva < ActiveRecord::Base
|
||||
validates_presence_of :stunden # Stunden Eingetragen?
|
||||
validates_presence_of :modul # Zugehöriges Modul eingetragen?
|
||||
# (zumindest eines)
|
||||
has_many :nlinks, as: :link
|
||||
|
||||
def title
|
||||
self.name
|
||||
end
|
||||
def full_name
|
||||
return self.typ + ' ' + self.name
|
||||
end
|
||||
@@ -69,7 +75,6 @@ class Lva < ActiveRecord::Base
|
||||
|
||||
end
|
||||
|
||||
|
||||
##
|
||||
# Lade Daten aus TISS und füge diese in die Datenbank ein.
|
||||
def tisshash(semester)
|
||||
|
||||
@@ -28,8 +28,11 @@ class Neuigkeit < ActiveRecord::Base
|
||||
scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)}
|
||||
scope :public, ->{includes(:rubrik).where("rubriken.public"=>:true)}
|
||||
scope :search, ->(query) {where("text like ? or title like ?", "%#{query}%", "%#{query}%")}
|
||||
LINKTYPES=["Thema", "Gallery", "Lva"]
|
||||
accepts_nested_attributes_for :calentries, :allow_destroy=>true , :reject_if=> lambda{|a| a[:start].blank?}
|
||||
before_validation :sanitize
|
||||
has_many :nlinks
|
||||
|
||||
def datum_nilsave
|
||||
self.datum.nil? ? Time.now + 42.years : self.datum
|
||||
end
|
||||
|
||||
10
app/models/nlink.rb
Normal file
10
app/models/nlink.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class Nlink < ActiveRecord::Base
|
||||
attr_accessible :link_id, :link_type, :neuigkeit_id, :neuigkeit,:link, :sort, :title
|
||||
belongs_to :neuigkeit
|
||||
belongs_to :link, :polymorphic=>true
|
||||
validates :neuigkeit, :presence=>true
|
||||
validates :link, :presence=>true
|
||||
validates :link_id, :uniqueness=>{:scope=>[:neuigkeit_id]}
|
||||
|
||||
|
||||
end
|
||||
@@ -19,6 +19,6 @@ class Thema < ActiveRecord::Base
|
||||
validates :themengruppe, :presence => true
|
||||
validates :title, :presence => true
|
||||
scope :search, ->(query) {where("text like ? or title like ?", "%#{query}%", "%#{query}%")}
|
||||
|
||||
has_many :nlinks, as: :link
|
||||
translates :title,:text, :versioning =>true, :fallbacks_for_empty_translations => true
|
||||
end
|
||||
|
||||
21
app/views/galleries/_nlink.html.erb
Normal file
21
app/views/galleries/_nlink.html.erb
Normal file
@@ -0,0 +1,21 @@
|
||||
<div class="media gallery-block">
|
||||
<div class="pull-left" href="#">
|
||||
<%= if(nlink.fotos.empty?)
|
||||
image_tag "no_image_128.png", {:class => "img-rounded"}
|
||||
else
|
||||
image_tag nlink.fotos.sample.datei.big_thumb.url, {:class => "img-rounded"}
|
||||
end %>
|
||||
</div>
|
||||
<div class="media-body">
|
||||
<small class="pull-left"><%= nlink.fotos.size.to_s + " " + I18n.t('fotos.bilder')%> </small>
|
||||
<small class="pull-right"><%=I18n.l(nlink.try(:datum).try(:to_date)) unless nlink.try(:datum).try(:to_date).nil? %></small></br>
|
||||
<h1><%= nlink.name %></h1>
|
||||
<p>
|
||||
<%= if nlink.desc.split.size > Gallery::WORD_COUNT
|
||||
nlink.desc.split[0..Gallery::WORD_COUNT].join(" ") + " ..."
|
||||
else
|
||||
nlink.desc
|
||||
end%>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -25,6 +25,27 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="media gallery-block">
|
||||
<div class="pull-left" href="#">
|
||||
<%= if(gallery.fotos.empty?)
|
||||
image_tag "no_image_128.png", {:class => "img-rounded"}
|
||||
else
|
||||
image_tag gallery.fotos.sample.datei.big_thumb.url, {:class => "img-rounded"}
|
||||
end %>
|
||||
</div>
|
||||
<div class="media-body">
|
||||
<small class="pull-left"><%= gallery.fotos.size.to_s + " " + I18n.t('fotos.bilder')%> </small>
|
||||
<small class="pull-right"><%=I18n.l(gallery.try(:datum).try(:to_date)) unless gallery.try(:datum).try(:to_date).nil? %></small></br>
|
||||
<h1><%= gallery.name %></h1>
|
||||
<p>
|
||||
<%= if gallery.desc.split.size > Gallery::WORD_COUNT
|
||||
gallery.desc.split[0..Gallery::WORD_COUNT].join(" ") + " ..."
|
||||
else
|
||||
gallery.desc
|
||||
end%>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<% end %> <!-- end link -->
|
||||
</div> <!-- close span6 -->
|
||||
<% end %> <!-- end row -->
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="content-wrap content-column">
|
||||
<%= semantic_form_for :search,:remote=>true, :url=>search_home_index_path, :html=>{:id=>"search_form", :method=>'get'} do |f| %>
|
||||
<%= f.input :query, :input_html => { :name => 'query' } %>
|
||||
<%= f.input :query, :input_html => { :name => 'query' } , :label=>false %>
|
||||
<% end %>
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
|
||||
3
app/views/lvas/_nlink.html.erb
Normal file
3
app/views/lvas/_nlink.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h2><%= nlink.title %></h2>
|
||||
<% render :partial=> "lvas/lva", :object=>nlink %>
|
||||
=
|
||||
11
app/views/neuigkeiten/_nlink_list.html.erb
Normal file
11
app/views/neuigkeiten/_nlink_list.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<li>
|
||||
<%= link_to nlink_list.link do %>
|
||||
<div class="contentbox" >
|
||||
<% p = nlink_list.link_type.downcase.pluralize+"/nlink" %>
|
||||
<%= raw(strip_links(render :partial=>p, :object=>nlink_list.link )) %>
|
||||
</div>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
12
app/views/neuigkeiten/_nlink_list_search.html.erb
Normal file
12
app/views/neuigkeiten/_nlink_list_search.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
<li>
|
||||
<%= link_to nlink_list_search.title, nlink_list_search %>
|
||||
<%= link_to "add:"+nlink_list_search.title, create_link_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit, :link_id=>nlink_list_search.id, :link_type=>nlink_list_search.class.to_s) %>
|
||||
<div class="contentbox" >
|
||||
<% p = nlink_list_search.class.to_s.downcase.pluralize+"/nlink" %>
|
||||
<%= render :partial=>p, :object=>nlink_list_search %>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
@@ -23,10 +23,24 @@
|
||||
<p></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% @calentries1.each do |ce|%>
|
||||
<%= render ce unless ce.nil? %>
|
||||
<% end %>
|
||||
<%= render 'layouts/pretty_toolbar', :object=> @toolbar_elements %>
|
||||
</div>
|
||||
|
||||
Siehe auch:
|
||||
<ul>
|
||||
<div id="nlink_list">
|
||||
<%= render partial: "nlink_list", collection: @neuigkeit.nlinks %>
|
||||
</div>
|
||||
<div id="nlink_list_search">
|
||||
<%= render partial: "nlink_list_search", collection: @nlink_search %>
|
||||
</div>
|
||||
</ul>
|
||||
|
||||
<%= semantic_form_for :find_link, :url=>find_link_rubrik_neuigkeit_path(@rubrik,@neuigkeit), :html=>{:id=>"search_form", :method=>'get'} do |f| %>
|
||||
<%= f.input :query, :input_html => { :name => 'query' },:label=>false %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
1
app/views/themen/_nlink.html.erb
Normal file
1
app/views/themen/_nlink.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= raw(strip_links(render :partial=> "themen/small", :object=>nlink)) %>
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="content-wrap content-column" >
|
||||
|
||||
<h2>sdffs</h2>
|
||||
<h1><%= @themengruppe.title %></h1>
|
||||
<p>
|
||||
<%= @themengruppe.text %>
|
||||
@@ -8,7 +8,7 @@
|
||||
<% @themengruppe.themen.each do |thema| %>
|
||||
<li>
|
||||
<div class="contentbox">
|
||||
<a href="#<%=thema.id%>">
|
||||
<a name="<%=thema.id%>" href="#<%=thema.id%>">
|
||||
<h2><%= thema.title %></h2>
|
||||
</a>
|
||||
<% unless thema.gremium.nil? %>
|
||||
@@ -17,6 +17,9 @@
|
||||
</p>
|
||||
<% end %>
|
||||
<%= render :partial => 'themen/small', :object => thema %>
|
||||
<% thema.nlinks.each do |l| %>
|
||||
<%= render l.neuigkeit %>
|
||||
<% end %>
|
||||
</div>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<div class="content-wrap content-column" >
|
||||
<h1><%= @themengruppe.title %></h1>
|
||||
<p>
|
||||
<%= @themengruppe.text %>
|
||||
</p>
|
||||
<ul class="unstyled linkbox-list" >
|
||||
<% @themen.each do |thema| %>
|
||||
<li>
|
||||
<div class="contentbox">
|
||||
<a href="#<%=thema.id%>">
|
||||
<h2><%= thema.title %></h2>
|
||||
</a>
|
||||
<% unless thema.gremium.nil? %>
|
||||
<p>
|
||||
<%= link_to "Zu dem Gremium ..." , thema.gremium %>
|
||||
</p>
|
||||
<% end %>
|
||||
<%= render :partial => 'themen/small', :object => thema %>
|
||||
</div>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= render :partial=>'layouts/pretty_toolbar' unless @toolbar_elements.empty?%>
|
||||
</div>
|
||||
@@ -92,6 +92,8 @@
|
||||
get 'unpublish'
|
||||
get 'add_calentry'
|
||||
get 'rm_calentry'
|
||||
get 'create_link'
|
||||
get 'find_link'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
13
db/migrate/20140328200432_create_nlinks.rb
Normal file
13
db/migrate/20140328200432_create_nlinks.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class CreateNlinks < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :nlinks do |t|
|
||||
t.string :title
|
||||
t.integer :sort
|
||||
t.integer :neuigkeit_id
|
||||
t.integer :link_id
|
||||
t.string :link_type
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
11
spec/factories/nlinks.rb
Normal file
11
spec/factories/nlinks.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :nlink do
|
||||
title "MyString"
|
||||
sort 1
|
||||
neuigkeit_id 1
|
||||
link_id 1
|
||||
link_type "MyString"
|
||||
end
|
||||
end
|
||||
5
spec/models/nlink_spec.rb
Normal file
5
spec/models/nlink_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Nlink do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Reference in New Issue
Block a user