diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index d05b234..2d33a88 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -3,7 +3,7 @@ class AttachmentsController < ApplicationController # GET /attachments.json load_and_authorize_resource def index - @attachments = Attachment.all +# @attachments = Attachment.all respond_to do |format| format.html # index.html.erb @@ -11,28 +11,43 @@ class AttachmentsController < ApplicationController end end - # GET /attachments/1 - # GET /attachments/1.json + # GET + # sets the titlepic flag for one attachment for one parent object def set_titlepic - @attachment = Attachment.find(params[:id]) - if @attachment.image? - @attachment.flag_titlepic = params[:titlepic] - @attachment.thema.titlepics << @attachment + @attachment = Attachment.find(params[:id]) + if @attachment.image? # if attachment is an Image set flag + @attachment.parent.attachments.update_all("flag_titlepic=0") + @attachment.flag_titlepic=true @attachment.save end - redirect_to @attachment.thema + respond_to do |format| + format.html { + redirect_to @attachment} + format.js { + @parent=@attachment.parent + @attachments=@parent.attachments + render :refresh_list + } + end end + # GET refresh_list + # refresh the attachment list for a parent object + def refresh_list + @parent = params[:parent_type].constantize.find(params[:parent_id]) + @attachments=@parent.attachments + respond_to do |format| + format.js + end + end + #get /attachments/ID def show @attachment = Attachment.find(params[:id]) - respond_to do |format| format.html # show.html.erb - format.json { render json: @attachment } end end # GET /attachments/new - # GET /attachments/new.json def new @attachment = Attachment.new @thema = Thema.find(params[:thema_id]) @@ -58,10 +73,8 @@ class AttachmentsController < ApplicationController @thema = Thema.find_by_id(params[:thema_id]) # logger.info "gg" @attachment.thema = @thema - @attachment.name=@attachment.datei.filename - @action="create" - - + @attachment.name=@attachment.datei.filename + @action="create" # logger.info "sdf" respond_to do |format| if @attachment.save @@ -86,11 +99,11 @@ class AttachmentsController < ApplicationController # PUT /attachments/1.json def update @attachment = Attachment.find(params[:id]) - @thema = @attachment.thema - + @parent= @attachment.parent + respond_to do |format| if @attachment.update_attributes(params[:attachment]) - format.html { redirect_to @thema, notice: 'Attachment was successfully updated.' } + format.html { redirect_to @parent, notice: 'Attachment was successfully updated.' } format.json { head :no_content } format.js {@attachment=Attachment.new; render action:"create"} else diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 4b9086a..dc335fc 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -21,6 +21,7 @@ class DocumentsController < ApplicationController @parent=@document.parent respond_to do |format| format.js + format.html end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 4148aca..297dbd8 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -24,6 +24,10 @@ class HomeController < ApplicationController t=YAML.load_file("#{::Rails.root.to_s}/config/contact_topic.yml") @themen = Thema.where(:id=>t) end + def treeview + authorize! :doadmin, User + @themengruppen = Themengruppe.intern.order(:priority).reverse + end def intern authorize! :seeintern, User @neuigkeiten = Neuigkeit.intern.recent diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 23d9f2f..7d6fae6 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,8 @@ module ApplicationHelper + def cache_array_key(array) + array.map{|c| c.id}.join('')+"_"+array.max{|c|c.updated_at.to_i}.updated_at.to_i.to_s+"_"+I18n.locale.to_s + end + def clean_calendar(cal) cal.rubrik.meetingtyps.each do |mt| mt.meetings.each do |m| diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 3c961c9..34f1839 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -1,2 +1,9 @@ module AttachmentsHelper + + def render_attachments_for(p) + a= Attachment.new + a.parent=p + render(partial:"attachments/attachment_list", object: p.attachments, locals: {editor: (can?(:edit, p)), parent: p} )+ ((can?(:edit, p))? (render partial:"attachments/form_bulk2", object: a ): "") + + end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index b1e7883..705ddae 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -12,11 +12,13 @@ class Attachment < ActiveRecord::Base has_paper_trail - attr_accessible :name, :datei, :datei_cache,:flag_titlepic + attr_accessible :name, :datei, :datei_cache,:flag_titlepic,:parent_id, :parent_type belongs_to :thema mount_uploader :datei, AttachmentUploader - validates :thema, :presence => true +# validates :thema, :presence => true validates :name, :presence => true + scope :titlepic, ->{where(flag_titlepic: true)} + default_scope order("LOWER(name)") belongs_to :parent, :polymorphic=>true def image? @@ -24,6 +26,9 @@ class Attachment < ActiveRecord::Base # %w(jpg png jpeg).include?(data_ext) datei.image?(datei.file) end + def self.parent_attachment_list_id(parent) + "attachments_for_"+parent.class.to_s+"_"+parent.id.to_s + end def to_jq_upload { diff --git a/app/models/document.rb b/app/models/document.rb index 7fff30a..f98535c 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -9,6 +9,7 @@ class Document < ActiveRecord::Base validate :parent, :presence=>true has_paper_trail TYPS = { 1=>"fet_docs", 10=>"protocol", 11=> "agenda"} + has_many :attachments, :as=>:parent def long_name if self.parent.class=="Meeting" ""+self.parent.text+ ""+ self.name diff --git a/app/models/foto.rb b/app/models/foto.rb index cbe9761..b8895c9 100644 --- a/app/models/foto.rb +++ b/app/models/foto.rb @@ -15,6 +15,7 @@ class Foto < ActiveRecord::Base attr_accessible :datei, :desc, :gallery_id, :title belongs_to :gallery mount_uploader :datei, FotoUploader + before_save :parse_exif resourcify def to_jq_upload { @@ -28,4 +29,11 @@ class Foto < ActiveRecord::Base "delete_type" => "DELETE" } end + def parse_exif + unless self.exif.nil? || self.exif.empty? + j=JSON.parse(self.exif) + datetime = j.select {|i| i.first == "DateTime"}.try(:first).try(:last) + self.taken_at=Time.new(datetime) unless datetime.nil? + end + end end diff --git a/app/models/meeting.rb b/app/models/meeting.rb index 2d82dff..425ad71 100644 --- a/app/models/meeting.rb +++ b/app/models/meeting.rb @@ -31,7 +31,7 @@ class Meeting < ActiveRecord::Base end t= t+ self.name.to_s # t = t + " " + I18n.l(self.calentry.start) unless self.calentry.nil? - t = t +" am "+ self.calentry.text unless self.calentry.nil? + t = t +" "+ I18n.t("date.am")+" "+ self.calentry.text unless self.calentry.nil? t end def create_announcement(user) diff --git a/app/models/neuigkeit.rb b/app/models/neuigkeit.rb index 5ad5e9b..69ecbb7 100755 --- a/app/models/neuigkeit.rb +++ b/app/models/neuigkeit.rb @@ -20,6 +20,9 @@ class Neuigkeit < ActiveRecord::Base has_many :calentries, as: :object has_many :nlinks has_one :meeting + has_many :attachments, :as=>:parent + + validates :rubrik, :presence=>true validates :author, :presence=>true @@ -46,7 +49,11 @@ class Neuigkeit < ActiveRecord::Base if self.has_meeting? return self.meeting.meetingtyp.picture else - return self.picture + unless self.attachments.where(flag_titlepic: true).first.nil? + return self.attachments.where(flag_titlepic: true).first.datei + else + return self.picture + end end end end @@ -108,16 +115,16 @@ class Neuigkeit < ActiveRecord::Base self.has_calentries? end def relevant_calentry - self.calentries.min_by{|c| c.days_to_today * 2 * ((c.is_past?)? 2:1)} + self.calentries.min_by{|c| c.days_to_today * 1.3 * ((c.is_past?)? 2:1)} end def update_cache if self.has_meeting? && !self.meeting.calentry.nil? - self.update_column(:cache_order, (self.meeting.calentry.start.to_date - Date.today).to_i.abs * 2) + self.update_column(:cache_order, (self.meeting.calentry.start.to_date - Date.today).to_i.abs * 1.3) self.update_column(:cache_relevant_date, self.meeting.calentry.start.to_date) else if self.is_event? - c = self.calentries.min_by{|c| c.days_to_today * 2 * ((c.is_past?)? 2:1)} - self.update_column(:cache_order, c.days_to_today * 2 * ((c.is_past?)? 2:1)) + c = self.calentries.min_by{|c| c.days_to_today * 1.3 * ((c.is_past?)? 2:1)} + self.update_column(:cache_order, c.days_to_today * 1.3 * ((c.is_past?)? 2:1)) self.update_column(:cache_relevant_date, (c.is_past?) ? c.ende.to_date : c.start.to_date) else unless self.datum.nil? diff --git a/app/models/studium.rb b/app/models/studium.rb index a701f6a..2355ae6 100755 --- a/app/models/studium.rb +++ b/app/models/studium.rb @@ -33,7 +33,7 @@ class Studium < ActiveRecord::Base has_many :moduls, :through=>:modulgruppen has_many :lvas, :through=>:moduls has_many :semester, :dependent => :destroy - + has_many :attachments, :as=>:parent validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/} validates :typ, :inclusion => {:in => ["Bachelor","Master"] } validates :name, :uniqueness => true, :presence=>true diff --git a/app/models/thema.rb b/app/models/thema.rb index c1503f3..9b77a1e 100644 --- a/app/models/thema.rb +++ b/app/models/thema.rb @@ -22,7 +22,7 @@ class Thema < ActiveRecord::Base # Each topic has multiple questions, that are also referenced in the FAQ. has_many :fragen # Attachments can be all data formats - has_many :attachments + has_many :attachments, :as=>:parent # attached pics can be used as title pictures has_many :titlepics, :as=>:parent, :class_name=>'Attachment', :conditions=>{:flag_titlepic=>true} # each topic has to belong to one group diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb index d08f8cd..407c604 100644 --- a/app/uploaders/attachment_uploader.rb +++ b/app/uploaders/attachment_uploader.rb @@ -29,14 +29,11 @@ end end version :thumb ,:if=>:image? do process :resize_to_fill => [64, 64] - process :convert => :jpg - def full_filename(for_file) - super.chomp(File.extname(super)) + '.jpg' - end end - version :cover , :if=>:image? do + + version :cover , :if=>:pdf? do process :cover process :resize_to_fit => [64,64] process :convert => :jpg @@ -44,9 +41,11 @@ end super.chomp(File.extname(super)) + '.jpg' end end + version :thumb_small , :if=>:image? do process :resize_to_fill => [32, 32] end + version :thumb_big , :if=>:image? do process :resize_to_fill => [200, 200] @@ -56,6 +55,10 @@ end end end + version :big_thumb , :if=>:image? do + process :resize_to_fill => [200,200] + end + version :resized, :if=>:image? do process :resize_to_fit => [1024,1024] end @@ -92,7 +95,9 @@ end def extention File.extname(full_filename(file.file)).downcase end - + def pdf?(for_file) + %w(.pdf).include?(File.extname(full_filename(for_file.file)).downcase) + end def image?(for_file) %w(.jpg .png .jpeg).include?(File.extname(full_filename(for_file.file)).downcase) end diff --git a/app/uploaders/foto_uploader.rb b/app/uploaders/foto_uploader.rb index 1a2385d..5058f26 100644 --- a/app/uploaders/foto_uploader.rb +++ b/app/uploaders/foto_uploader.rb @@ -32,9 +32,12 @@ class FotoUploader < CarrierWave::Uploader::Base # end # general settings + process :fix_exif_rotation + process :store_exif process :strip process :convert => 'jpg' + # Create different versions of your uploaded files: version :thumb do @@ -62,5 +65,9 @@ class FotoUploader < CarrierWave::Uploader::Base # "something.jpg" if original_filename # end - + def store_exif + img = Magick::Image.read(current_path) + model.exif=img.first.get_exif_by_entry().to_json + + end end diff --git a/app/views/attachments/_attachment.html.erb b/app/views/attachments/_attachment.html.erb index 2b45971..f46acd5 100644 --- a/app/views/attachments/_attachment.html.erb +++ b/app/views/attachments/_attachment.html.erb @@ -4,6 +4,7 @@ <% if (!["jpg","png","jpeg"].find_index(data_ext).nil?) %> <%= image_tag attachment.datei.thumb.url %> <% else %> + <%= image_tag "pdf-logo.jpg" %> <% end %> <%= attachment.name %> diff --git a/app/views/attachments/_attachment_list.html.erb b/app/views/attachments/_attachment_list.html.erb new file mode 100644 index 0000000..02d40b9 --- /dev/null +++ b/app/views/attachments/_attachment_list.html.erb @@ -0,0 +1,30 @@ + + <% attachment_list.each do |a| %> + + + <% if editor %> + + <% end %> + + <% end %> +
+ <%= fa_icon("tag") if a.flag_titlepic %> + <%= link_to a.datei.url do %> + <%= render partial:"attachments/attachment_new", object: a %> + <% end %> + + +
diff --git a/app/views/attachments/_attachment_new.html.erb b/app/views/attachments/_attachment_new.html.erb new file mode 100644 index 0000000..197c819 --- /dev/null +++ b/app/views/attachments/_attachment_new.html.erb @@ -0,0 +1,14 @@ +<% attachment=attachment_new %> + <% data_ext = attachment.datei.file.try(:extension).try(:downcase) %> + + + <% if (!["jpg","png","jpeg"].find_index(data_ext).nil?) %> + <%= image_tag attachment.datei.thumb_small.url %> + <% elsif (!["pdf"].find_index(data_ext).nil?)%> + <%= image_tag attachment.datei.cover.url %> + + <% else %> + <%= ff_icon("ffi1-note20 fa-2x") %> + + <% end %> + <%= attachment.name %> diff --git a/app/views/attachments/_form_bulk2.html.erb b/app/views/attachments/_form_bulk2.html.erb new file mode 100644 index 0000000..16958a1 --- /dev/null +++ b/app/views/attachments/_form_bulk2.html.erb @@ -0,0 +1,145 @@ + +
+ <%= semantic_form_for [form_bulk2], :remote=>true, :html => { :multipart => true, :id => "fileupload" } do |f| %> + +
+ +
+
+ + + + Add files... + <%= f.file_field :datei, :multiple=>true %> + <%= f.input :parent_id , as: :hidden %> + <%= f.input :parent_type, as: :hidden %> + + + + + +
+
+ +
+
+
+
+
+
+ +
+
+ + +
+ <% end %> + +
+ + + + + + + + diff --git a/app/views/attachments/edit.html.erb b/app/views/attachments/edit.html.erb index 919ea5c..be5e0f3 100644 --- a/app/views/attachments/edit.html.erb +++ b/app/views/attachments/edit.html.erb @@ -3,4 +3,4 @@ <%= render 'form' %> -<%= link_to 'Back', thema_attachments_path(@attachment.thema,@attachment) %> +<%= link_to 'Back', attachments_path(@attachment) %> diff --git a/app/views/attachments/refresh_list.js.erb b/app/views/attachments/refresh_list.js.erb new file mode 100644 index 0000000..d4d1750 --- /dev/null +++ b/app/views/attachments/refresh_list.js.erb @@ -0,0 +1 @@ +$("#<%= Attachment.parent_attachment_list_id(@parent) %>").replaceWith("<%= escape_javascript ( render partial:"attachments/attachment_list", object:@attachments, locals: {editor: true, parent: @parent} ) %>") \ No newline at end of file diff --git a/app/views/attachments/show.html.erb b/app/views/attachments/show.html.erb index b43b363..2109dda 100644 --- a/app/views/attachments/show.html.erb +++ b/app/views/attachments/show.html.erb @@ -1,10 +1,10 @@

<%= notice %>

-

Name: <%= @attachment.name %> + <%= render @attachment %>

<%= link_to 'Edit', edit_attachment_path(@attachment) %> | -<%= link_to 'Back', attachments_path %> +<%= link_to 'Back', polymorphic_path(@attachment.parent) %> diff --git a/app/views/beispiele/_beispiel.html.erb b/app/views/beispiele/_beispiel.html.erb index 88ab024..8f9f51e 100644 --- a/app/views/beispiele/_beispiel.html.erb +++ b/app/views/beispiele/_beispiel.html.erb @@ -1,18 +1,19 @@
-
- +
<%=link_to ffi1_icon("note20")+" " + beispiel.name + " " + I18n.l(beispiel.datum), beispiel.beispieldatei.url, title: beispiel.desc %> - - <%= I18n.t("file.size") + ": " + (beispiel.beispieldatei.size/1024.0).round(2).to_s %>KiB
- - <%= - if can?(:like, beispiel) - link_to ffi1_icon("like3")+" like" + "("+beispiel.get_likes.size.to_s+")", like_beispiel_path(beispiel),title: "liked by " + ((current_user.liked?(beispiel)) ? ("you and " + ((beispiel.get_likes.size - 1).to_s + " others")) : beispiel.get_likes.size.to_s), remote: true - else - "liked by " + beispiel.get_likes.size.to_s - end - %> +
+
+ <%= (beispiel.beispieldatei.size/1024.0).round(2).to_s %>KiB +
+
+ <%= + if can?(:like, beispiel) + link_to ffi1_icon("like3")+" like" + "("+beispiel.get_likes.size.to_s+")", like_beispiel_path(beispiel),title: "liked by " + ((current_user.liked?(beispiel)) ? ("you and " + ((beispiel.get_likes.size - 1).to_s + " others")) : beispiel.get_likes.size.to_s), remote: true + else + "liked by " + beispiel.get_likes.size.to_s + end + %> <%= if can?(:dislike, beispiel) @@ -23,15 +24,17 @@ %> - <%= link_to ff_icon("icon-pencil")+" edit", edit_beispiel_path(beispiel) if can? :edit, beispiel%> - <%= link_to ff_icon("icon-remove")+" delete", beispiel_path(beispiel), :method=>:delete, :data=>{:confirm=>I18n.t('beispiel.sure')} if can? :delete, beispiel %> + <%= link_to ff_icon("icon-pencil")+"edit", edit_beispiel_path(beispiel) if can? :edit, beispiel%> + <%= link_to fa_icon("trash")+"delete", beispiel_path(beispiel), :method=>:delete, :data=>{:confirm=>I18n.t('beispiel.sure')} if can? :delete, beispiel %> <% link_to "Refresh", beispiel_path(beispiel,show_comments: true), remote: true %>
-
-
+
+ <% unless beispiel.desc.nil? || beispiel.desc.empty? %> +
+
+ <%= beispiel.desc %>
- - + <% end %>
diff --git a/app/views/documents/_document.html.erb b/app/views/documents/_document.html.erb index d66e778..d1563f6 100644 --- a/app/views/documents/_document.html.erb +++ b/app/views/documents/_document.html.erb @@ -4,5 +4,5 @@ <%= fa_icon("file-text") %> <%= link_to document.name, document %> - <%= link_to "edit", edit_document_path(document),:remote=>true if can? :edit, document %> + <%= link_to "rename", edit_document_path(document),:remote=>true if can? :edit, document %>
diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index 124e77d..8dcb20b 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -17,7 +17,10 @@ <% end %> + + +<%= render_attachments_for(@document) %> diff --git a/app/views/home/_beispiele.html.erb b/app/views/home/_beispiele.html.erb index 042288c..0cb337c 100644 --- a/app/views/home/_beispiele.html.erb +++ b/app/views/home/_beispiele.html.erb @@ -19,7 +19,7 @@ <%= b.updated_at.to_s%>
- <%end%> + <% end %> <% end %> diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index fc9b0cc..61a4ff1 100755 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -24,45 +24,19 @@
  • <%= link_to ffi1_icon("quiz")+ I18n.t("themengruppe.faqs"), faqs_themengruppen_path,class: :linkbox %> - -
  • <%= link_to ffi1_icon("books19")+"Beispielsammlung", studium_path(Studium.first, {:ansicht=>'semesteransicht'}) ,class: :btn ,class: :linkbox %>
  • -
  • <%= link_to "Alte Beispielsammlung", "http://www.fet.at/alt/bin/view/Beispielsammlung/WebHome" ,class: :btn ,class: :linkbox %>
  • - - - <% @stickythemen.each do |t1| %> -
  • - <%= link_to t1 do %> - <%= render partial: "themen/nlink", object: t %> - <%= end %> -
  • - <% end %> - - - -

    + <%= render 'beispiele' %>
    diff --git a/app/views/home/treeview.html.erb b/app/views/home/treeview.html.erb new file mode 100644 index 0000000..756d17f --- /dev/null +++ b/app/views/home/treeview.html.erb @@ -0,0 +1,69 @@ +Intern + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 85b802e..8993188 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -56,10 +56,6 @@ <%= yield %> -
    -
    -
    -