document/meeting updates

This commit is contained in:
Andreas Stephanides
2015-01-03 10:06:58 +01:00
parent de8802c34a
commit d72f78488d
24 changed files with 278 additions and 54 deletions

View File

@@ -122,7 +122,14 @@ class Ability
can :manage, Meeting
can :manage, Meetingtyp
end
unless user.has_role?( "fetadmin")
cannot :delete, Document
cannot :delete, Meeting
end
if user.has_role?( "fetadmin")
can :manage, Meetingtyp
end
# Rechteverwaltung Kalender
can [:show, :index], Calendar, :public => true

View File

@@ -1,17 +1,64 @@
class Document < ActiveRecord::Base
attr_accessible :etherpadkey, :name, :parent, :text, :typ, :parent_id, :parent_type
attr_accessible :name, :parent, :text, :typ, :parent_id, :parent_type
belongs_to :parent, :polymorphic => true
validate :name, :length=>{minimum:3}
validate :text, :presence=>true
validate :typ, :presence=>true
validate :parent, :presence=>true
has_paper_trail
TYPS = { 1=>"fet_docs", 10=>"protocol", 11=> "agenda"}
def self.new_divid_for(parent)
"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('/home/andreas/www/APIKEY.txt'))
end
def ether
if @ep.nil?
@ep=Document.ether
end
@ep
end
def is_etherpad?
!(etherpadkey.nil? || etherpadkey.empty?)
end
def move_to_etherpad
unless self.is_etherpad? || self.id.nil?
self.etherpadkey="document_"+ self.id.to_s
self.ep_pad.html = '<div>'+self.text+'</div>'
end
end
def dump_to_etherpad
if self.is_etherpad?
self.ep_pad.html = '<div>'+self.text+'</div>'
else
self.move_to_etherpad
end
end
def read_from_etherpad
self.text=strip_control_chars(self.ep_pad.html)
end
def ep_pad
self.ep_group.pad(self.etherpadkey)
end
def ep_group
t= (self.typ.nil?) ? 1 : self.typ
Document.ether.group(Document::TYPS[t])
end
searchable do
text :text
text :name, :boost=>4.0
if typ = 10 || typ=11
text :meeting do
parent.text unless parent.nil?
end
end
end
end

View File

@@ -21,6 +21,7 @@ class Meeting < ActiveRecord::Base
unless self.meetingtyp.try(:name).to_s.empty?
t = self.meetingtyp.name.to_s+", "
else
t=""
t = parent.title.to_s + ", " if self.name.empty?
end
t= t+ self.name.to_s
@@ -52,6 +53,13 @@ class Meeting < ActiveRecord::Base
end
end
def create_calentry
if self.calentry.nil?
ce =Calentry.new
ce.typ=2
self.calentry=ce
end
end
def create_agenda
if self.agenda.nil?
d=Document.new
@@ -61,7 +69,16 @@ class Meeting < ActiveRecord::Base
self.agenda=d
end
end
def self.new_with_date_and_typ(parent,start, typ)
m= Meeting.new
m.parent=parent
m.calentry=Calentry.new
m.calentry.typ=2
m.calentry.start=start
m.calentry.dauer=4
m.meetingtyp=typ
m
end
def self.new_divid_for(parent)
"meeting_new_parent_" + parent.class.to_s + "_" + parent.id.to_s
end
@@ -69,6 +86,45 @@ class Meeting < ActiveRecord::Base
"meeting_"+self.id.to_s
end
def update_time_from_protocol
st= /Beginn[\s:]*([^<>]*)/.match(self.protocol.text)[1].to_s
st= /Anfang[\s:]*([^<>]*)/.match(self.protocol.text)[1].to_s if st.empty?
self.calentry.start=(self.calentry.start.to_date.to_s + " " +st).to_datetime unless st.empty?
st= /Ende[\s:]*([^<>]*)/.match(self.protocol.text)[1].to_s
self.calentry.ende=(self.calentry.ende.to_date.to_s + " " +st).to_datetime unless st.empty?
end
def agenda_text
unless self.agenda.nil?
t= self.agenda.text
else
t= ""
end
t
end
def protocol_text
unless self.protocol.nil?
t= self.protocol.text
else
t= ""
end
t
end
searchable do
text :text
text :name, :boost=>4.0
text :meetingtyp do
meetingtyp.name
end
text :protocol do
self.protocol_text
end
text :agenda do
self.agenda_text
end
end
end