services_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. class ServicesController < ApplicationController
  2. include SortableTable
  3. before_filter :upgrade_warning, only: :index
  4. def index
  5. set_table_sort sorts: %w[provider name global], default: { provider: :asc }
  6. @services = current_user.services.reorder(table_sort).page(params[:page])
  7. respond_to do |format|
  8. format.html
  9. format.json { render json: @services }
  10. end
  11. end
  12. def destroy
  13. @services = current_user.services.find(params[:id])
  14. @services.destroy
  15. respond_to do |format|
  16. format.html { redirect_to services_path }
  17. format.json { head :no_content }
  18. end
  19. end
  20. def toggle_availability
  21. @service = current_user.services.find(params[:id])
  22. @service.toggle_availability!
  23. respond_to do |format|
  24. format.html { redirect_to services_path }
  25. format.json { render json: @service }
  26. end
  27. end
  28. def callback
  29. @service = current_user.services.initialize_or_update_via_omniauth(request.env['omniauth.auth'])
  30. if @service && @service.save
  31. redirect_to services_path, notice: "The service was successfully created."
  32. else
  33. redirect_to services_path, error: "Error creating the service."
  34. end
  35. end
  36. end