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/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/neuigkeit.rb b/app/models/neuigkeit.rb index 5ad5e9b..bdb1e7d 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 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 @@ +
| + <%= fa_icon("tag") if a.flag_titlepic %> + <%= link_to a.datei.url do %> + <%= render partial:"attachments/attachment_new", object: a %> + <% end %> + | + <% if editor %> ++ + | + <% end %> +
<%= 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 "Qualifikationsprofil", studium_path( @studium, :ansicht=>"qualifikationsprofil")%>
+ <%= render_attachments_for(@studium) %> + <%= raw(@studium.desc) %>