Project

General

Profile

Revision a7978929

Added by Ondřej Pražák almost 8 years ago

progress

View differences:

app/controllers/foreman_pipeline/api/jobs_controller.rb
146 146
      respond_for_show
147 147
    end
148 148

  
149
    api :GET, "/organizations/:organization_id/jobs/:id/current_paths", N_("List environment paths of a job")
150
    param_group :job_id
151
    def current_paths
152
      paths = @job.paths.map(&:full_path)
153

  
154
      current = paths.inject([]) do |result, path|
155
        result << { :environments => path }
156
      end
157

  
158
      collection = {
159
        :results => current,
160
        :total => current.size,
161
        :subtotal => current.size
162
      }      
163
      respond_for_index(:collection => collection)
164
    end
149
    # api :GET, "/organizations/:organization_id/jobs/:id/current_paths", N_("List environment paths of a job")
150
    # param_group :job_id
151
    # def current_paths
152
    #   paths = @job.paths.map(&:full_path)
153

  
154
    #   current = paths.inject([]) do |result, path|
155
    #     result << { :environments => path }
156
    #   end
157

  
158
    #   collection = {
159
    #     :results => current,
160
    #     :total => current.size,
161
    #     :subtotal => current.size
162
    #   }      
163
    #   respond_for_index(:collection => collection)
164
    # end
165 165

  
166 166
    api :GET, "/organizations/:organization_id/jobs/:id/available_paths", N_("List environment paths available for a job")
167 167
    param_group :job_id
168 168
    def available_paths
169
      all_paths = @organization.promotion_paths.map(&:shift)
170
      available = (all_paths - @job.paths).map(&:full_path)
169
      available = [@job.environment.full_path] rescue []
171 170

  
172 171
      paths = available.inject([]) do |result, path|
173 172
        result << { :environments => path }
174 173
      end
174
      paths = [{ :environments => [] }] if paths.empty?
175 175

  
176 176
      collection = {
177 177
        :results => paths,
178 178
        :total => paths.size,
179 179
        :subtotal => paths.size
180 180
      }
181
      
181 182
      respond_for_index(:collection => collection)
182 183
    end
183 184

  

Also available in: Unified diff