<commit_before>module FassetsPresentations
  class FramesController < ApplicationController
    include AssetsHelper
    include FramesHelper
    before_filter :authenticate_user!, :except => [:show]
    before_filter :find_presentation, :except => [:markup_preview]
    before_filter :find_frame, :except => [:new, :create, :sort, :markup_preview]
    def create
      if params[:id]
        frame = Frame.find(params[:id]).clone();
        frame.presentation_id = @presentation.id
      else
        position = Frame.where(:presentation_id => @presentation.id).maximum(:position)+1
        frame =  Frame.create(params[:frame].merge({:presentation_id => @presentation.id, :position => position}))
      end
      respond_to do |format|
        if frame.save
          update_positions()
          flash[:notice] = "Frame succesfully created!"
          format.html {redirect_to edit_presentation_frame_path(@presentation, frame)}
          format.json {render :status => :created, :json => frame.to_json}
        else
          flash[:error] = "Title of frame cannot be empty"
          format.html {redirect_to edit_presentation_path(@presentation)}
        end
      end
    end
    def edit
      if @frame.parent == nil
        is_root_frame = true
        if @frame.children.first
          @frame = @frame.children.first
          redirect_to edit_presentation_frame_path(@presentation, @frame)
          return
        end
      else
        is_root_frame = false
      end
      render :template => "fassets_presentations/frames/edit", :locals => {:is_root_frame => is_root_frame}
    end
    def edit_wysiwyg
      if @frame.parent == nil
        is_root_frame = true
        if @frame.children.first
          @frame = @frame.children.first
          redirect_to edit_wysiwyg_presentation_frame_path(@presentation, @frame)
          return
        end
      else
        is_root_frame = false
      end
      render :template => "fassets_presentations/frames/edit_wysiwyg", :locals => {:is_root_frame => is_root_frame}      
    end
    def update
      arrange_slots()
      begin
        to_fp_html(params[:frame][:content][slot_name][:markup])
      rescue
        flash[:error] = "Could not update frame - Invalid markup!"
        redirect_to edit_presentation_frame_path(@presentation, @frame)
        return
      end
      if @frame.update_attributes(params[:frame])
        flash[:notice] = "frame succesfully updated!"
      else
        flash[:error] = "Could not update frame!"
      end
      redirect_to edit_presentation_frame_path(@presentation, @frame)
    end
    def update_wysiwyg
      params[:frame][:content].each do |slot_name, value|
        begin
          params[:frame][:content][slot_name][:markup] = html_to_markdown(params[:frame][:content][slot_name][:markup])
        rescue
          flash[:error] = "Could not update frame - Conversion to markup failed!"
          redirect_to edit_wysiwyg_presentation_frame_path(@presentation, @frame)
          return
        end
        logger.debug("Markdown"+params[:frame][:content][slot_name][:markup])
      end
      arrange_slots()
      if @frame.update_attributes(params[:frame])<commit_msg>Fix: Before the slot_name variable is used it should be defined.<commit_after>module FassetsPresentations
  class FramesController < ApplicationController
    include AssetsHelper
    include FramesHelper
    before_filter :authenticate_user!, :except => [:show]
    before_filter :find_presentation, :except => [:markup_preview]
    before_filter :find_frame, :except => [:new, :create, :sort, :markup_preview]
    def create
      if params[:id]
        frame = Frame.find(params[:id]).clone();
        frame.presentation_id = @presentation.id
      else
        position = Frame.where(:presentation_id => @presentation.id).maximum(:position)+1
        frame =  Frame.create(params[:frame].merge({:presentation_id => @presentation.id, :position => position}))
      end
      respond_to do |format|
        if frame.save
          update_positions()
          flash[:notice] = "Frame succesfully created!"
          format.html {redirect_to edit_presentation_frame_path(@presentation, frame)}
          format.json {render :status => :created, :json => frame.to_json}
        else
          flash[:error] = "Title of frame cannot be empty"
          format.html {redirect_to edit_presentation_path(@presentation)}
        end
      end
    end
    def edit
      if @frame.parent == nil
        is_root_frame = true
        if @frame.children.first
          @frame = @frame.children.first
          redirect_to edit_presentation_frame_path(@presentation, @frame)
          return
        end
      else
        is_root_frame = false
      end
      render :template => "fassets_presentations/frames/edit", :locals => {:is_root_frame => is_root_frame}
    end
    def edit_wysiwyg
      if @frame.parent == nil
        is_root_frame = true
        if @frame.children.first
          @frame = @frame.children.first
          redirect_to edit_wysiwyg_presentation_frame_path(@presentation, @frame)
          return
        end
      else
        is_root_frame = false
      end
      render :template => "fassets_presentations/frames/edit_wysiwyg", :locals => {:is_root_frame => is_root_frame}      
    end
    def update
      arrange_slots()
      params[:frame][:content].each do |slot_name, value|
        begin
          to_fp_html(params[:frame][:content][slot_name][:markup])
        rescue
          flash[:error] = "Could not update frame - Invalid markup!"
          redirect_to edit_presentation_frame_path(@presentation, @frame)
          return
        end
      end
      if @frame.update_attributes(params[:frame])
        flash[:notice] = "frame succesfully updated!"
      else
        flash[:error] = "Could not update frame!"
      end
      redirect_to edit_presentation_frame_path(@presentation, @frame)
    end
    def update_wysiwyg
      params[:frame][:content].each do |slot_name, value|
        begin
          params[:frame][:content][slot_name][:markup] = html_to_markdown(params[:frame][:content][slot_name][:markup])
        rescue
          flash[:error] = "Could not update frame - Conversion to markup failed!"
          redirect_to edit_wysiwyg_presentation_frame_path(@presentation, @frame)
          return
        end
        logger.debug("Markdown"+params[:frame][:content][slot_name][:markup])
      end
      arrange_slots()
      if @frame.update_attributes(params[:frame])
{'fraction_non_alphanumeric': 0.10309278350515463, 'fraction_numerical': 0.00030773965225419295, 'mean_word_length': 2.7746806039488967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2401072', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1814, 'n_words': 404}