Neuigkeiten updateund lva

This commit is contained in:
Andreas Stephanides
2013-03-24 00:53:30 +01:00
parent 7494e76701
commit d6ce165782
10 changed files with 123 additions and 48 deletions

View File

@@ -1,5 +1,5 @@
class NeuigkeitenController < ApplicationController
before_filter {@toolbar_elements=[]}
def index
@neuigkeiten = Neuigkeit.all
end
@@ -7,7 +7,9 @@ class NeuigkeitenController < ApplicationController
def show
@neuigkeit = Neuigkeit.find(params[:id])
if can? :edit, @neuigkeit
@toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_neuigkeit_path(@neuigkeit),:icon=>:pencil}
end
end
def new

View File

@@ -1,5 +1,5 @@
class RubrikenController < ApplicationController
before_filter {@toolbar_elements=[]}
def index
@rubriken = Rubrik.all

View File

@@ -1,50 +1,48 @@
class StudienController < ApplicationController
before_filter {@toolbar_elements =[]}
def index
@studien = Studium.all
end
@toolbar_elements<<{:icon =>:plus, :text=> I18n.t('studien.new') ,:path=>new_studium_path }
end
def show
@studium= Studium.find(params[:id])
@studienphasen=[]
[1, 2 ,3].each do |ph|
modulgruppen_phase=@studium.modulgruppen.where(:phase=>ph)
if modulgruppen_phase.count==1
opts={:width=>12, :slice=>1}
elsif modulgruppen_phase.count <= 4
opts={:width=>6, :slice=>2}
else
opts={:width=>4, :slice=>3}
end
modulgruppen =[]
modulgruppen_phase.each_slice(opts[:slice]) do |s|
modulgruppen<<s
end
[1, 2 ,3].each do |ph|
modulgruppen_phase=@studium.modulgruppen.where(:phase=>ph)
if modulgruppen_phase.count==1
opts={:width=>12, :slice=>1}
elsif modulgruppen_phase.count <= 4
opts={:width=>6, :slice=>2}
else
opts={:width=>4, :slice=>3}
end
modulgruppen =[]
modulgruppen_phase.each_slice(opts[:slice]) do |s|
modulgruppen<<s
end
@studienphasen << {:modulgruppen=>modulgruppen, :phase => ph}.merge(opts)
@toolbar_elements=[{:text => '<i class="icon-plus"></i> '.html_safe + I18n.t('studien.new') , :path => new_studium_modulgruppe_path(@studium) }]
@toolbar_elements<<{:text => '<i class="icon-pencil"></i> '.html_safe + I18n.t('common.edit'),:path=>edit_studium_path(@studium)}
@toolbar_elements<<{:link=> link_to('Destroy', @studium, method: :delete, data: { confirm: 'Are you sure?' })}
end
end
@toolbar_elements=[{:icon =>:plus ,:text=> I18n.t('studien.new') , :path => new_studium_modulgruppe_path(@studium) }]
@toolbar_elements<<{:icon=>:pencil,:text =>I18n.t('common.edit'),:path => edit_studium_path(@studium)}
@toolbar_elements<<{:text=> I18n.t('common.delete'),:path => studium_path(@studium), :method=> :delete,:confirm=>"Sure?" }
end
def new
@studium = Studium.new
end
# GET /studia/1/edit
def edit
@studium = Studium.find(params[:id])
@toolbar_elements=[{:text => I18n.t('studien.anzeigen') , :path => url_for(@studium) }]
@toolbar_elements<<{:text =>I18n.t('studien.allestudien'),:path=>studien_path(@studium)}
end
# POST /studia
# POST /studia.json
def create
@studium = Studium.new(params[:studium])
respond_to do |format|
if @studium.save
format.html { redirect_to url_for(@studium), notice: 'Studium was successfully created.' }
@@ -57,20 +55,16 @@ class StudienController < ApplicationController
def update
@studium = Studium.find(params[:id])
respond_to do |format|
if @studium.update_attributes(params[:studium])
format.html { redirect_to url_for(@studium), notice: 'Studium was successfully updated.' }
redirect_to url_for(@studium), notice: 'Studium was successfully updated.'
else
format.html { render action: "edit" }
render action: "edit"
end
end
end
# DELETE /studia/1
# DELETE /studia/1.json
def destroy
@studium = Studium.find(params[:id])
@studium.destroy

View File

@@ -8,10 +8,41 @@ module ApplicationHelper
end
def toolbar_html(elemente)
html = ""
elemente.each do |e|
html = html + link_to(e[:text],e[:path]) + " | "
end
#html= html + "</ul>"
limiter = " | "
elemente.each do |e|
if !e[:icon].nil?
case e[:icon]
when :pencil
text = '<i class="icon-pencil"></i>'.html_safe + e[:text]
when :plus
text ='<i class="icon-plus"></i>'.html_safe+e[:text]
else
text = e[:text]
end
else
text =e[:text]
end
if e[:link].nil?
if !e[:method].nil?
if !e[:confirm].nil?
html = html + link_to(text,e[:path],:confirm=>e[:confirm],:method=>e[:method])
else
html = html + link_to(text,e[:path],:method => e[:method])
end
else
if !e[:confirm].nil?
html=html + link_to(text,e[:path],:confirm=>e[:confirm])
else
html= html + link_to(text,e[:path])
end
end
else
html = html + e[:link]
end
html=html+limiter
end
raw(html)
end
end
end

View File

@@ -5,4 +5,37 @@ class Lva < ActiveRecord::Base
has_and_belongs_to_many :semester
translates :desc, :fallbacks_for_empty_translations => true
has_many :beispiele , :class_name => "Beispiel"
after_initialize :load_tissdata
def hash
url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W"
@hash=Hash.from_xml(open(url).read)
end
def objective
@hash["course"]["objective"][I18n.locale.to_s]
end
def techingContent
@hash["course"]["teachingContent"][I18n.locale.to_s]
end
def person
@person
end
private
def load_tissdata
url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W"
begin
@hash=Hash.from_xml(open(url).read)["tuvienna"]
@person=[]
# @person = @hash["course"]["lecturers"]["oid"]
@hash["course"]["lecturers"]["oid"].each do |pid|
@person << Hash.from_xml(open("https://tiss.tuwien.ac.at/adressbuch/adressbuch/person_via_oid/" + pid.to_s + ".xml").read)["tuvienna"]["person"]
end
rescue OpenURI::HTTPError => e
end
end
end

View File

@@ -1,5 +1,11 @@
<div style="border: solid 1px; padding:2px"><p>
<b><%= link_to "Modul "+ modul.name , modul_path(modul) %> </b>
<b><%=
if modul.name.nil?
name=""
else
name=modul.name
end
link_to "Modul "+name , modul_path(modul) %> </b>
</p>
<p>
<%= raw(modul.desc) %>
@@ -11,5 +17,5 @@ LVAs:
<% end %>
</ul>
<% link_to '<i class="icon-pencil"></i>'.html_safe+I18n.t("common.edit"), edit_modul_path(modul) %>
<% # @toolbar_elements << {:icon=>:pencil,:text=>I18n.t("common.edit"),:path=> edit_modul_path(modul)} %>
</div>

View File

@@ -1,2 +1,5 @@
<h2><%=neuigkeit.title %></h2>
<h2><%= link_to neuigkeit.title,neuigkeit_path(neuigkeit) %></h2>
<%= if !neuigkeit.author.nil?
neuigkeit.author.name
end %>
<p><%= raw(neuigkeit.text) %></p>

View File

@@ -1,11 +1,14 @@
<ul class="breadcrumb">
<li><%= link_to "Neuigkeiten", rubriken_path %></li>
<li><span class="divider">/</span></li>
<li><%= link_to @neuigkeit.rubrik.name , rubrik_path(@neuigkeit.rubrik) %> </li>
</ul>
<p id="notice"><%= notice %></p>
<%= render @neuigkeit %>
<p>
<b>Datum:</b>
<%= @neuigkeit.datum %>
</p>
<% elements=[link_to('Edit', edit_neuigkeit_path(@neuigkeit))]
elements << link_to('Back', rubrik_path(@neuigkeit.rubrik)) %>
<%= toolbar_html (elements) %>
<%= toolbar_html (@toolbar_elements) %>

View File

@@ -40,3 +40,5 @@
<%= link_to 'Back', rubriken_path %> |
<%= link_to 'Destroy', @rubrik, method: :delete, data: { confirm: 'Are you sure?' } %>
</span></div>
<%= toolbar_html(@toolbar_elements)%>

View File

@@ -12,3 +12,4 @@
<br />
<%= link_to I18n.t("studien.new"), new_studium_path %>
<%= toolbar_html(@toolbar_elements) %>