debian-mirror-gitlab/app/assets/javascripts/packages/details/components/package_files.vue

166 lines
4.4 KiB
Vue
Raw Normal View History

2021-02-22 17:27:13 +05:30
<script>
2021-09-04 01:27:46 +05:30
import { GlLink, GlTable, GlDropdownItem, GlDropdown, GlIcon, GlButton } from '@gitlab/ui';
2021-02-22 17:27:13 +05:30
import { last } from 'lodash';
2021-03-11 19:13:27 +05:30
import { numberToHumanSize } from '~/lib/utils/number_utils';
2021-02-22 17:27:13 +05:30
import { __ } from '~/locale';
2021-09-04 01:27:46 +05:30
import FileSha from '~/packages/details/components/file_sha.vue';
2021-02-22 17:27:13 +05:30
import Tracking from '~/tracking';
import FileIcon from '~/vue_shared/components/file_icon.vue';
2021-03-11 19:13:27 +05:30
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
2021-02-22 17:27:13 +05:30
export default {
name: 'PackageFiles',
components: {
GlLink,
GlTable,
2021-09-04 01:27:46 +05:30
GlIcon,
GlDropdown,
GlDropdownItem,
GlButton,
2021-02-22 17:27:13 +05:30
FileIcon,
TimeAgoTooltip,
2021-09-04 01:27:46 +05:30
FileSha,
2021-02-22 17:27:13 +05:30
},
mixins: [Tracking.mixin()],
props: {
packageFiles: {
type: Array,
required: false,
default: () => [],
},
2021-09-04 01:27:46 +05:30
canDelete: {
type: Boolean,
default: false,
required: false,
},
2021-02-22 17:27:13 +05:30
},
computed: {
filesTableRows() {
2021-03-08 18:12:59 +05:30
return this.packageFiles.map((pf) => ({
2021-02-22 17:27:13 +05:30
...pf,
size: this.formatSize(pf.size),
pipeline: last(pf.pipelines),
}));
},
showCommitColumn() {
2021-03-08 18:12:59 +05:30
return this.filesTableRows.some((row) => Boolean(row.pipeline?.id));
2021-02-22 17:27:13 +05:30
},
filesTableHeaderFields() {
return [
{
key: 'name',
label: __('Name'),
},
{
key: 'commit',
label: __('Commit'),
hide: !this.showCommitColumn,
},
{
key: 'size',
label: __('Size'),
},
{
key: 'created',
label: __('Created'),
class: 'gl-text-right',
},
2021-09-04 01:27:46 +05:30
{
key: 'actions',
label: '',
hide: !this.canDelete,
class: 'gl-text-right',
tdClass: 'gl-w-4',
},
2021-03-08 18:12:59 +05:30
].filter((c) => !c.hide);
2021-02-22 17:27:13 +05:30
},
},
methods: {
formatSize(size) {
return numberToHumanSize(size);
},
2021-09-04 01:27:46 +05:30
hasDetails(item) {
return item.file_sha256 || item.file_md5 || item.file_sha1;
},
},
i18n: {
deleteFile: __('Delete file'),
2021-02-22 17:27:13 +05:30
},
};
</script>
<template>
<div>
<h3 class="gl-font-lg gl-mt-5">{{ __('Files') }}</h3>
<gl-table
:fields="filesTableHeaderFields"
:items="filesTableRows"
:tbody-tr-attr="{ 'data-testid': 'file-row' }"
>
2021-09-04 01:27:46 +05:30
<template #cell(name)="{ item, toggleDetails, detailsShowing }">
<gl-button
v-if="hasDetails(item)"
:icon="detailsShowing ? 'angle-up' : 'angle-down'"
:aria-label="detailsShowing ? __('Collapse') : __('Expand')"
category="tertiary"
size="small"
@click="toggleDetails"
/>
2021-02-22 17:27:13 +05:30
<gl-link
:href="item.download_path"
2021-09-04 01:27:46 +05:30
class="gl-text-gray-500"
2021-02-22 17:27:13 +05:30
data-testid="download-link"
@click="$emit('download-file')"
>
<file-icon
:file-name="item.file_name"
css-classes="gl-relative file-icon"
class="gl-mr-1 gl-relative"
/>
2021-09-04 01:27:46 +05:30
<span>{{ item.file_name }}</span>
2021-02-22 17:27:13 +05:30
</gl-link>
</template>
2021-03-08 18:12:59 +05:30
<template #cell(commit)="{ item }">
2021-02-22 17:27:13 +05:30
<gl-link
2021-06-08 01:23:25 +05:30
v-if="item.pipeline && item.pipeline.project"
2021-02-22 17:27:13 +05:30
:href="item.pipeline.project.commit_url"
class="gl-text-gray-500"
data-testid="commit-link"
>{{ item.pipeline.git_commit_message }}</gl-link
>
</template>
<template #cell(created)="{ item }">
<time-ago-tooltip :time="item.created_at" />
</template>
2021-09-04 01:27:46 +05:30
<template #cell(actions)="{ item }">
<gl-dropdown category="tertiary" right>
<template #button-content>
<gl-icon name="ellipsis_v" />
</template>
<gl-dropdown-item data-testid="delete-file" @click="$emit('delete-file', item)">
{{ $options.i18n.deleteFile }}
</gl-dropdown-item>
</gl-dropdown>
</template>
<template #row-details="{ item }">
<div
class="gl-display-flex gl-flex-direction-column gl-flex-grow-1 gl-bg-gray-10 gl-rounded-base gl-inset-border-1-gray-100"
>
<file-sha
v-if="item.file_sha256"
data-testid="sha-256"
title="SHA-256"
:sha="item.file_sha256"
/>
<file-sha v-if="item.file_md5" data-testid="md5" title="MD5" :sha="item.file_md5" />
<file-sha v-if="item.file_sha1" data-testid="sha-1" title="SHA-1" :sha="item.file_sha1" />
</div>
</template>
2021-02-22 17:27:13 +05:30
</gl-table>
</div>
</template>