2017-12-21 15:05:47 +00:00
|
|
|
<script>
|
|
|
|
|
2018-01-04 19:50:06 +00:00
|
|
|
/* This is a re-usable vue component for rendering a project avatar that
|
|
|
|
does not need to link to the project's profile. The image and an optional
|
|
|
|
tooltip can be configured by props passed to this component.
|
2017-12-21 15:05:47 +00:00
|
|
|
|
2018-01-04 19:50:06 +00:00
|
|
|
Sample configuration:
|
2017-12-21 15:05:47 +00:00
|
|
|
|
2018-01-04 19:50:06 +00:00
|
|
|
<project-avatar-image
|
|
|
|
:lazy="true"
|
|
|
|
:img-src="projectAvatarSrc"
|
|
|
|
:img-alt="tooltipText"
|
|
|
|
:tooltip-text="tooltipText"
|
|
|
|
tooltip-placement="top"
|
|
|
|
/>
|
2017-12-21 15:05:47 +00:00
|
|
|
|
2018-01-04 19:50:06 +00:00
|
|
|
*/
|
2017-12-21 15:05:47 +00:00
|
|
|
|
2018-01-04 19:50:06 +00:00
|
|
|
import defaultAvatarUrl from 'images/no_avatar.png';
|
|
|
|
import { placeholderImage } from '../../../lazy_loader';
|
|
|
|
import tooltip from '../../directives/tooltip';
|
2017-12-21 15:05:47 +00:00
|
|
|
|
2018-01-04 19:50:06 +00:00
|
|
|
export default {
|
|
|
|
name: 'ProjectAvatarImage',
|
|
|
|
directives: {
|
|
|
|
tooltip,
|
2017-12-21 15:05:47 +00:00
|
|
|
},
|
2018-01-04 19:50:06 +00:00
|
|
|
props: {
|
|
|
|
lazy: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
imgSrc: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: defaultAvatarUrl,
|
|
|
|
},
|
|
|
|
cssClasses: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
imgAlt: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'project avatar',
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 20,
|
|
|
|
},
|
|
|
|
tooltipText: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
tooltipPlacement: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'top',
|
|
|
|
},
|
2017-12-21 15:05:47 +00:00
|
|
|
},
|
2018-01-04 19:50:06 +00:00
|
|
|
computed: {
|
|
|
|
// API response sends null when gravatar is disabled and
|
|
|
|
// we provide an empty string when we use it inside project avatar link.
|
|
|
|
// In both cases we should render the defaultAvatarUrl
|
|
|
|
sanitizedSource() {
|
|
|
|
return this.imgSrc === '' || this.imgSrc === null ? defaultAvatarUrl : this.imgSrc;
|
|
|
|
},
|
|
|
|
resultantSrcAttribute() {
|
|
|
|
return this.lazy ? placeholderImage : this.sanitizedSource;
|
|
|
|
},
|
|
|
|
tooltipContainer() {
|
|
|
|
return this.tooltipText ? 'body' : null;
|
|
|
|
},
|
|
|
|
avatarSizeClass() {
|
|
|
|
return `s${this.size}`;
|
|
|
|
},
|
2017-12-21 15:05:47 +00:00
|
|
|
},
|
2018-01-04 19:50:06 +00:00
|
|
|
};
|
2017-12-21 15:05:47 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<img
|
|
|
|
v-tooltip
|
|
|
|
:class="{
|
2018-01-04 19:50:06 +00:00
|
|
|
lazy: lazy,
|
2017-12-21 15:05:47 +00:00
|
|
|
[avatarSizeClass]: true,
|
|
|
|
[cssClasses]: true
|
|
|
|
}"
|
|
|
|
:src="resultantSrcAttribute"
|
|
|
|
:width="size"
|
|
|
|
:height="size"
|
|
|
|
:alt="imgAlt"
|
|
|
|
:data-src="sanitizedSource"
|
|
|
|
:data-container="tooltipContainer"
|
|
|
|
:data-placement="tooltipPlacement"
|
|
|
|
:title="tooltipText"
|
2018-06-11 09:49:47 +00:00
|
|
|
class="avatar"
|
2017-12-21 15:05:47 +00:00
|
|
|
/>
|
|
|
|
</template>
|