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

@@ -115,3 +115,4 @@ gem 'sunspot_solr'
gem 'sitemap_generator'
gem 'whenever'
gem 'yaml_db'
gem 'etherpad-lite'

View File

@@ -1,5 +1,5 @@
class DocumentsController < ApplicationController
# require('etherpad-lite')
load_and_authorize_resource
def index
respond_to do |format|
@@ -18,13 +18,64 @@ class DocumentsController < ApplicationController
end
def edit
@document = Document.find(params[:id])
@parent=@document.parent
respond_to do |format|
format.js
end
end
def dump_to_etherpad
@document = Document.find(params[:id])
@document.dump_to_etherpad
@document.save
# author = ether.author('author_1')
# pad=group.pad(@document.etherpadkey)
# pad.html='<div>'+@document.text+'</div>'
redirect_to action: :show
end
def read_from_etherpad
@document = Document.find(params[:id])
@document.read_from_etherpad
@document.save
render :show
end
def write_etherpad
@document = Document.find(params[:id])
ether=Document.ether
author = Document.ether.author("fetsite_"+current_user.uid, :name => current_user.text)
author = Document.ether.author("author_1")
session[:ep_sessions]={} if session[:ep_sessions].nil?
group=@document.ep_group
sess = session[:ep_sessions][group.id] ? ether.get_session(session[:ep_sessions][group.id]) : group.create_session(author, 60)
if sess.expired?
sess.delete
sess = group.create_session(author, 60)
end
session[:ep_sessions][group.id] = sess.id
# Set the EtherpadLite session cookie. This will automatically be picked up by the jQuery plugin's iframe.
cookies[:sessionID] = {:value => sess.id, :domain => "www.fet.at"}
#cookies[:sessionID] = {:value => sess.id}
cookies[:sessionID1]=sess.id
# cookies[:sdf]=sess.id
# pad=ether.pad(@document.etherpadkey)
# redirect_to "http://www.fet.at/etherpad/p/"+@document.ep_pad.id
#render :write
end
def write
@document = Document.find(params[:id])
if @document.is_etherpad?
redirect_to action: :write_etherpad
else
@parent=@document.parent
respond_to do |format|
format.html
end
end
end
def create

View File

@@ -2,7 +2,8 @@ class HomeController < ApplicationController
def index
@beispiele = Beispiel.last([Beispiel.count, 3].min)
@neuigkeiten = Neuigkeit.recent
t=YAML.load_file("#{::Rails.root.to_s}/config/start_topic.yml")
@starttopic= @themen = Thema.where(:id=>t).first
end
def dev

View File

@@ -42,8 +42,8 @@ end
@meeting=Meeting.new
@meeting.parent=params[:parent_type].constantize.find(params[:parent_id])
@parent=@meeting.parent
@meeting.calentry=Calentry.new
# @meeting.typ = 1
@meeting.calentry=Calentry.new
@meeting.calentry.typ = 2
respond_to do |format|
format.js
end

View File

@@ -40,6 +40,11 @@ class ThemenController < ApplicationController
# @thema.text = @thema.text.sanitize
render :edit
end
def version
@thema = Thema.find(params[:id])
end
def verwalten
@thema = Thema.find(params[:id])
@attachment=Attachment.new
@@ -107,7 +112,14 @@ class ThemenController < ApplicationController
format.js
end
end
def attachments
def documents
@thema = Thema.find(params[:id])
@documents=@thema.documents
respond_to do |format|
format.js
end
end
def attachments
@thema = Thema.find(params[:id])
@attachments=@thema.attachments
@attachment=Attachment.new

View File

@@ -1,7 +1,28 @@
module ApplicationHelper
def current_url1(overwrite={})
url_for :params => params.merge(overwrite).except(:controller,:action,:ansicht)
end
def strip_control_chars(value)
value.chars.inject("") do |str, char|
unless char.ascii_only? && (char.ord < 32 || char.ord == 127)
str << char
end
str
end
end
def convert_topic_to_meeting(t,mt)
m=Meeting.new_with_date_and_typ(t,t.title.to_date+16.hour,mt)
m.save
m.create_protocol
m.protocol.text=t.text
m.protocol.save
m.update_time_from_protocol
m.save
t.meetings << m
t.save
end
def current_url1(overwrite={})
url_for :params => params.merge(overwrite).except(:controller,:action,:ansicht)
end
def switch_locale_url(target_locale)

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

View File

@@ -4,10 +4,15 @@
<%= semantic_form_for @calentry, :remote=>true, :html=>{:class=>"inline"} do |f| %>
<%= f.input :start, :as => :datetimepicker %>
<%= f.input :dauer , :as => :string, :append=>"h" %>
<% if @calentry.typ==1 %>
<%= f.input :dauer , :as => :string, :append=>"h" %>
<% else %>
<%= f.input :ende, :as => :datetimepicker %>
<% end %>
<%= f.input :object_id , :as => :hidden %>
<%= f.input :object_type , :as => :hidden %>
<%= f.input :typ , :as => :hidden %>
<%= f.input :typ , :as => :hidden %>
<%= f.action :submit, :as => :input_ %>

View File

@@ -1,6 +0,0 @@
<h1>Editing Dokument</h1>
<%= render 'form' %>
<%= link_to 'Show', @document %> |

View File

@@ -1,8 +1,10 @@
<%= link_to "parent" , @document.parent %>
<%= link_to "show", document_path(@document), remote: true %>
<%= link_to "Write", write_document_path(@document) %>
<%= link_to "read", read_from_etherpad_document_path(@document) %>
<%= link_to "dump", dump_to_etherpad_document_path(@document) %>
<h2><%= @document.name %></h2>
<div id="">
<%= raw(@document.text) %>
<%= semantic_form_for @document, :html=>{:class=>""} do |f| %>
<%= f.input :text, :as=>:tinymce_text %>
<%= f.action :submit, :as => :input_ %>
</div>
<% end %>
<%= tinymce %>

View File

@@ -1,7 +1,7 @@
<%= tinymce_assets %>
<%= semantic_form_for @frage do |f| %>
<%= f.inputs do %>
<%= f.input :title %>
<%= f.input :title , :as=>:text %>
<%= f.input :thema %>
<%= f.input :text, :as=>:tinymce_text%>
<% end %>

View File

@@ -1,7 +1,7 @@
<%= tinymce_assets %>
<%= semantic_form_for @frage , :remote=>true do |f| %>
<%= f.inputs do %>
<%= f.input :title %>
<%= f.input :title, :as=>:text %>
<%= f.input :thema %>
<%= f.input :text, :as=>:tinymce_text%>
<% end %>

View File

@@ -1,5 +1,6 @@
<div class="content-wrap content-column">
<h1><%= I18n.t('home.willkommen') %></h1></p>
<h1><%= I18n.t('home.willkommen') %></h1>
<%= render partial: "themen/small", object: @starttopic %>
<div class="container-fluid">
<div class="row-fluid">
<div class="span6">

View File

@@ -4,7 +4,4 @@
<%= render partial: "themen/small", object: th %>
<% end %>
</div>

View File

@@ -1,9 +1,17 @@
<% if user_signed_in? %>
<li>Logged in as : <%= current_user.email %>
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
</li>
<% else %>
<li>
<%= link_to('Login', new_user_session_path) %>
</li>
<% end %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= ff_icon('icon-user')%><b class="caret"></b></a>
<ul class="dropdown-menu">
<li style="padding:5px">
<%= image_tag current_user.fetprofile.picture.thumb.url,class: "pull-left" unless current_user.fetprofile.nil? %>
<%= current_user.email %> is logged in.
</li>
<li><%= link_to('Logout', destroy_user_session_path, :method => :delete) %> </li>
</ul>
</li>
<% else %>
<li>
<%= link_to('Login', new_user_session_path) %>
</li>
<% end %>

View File

@@ -35,7 +35,9 @@
</ul>
</li>
</ul>
<%= render 'layouts/login' %>
</ul>
<!--<span class="pull-right"><%if I18n.locale == :en %>
<%= link_to image_tag("/flaggen/png/at.png") + " Deutsch" ,switch_locale_url(:de)%>
<% elsif I18n.locale == :de %>
@@ -44,6 +46,7 @@
</span>-->
</div>
</div>
</div>
</div>

View File

@@ -8,9 +8,9 @@
<%= f.semantic_fields_for :calentry, @meeting.calentry do |ff| %>
<%= ff.input :start, :as => :datetimepicker %>
<%= ff.input :dauer , :as => :string, :append=>"h" %>
<%= ff.input :typ %>
<% ff.input :object_id %>
<%= ff.input :ende, :as => :datetimepicker %>
<%= ff.input :typ %>
<% ff.input :object_id, :as=>:hidden %>
<% ff.input :object_type %>
<% end %>

View File

@@ -1,4 +1,6 @@
<%= content_for :header do %>
<title>Fetsite - <%= @rubrik.name %></title>
<% set_meta_tags :og => {
:title => @rubrik.name.to_s,
@@ -8,7 +10,9 @@
<%= display_meta_tags %>
<% end %>
<%= render 'tabs' %>
<%= render 'layouts/pretty_toolbar', :object=> @toolbar_elements %>
<p id="notice"><%= notice %></p>
<div class="content-wrap content-column">
<div class="container-fluid">
@@ -52,7 +56,6 @@
</div>
<br>
<%= render 'layouts/pretty_toolbar', :object=> @toolbar_elements %>
</div>
</div>

View File

@@ -9,6 +9,9 @@
<li><%= link_to sanitize_thema_path(thema),:remote=>true do %> <%= ff_icon('icon-leaf') %> Sanitize <% end %> </li>
<li><%= link_to fragen_thema_path(thema),:remote=>true do %> Fragen <% end %></li>
<li><%= link_to documents_thema_path(thema),:remote=>true do %> Fragen <% end %></li>
<li><%= link_to meetings_thema_path(thema),:remote=>true do %> Fragen <% end %></li>
<li><%= link_to attachments_thema_path(thema),:remote=>true do %> Attachments <% end %></li>
</ul>
</li>

View File

@@ -1,5 +1,8 @@
<div class="content-wrap content-column">
<h1><%= I18n.t('home.willkommen') %></h1></p>
<h1><%= I18n.t('home.willkommen') %></h1>
<%= raw(@starttopic.text) %>
<div class="container-fluid">
<div class="row-fluid">
<div class="span6">

View File

@@ -156,6 +156,8 @@ Fetsite::Application.routes.draw do
get :verwalten
get :sanitize
get :is_updated
get :documents
get :meetings
end
resources :attachments
end
@@ -163,7 +165,14 @@ Fetsite::Application.routes.draw do
resources :calendars
get 'verwalten/calendars', :controller=>:calendars, :action=>:verwalten, :as=>'calendars_verwalten'
resources :calentries
resources :documents
resources :documents do
member do
get :write
get :write_etherpad
get :read_from_etherpad
get :dump_to_etherpad
end
end
resources :meetings do
member do
get :announce