2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-23 04:36:35 -04:00
|
|
|
module Clusters
|
2017-10-05 13:45:15 -04:00
|
|
|
class ClusterPresenter < Gitlab::View::Presenter::Delegated
|
2018-12-09 23:05:23 -05:00
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include IconsHelper
|
|
|
|
|
2017-10-05 13:45:15 -04:00
|
|
|
presents :cluster
|
|
|
|
|
2018-12-09 23:05:23 -05:00
|
|
|
# We do not want to show the group path for clusters belonging to the
|
|
|
|
# clusterable, only for the ancestor clusters.
|
|
|
|
def item_link(clusterable_presenter)
|
|
|
|
if cluster.group_type? && clusterable != clusterable_presenter.subject
|
|
|
|
contracted_group_name(cluster.group) + ' / ' + link_to_cluster
|
|
|
|
else
|
|
|
|
link_to_cluster
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-05 13:45:15 -04:00
|
|
|
def gke_cluster_url
|
2017-10-23 04:36:35 -04:00
|
|
|
"https://console.cloud.google.com/kubernetes/clusters/details/#{provider.zone}/#{name}" if gcp?
|
2017-10-05 13:45:15 -04:00
|
|
|
end
|
2017-12-05 11:09:04 -05:00
|
|
|
|
2018-12-09 23:05:23 -05:00
|
|
|
def can_read_cluster?
|
|
|
|
can?(current_user, :read_cluster, cluster)
|
|
|
|
end
|
|
|
|
|
2018-12-13 02:53:15 -05:00
|
|
|
def cluster_type_description
|
|
|
|
if cluster.project_type?
|
|
|
|
s_("ClusterIntegration|Project cluster")
|
|
|
|
elsif cluster.group_type?
|
|
|
|
s_("ClusterIntegration|Group cluster")
|
2019-04-09 22:13:43 -04:00
|
|
|
elsif cluster.instance_type?
|
|
|
|
s_("ClusterIntegration|Instance cluster")
|
2018-12-13 02:53:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-30 06:33:43 -04:00
|
|
|
def show_path
|
|
|
|
if cluster.project_type?
|
|
|
|
project_cluster_path(project, cluster)
|
2018-10-22 23:51:29 -04:00
|
|
|
elsif cluster.group_type?
|
|
|
|
group_cluster_path(group, cluster)
|
2019-04-09 22:13:43 -04:00
|
|
|
elsif cluster.instance_type?
|
|
|
|
admin_cluster_path(cluster)
|
2018-10-30 06:33:43 -04:00
|
|
|
else
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
2018-12-09 23:05:23 -05:00
|
|
|
|
2019-03-29 14:23:18 -04:00
|
|
|
def read_only_kubernetes_platform_fields?
|
|
|
|
!cluster.provided_by_user?
|
|
|
|
end
|
|
|
|
|
2018-12-09 23:05:23 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def clusterable
|
|
|
|
if cluster.group_type?
|
|
|
|
cluster.group
|
|
|
|
elsif cluster.project_type?
|
|
|
|
cluster.project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def contracted_group_name(group)
|
|
|
|
sanitize(group.full_name)
|
|
|
|
.sub(%r{\/.*\/}, "/ #{contracted_icon} /")
|
|
|
|
.html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def contracted_icon
|
|
|
|
sprite_icon('ellipsis_h', size: 12, css_class: 'vertical-align-middle')
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_to_cluster
|
|
|
|
link_to_if(can_read_cluster?, cluster.name, show_path)
|
|
|
|
end
|
2017-10-05 13:45:15 -04:00
|
|
|
end
|
|
|
|
end
|