2017-12-05 01:47:27 +00:00
|
|
|
<template>
|
2019-06-09 23:33:52 +00:00
|
|
|
<!-- <div class="character-images row">-->
|
|
|
|
<div class="character-images">
|
2017-12-05 01:47:27 +00:00
|
|
|
<div v-show="loading" class="alert alert-info">Loading images.</div>
|
|
|
|
<template v-if="!loading">
|
2019-12-07 15:23:22 +00:00
|
|
|
<div class="images-navigate-up">
|
|
|
|
<i class="fa fa-angle-up"></i>
|
|
|
|
</div>
|
|
|
|
|
2019-06-23 21:15:21 +00:00
|
|
|
<!-- @click="handleImageClick($event, image)" -->
|
|
|
|
<div v-for="image in images" :key="image.id" class="character-image-wrapper">
|
|
|
|
<a :href="imageUrl(image)" target="_blank">
|
|
|
|
<img :src="imageUrl(image)" class="character-image">
|
|
|
|
</a>
|
|
|
|
<div class="image-description" v-if="!!image.description">{{image.description}}</div>
|
|
|
|
</div>
|
2017-12-05 01:47:27 +00:00
|
|
|
</template>
|
|
|
|
<div v-if="!loading && !images.length" class="alert alert-info">No images.</div>
|
2017-12-06 03:34:51 +00:00
|
|
|
<div class="image-preview" v-show="previewImage" @click="previewImage = ''">
|
2019-01-03 17:38:17 +00:00
|
|
|
<img :src="previewImage"/>
|
2018-04-08 00:22:32 +00:00
|
|
|
<div class="modal-backdrop show"></div>
|
2017-12-06 03:34:51 +00:00
|
|
|
</div>
|
2017-12-05 01:47:27 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-01-03 17:38:17 +00:00
|
|
|
import {Component, Prop} from '@f-list/vue-ts';
|
2017-12-05 01:47:27 +00:00
|
|
|
import Vue from 'vue';
|
2019-01-03 17:38:17 +00:00
|
|
|
import {CharacterImage} from '../../interfaces';
|
2017-12-05 01:47:27 +00:00
|
|
|
import * as Utils from '../utils';
|
|
|
|
import {methods} from './data_store';
|
2019-01-03 17:38:17 +00:00
|
|
|
import {Character} from './interfaces';
|
2019-09-24 19:53:43 +00:00
|
|
|
import core from '../../chat/core';
|
2017-12-05 01:47:27 +00:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class ImagesView extends Vue {
|
|
|
|
@Prop({required: true})
|
2018-03-04 02:32:26 +00:00
|
|
|
private readonly character!: Character;
|
2017-12-06 03:34:51 +00:00
|
|
|
@Prop()
|
|
|
|
private readonly usePreview?: boolean;
|
2017-12-05 01:47:27 +00:00
|
|
|
private shown = false;
|
2017-12-06 03:34:51 +00:00
|
|
|
previewImage = '';
|
2017-12-05 01:47:27 +00:00
|
|
|
images: CharacterImage[] = [];
|
|
|
|
loading = true;
|
|
|
|
error = '';
|
|
|
|
|
|
|
|
imageUrl = (image: CharacterImage) => methods.imageUrl(image);
|
|
|
|
thumbUrl = (image: CharacterImage) => methods.imageThumbUrl(image);
|
|
|
|
|
|
|
|
async show(): Promise<void> {
|
|
|
|
if(this.shown) return;
|
|
|
|
try {
|
|
|
|
this.error = '';
|
|
|
|
this.shown = true;
|
|
|
|
this.loading = true;
|
2019-09-24 19:53:43 +00:00
|
|
|
this.images = await this.resolveImages();
|
2017-12-05 01:47:27 +00:00
|
|
|
} catch(e) {
|
|
|
|
this.shown = false;
|
|
|
|
if(Utils.isJSONError(e))
|
|
|
|
this.error = <string>e.response.data.error;
|
|
|
|
Utils.ajaxError(e, 'Unable to load images.');
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
}
|
2017-12-06 03:34:51 +00:00
|
|
|
|
2019-09-24 19:53:43 +00:00
|
|
|
async resolveImages(): Promise<CharacterImage[]> {
|
|
|
|
const c = await core.cache.profileCache.get(this.character.character.name);
|
|
|
|
|
|
|
|
if ((c) && (c.meta) && (c.meta.images)) {
|
|
|
|
return c.meta.images;
|
|
|
|
}
|
|
|
|
|
|
|
|
return methods.imagesGet(this.character.character.id);
|
|
|
|
}
|
|
|
|
|
2017-12-06 03:34:51 +00:00
|
|
|
handleImageClick(e: MouseEvent, image: CharacterImage): void {
|
|
|
|
if(this.usePreview) {
|
|
|
|
this.previewImage = methods.imageUrl(image);
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
2017-12-05 01:47:27 +00:00
|
|
|
}
|
|
|
|
</script>
|