2020-01-07 04:07:59 -05:00
|
|
|
<script>
|
2020-06-11 14:08:28 -04:00
|
|
|
import { GlTooltipDirective, GlLink, GlButton, GlCollapse, GlIcon, GlBadge } from '@gitlab/ui';
|
2020-08-17 17:09:56 -04:00
|
|
|
import { difference, get } from 'lodash';
|
2020-06-11 14:08:28 -04:00
|
|
|
import { __, s__, sprintf } from '~/locale';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { ASSET_LINK_TYPE } from '../constants';
|
2020-01-07 04:07:59 -05:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ReleaseBlockAssets',
|
|
|
|
components: {
|
|
|
|
GlLink,
|
2020-06-11 14:08:28 -04:00
|
|
|
GlButton,
|
|
|
|
GlCollapse,
|
|
|
|
GlIcon,
|
|
|
|
GlBadge,
|
2020-01-07 04:07:59 -05:00
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
assets: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2020-06-11 14:08:28 -04:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isAssetsExpanded: true,
|
|
|
|
};
|
|
|
|
},
|
2020-01-07 04:07:59 -05:00
|
|
|
computed: {
|
2020-06-11 14:08:28 -04:00
|
|
|
imageLinks() {
|
|
|
|
return this.linksForType(ASSET_LINK_TYPE.IMAGE);
|
|
|
|
},
|
|
|
|
packageLinks() {
|
|
|
|
return this.linksForType(ASSET_LINK_TYPE.PACKAGE);
|
|
|
|
},
|
|
|
|
runbookLinks() {
|
|
|
|
return this.linksForType(ASSET_LINK_TYPE.RUNBOOK);
|
|
|
|
},
|
|
|
|
otherLinks() {
|
|
|
|
return difference(this.assets.links, [
|
|
|
|
...this.imageLinks,
|
|
|
|
...this.packageLinks,
|
|
|
|
...this.runbookLinks,
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
sections() {
|
|
|
|
return [
|
|
|
|
{
|
2020-12-23 19:10:25 -05:00
|
|
|
links: get(this.assets, 'sources', []).map((s) => ({
|
2020-06-11 14:08:28 -04:00
|
|
|
url: s.url,
|
|
|
|
name: sprintf(__('Source code (%{fileExtension})'), { fileExtension: s.format }),
|
|
|
|
})),
|
|
|
|
iconName: 'doc-code',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: s__('ReleaseAssetLinkType|Images'),
|
|
|
|
links: this.imageLinks,
|
|
|
|
iconName: 'container-image',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: s__('ReleaseAssetLinkType|Packages'),
|
|
|
|
links: this.packageLinks,
|
|
|
|
iconName: 'package',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: s__('ReleaseAssetLinkType|Runbooks'),
|
|
|
|
links: this.runbookLinks,
|
|
|
|
iconName: 'book',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: s__('ReleaseAssetLinkType|Other'),
|
|
|
|
links: this.otherLinks,
|
|
|
|
iconName: 'link',
|
|
|
|
},
|
2020-12-23 19:10:25 -05:00
|
|
|
].filter((section) => section.links.length > 0);
|
2020-06-11 14:08:28 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggleAssetsExpansion() {
|
|
|
|
this.isAssetsExpanded = !this.isAssetsExpanded;
|
|
|
|
},
|
|
|
|
linksForType(type) {
|
2020-12-23 19:10:25 -05:00
|
|
|
return this.assets.links.filter((l) => l.linkType === type);
|
2020-06-11 14:08:28 -04:00
|
|
|
},
|
2020-01-07 04:07:59 -05:00
|
|
|
},
|
2020-06-11 14:08:28 -04:00
|
|
|
externalLinkTooltipText: __('This link points to external content'),
|
2020-01-07 04:07:59 -05:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2020-06-26 02:09:03 -04:00
|
|
|
<div class="card-text gl-mt-3">
|
2020-10-06 11:08:33 -04:00
|
|
|
<gl-button
|
|
|
|
data-testid="accordion-button"
|
|
|
|
variant="link"
|
|
|
|
class="gl-font-weight-bold"
|
|
|
|
@click="toggleAssetsExpansion"
|
|
|
|
>
|
|
|
|
<gl-icon
|
|
|
|
name="chevron-right"
|
|
|
|
class="gl-transition-medium"
|
|
|
|
:class="{ 'gl-rotate-90': isAssetsExpanded }"
|
|
|
|
/>
|
|
|
|
{{ __('Assets') }}
|
|
|
|
<gl-badge size="sm" variant="neutral" class="gl-display-inline-block">{{
|
|
|
|
assets.count
|
|
|
|
}}</gl-badge>
|
|
|
|
</gl-button>
|
|
|
|
<gl-collapse v-model="isAssetsExpanded">
|
|
|
|
<div class="gl-pl-6 gl-pt-3 js-assets-list">
|
|
|
|
<template v-for="(section, index) in sections">
|
|
|
|
<h5 v-if="section.title" :key="`section-header-${index}`" class="gl-mb-2">
|
|
|
|
{{ section.title }}
|
|
|
|
</h5>
|
|
|
|
<ul :key="`section-body-${index}`" class="list-unstyled gl-m-0">
|
|
|
|
<li v-for="link in section.links" :key="link.url" class="gl-display-flex">
|
|
|
|
<gl-link
|
|
|
|
:href="link.directAssetUrl || link.url"
|
|
|
|
class="gl-display-flex gl-align-items-center gl-line-height-24"
|
|
|
|
>
|
|
|
|
<gl-icon :name="section.iconName" class="gl-mr-2 gl-flex-shrink-0 gl-flex-grow-0" />
|
|
|
|
{{ link.name }}
|
|
|
|
<gl-icon
|
|
|
|
v-if="link.external"
|
|
|
|
v-gl-tooltip
|
|
|
|
name="external-link"
|
|
|
|
:aria-label="$options.externalLinkTooltipText"
|
|
|
|
:title="$options.externalLinkTooltipText"
|
|
|
|
data-testid="external-link-indicator"
|
|
|
|
class="gl-ml-2 gl-flex-shrink-0 gl-flex-grow-0 gl-text-gray-400"
|
|
|
|
/>
|
|
|
|
</gl-link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</template>
|
2020-01-07 04:07:59 -05:00
|
|
|
</div>
|
2020-10-06 11:08:33 -04:00
|
|
|
</gl-collapse>
|
2020-01-07 04:07:59 -05:00
|
|
|
</div>
|
|
|
|
</template>
|