AutoCommit Mon Aug 10 13:03:04 CEST 2015

This commit is contained in:
Andreas Stephanides
2015-08-10 13:03:04 +02:00
parent cb73bbfa43
commit 3835c0e773
6 changed files with 115 additions and 107 deletions

View File

@@ -33,6 +33,7 @@ class Survey::QuestionsController < ApplicationController
@template = Survey::Question.find(params[:id]) @template = Survey::Question.find(params[:id])
parent= params[:parent_type].constantize.find(params[:parent_id]) parent= params[:parent_type].constantize.find(params[:parent_id])
@survey_question = @template.copy_from_template_for(parent) @survey_question = @template.copy_from_template_for(parent)
@survey_question.user=current_user
render action: :show render action: :show
end end
@@ -64,7 +65,7 @@ class Survey::QuestionsController < ApplicationController
# POST /survey/questions.json # POST /survey/questions.json
def create def create
@survey_question = Survey::Question.new(params[:survey_question]) @survey_question = Survey::Question.new(params[:survey_question])
@survey_question.user=current_user
respond_to do |format| respond_to do |format|
if @survey_question.save if @survey_question.save
format.html { redirect_to @survey_question, notice: 'Question was successfully created.' } format.html { redirect_to @survey_question, notice: 'Question was successfully created.' }
@@ -78,7 +79,8 @@ class Survey::QuestionsController < ApplicationController
# PUT /survey/questions/1.json # PUT /survey/questions/1.json
def update def update
@survey_question = Survey::Question.find(params[:id]) @survey_question = Survey::Question.find(params[:id])
@survey_question.user=current_user
@survey_question.save
respond_to do |format| respond_to do |format|
if @survey_question.update_attributes(params[:survey_question]) if @survey_question.update_attributes(params[:survey_question])
format.html { redirect_to @survey_question, notice: 'Question was successfully updated.' } format.html { redirect_to @survey_question, notice: 'Question was successfully updated.' }

View File

@@ -11,10 +11,17 @@ class Ability
end end
user ||= User.new # guest user (not logged in) user ||= User.new # guest user (not logged in)
can :manage, Survey::Question if( user.has_role?("fetuser") || user.has_role?("fetadmin"))
can :manage, Survey::Choice can [:show,:answer, :create,:new, :create_from_template, :flag], Survey::Question
can :manage, Survey::Answer can [:edit, :update, :flag_delete], Survey::Question, :flag_locked=>false
can :flag_locked, Survey::Question, :user_id=>user.id
can [:show,:new], Survey::Choice
can [:edit,:update, :delete,:create], Survey::Choice, :question=>{:flag_locked=>false}
can :manage, Survey::Answer
end
if user.has_role?("fetadmin")
can [:delete,:flag_template], Survey::Question
end
#--------------------------------------------------- #---------------------------------------------------
can [:index,:hide], Comment can [:index,:hide], Comment

View File

@@ -5,11 +5,11 @@ class Survey::Question < ActiveRecord::Base
has_many :choices, dependent: :destroy, class_name: "Survey::Choice" has_many :choices, dependent: :destroy, class_name: "Survey::Choice"
has_many :answers, through: :choices has_many :answers, through: :choices
include IsCommentable include IsCommentable
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1"} FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1","locked"=>"fa fa-key"}
FLAG_CONFIRM={"delete"=> "Sicher loeschen?"} FLAG_CONFIRM={"delete"=> "Sicher loeschen?"}
scope :templates, ->{ where(flag_template: true)} scope :templates, ->{ where(flag_template: true)}
acts_as_flagable acts_as_flagable
belongs_to :user
def copy_from_template_for(parent) def copy_from_template_for(parent)
unless self.flag_template unless self.flag_template
return nil return nil

View File

@@ -1,10 +1,12 @@
<%= content_for :header do %> <%= content_for :header do %>
<title>Fetsite - <%= @lva.full_name %></title> <title>Fetsite - <%= @lva.full_name %></title>
<% set_meta_tags :og => { <% set_meta_tags :og => {
:url=>lva_path(:theme=>nil) } :url=>lva_path(:theme=>nil)
%> }
<%= display_meta_tags %> %>
<%= display_meta_tags %>
<% end %> <% end %>
<div itemscope itemtype="schema.org/Article" > <div itemscope itemtype="schema.org/Article" >
<div class="container-fluid"> <div class="container-fluid">
<%= render 'studien/tabs'%> <%= render 'studien/tabs'%>
@@ -12,115 +14,109 @@
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
<%= render 'layouts/pretty_toolbar' %> <%= render 'layouts/pretty_toolbar' %>
</div> </div>
</div> </div>
<div class="row-fluid"> <div class="row-fluid">
<div class="span8"> <div class="span8">
<h1 itemprop="name"><%= @lva.full_name %></h1> <h1 itemprop="name"><%= @lva.full_name %></h1>
<meta itemprop="url" content="<%= lva_path(@lva) %>" /> <meta itemprop="url" content="<%= lva_path(@lva) %>" />
<ul class="linklist"> <ul class="linklist">
<li> <li>
<%= link_to ffi1_icon("live2")+"ET-Forum", @lva.forumlink, class: :linkbox, itemprop: "discussionUrl" unless @lva.forumlink.nil? or @lva.forumlink.empty?%> <%= link_to ffi1_icon("live2")+"ET-Forum", @lva.forumlink, class: :linkbox, itemprop: "discussionUrl" unless @lva.forumlink.nil? or @lva.forumlink.empty?%>
</li> </li>
<li> <li>
<%= link_to "TISS", @lva.tisslink, class: :linkbox %> <%= link_to "TISS", @lva.tisslink, class: :linkbox %>
</li> </li>
</ul> </ul>
<div itemprop="articleBody"> <div itemprop="articleBody">
<h2><%= I18n.t('lva.pruefungsinfo')%></h2> <h2><%= I18n.t('lva.pruefungsinfo')%></h2>
<div class=""> <div class="">
<%= @lva.pruefungsinformation.to_s.html_safe %> <%= @lva.pruefungsinformation.to_s.html_safe %>
</div> </div>
<h2><%= I18n.t('lva.lernaufwand')%></h2> <h2><%= I18n.t('lva.lernaufwand')%></h2>
<div class=""> <div class="">
<%= @lva.lernaufwand %> <%= @lva.lernaufwand %>
</div> </div>
<h2><%= I18n.t('lva.desc')%></h2> <h2><%= I18n.t('lva.desc')%></h2>
<div class=""> <div class="">
<%= @lva.desc.to_s.html_safe %> <%= @lva.desc.to_s.html_safe %>
</div> </div>
</div> </div>
</div> </div>
<div class="span4"> <div class="span4">
<div class="contentbox"> <div class="contentbox">
<ul> <ul>
<li><b><%= I18n.t('lva.lvanr')%>:</b> <%=@lva.lvanr %></li> <li><b><%= I18n.t('lva.lvanr')%>:</b> <%=@lva.lvanr %></li>
<li><b>ECTS:</b> <%=@lva.ects %></li> <li><b>ECTS:</b> <%=@lva.ects %></li>
<li><b><%= I18n.t('lva.stunden')%>:</b> <%=@lva.stunden %></li> <li><b><%= I18n.t('lva.stunden')%>:</b> <%=@lva.stunden %></li>
</ul> </ul>
<h2><%= I18n.t('lva.module')%></h2> <h2><%= I18n.t('lva.module')%></h2>
<ul> <ul>
<% @lva.modul.each do |modul| %> <% @lva.modul.each do |modul| %>
<li><b><%= link_to modul.name , modul_path(modul)%></b> <li><b><%= link_to modul.name , modul_path(modul)%></b>
<ul> <ul>
<% modul.modulgruppen.each do |g| %> <% modul.modulgruppen.each do |g| %>
<li><%= link_to g.studium.title_context , studium_path(g.studium)%> (<%=link_to g.name, modulgruppe_path(g)%>)</li>
<li><%= link_to g.studium.title_context , studium_path(g.studium)%> (<%=link_to g.name, modulgruppe_path(g)%>)</li> <% end %>
<% end %> </ul>
</ul> </li>
</li> <% end %>
</ul>
<% end %> </div>
</ul> <div class="contentbox">
</div> <h2> <%= I18n.t "lecturers.lecturers" %> </h2>
<div class="contentbox"> <% @lva.lecturers.each do |lec| %>
<h2> <%= I18n.t "lecturers.lecturers" %> </h2> <%= render :partial=>'lecturers/lec_lva', :object=>lec %>
<% @lva.lecturers.each do |lec| %> <% end %>
<%= render :partial=>'lecturers/lec_lva', :object=>lec %> </div>
<% end %>
</div>
</div> </div>
</div> </div>
<div class="row-fluid">
<div class="row-fluid">
<div class="span12"> <div class="span12">
<h2><%= I18n.t("lva.bspe") %></h2> <h2><%= I18n.t("lva.bspe") %></h2>
<p><%= I18n.t("lva.ratebsp")%> <%= link_to ffi1_icon("facebook1") + I18n.t('home.fblogin'), user_omniauth_authorize_path(:facebook) ,class: :linkbox %> <p><%= I18n.t("lva.ratebsp")%> <%= link_to ffi1_icon("facebook1") + I18n.t('home.fblogin'), user_omniauth_authorize_path(:facebook) ,class: :linkbox %>
</p> </p>
<%= link_to t("beispiel.zip") , beispiel_sammlung_lva_path(@lva), class: :linkbox %> <%= link_to t("beispiel.zip") , beispiel_sammlung_lva_path(@lva), class: :linkbox %>
<% @beispiele_all.each do |b| %> <% @beispiele_all.each do |b| %>
<% cache("beispiel_" +I18n.locale.to_s+b.id.to_s+can?(:delete,b).to_s+"_"+can?(:edit,b).to_s + "_" + can?(:flag, b).to_s + "_" + can?(:like, b).to_s + "_" + b.updated_at.try(:utc).try(:to_s) + get_theme_help(current_user).to_s) do %> <% cache("beispiel_" +I18n.locale.to_s+b.id.to_s+can?(:delete,b).to_s+"_"+can?(:edit,b).to_s + "_" + can?(:flag, b).to_s+ can?(:comment, b).to_s + "_" + can?(:like, b).to_s + "_" + b.updated_at.try(:utc).try(:to_s) + get_theme_help(current_user).to_s) do %>
<%= render b%> <%= render b%>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
</div> </div>
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
<% unless @lva.nlinks.empty? %> <% unless @lva.nlinks.empty? %>
<h2><%= I18n.t("rubrik.title") %></h2> <h2><%= I18n.t("rubrik.title") %></h2>
<% @lva.nlinks.each do |l| %> <% @lva.nlinks.each do |l| %>
<%= render l.neuigkeit %> <%= render l.neuigkeit %>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
</div> </div>
<% cache("lva_beispiel_form_bulk_"+@lva.id.to_s+I18n.locale.to_s+@lva.updated_at.to_i.to_s) do %> <% cache("lva_beispiel_form_bulk_"+@lva.id.to_s+I18n.locale.to_s+@lva.updated_at.to_i.to_s) do %>
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
<%= render 'beispiele/form_bulk' %> <%= render 'beispiele/form_bulk' %>
</div> </div>
</div> </div>
<% end %> <% end %>
<% unless @crawlobjects.nil? %> <% unless @crawlobjects.nil? %>
<div class="row-fluid"> <div class="row-fluid">
<div class="span12"> <div class="span12">
<% @crawlobjects.each do |co| %> <% @crawlobjects.each do |co| %>
<%= render co %> <%= render co %>
<% end %> <% end %>
</div> </div>
</div> </div>
<% end %> <% end %>
</div> </div>

View File

@@ -2,7 +2,7 @@
<%= div_tag_for(choice) do %> <%= div_tag_for(choice) do %>
<% <%
if current_user.nil? unless can?(:answer,choice.question)
t=choice.text t=choice.text
else else
value=(current_user.id.nil?)? false : choice.answers.where(user_id: current_user.id).count>0 value=(current_user.id.nil?)? false : choice.answers.where(user_id: current_user.id).count>0
@@ -13,7 +13,7 @@ end
%> %>
<%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true <%= t %> <%= link_to fa_icon("pencil"), edit_survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true if can? :edit, choice
%> %>
<%= link_to fa_icon("trash"), survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true , method: :delete, data: { confirm: 'Are you sure?' } %> <%= link_to fa_icon("trash"), survey_choice_path(choice) , class: "btn btn-link navbar-btn" , remote: true , method: :delete, data: { confirm: 'Are you sure?' } if can? :delete,choice %>
<% end %> <% end %>

View File

@@ -1,4 +1,4 @@
<% if current_user.nil? %> <% unless can?(:answer,question) %>
<%= div_tag_for(question) do%> <%= div_tag_for(question) do%>
<%= render partial: "survey/questions/answeredquestion", object: question unless question.flag_delete%> <%= render partial: "survey/questions/answeredquestion", object: question unless question.flag_delete%>
<% end %> <% end %>
@@ -7,16 +7,19 @@
<div > <div >
<b><%= question.title%></b> <b><%= question.title%></b>
<%= question.text %> <%= question.text %>
<%= link_to fa_icon("pencil"), edit_survey_question_path(question) , class: "btn btn-link navbar-btn" , remote: true %> <%= link_to fa_icon("pencil"), edit_survey_question_path(question) , class: "btn btn-link navbar-btn" , remote: true if can? :edit, question %>
<%= flag_link(question, "delete")%>
<%= flag_link(question, "template")%> <%= flag_link(question, "locked") %>
<%= flag_link(question, "template") %>
<%= flag_link(question, "delete") %>
<% unless question.flag_delete %> <% unless question.flag_delete %>
<ul class="choice-list"> <ul class="choice-list">
<% question.choices.each do |c| %> <% question.choices.each do |c| %>
<li><%= render c %></li> <li><%= render c %></li>
<% end %> <% end %>
</ul> </ul>
<%= link_to "+" , new_survey_choice_path(params:{question_id: question.id}), remote: true%> <%= link_to "+" , new_survey_choice_path(params:{question_id: question.id}), remote: true if can? :edit, question %>
<% end %> <% end %>
</div> </div>
<%= render partial: "survey/questions/answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0 unless question.flag_delete %> <%= render partial: "survey/questions/answeredquestion", object: question if question.answers.where(user_id: current_user.id).count>0 unless question.flag_delete %>