From d72f78488d736e0920a2030ad5f13f2e66c763e2 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sat, 3 Jan 2015 10:06:58 +0100 Subject: [PATCH] document/meeting updates --- Gemfile | 1 + app/controllers/documents_controller.rb | 57 ++++++++++++++++++- app/controllers/home_controller.rb | 3 +- app/controllers/meetings_controller.rb | 4 +- app/controllers/themen_controller.rb | 18 +++++- app/helpers/application_helper.rb | 27 ++++++++- app/models/ability.rb | 9 ++- app/models/document.rb | 51 ++++++++++++++++- app/models/meeting.rb | 62 ++++++++++++++++++++- app/views/calentries/_nested_form.html.erb | 9 ++- app/views/documents/edit.html.erb | 6 -- app/views/documents/show.html.erb | 14 +++-- app/views/fragen/_form.html.erb | 2 +- app/views/fragen/_rform.html.erb | 2 +- app/views/home/index.html.erb | 3 +- app/views/home/kontakt.html.erb | 3 - app/views/layouts/_login.html.erb | 24 +++++--- app/views/layouts/application.html.erb | Bin 1852 -> 1791 bytes app/views/layouts/menu.html.erb | 7 ++- app/views/meetings/_nested_form.html.erb | 6 +- app/views/rubriken/show.html.erb | 5 +- app/views/themen/_verw_liste.html.erb | 3 + app/views/themes/blue1/home/index.html.erb | 5 +- config/routes.rb | 11 +++- 24 files changed, 278 insertions(+), 54 deletions(-) delete mode 100755 app/views/documents/edit.html.erb diff --git a/Gemfile b/Gemfile index 12a6f4a..a83dee3 100755 --- a/Gemfile +++ b/Gemfile @@ -115,3 +115,4 @@ gem 'sunspot_solr' gem 'sitemap_generator' gem 'whenever' gem 'yaml_db' +gem 'etherpad-lite' \ No newline at end of file diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 8b28cb9..dce8233 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -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='
'+@document.text+'
' + 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 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 806822f..34725b2 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/app/controllers/meetings_controller.rb b/app/controllers/meetings_controller.rb index 120c297..7bad531 100644 --- a/app/controllers/meetings_controller.rb +++ b/app/controllers/meetings_controller.rb @@ -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 diff --git a/app/controllers/themen_controller.rb b/app/controllers/themen_controller.rb index b3d1ede..3490b13 100644 --- a/app/controllers/themen_controller.rb +++ b/app/controllers/themen_controller.rb @@ -11,7 +11,7 @@ class ThemenController < ApplicationController @toolbar_elements = [{:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t("thema.manage"), :path=>verwalten_thema_path(@thema)}] @toolbar_elements << [{:icon=>:pencil, :hicon=>'icon-pencil', :text=>I18n.t('thema.edit'), :path=>edit_thema_path(@thema)}] @toolbar_elements << {:hicon=>'icon-remove-circle', :text=>I18n.t('thema.remove'), :path=>thema_path(@thema), :method=>:delete, :confirm=>I18n.t('thema.sure')} - + respond_to do |format| format.html { redirect_to :controller=>'themengruppen', :id=>@thema.themengruppe.id, :action=>:show, :anchor=> "thema_"+params[:id].to_s @@ -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 @@ -67,7 +72,7 @@ class ThemenController < ApplicationController def edit @thema = Thema.find(params[:id]) - + respond_to do |format| format.html format.js { @themen= @thema.themengruppe.themen } @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 32b5582..5395ac8 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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) diff --git a/app/models/ability.rb b/app/models/ability.rb index 40bc4d8..7bfcec3 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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 diff --git a/app/models/document.rb b/app/models/document.rb index 5d3a20c..bf3714a 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -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 = '
'+self.text+'
' + end + end + def dump_to_etherpad + if self.is_etherpad? + self.ep_pad.html = '
'+self.text+'
' + 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 diff --git a/app/models/meeting.rb b/app/models/meeting.rb index 08bef44..933ec2f 100644 --- a/app/models/meeting.rb +++ b/app/models/meeting.rb @@ -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 diff --git a/app/views/calentries/_nested_form.html.erb b/app/views/calentries/_nested_form.html.erb index 8421935..0add235 100644 --- a/app/views/calentries/_nested_form.html.erb +++ b/app/views/calentries/_nested_form.html.erb @@ -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_ %> diff --git a/app/views/documents/edit.html.erb b/app/views/documents/edit.html.erb deleted file mode 100755 index e3ab18b..0000000 --- a/app/views/documents/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing Dokument

- -<%= render 'form' %> - -<%= link_to 'Show', @document %> | - diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index 1cbc4c0..de22fd5 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -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) %>

<%= @document.name %>

+
<%= raw(@document.text) %> -<%= semantic_form_for @document, :html=>{:class=>""} do |f| %> - <%= f.input :text, :as=>:tinymce_text %> -<%= f.action :submit, :as => :input_ %> - -<% end %> -<%= tinymce %> +
+ diff --git a/app/views/fragen/_form.html.erb b/app/views/fragen/_form.html.erb index 07f8b7d..dc4ef15 100644 --- a/app/views/fragen/_form.html.erb +++ b/app/views/fragen/_form.html.erb @@ -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 %> diff --git a/app/views/fragen/_rform.html.erb b/app/views/fragen/_rform.html.erb index b772066..db2efe0 100644 --- a/app/views/fragen/_rform.html.erb +++ b/app/views/fragen/_rform.html.erb @@ -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 %> diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index c9ab07a..2f5fb3b 100755 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,5 +1,6 @@
-

<%= I18n.t('home.willkommen') %>

+

<%= I18n.t('home.willkommen') %>

+<%= render partial: "themen/small", object: @starttopic %>
diff --git a/app/views/home/kontakt.html.erb b/app/views/home/kontakt.html.erb index 68ff483..764a481 100644 --- a/app/views/home/kontakt.html.erb +++ b/app/views/home/kontakt.html.erb @@ -3,8 +3,5 @@ <% @themen.each do |th| %> <%= render partial: "themen/small", object: th %> <% end %> - - -
diff --git a/app/views/layouts/_login.html.erb b/app/views/layouts/_login.html.erb index 7a65018..133ed37 100644 --- a/app/views/layouts/_login.html.erb +++ b/app/views/layouts/_login.html.erb @@ -1,9 +1,17 @@ <% if user_signed_in? %> -
  • Logged in as : <%= current_user.email %> - <%= link_to('Logout', destroy_user_session_path, :method => :delete) %> -
  • - <% else %> -
  • - <%= link_to('Login', new_user_session_path) %> -
  • - <% end %> + +<% else %> +
  • + <%= link_to('Login', new_user_session_path) %> +
  • +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b6c22eebb6f81a3d26369a41650b28fab18ae233..13182739bedae500d2febfd0f6d257a2d46a45da 100755 GIT binary patch delta 17 YcmdnP_n&tIBkLyCE=ER%$tT&00XFLer2qf` delta 80 zcmey*yN7QBBkN`+)=oxyo8p4RJcZ<(#NuLGrGnC&9NnVK^o$ZEI|T(BRa=Fk)V!3` hA_euF#LE2Al4AXw{PfH`bp=&B8-0*QyU9Il#Q-=h8nyrc diff --git a/app/views/layouts/menu.html.erb b/app/views/layouts/menu.html.erb index 04b795c..9a6d97c 100644 --- a/app/views/layouts/menu.html.erb +++ b/app/views/layouts/menu.html.erb @@ -35,15 +35,18 @@ - + <%= render 'layouts/login' %> + + - +
    +
    diff --git a/app/views/meetings/_nested_form.html.erb b/app/views/meetings/_nested_form.html.erb index dcd269e..db36946 100644 --- a/app/views/meetings/_nested_form.html.erb +++ b/app/views/meetings/_nested_form.html.erb @@ -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 %> diff --git a/app/views/rubriken/show.html.erb b/app/views/rubriken/show.html.erb index a74232b..c3b567b 100755 --- a/app/views/rubriken/show.html.erb +++ b/app/views/rubriken/show.html.erb @@ -1,4 +1,6 @@ <%= content_for :header do %> + + Fetsite - <%= @rubrik.name %> <% 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 %>

    <%= notice %>

    @@ -52,7 +56,6 @@

    -<%= render 'layouts/pretty_toolbar', :object=> @toolbar_elements %>
    diff --git a/app/views/themen/_verw_liste.html.erb b/app/views/themen/_verw_liste.html.erb index 920fef3..12713b2 100644 --- a/app/views/themen/_verw_liste.html.erb +++ b/app/views/themen/_verw_liste.html.erb @@ -9,6 +9,9 @@
  • <%= link_to sanitize_thema_path(thema),:remote=>true do %> <%= ff_icon('icon-leaf') %> Sanitize <% end %>
  • <%= link_to fragen_thema_path(thema),:remote=>true do %> Fragen <% end %>
  • +
  • <%= link_to documents_thema_path(thema),:remote=>true do %> Fragen <% end %>
  • +
  • <%= link_to meetings_thema_path(thema),:remote=>true do %> Fragen <% end %>
  • +
  • <%= link_to attachments_thema_path(thema),:remote=>true do %> Attachments <% end %>
  • diff --git a/app/views/themes/blue1/home/index.html.erb b/app/views/themes/blue1/home/index.html.erb index c9ab07a..fcec724 100644 --- a/app/views/themes/blue1/home/index.html.erb +++ b/app/views/themes/blue1/home/index.html.erb @@ -1,5 +1,8 @@
    -

    <%= I18n.t('home.willkommen') %>

    +

    <%= I18n.t('home.willkommen') %>

    +<%= raw(@starttopic.text) %> + +
    diff --git a/config/routes.rb b/config/routes.rb index 082344b..713df3d 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -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