Class: WorksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/works_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#_edition_exists, #after_sign_in_path_for, #deny_access, #expansion_exists, #fill_platforms, #game_exists, #game_maker_only, #has_query, #ignore_referral_spam, #reviewer_only, #work_exists, #xhr_only

Instance Method Details

#combineObject


91
92
93
94
95
96
97
98
99
# File 'app/controllers/works_controller.rb', line 91

def combine
	@work = Work.friendly.find(params[:id])
	@search = WorksSearch.new(query: @work.original_title)
	results = @search.search.only(:id)
	@same_work_data = []
	results.load().each do |w|
		@same_work_data << w unless w.id == @work.id
	end
end

#do_combineObject


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/works_controller.rb', line 33

def do_combine
	@combine_work_ids = params.require(:work_ids)
	@older_work = nil
	@combine_works = []
	@combine_work_ids.each do |w|
		@work = Work.friendly.find(w)
		@combine_works << @work
		if @older_work.present? == false
			@older_work = @work
		elsif @work.original_release_date.present?
			if not @older_work.original_release_date.present? or
				@older_work.original_release_date > @work.original_release_date or
				(@older_work.original_release_date == @work.original_release_date and @older_work.id > @work.id)
				@older_work = @work
			end
		end
	end

	@combine_works.delete(@older_work)
	@combine_works.each do |work|
		work.editions.each do |edition|
			edition.work_id = @older_work.id
			edition.save
		end
		work.destroy
	end
	@older_work.slug = nil
	@older_work.save()
	flash[:success] = "Your editions were combined!"
	redirect_to work_path(@older_work)
end

#do_splitObject


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/works_controller.rb', line 67

def do_split
	split_editions = []
	@work.editions.each do |e|
		if @split_edition_ids.include? e.id
			@older_split = decide_older_edition(@older_split, e)
			split_editions << e
		else
			@older_keep = decide_older_edition(@older_keep, e)
		end
	end
	@work.original_release_date = @older_keep
	@work.slug = nil
	@work.save

	@split_work = Work.new(:original_title => @work.original_title, :original_release_date => @older_split)
	if @split_work.save
		split_editions.each do |e|
			e.work = @split_work
			e.save
		end
	end
	flash[:notice] = "New edition created!"
	redirect_to work_path(@split_work)
end

#searchObject


16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/works_controller.rb', line 16

def search
	params = work_params
	@work = Work.find_by(original_title: params[:original_title], original_release_date: params[:original_release_date])
	respond_to do |format|
		if @work.present?
			format.json { render :json => { :existing_work => @work, :status => :exists } }
		else
			format.json { render :json => { :status => :none_exists }  }
		end
	end
end

#search_indexObject


27
28
29
30
31
32
# File 'app/controllers/works_controller.rb', line 27

def search_index
	@search = WorksSearch.new(query: params[:q])
	results = @search.search.only(:id)
	@games = results.paginate(:page => params[:page]).load()
	@qty = @games.count
end

#showObject


100
101
102
103
# File 'app/controllers/works_controller.rb', line 100

def show
	@work = Work.friendly.find(params[:id])
	@editions = Edition.where(work_id: @work.id).paginate(:page => params[:page]).order('release_date desc')
end

#splitObject


64
65
66
# File 'app/controllers/works_controller.rb', line 64

def split
	@work = Work.friendly.find(params[:id])
end