From 5b3c096c9e0c9e8e7e1cb35c1b9e347995b948f5 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 15 Oct 2018 16:37:51 +1300 Subject: Convert clusters to use a top-level controller In preparation so that we can create both cluster attached to project and cluster attached to group. - Move ClustersController to top level - Move Clusters::ApplicationsController to top-level too - Creates a Clusters::BaseController to share common functions - Do not rely on @project ivar. Anything could set the ivar. - Fix Vue page components due to new data-page value Because of the controller change we have gone from `projects:clusters:new` to `clusters:new`, so we need to update the file location of the page components. There is somewhere a function that will convert data-page to a file location. On that note, projects/clusters/gcp/new/, translate to Projects::Clusters::Gcp#new doesn't exist so replace that with clusters/create_gcp/ and clusters/create_user/ --- config/routes.rb | 17 +++++++++++++++++ config/routes/project.rb | 15 +-------------- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'config') diff --git a/config/routes.rb b/config/routes.rb index 37c7f98ec98..cfb81cabfe4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -84,6 +84,23 @@ Rails.application.routes.draw do draw :instance_statistics end + concern :clusterable do + resources :clusters, except: [:edit, :create], controller: '/clusters' do + collection do + post :create_gcp + post :create_user + end + + member do + get :status, format: :json + + scope :applications do + post '/:application', to: '/clusters/applications#create', as: :install_applications + end + end + end + end + draw :api draw :sidekiq draw :help diff --git a/config/routes/project.rb b/config/routes/project.rb index 73c46f72168..387d2363552 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -206,20 +206,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do end end - resources :clusters, except: [:edit, :create] do - collection do - post :create_gcp - post :create_user - end - - member do - get :status, format: :json - - scope :applications do - post '/:application', to: 'clusters/applications#create', as: :install_applications - end - end - end + concerns :clusterable resources :environments, except: [:destroy] do member do -- cgit v1.2.1 From 88800abcd8741b07114c2850e00b74fbecfbf90e Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Fri, 19 Oct 2018 14:42:30 +1300 Subject: Abstract out project out of ClustersController To the extent possible swap out `project` with `clusterable` - Abstract paths for showing cluster or clusters. This will allow us to swap in alternative paths for group level cluster - Push :project_id and :namespace_id params from the URL to the POST body. - Create a nice helper for to generate links for the destroy action For some reason, spec :project_id and :namespace_id param are not going through `to_param` for a JSON format. Manually call `to_param` to fix specs. - Move :layout to BaseController --- config/routes.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'config') diff --git a/config/routes.rb b/config/routes.rb index cfb81cabfe4..bf5023eeec2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,6 +74,21 @@ Rails.application.routes.draw do resources :issues, module: :boards, only: [:index, :update] end + resources :clusters, only: [:update, :destroy] do + collection do + post :create_user + post :create_gcp + end + + member do + scope :applications do + post '/:application', to: 'clusters/applications#create', as: :install_applications + end + + get :status, format: :json + end + end + # UserCallouts resources :user_callouts, only: [:create] @@ -85,20 +100,7 @@ Rails.application.routes.draw do end concern :clusterable do - resources :clusters, except: [:edit, :create], controller: '/clusters' do - collection do - post :create_gcp - post :create_user - end - - member do - get :status, format: :json - - scope :applications do - post '/:application', to: '/clusters/applications#create', as: :install_applications - end - end - end + resources :clusters, only: [:index, :new, :show], controller: '/clusters' end draw :api -- cgit v1.2.1 From 1a1fdf8efe1923ba781e978e858c009264020e72 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Thu, 1 Nov 2018 13:39:01 +1300 Subject: Resolve controller sharing concern Use ClustersController as base while having Projects::ClustersController to inform what `clusterable` is. Thanks @ayufan for the great suggestion ! - View changes to work with new approach - Fix javascript for new approach - Fix feature specs for new approach - Fix QA --- config/routes.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'config') diff --git a/config/routes.rb b/config/routes.rb index bf5023eeec2..d2d91647d0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,7 +74,18 @@ Rails.application.routes.draw do resources :issues, module: :boards, only: [:index, :update] end - resources :clusters, only: [:update, :destroy] do + # UserCallouts + resources :user_callouts, only: [:create] + + get 'ide' => 'ide#index' + get 'ide/*vueroute' => 'ide#index', format: false + + draw :operations + draw :instance_statistics + end + + concern :clusterable do + resources :clusters, only: [:index, :new, :show, :update, :destroy] do collection do post :create_user post :create_gcp @@ -85,22 +96,9 @@ Rails.application.routes.draw do post '/:application', to: 'clusters/applications#create', as: :install_applications end - get :status, format: :json + get :cluster_status, format: :json end end - - # UserCallouts - resources :user_callouts, only: [:create] - - get 'ide' => 'ide#index' - get 'ide/*vueroute' => 'ide#index', format: false - - draw :operations - draw :instance_statistics - end - - concern :clusterable do - resources :clusters, only: [:index, :new, :show], controller: '/clusters' end draw :api -- cgit v1.2.1