PrototypeR4::Application.routes.draw do

  devise_for :users
  
  # routes for sinatra app
  match '/site/set_registered', :to => CentralServerExchangeApp  
  match '/site/public_key', :to => CentralServerExchangeApp 
  match '/site/update', :to => GithubApp
  match '/purchase/:type', :to => CentralServerExchangeApp
  match "/panel/:app_name/frontend/:action" => redirect {|params| "/panel/#{params[:app_name]}/#{params[:action]}" }


  # routes for admin
  namespace :admin do
    resources :assets
    resources :designs do
      collection do
        get 'upload_package'
        post 'upload_package'
      end
      member do
        post 'edit_file'  => 'designs#edit_file'
      end
    end
    resources :items
    resources :links do
      member do
        get 'delete'
      end
    end
    resources :pages do
      member do
        get 'delete'
        get 'reload_themes'
      end
    end
    resources :page_parts
    resources :purchases do
      collection do
        get 'install_app'
      end
      member do
        get 'download'
      end
    end
    resources :sites
    resources :snippets
    resources :translations
    resources :users
    resources :user_info_models
    resources :user_role_models
  end
  # end admin
  
  namespace :panel do
    resources :users
  end
  
  # routes for gridfs files
  match "/gridfs/*path" => "gridfs#serve"
  # match "/images/*path" => "gridfs#serve_images"
  # match "/admin/pages/images/*path" => "gridfs#serve_images"
  
  # routes for pages to generate
  match '*page_name' => 'pages#show', :as => :page, :constraints => lambda{|request|
    !request.path.starts_with?("/panel")
  }
  
  root :to => 'pages#index'
  
end
