Commit f05b9ebd authored by Zack Cuddy's avatar Zack Cuddy

Replace Notice with Toast

Update Projects
Update Uploads
Update Nodes

Lint

Fix tests
parent de5869d5
import initVueAlerts from '~/vue_alerts';
import showToast from '~/vue_shared/plugins/global_toast';
document.addEventListener('DOMContentLoaded', initVueAlerts);
document.addEventListener('DOMContentLoaded', () => {
initVueAlerts();
const toasts = document.querySelectorAll('.js-toast-message');
toasts.forEach(toast => showToast(toast.dataset.message));
});
......@@ -20,7 +20,8 @@ class Admin::Geo::NodesController < Admin::Geo::ApplicationController
@node = ::Geo::NodeCreateService.new(geo_node_params).execute
if @node.persisted?
redirect_to admin_geo_nodes_path, notice: _('Node was successfully created.')
flash[:toast] = _('Node was successfully created.')
redirect_to admin_geo_nodes_path
else
@nodes = GeoNode.all
......@@ -34,7 +35,8 @@ class Admin::Geo::NodesController < Admin::Geo::ApplicationController
def update
if ::Geo::NodeUpdateService.new(@node, geo_node_params).execute
redirect_to admin_geo_nodes_path, notice: _('Node was successfully updated.')
flash[:toast] = _('Node was successfully updated.')
redirect_to admin_geo_nodes_path
else
render :edit
end
......
......@@ -26,42 +26,49 @@ class Admin::Geo::ProjectsController < Admin::Geo::ApplicationController
def destroy
unless @registry.project.nil?
return redirect_back_or_admin_geo_projects(alert: s_('Geo|Could not remove tracking entry for an existing project.'))
flash[:alert] = s_('Geo|Could not remove tracking entry for an existing project.')
return redirect_back_or_default(default: admin_geo_projects_path)
end
@registry.destroy
redirect_back_or_admin_geo_projects(notice: s_('Geo|Tracking entry for project (%{project_id}) was successfully removed.') % { project_id: @registry.project_id })
flash[:toast] = s_('Geo|Tracking entry for project (%{project_id}) was successfully removed.') % { project_id: @registry.project_id }
redirect_back_or_default(default: admin_geo_projects_path)
end
def reverify
@registry.flag_repository_for_reverify!
redirect_back_or_admin_geo_projects(notice: s_('Geo|%{name} is scheduled for re-verify') % { name: @registry.project.full_name })
flash[:toast] = s_('Geo|%{name} is scheduled for re-verify') % { name: @registry.project.full_name }
redirect_back_or_default(default: admin_geo_projects_path)
end
def resync
@registry.flag_repository_for_resync!
redirect_back_or_admin_geo_projects(notice: s_('Geo|%{name} is scheduled for re-sync') % { name: @registry.project.full_name })
flash[:toast] = s_('Geo|%{name} is scheduled for re-sync') % { name: @registry.project.full_name }
redirect_back_or_default(default: admin_geo_projects_path)
end
def force_redownload
@registry.flag_repository_for_redownload!
redirect_back_or_admin_geo_projects(notice: s_('Geo|%{name} is scheduled for forced re-download') % { name: @registry.project.full_name })
flash[:toast] = s_('Geo|%{name} is scheduled for forced re-download') % { name: @registry.project.full_name }
redirect_back_or_default(default: admin_geo_projects_path)
end
def reverify_all
Geo::Batch::ProjectRegistrySchedulerWorker.perform_async(:reverify_repositories)
redirect_back_or_admin_geo_projects(notice: s_('Geo|All projects are being scheduled for re-verify'))
flash[:toast] = s_('Geo|All projects are being scheduled for re-verify')
redirect_back_or_default(default: admin_geo_projects_path)
end
def resync_all
Geo::Batch::ProjectRegistrySchedulerWorker.perform_async(:resync_repositories)
redirect_back_or_admin_geo_projects(notice: s_('Geo|All projects are being scheduled for re-sync'))
flash[:toast] = s_('Geo|All projects are being scheduled for re-sync')
redirect_back_or_default(default: admin_geo_projects_path)
end
private
......@@ -70,10 +77,6 @@ class Admin::Geo::ProjectsController < Admin::Geo::ApplicationController
@registry = ::Geo::ProjectRegistry.find_by_id(params[:id])
end
def redirect_back_or_admin_geo_projects(params)
redirect_back_or_default(default: admin_geo_projects_path, options: params)
end
def finder
@finder ||= ::Geo::ProjectRegistryStatusFinder.new
end
......
......@@ -9,12 +9,14 @@ class Admin::Geo::UploadsController < Admin::Geo::ApplicationController
def destroy
if registry.upload
return redirect_admin_geo_uploads(alert: s_('Geo|Could not remove tracking entry for an existing upload.'))
flash[:alert] = s_('Geo|Could not remove tracking entry for an existing upload.')
return redirect_back_or_default(default: admin_geo_uploads_path)
end
registry.destroy
redirect_admin_geo_uploads(notice: s_('Geo|Tracking entry for upload (%{type}/%{id}) was successfully removed.') % { type: registry.file_type, id: registry.file_id })
flash[:toast] = s_('Geo|Tracking entry for upload (%{type}/%{id}) was successfully removed.') % { type: registry.file_type, id: registry.file_id }
redirect_back_or_default(default: admin_geo_uploads_path)
end
private
......@@ -31,8 +33,4 @@ class Admin::Geo::UploadsController < Admin::Geo::ApplicationController
def registry
@registry ||= ::Geo::UploadRegistry.find_by_id(params[:id])
end
def redirect_admin_geo_uploads(options)
redirect_back_or_default(default: admin_geo_uploads_path, options: options)
end
end
......@@ -102,7 +102,7 @@ describe Admin::Geo::ProjectsController, :geo do
synced_registry.update_column(:project_id, -1)
expect(subject).to redirect_to(admin_geo_projects_path)
expect(flash[:notice]).to include('was successfully removed')
expect(flash[:toast]).to include('was successfully removed')
expect { Geo::ProjectRegistry.find(synced_registry.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
end
......@@ -129,7 +129,7 @@ describe Admin::Geo::ProjectsController, :geo do
it 'flags registry for reverify' do
expect(subject).to redirect_to(admin_geo_projects_path)
expect(flash[:notice]).to include('is scheduled for re-verify')
expect(flash[:toast]).to include('is scheduled for re-verify')
expect(synced_registry.reload.pending_verification?).to be_truthy
end
end
......@@ -147,7 +147,7 @@ describe Admin::Geo::ProjectsController, :geo do
it 'flags registry for resync' do
expect(subject).to redirect_to(admin_geo_projects_path)
expect(flash[:notice]).to include('is scheduled for re-sync')
expect(flash[:toast]).to include('is scheduled for re-sync')
expect(synced_registry.reload.resync_repository?).to be_truthy
end
end
......@@ -173,7 +173,7 @@ describe Admin::Geo::ProjectsController, :geo do
it 'redirects back and display confirmation' do
Sidekiq::Testing.inline! do
expect(subject).to redirect_to(admin_geo_projects_path)
expect(flash[:notice]).to include('All projects are being scheduled for re-verify')
expect(flash[:toast]).to include('All projects are being scheduled for re-verify')
end
end
end
......@@ -198,7 +198,7 @@ describe Admin::Geo::ProjectsController, :geo do
it 'redirects back and display confirmation' do
expect(subject).to redirect_to(admin_geo_projects_path)
expect(flash[:notice]).to include('All projects are being scheduled for re-sync')
expect(flash[:toast]).to include('All projects are being scheduled for re-sync')
end
end
end
......@@ -215,7 +215,7 @@ describe Admin::Geo::ProjectsController, :geo do
it 'flags registry for re-download' do
expect(subject).to redirect_to(admin_geo_projects_path)
expect(flash[:notice]).to include('is scheduled for forced re-download')
expect(flash[:toast]).to include('is scheduled for forced re-download')
expect(synced_registry.reload.should_be_redownloaded?('repository')).to be_truthy
end
end
......
......@@ -108,7 +108,7 @@ describe Admin::Geo::UploadsController, :geo do
registry.update_column(:file_id, -1)
expect(subject).to redirect_to(admin_geo_uploads_path)
expect(flash[:notice]).to include('was successfully removed')
expect(flash[:toast]).to include('was successfully removed')
expect { Geo::UploadRegistry.find(registry.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment