Class: Admin::SystemsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::SystemsController
- Includes:
- ManyHelper
- Defined in:
- app/controllers/admin/systems_controller.rb
Instance Method Summary (collapse)
-
- (Object) add_person
-
- (Object) biz_processes
Many2many relationship to Biz Processes.
-
- (Object) clone
-
- (Object) controls
Many2many relationship to Controls.
-
- (Object) create
Create a system.
-
- (Object) create_person
Another way to attach a biz process.
-
- (Object) destroy
Delete a system.
-
- (Object) destroy_person
Another way to detach a biz process.
-
- (Object) edit
Edit system form.
-
- (Object) index
List Systems.
-
- (Object) new
New system form.
-
- (Object) sections
Many2many relationship to COs.
-
- (Object) show
Show a system.
-
- (Object) update
Update a system.
Methods included from ManyHelper
#edit_children, #edit_children_inline, #edit_many, #edit_many_anon, #edit_many_attach, #get_many2many, #post_many2many
Instance Method Details
- (Object) add_person
157 158 159 |
# File 'app/controllers/admin/systems_controller.rb', line 157 def add_person @system = System.find(params[:id]) end |
- (Object) biz_processes
Many2many relationship to Biz Processes
149 150 151 152 153 154 155 |
# File 'app/controllers/admin/systems_controller.rb', line 149 def biz_processes if request.put? post_many2many(:left_class => System, :right_class => BizProcess) else get_many2many(:left_class => System, :right_class => BizProcess) end end |
- (Object) clone
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'app/controllers/admin/systems_controller.rb', line 186 def clone raise "cannot clone without cycle" unless @cycle @orig = System.find(params[:id]) @system = System.new @system.title = "Copy of #{@orig.title}" @system.slug = "COPY-#{@orig.slug}-#{Time.new.to_i}" @system.infrastructure = @orig.infrastructure @system.description = @orig.description @system.biz_processes += @orig.biz_processes @system.sections += @orig.sections @orig.system_controls.each do |sc| @system.system_controls << SystemControl.new(:control => sc.control, :cycle => @cycle) end if @system.save flash[:notice] = 'System was successfuly cloned.' redirect_to edit_system_path(@system) else flash[:error] = 'Failed' + @system.errors.inspect redirect_to systems_path end end |
- (Object) controls
Many2many relationship to Controls
131 132 133 134 135 136 137 |
# File 'app/controllers/admin/systems_controller.rb', line 131 def controls if request.put? post_many2many(:left_class => System, :right_class => Control) else get_many2many(:left_class => System, :right_class => Control) end end |
- (Object) create
Create a system
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/admin/systems_controller.rb', line 49 def create documents_params = params[:system].delete("document") || {} @system = System.new(params[:system]) # Accumulate results results = [] documents_params.each_pair do |index, doc_params| next if doc_params["link"].blank? # Create / delete / update attached doc # TODO: find existing doc, gdoc integration doc = @system.documents.create(doc_params) results << doc end results << @system.save respond_to do |format| if results.all? format.html { redirect_to(edit_system_path(@system), :notice => 'System was successfully created.') } format.xml { render :xml => @system, :status => :created, :location => @system } else flash.now[:error] = 'Could not create.' format.html { render :action => "new" } format.xml { render :xml => @system.errors, :status => :unprocessable_entity } end end end |
- (Object) create_person
Another way to attach a biz process
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/admin/systems_controller.rb', line 162 def create_person @system = System.find(params[:id]) @system_person = SystemPerson.new(params[:system_person]) @system_person.system = @system if @system_person.save flash[:notice] = 'Contact was successfully attached.' redirect_to edit_system_path(@system) else flash[:error] = 'Failed' + @system_person.errors.inspect redirect_to add_person_system_path(@system_person.person) end end |
- (Object) destroy
Delete a system
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/admin/systems_controller.rb', line 115 def destroy system = System.find(params[:id]) success = system.document_systems.destroy && system.system_controls.destroy && system.biz_process_systems.destroy && system.system_sections.destroy && system.destroy respond_to do |format| format.html { redirect_to(systems_url) } format.xml { head :ok } end end |
- (Object) destroy_person
Another way to detach a biz process
176 177 178 179 180 181 182 183 184 |
# File 'app/controllers/admin/systems_controller.rb', line 176 def destroy_person sysp = SystemPerson.first(:person_id => params[:person_id], :system_id => params[:id]) if sysp && sysp.destroy flash[:notice] = 'Contact was successfully detached.' else flash[:error] = 'Failed' end redirect_to edit_system_path(System.find(params[:id])) end |
- (Object) edit
Edit system form
40 41 42 43 44 45 46 |
# File 'app/controllers/admin/systems_controller.rb', line 40 def edit @system = System.find(params[:id]) # A couple of lines for new docs @system.documents << Document.new @system.documents << Document.new end |
- (Object) index
List Systems
6 7 8 9 10 11 12 13 |
# File 'app/controllers/admin/systems_controller.rb', line 6 def index @systems = System.order(:slug) respond_to do |format| format.html format.xml { render :xml => @systems } end end |
- (Object) new
New system form
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/admin/systems_controller.rb', line 26 def new @system = System.new # A couple of lines for new docs @system.documents << Document.new @system.documents << Document.new respond_to do |format| format.html format.xml { render :xml => @system } end end |
- (Object) sections
Many2many relationship to COs
140 141 142 143 144 145 146 |
# File 'app/controllers/admin/systems_controller.rb', line 140 def sections if request.put? post_many2many(:left_class => System, :right_class => Section) else get_many2many(:left_class => System, :right_class => Section) end end |
- (Object) show
Show a system
16 17 18 19 20 21 22 23 |
# File 'app/controllers/admin/systems_controller.rb', line 16 def show @system = System.find(params[:id]) respond_to do |format| format.html format.xml { render :xml => @system } end end |
- (Object) update
Update a system
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/admin/systems_controller.rb', line 78 def update @system = System.find(params[:id]) # Accumulate results results = [] documents_params = params[:system].delete("document") || {} documents_params.each_pair do |index, doc_params| next if doc_params["link"].blank? is_delete = doc_params.delete("delete") == "1" id = doc_params.delete("id") # Create / delete / update attached doc if id.blank? doc = @system.documents.create(doc_params) results << doc elsif is_delete results << @system.document_systems.first(:document_id => id).destroy results << Document.first(:id => id).destroy else results << Document.find(id).update_attributes(doc_params) end end results << @system.update_attributes(params[:system]) respond_to do |format| if results.all? format.html { redirect_to(edit_system_path(@system), :notice => 'System was successfully updated.') } format.xml { head :ok } else flash.now[:error] = 'Could not update.' format.html { render :action => "edit" } format.xml { render :xml => @system.errors, :status => :unprocessable_entity } end end end |