OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / controllers / provider_statuses_controller.rb
1 class ProviderStatusesController < ApplicationController
2   before_action :authenticate_admin!, :only => [:index, :show, :edit, :update, :destroy, :licenses_import, :artists_import, :original_pictures_import, :import, :import_all]
3   
4   def index
5     @page = ProviderStatus.page params[:page]
6     @page_size = ProviderStatus.page_size params[:page_size]
7     @hide = params[:hide]
8     @provider_statuses = if @hide.blank?
9       ProviderStatus.list(@page, @page_size)
10     else
11       ProviderStatus.available_list(@page, @page_size)
12     end
13
14     respond_to do |format|
15       format.html # index.html.erb
16       format.json { render :json => @provider_statuses.to_json(ProviderStatus.list_json_opt) }
17     end
18   end
19
20   def show
21     @provider_status = ProviderStatus.show(params[:id], @admin)
22
23     respond_to do |format|
24       format.html # show.html.erb
25       format.json { render :json => @provider_status.to_json(ProviderStatus.show_json_opt) }
26     end
27   end
28
29   def edit
30     @provider_status = ProviderStatus.edit(params[:id], @admin)
31     respond_to do |format|
32       format.html 
33       format.js
34     end
35   end
36
37   def update
38     @provider_status = ProviderStatus.edit(params[:id], @admin)
39     @provider_status.attributes = params[:provider_status]
40     @provider_status.overwrite
41     respond_to do |format|
42       if @provider_status.save
43         flash[:notice] = I18n.t('provider_statuses.flash.notice.created')
44         format.html { redirect_to @provider_status }
45         format.json { head :ok }
46       else
47         format.html { render action: "edit" }
48         format.json { render json: @provider_status.errors, status: :unprocessable_entity }
49       end
50     end
51   end
52
53   def destroy
54     @provider_status = ProviderStatus.edit(params[:id], @admin)
55     respond_to do |format|
56       if @provider_status.stop
57         flash[:notice] = I18n.t('provider_statuses.flash.notice.stopped')
58         format.html { redirect_to provider_statuses_url }
59         format.json { head :ok }
60       else
61         flash[:notice] = I18n.t('provider_statuses.flash.notice.not_stopped')
62         format.html { render action: "edit" }
63         format.json { render json: @provider_status.errors, status: :unprocessable_entity }
64       end
65     end
66   end
67   
68   def licenses_import
69     @provider_status = ProviderStatus.show(params[:id], @admin)
70     raise ActiveRecord::Forbidden if @provider_status.status == 0
71     @import_result = @provider_status.licenses_import params[:date]
72     respond_to do |format|
73       format.html # show.html.erb
74       format.json { render :json => @import_result.to_json() }
75     end
76   end
77   
78   def artists_import
79     @provider_status = ProviderStatus.show(params[:id], @admin)
80     raise ActiveRecord::Forbidden if @provider_status.status == 0
81     @import_result = @provider_status.artists_import params[:date]
82     respond_to do |format|
83       format.html # show.html.erb
84       format.json { render :json => @import_result.to_json() }
85     end
86   end
87   
88   def original_pictures_import
89     @provider_status = ProviderStatus.show(params[:id], @admin)
90     raise ActiveRecord::Forbidden if @provider_status.status == 0
91     @import_result = @provider_status.original_pictures_import params[:date]
92     respond_to do |format|
93       format.html # show.html.erb
94       format.json { render :json => @import_result.to_json() }
95     end
96   end
97   
98   def import
99     @provider_status = ProviderStatus.show(params[:id], @admin)
100     raise ActiveRecord::Forbidden if @provider_status.status == 0
101     @import_result = @provider_status.import params[:date]
102     respond_to do |format|
103       format.html # show.html.erb
104       format.json { render :json => @failures.to_json() }
105     end
106   end
107   
108   def import_all
109     ProviderStatus.approve_list.each do |provider_status|
110       @provider_status = provider_status params[:date]
111     end
112     respond_to do |format|
113       format.html { render :text => 'ok'}
114       format.json { render :json => {}.to_json() }
115     end
116   end
117   
118 end