2018-05-09 12:01:36 +05:30
|
|
|
<script>
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
2019-02-15 15:39:39 +05:30
|
|
|
import { GlLoadingIcon, GlTooltipDirective } from '@gitlab/ui';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Badge',
|
|
|
|
components: {
|
|
|
|
Icon,
|
2018-12-13 13:39:08 +05:30
|
|
|
GlLoadingIcon,
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
directives: {
|
2019-02-15 15:39:39 +05:30
|
|
|
GlTooltip: GlTooltipDirective,
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
imageUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
linkUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
hasError: false,
|
|
|
|
isLoading: true,
|
|
|
|
numRetries: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
imageUrlWithRetries() {
|
|
|
|
if (this.numRetries === 0) {
|
|
|
|
return this.imageUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${this.imageUrl}#retries=${this.numRetries}`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
imageUrl() {
|
|
|
|
this.hasError = false;
|
|
|
|
this.isLoading = true;
|
|
|
|
this.numRetries = 0;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onError() {
|
|
|
|
this.isLoading = false;
|
|
|
|
this.hasError = true;
|
|
|
|
},
|
|
|
|
onLoad() {
|
|
|
|
this.isLoading = false;
|
|
|
|
},
|
|
|
|
reloadImage() {
|
|
|
|
this.hasError = false;
|
|
|
|
this.isLoading = true;
|
|
|
|
this.numRetries += 1;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2019-02-15 15:39:39 +05:30
|
|
|
<a v-show="!isLoading && !hasError" :href="linkUrl" target="_blank" rel="noopener noreferrer">
|
2018-05-09 12:01:36 +05:30
|
|
|
<img
|
|
|
|
:src="imageUrlWithRetries"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="project-badge"
|
|
|
|
aria-hidden="true"
|
2018-05-09 12:01:36 +05:30
|
|
|
@load="onLoad"
|
|
|
|
@error="onError"
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
<gl-loading-icon v-show="isLoading" :inline="true" />
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
<div v-show="hasError" class="btn-group">
|
2018-11-08 19:23:39 +05:30
|
|
|
<div class="btn btn-default btn-sm disabled">
|
2018-05-09 12:01:36 +05:30
|
|
|
<icon
|
2018-11-08 19:23:39 +05:30
|
|
|
:size="16"
|
2018-05-09 12:01:36 +05:30
|
|
|
class="prepend-left-8 append-right-8"
|
2018-11-18 11:00:15 +05:30
|
|
|
name="doc-image"
|
2018-05-09 12:01:36 +05:30
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-02-15 15:39:39 +05:30
|
|
|
<div class="btn btn-default btn-sm disabled">
|
2018-05-09 12:01:36 +05:30
|
|
|
<span class="prepend-left-8 append-right-8">{{ s__('Badges|No badge image') }}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button
|
2018-11-08 19:23:39 +05:30
|
|
|
v-show="hasError"
|
2019-02-15 15:39:39 +05:30
|
|
|
v-gl-tooltip.hover
|
2018-05-09 12:01:36 +05:30
|
|
|
:title="s__('Badges|Reload badge image')"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="btn btn-transparent btn-sm text-primary"
|
|
|
|
type="button"
|
2018-05-09 12:01:36 +05:30
|
|
|
@click="reloadImage"
|
|
|
|
>
|
2019-02-15 15:39:39 +05:30
|
|
|
<icon :size="16" name="retry" />
|
2018-05-09 12:01:36 +05:30
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</template>
|