diff --git a/app/controllers/lvas_controller.rb b/app/controllers/lvas_controller.rb index 7f0bd65..a76a7fa 100755 --- a/app/controllers/lvas_controller.rb +++ b/app/controllers/lvas_controller.rb @@ -18,6 +18,9 @@ class LvasController < ApplicationController @toolbar_elements<<{:hicon=>'icon-plus-sign', :icon=>:plus, :text => "Neues Beispiel", :path=> new_beispiel_path(:lva_id =>@lva.id)} @toolbar_elements<<{:hicon=>'icon-pencil', :icon=>:pencil,:text =>I18n.t('common.edit'),:path => edit_lva_path(@lva)} @toolbar_elements << {:hicon=>'icon-remove-circle', :text=>I18n.t('common.delete'), :path=> lva_path(@lva), :method=>:delete, :confirm=>'Sure?' } + @toolbar_elements << {:hicon=>'icon-remove-circle', :text=>"df", :path=> lva_compare_tiss_path(@lva)} + + end # GET /lvas/new @@ -38,11 +41,21 @@ class LvasController < ApplicationController end def compare_tiss - + @lva = Lva.find_by_id(params[:lva_id]) + @lvatiss = Lva.new + @lvatiss.lvanr=@lva.lvanr + @lvatiss.load_tissdata("-2013W") + end def load_tiss - + @lva = Lva.find_by_id(params[:lva_id]) + @lva.load_tissdata("-2013W") + if @lva.save + redirect_to @lva , notice: 'Lva von TISS geleaden.' + else + redirect_to @lva, action: :compare_tiss + end end @@ -54,7 +67,7 @@ class LvasController < ApplicationController respond_to do |format| if @lva.save - @lva.add_semesters + @lva.add_semesters format.html { redirect_to @lva, notice: 'Lva was successfully created.' } else diff --git a/app/models/lva.rb b/app/models/lva.rb index 4bf9bf8..e963d0d 100755 --- a/app/models/lva.rb +++ b/app/models/lva.rb @@ -36,14 +36,14 @@ class Lva < ActiveRecord::Base ERLAUBTE_TYPEN = ['VO', 'UE', 'VU', 'LU', 'SE', 'andere']; - has_paper_trail # Versionsverfolgung + has_paper_trail :ignore=>[:desc, :pruefungsinformation]# Versionsverfolgung attr_accessible :desc, :ects, :lvanr, :name, :stunden, :modul_ids, :semester_ids, :pruefungsinformation, :lernaufwand, :typ, :lecturer_ids has_and_belongs_to_many :modul,:uniq=>true # Gehört zu einem Modul has_and_belongs_to_many :semester #Gehört zu einem Semester( derzeit nicht implementiert) has_many :beispiele , :class_name => "Beispiel" has_and_belongs_to_many :lecturers - translates :desc, :fallbacks_for_empty_translations => true + translates :desc,:pruefungsinformation, :fallbacks_for_empty_translations => true, :versioning=>true 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? @@ -72,10 +72,35 @@ class Lva < ActiveRecord::Base ## # Lade Daten aus TISS und füge diese in die Datenbank ein. + def tisshash(semester) + url= "https://tiss.tuwien.ac.at/api/course/"+ lvanr.to_s.gsub(".","")+semester + hash=Hash.from_xml(open(url).read)["tuvienna"] + end def load_tissdata(semester) - url= "https://tiss.tuwien.ac.at/api/course/"+ lvanr.to_s.gsub(".","")+semester -# begin + urlp="https://tiss.tuwien.ac.at/api/course/"+ lvanr.to_s.gsub(".","")+"-" + begin + url= urlp+Time.now.year.to_s+"W" hash=Hash.from_xml(open(url).read)["tuvienna"] + rescue OpenURI::HTTPError => e + begin + url= urlp+Time.now.year.to_s+"S" + hash=Hash.from_xml(open(url).read)["tuvienna"] + rescue OpenURI::HTTPError => e + begin + url= urlp+(Time.now.year-1).to_s+"W" + hash=Hash.from_xml(open(url).read)["tuvienna"] + rescue OpenURI::HTTPError => e + + end + + end + + end + + + +# begin + # person=[] # if hash["course"]["lecturers"]["oid"].is_a? String # person = @hash["course"]["lecturers"]["oid"] @@ -84,15 +109,60 @@ class Lva < ActiveRecord::Base # person << Hash.from_xml(open("https://tiss.tuwien.ac.at/adressbuch/adressbuch/person_via_oid/" + pid.to_s + ".xml").read)["tuvienna"]["person"] # end # end - # rescue OpenURI::HTTPError => e - # end - self.name=hash["course"]["title"][I18n.locale.to_s] - self.pruefungsinformation = hash["course"]["examinationModalities"][I18n.locale.to_s] - self.desc= hash["course"]["objective"][I18n.locale.to_s]+hash["course"]["teachingContent"][I18n.locale.to_s] + self.name=hash["course"]["title"]["de"] + self.pruefungsinformation = hash["course"]["examinationModalities"][I18n.locale.to_s].to_s + self.desc= hash["course"]["objective"][I18n.locale.to_s]+"

"+hash["course"]["teachingContent"][I18n.locale.to_s] self.typ=hash["course"]["courseType"] self.stunden=hash["course"]["weeklyHours"] - end - + #hash["course"]["url"] + if hash["course"]["lecturers"]["oid"].is_a? Array + hash["course"]["lecturers"]["oid"].each do |oid| + lecturer= self.lecturers.where(:oid=>oid).first + if lecturer.nil? + lecturer=Lecturer.where(:oid=>oid).first + if lecturer.nil? + logger.debug "Neuen Lecturer laden" + lecturer=Lecturer.new + lecturer.oid=oid + lecturer.load_tissdata + if lecturer.save + self.lecturers << lecturer + else + logger.fatal "Invaliden Lecturer erzeugt" + end + else + logger.debug "Lecturer hinzufügen" + self.lecturers << lecturer + end + end + end + else + oid= hash["course"]["lecturers"]["oid"] + lecturer= self.lecturers.where(:oid=>oid).first + if lecturer.nil? + lecturer=Lecturer.where(:oid=>oid).first + if lecturer.nil? + logger.info "Neuen Lecturer laden" + lecturer=Lecturer.new + lecturer.oid=oid + lecturer.load_tissdata + if lecturer.save + self.lecturers << lecturer + else + logger.fatal "Invaliden Lecturer erzeugt" + end + else + + logger.info "Lecturer hinzufügen" + lecturer.load_tissdata + lecturer.save + self.lecturers << lecturer + end + end + + end + + end end diff --git a/app/views/lecturers/index.html.erb b/app/views/lecturers/index.html.erb index fe977db..8595cc6 100644 --- a/app/views/lecturers/index.html.erb +++ b/app/views/lecturers/index.html.erb @@ -16,7 +16,7 @@ <%= lecturer.name %> <%= lecturer.email %> <%= lecturer.oid %> - <%= lecturer.picture %> + <%= image_tag lecturer.picture.thumb %> <%= link_to 'Show', lecturer %> <%= link_to 'Edit', edit_lecturer_path(lecturer) %> <%= link_to 'Destroy', lecturer, method: :delete, data: { confirm: 'Are you sure?' } %> diff --git a/app/views/lvas/_lva.html.erb b/app/views/lvas/_lva.html.erb index e78e1f7..a49bb55 100755 --- a/app/views/lvas/_lva.html.erb +++ b/app/views/lvas/_lva.html.erb @@ -1,28 +1,25 @@ -<% @lva.modul.each do |modul| %> -<% modul.modulgruppen.each do |g| %> - -<% end %> -

<%= notice %>

+ +

<%=lva.typ.to_s + ' ' + lva.name %>

+

Prüfungsinformation

+
+ <%= lva.pruefungsinformation.to_s.html_safe %> +
+

Lernaufwand

+
+ <%= lva.lernaufwand %> +
+

Beschreibung

+
+ <%= lva.desc.to_s.html_safe %> +
+ +

- <%= @lva.lvanr %> - <%= @lva.name %> <%= @lva.ects %> ECTS/ <%= @lva.stunden %> Std - + <%= lva.lvanr %> + <%= lva.name %> <%= lva.ects %> ECTS/ <%= lva.stunden %> Std

- <%= @lva.desc %> +

- -<%= toolbar_html(@toolbar_elements) %> diff --git a/config/routes.rb b/config/routes.rb index bdfe913..b97e959 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -62,9 +62,11 @@ end get 'load_tiss' post 'show_tiss' end -resources :beispiele#, :only=>[:show,:index,:create] - resources :lvas do resources :beispiele#, :only=>[:show,:index,:create] + resources :lvas do + get 'compare_tiss' + get 'load_tiss' + resources :beispiele#, :only=>[:show,:index,:create] end resources :fragen