Sha256: 87fdd9849bd75a489adf3d5013a4c4d156149b8d4dcab42c349a81461182ed43

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

module Coupler
  module Extensions
    module Imports
      def self.registered(app)
        app.post "/projects/:project_id/imports/upload" do
          @import = Models::Import.new(:data => params[:data], :project => @project)
          erb :'imports/new'
        end

        app.post "/projects/:project_id/imports" do
          @import = Models::Import.new(params[:import].merge(:project_id => @project.id))

          if @import.save
            @resource = Models::Resource.new(:import => @import)
            if @resource.valid?
              if @import.import!
                @resource.save
                redirect("/projects/#{@project.id}/resources/#{@resource.id}")
              else
                redirect("/projects/#{@project.id}/imports/#{@import.id}/edit")
              end
            end
          end
          erb(:'imports/new')
        end

        app.get "/projects/:project_id/imports/:id/edit" do
          @import = Models::Import[:id => params[:id], :project_id => @project.id]
          raise ImportNotFound    unless @import
          erb(:'imports/edit')
        end

        app.put "/projects/:project_id/imports/:id" do
          @import = Models::Import[:id => params[:id], :project_id => @project.id]
          raise ImportNotFound    unless @import
          @import.repair_duplicate_keys!(params[:delete])
          @resource = Models::Resource.create(:import => @import)
          redirect("/projects/#{@project.id}/resources/#{@resource.id}")
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
coupler-0.0.7-java lib/coupler/extensions/imports.rb
coupler-0.0.6-java lib/coupler/extensions/imports.rb
coupler-0.0.4-java lib/coupler/extensions/imports.rb
coupler-0.0.3-java lib/coupler/extensions/imports.rb
coupler-0.0.2-java lib/coupler/extensions/imports.rb
coupler-0.0.1-java lib/coupler/extensions/imports.rb