OSDN Git Service

t#31056:add diff import
[pettanr/pettanr.git] / app / controllers / provider_statuses_controller.rb
index 9395eea..241917c 100644 (file)
@@ -1,7 +1,37 @@
 class ProviderStatusesController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
-  before_filter :authenticate_admin!, :only => [:index, :show, :edit, :update, :destroy, :licenses_import, :artists_import]
-
+  before_filter :authenticate_admin!, :only => [:index, :show, :edit, :update, :destroy, :licenses_import, :artists_import, :original_pictures_import, :import]
+  
+  private
+  
+  def licenses_port
+    licenses = export_by('licenses_export', @provider_status, params[:date])
+    return nil unless licenses
+    ProviderLicense.import @provider_status.provider.id, licenses
+  end
+  
+  def artists_port
+    artists = export_by('artists_export', @provider_status, params[:date])
+    return nil unless artists
+    ProviderArtist.import @provider_status.provider.id, artists
+  end
+  
+  def original_pictures_port
+    original_pictures = export_by('original_pictures_export', @provider_status, params[:date])
+    return nil unless original_pictures
+    pictures = export_by('pictures_export', @provider_status, params[:date])
+    return nil unless pictures
+    ProviderOriginalPicture.import @provider_status.provider.id, original_pictures, pictures
+  end
+  
+  def port
+    exports = export_by('export', @provider_status, params[:date])
+    return nil unless exports
+    ProviderStatus.import @provider_status.provider.id, exports
+  end
+  
+  public
+  
   def index
     @page = ProviderStatus.page params[:page]
     @page_size = ProviderStatus.page_size params[:page_size]
@@ -41,7 +71,8 @@ class ProviderStatusesController < ApplicationController
     @provider_status.overwrite
     respond_to do |format|
       if @provider_status.save
-        format.html { redirect_to @provider_status, notice: 'ProviderStatus was successfully updated.' }
+        flash[:notice] = I18n.t('provider_statuses.flash.notice.created')
+        format.html { redirect_to @provider_status }
         format.json { head :ok }
       else
         format.html { render action: "edit" }
@@ -52,19 +83,23 @@ class ProviderStatusesController < ApplicationController
 
   def destroy
     @provider_status = ProviderStatus.edit(params[:id], @admin)
-    @provider_status.destroy
     respond_to do |format|
-      format.html { redirect_to comics_url }
-      format.json { head :ok }
+      if @provider_status.stop
+        flash[:notice] = I18n.t('provider_statuses.flash.notice.stopped')
+        format.html { redirect_to provider_statuses_url }
+        format.json { head :ok }
+      else
+        flash[:notice] = I18n.t('provider_statuses.flash.notice.not_stopped')
+        format.html { render action: "edit" }
+        format.json { render json: @provider_status.errors, status: :unprocessable_entity }
+      end
     end
   end
   
   def licenses_import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    t = ymd_to_time params[:date]
-    url = export_url @provider_status.provider.demander_url, 'licenses_export', @provider_status.token, t
-    @failures = ProviderLicense.import @provider_status.provider.id, export_from_provider(url)
+    @failures = licenses_port
     respond_to do |format|
       format.html # show.html.erb
       format.json { render :json => @failures.to_json() }
@@ -74,9 +109,28 @@ class ProviderStatusesController < ApplicationController
   def artists_import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    t = ymd_to_time params[:date]
-    url = export_url @provider_status.provider.demander_url, 'artists_export', @provider_status.token, t
-    @failures = ProviderArtist.import @provider_status.provider.id, export_from_provider(url)
+    @failures = artists_port
+    respond_to do |format|
+      format.html # show.html.erb
+      format.json { render :json => @failures.to_json() }
+    end
+  end
+  
+  def original_pictures_import
+    @provider_status = ProviderStatus.show(params[:id], @admin)
+    raise ActiveRecord::Forbidden if @provider_status.status == 0
+    @failures = original_pictures_port
+    respond_to do |format|
+      format.html # show.html.erb
+      format.json { render :json => @failures.to_json() }
+    end
+  end
+  
+  def import
+    @provider_status = ProviderStatus.show(params[:id], @admin)
+    raise ActiveRecord::Forbidden if @provider_status.status == 0
+    @failures = port
+    p @failures
     respond_to do |format|
       format.html # show.html.erb
       format.json { render :json => @failures.to_json() }