merge latest

This commit is contained in:
2018-05-14 20:17:30 +02:00
21 changed files with 652 additions and 110 deletions

View File

@@ -10,7 +10,7 @@ class Document < ActiveRecord::Base
has_paper_trail
TYPS = { 1=>"fet_docs", 10=>"protocol", 11=> "agenda"}
has_many :attachments, :as=>:parent
def long_name
def long_name
if self.parent.class=="Meeting"
"<b>"+self.parent.text+ "</b>"+ self.name
else
@@ -18,20 +18,20 @@ class Document < ActiveRecord::Base
end
end
def self.new_divid_for(parent)
"document_new_parent_" + parent.class.to_s + "_" + parent.id.to_s
"document_new_parent_" + parent.class.to_s + "_" + parent.id.to_s
end
def divid
"document_"+self.id.to_s
end
def self.ether
EtherpadLite.connect('http://www.fet.at/etherpad', File.new('/srv/etherpad/etherpad-lite/APIKEY.txt'))
EtherpadLite.connect('https://www.fet.at/etherpad', File.new('config/etherpad/APIKEY.txt'))#https://www.etherpad.fet.at
end
def create_pdf
require "open3"
#url=blank_document_url({id: self.id, host: host, port: port})
# url=Rails.application.routes.url_helpers.blank_document_url({id: self.id, host: host, port: port})
file = Tempfile.new(['document', '.pdf'])
bin=Rails.application.config.pdf_bin
sin,sout,serr=Open3.popen3("#{bin} --header-html \"file://#{Rails.root}/app/views/documents/header.html\" --footer-html \"file://#{Rails.root}/app/views/documents/footer.html\" --replace title1 \"#{self.name}\" - #{file.path}")
@@ -71,6 +71,7 @@ class Document < ActiveRecord::Base
def move_to_etherpad
unless self.is_etherpad? || self.id.nil?
self.etherpadkey="document_"+ self.id.to_s
if self.text.nill?
self.ep_pad.html = '<div>'+"text"+'</div>'
else
@@ -91,7 +92,7 @@ class Document < ActiveRecord::Base
end
def read_from_etherpad
self.text=ApplicationController.helpers.strip_control_chars( self.ep_pad.html)
end
def ep_pad
self.ep_group.pad(self.etherpadkey)
@@ -101,16 +102,16 @@ class Document < ActiveRecord::Base
Document.ether.group(Document::TYPS[t])
end
def text_stripped
ApplicationController.helpers.strip_control_chars(ApplicationController.helpers.strip_tags(text.to_s.gsub("<"," <").gsub(">","> ").to_s))
ApplicationController.helpers.strip_control_chars(ApplicationController.helpers.strip_tags(text.to_s.gsub("<"," <").gsub(">","> ").to_s))
end
searchable do
text :text, stored: true do |d|
d.text_stripped
end
text :name, :boost=>4.0, :stored=> true
text :meeting, stored: true do |d|
(d.parent.is_a?(Meeting))? d.try(:parent).try(:text).to_s : ""
text :name, :boost=>4.0, :stored=> true
text :meeting, stored: true do |d|
(d.parent.is_a?(Meeting))? d.try(:parent).try(:text).to_s : ""
end
end
def maketoc
@@ -124,20 +125,20 @@ class Document < ActiveRecord::Base
l=2
f=true;
s="<ul>"
c.each do |h|
c.each do |h|
s=s+ "</li></ul></li>"*(l-h["level"]) if (h["level"]<l) and !f
s=s+" </li>" if (h["level"]==l) and !f
s=s+" </li>" if (h["level"]==l) and !f
if (h["level"]>l)
s=s + "<ul><li>" * (h["level"]-l)
s=s + "<ul><li>" * (h["level"]-l)
else
s=s+"<li>"
end
end
s=s+h["text"]
l = h["level"]
f=false
end
s=s+"</ul>"*(l-2) if (l>2)
s=s+"</ul>"*(l-2) if (l>2)
s=s+"</ul>"
self.toc=s
end

View File

@@ -16,9 +16,9 @@ class Neuigkeit < ActiveRecord::Base
attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture,:picture_cache, :calentries_attributes, :flag_important
belongs_to :author, :class_name =>'User'
belongs_to :rubrik, :class_name =>'Rubrik', :foreign_key => "rubrik_id"
has_one :calendar, through: :rubrik
has_one :calendar, through: :rubrik
has_many :calentries, as: :object, :dependent=> :destroy
has_many :nlinks, :dependent=> :destroy
has_many :nlinks, :dependent=> :destroy
has_one :meeting
has_many :attachments, :as=>:parent
has_one :title_pic, :class_name=>"Attachment", :as=>:parent, :conditions=>["attachments.flag_titlepic =?", true]
@@ -60,11 +60,11 @@ class Neuigkeit < ActiveRecord::Base
end
def read_attribute(name,options={})
if translated?(name)
a=super(name,options)
a=self.translation_for(options[:locale] || I18n.locale).read_attribute(name) if self.no_fallbacks
a=super(name,options)
a=self.translation_for(options[:locale] || I18n.locale).read_attribute(name) if self.no_fallbacks
a
else
else
super(name)
end
end
@@ -91,7 +91,7 @@ class Neuigkeit < ActiveRecord::Base
!self.meeting.nil?
end
def self.published
where("datum <= ? AND datum IS NOT NULL", Time.now.to_date)
where("datum <= ? AND datum IS NOT NULL", Time.now.to_date)
end
def datum_nilsave
@@ -132,7 +132,17 @@ class Neuigkeit < ActiveRecord::Base
"...."
else
words[0..100].join(" ")+ " ..." unless words.nil?
end
end
def text_infoscreen_words
md = /<p>(?<text>[^\<\>]*)/.match Sanitize.clean(self.text,:elements=>['p'])
words=md[:text].split(" ") unless md.nil?
if words.nil? || words.empty?
"...."
else
words[0..1000].join(" ")+ " ..." unless words.nil?
end
end
def has_calentries?
@@ -143,7 +153,7 @@ class Neuigkeit < ActiveRecord::Base
end
def relevant_calentry
ce = self.calentries.min_by{|c| c.days_to_today * 1.3 * ((c.is_past?)? 2:1)} if self.is_event?
ce= self.meeting.calentry if self.has_meeting?
ce= self.meeting.calentry if self.has_meeting?
ce
end
def update_cache
@@ -151,8 +161,8 @@ class Neuigkeit < ActiveRecord::Base
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)
self.touch
else
if self.is_event?
else
if self.is_event?
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)
@@ -184,7 +194,7 @@ class Neuigkeit < ActiveRecord::Base
end
end
searchable do
text :text
text :text
text :datum
text :title
end