Class: Mygengo::JobsController

Inherits:
MygengoController
  • Object
show all
Defined in:
lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb

Constant Summary collapse

URL_REGEXP =
/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix

Instance Method Summary collapse

Instance Method Details

#approveObject



119
120
121
122
123
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 119

def approve  
  @job = Mugen::Job.approve(params[:id])
  
  redirect_to mygengo_jobs_path
end

#createObject

POST /jobs POST /jobs.xml



94
95
96
97
98
99
100
101
102
103
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 94

def create      
  params[:job]['body_src'] = sanitize(params[:job]['body_src'])
  if params[:job]['callback_url'].empty? || 
     !params[:job]['callback_url'].match(URL_REGEXP)
    params[:job].delete('callback_url') 
  end
  flag = Mugen::Job.create(params[:job])    

  redirect_to mygengo_jobs_path
end

#destroyObject

DELETE /jobs/1 DELETE /jobs/1.xml



139
140
141
142
143
144
145
146
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 139

def destroy    
  @job = Mugen::Job.delete(params[:id])
  
  respond_to do |format|
    format.html { redirect_to(mygengo_jobs_url) }
    format.xml  { head :ok }
  end
end

#editObject

GET /jobs/1/edit



88
89
90
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 88

def edit         
  @job = Mugen::Job.find(params[:id])
end

#indexObject

GET /jobs GET /jobs.xml



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 6

def index
  @job_ids = Mugen::Jobs.all
  if @job_ids
    @jobs = @job_ids.collect {|j| 
      Mugen::Job.find(j['job_id']).merge('comments' => Mugen::Job.comments(j['job_id']))
    }
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @jobs }
    end
  else
    redirect_to 
  end    
end

#newObject

GET /jobs/new GET /jobs/new.xml



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 74

def new
  @job = Mugen::Job                                                    
  @languages = Mugen::Service.languages
  @language_pairs = Mugen::Service.language_pairs
  @language_src = @languages.collect { |lp| [ lp["language"], lp['lc'] ] }.uniq.sort
  @language_tgt = @languages.collect { |lp| [ lp["language"], lp['lc']  ] }.uniq.sort

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @job }
  end
end

#purchaseObject



113
114
115
116
117
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 113

def purchase 
  @job = Mugen::Job.purchase(params[:id])
  
  redirect_to mygengo_jobs_path
end

#rejectObject



131
132
133
134
135
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 131

def reject  
  @job = Mugen::Job.reject(params[:id], params[:job])
  
  redirect_to mygengo_jobs_path
end

#reject_formObject



46
47
48
49
50
51
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 46

def reject_form  
  @job = Mugen::Job.find(params[:id])
  @preview = Mugen::Job.preview(@job['job_id'])
  @comments = Mugen::Job.comments(@job['job_id']) 
  @job.merge!('comments' => @comments)        
end

#review_formObject



38
39
40
41
42
43
44
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 38

def review_form 
  @job = Mugen::Job.find(params[:id])
  @preview = Mugen::Job.preview(@job['job_id'])
  @comments = Mugen::Job.comments(@job['job_id']) 
  @job.merge!('comments' => @comments)        
  @feedback = Mugen::Job.feedback(@job['job_id'])    
end

#reviseObject



125
126
127
128
129
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 125

def revise
  @job = Mugen::Job.revise(params[:id], params[:job])
  
  redirect_to mygengo_jobs_path
end

#revise_formObject



53
54
55
56
57
58
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 53

def revise_form   
  @job = Mugen::Job.find(params[:id])
  @preview = Mugen::Job.preview(@job['job_id'])
  @comments = Mugen::Job.comments(@job['job_id']) 
  @job.merge!('comments' => @comments)        
end

#revisionObject

GET /jobs/1 GET /jobs/1.xml



62
63
64
65
66
67
68
69
70
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 62

def revision
  @job = Mugen::Job.find(params[:job_id])    
  @revision = Mugen::Job.revision(params[:job_id], params[:id])
  
  respond_to do |format|
    format.html {}
    format.xml  { render :xml => @job }
  end
end

#showObject

GET /jobs/1 GET /jobs/1.xml



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 23

def show
  @job = Mugen::Job.find(params[:id])
  @preview = Mugen::Job.preview(@job['job_id'])
  @comments = Mugen::Job.comments(@job['job_id']) 
  @job.merge!('comments' => @comments)    
  @feedback = Mugen::Job.feedback(@job['job_id'])
  @revisions = Mugen::Job.revisions(@job['job_id'])
  @revisions = [@revisions] if @revisions.is_a?(Hash)

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @job }
  end
end

#updateObject

PUT /jobs/1 PUT /jobs/1.xml



107
108
109
110
111
# File 'lib/generators/mugen/templates/app/controllers/mygengo/jobs_controller.rb', line 107

def update
  @job = Mugen::Job.update(params[:id])
  
  redirect_to mygengo_jobs_path
end