Нет описания http://j1x-huginn.herokuapp.com

scenarios_controller.rb 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. class ScenariosController < ApplicationController
  2. skip_before_filter :authenticate_user!, :only => :export
  3. def index
  4. @scenarios = current_user.scenarios.page(params[:page])
  5. respond_to do |format|
  6. format.html
  7. format.json { render json: @scenarios }
  8. end
  9. end
  10. def new
  11. @scenario = current_user.scenarios.build
  12. respond_to do |format|
  13. format.html
  14. format.json { render json: @scenario }
  15. end
  16. end
  17. def show
  18. @scenario = current_user.scenarios.find(params[:id])
  19. @agents = @scenario.agents.preload(:scenarios).page(params[:page])
  20. respond_to do |format|
  21. format.html
  22. format.json { render json: @scenario }
  23. end
  24. end
  25. def share
  26. @scenario = current_user.scenarios.find(params[:id])
  27. respond_to do |format|
  28. format.html
  29. format.json { render json: @scenario }
  30. end
  31. end
  32. def export
  33. @scenario = Scenario.find(params[:id])
  34. raise ActiveRecord::RecordNotFound unless @scenario.public? || (current_user && current_user.id == @scenario.user_id)
  35. @exporter = AgentsExporter.new(:name => @scenario.name,
  36. :description => @scenario.description,
  37. :guid => @scenario.guid,
  38. :tag_fg_color => @scenario.tag_fg_color,
  39. :tag_bg_color => @scenario.tag_bg_color,
  40. :source_url => @scenario.public? && export_scenario_url(@scenario),
  41. :agents => @scenario.agents)
  42. response.headers['Content-Disposition'] = 'attachment; filename="' + @exporter.filename + '"'
  43. render :json => JSON.pretty_generate(@exporter.as_json)
  44. end
  45. def edit
  46. @scenario = current_user.scenarios.find(params[:id])
  47. respond_to do |format|
  48. format.html
  49. format.json { render json: @scenario }
  50. end
  51. end
  52. def create
  53. @scenario = current_user.scenarios.build(params[:scenario])
  54. respond_to do |format|
  55. if @scenario.save
  56. format.html { redirect_to @scenario, notice: 'This Scenario was successfully created.' }
  57. format.json { render json: @scenario, status: :created, location: @scenario }
  58. else
  59. format.html { render action: "new" }
  60. format.json { render json: @scenario.errors, status: :unprocessable_entity }
  61. end
  62. end
  63. end
  64. def update
  65. @scenario = current_user.scenarios.find(params[:id])
  66. respond_to do |format|
  67. if @scenario.update_attributes(params[:scenario])
  68. format.html { redirect_to @scenario, notice: 'This Scenario was successfully updated.' }
  69. format.json { head :no_content }
  70. else
  71. format.html { render action: "edit" }
  72. format.json { render json: @scenario.errors, status: :unprocessable_entity }
  73. end
  74. end
  75. end
  76. def destroy
  77. @scenario = current_user.scenarios.find(params[:id])
  78. @scenario.destroy
  79. respond_to do |format|
  80. format.html { redirect_to scenarios_path }
  81. format.json { head :no_content }
  82. end
  83. end
  84. end