メタデータの読み込み中・読み込み失敗を表示するようにした
This commit is contained in:
parent
ec4e0f3dda
commit
e1dd2b1c8f
@ -4,10 +4,18 @@ import MetadataPreview from './components/MetadataPreview.vue';
|
|||||||
|
|
||||||
export const bus = new Vue({name: "EventBus"});
|
export const bus = new Vue({name: "EventBus"});
|
||||||
|
|
||||||
|
export enum MetadataLoadState {
|
||||||
|
Inactive,
|
||||||
|
Loading,
|
||||||
|
Success,
|
||||||
|
Failed,
|
||||||
|
}
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
data: {
|
data: {
|
||||||
metadata: null
|
metadata: null,
|
||||||
|
metadataLoadState: MetadataLoadState.Inactive,
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
TagInput,
|
TagInput,
|
||||||
@ -28,6 +36,7 @@ new Vue({
|
|||||||
|
|
||||||
if (url.trim() === '' || !/^https?:\/\//.test(url)) {
|
if (url.trim() === '' || !/^https?:\/\//.test(url)) {
|
||||||
this.metadata = null;
|
this.metadata = null;
|
||||||
|
this.metadataLoadState = MetadataLoadState.Inactive;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +45,8 @@ new Vue({
|
|||||||
},
|
},
|
||||||
// メタデータの取得
|
// メタデータの取得
|
||||||
fetchMetadata(url: string) {
|
fetchMetadata(url: string) {
|
||||||
|
this.metadataLoadState = MetadataLoadState.Loading;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/checkin/card',
|
url: '/api/checkin/card',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
@ -45,8 +56,10 @@ new Vue({
|
|||||||
}
|
}
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
this.metadata = data;
|
this.metadata = data;
|
||||||
|
this.metadataLoadState = MetadataLoadState.Success;
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
this.metadata = null;
|
this.metadata = null;
|
||||||
|
this.metadataLoadState = MetadataLoadState.Failed;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="form-row" v-if="metadata !== null">
|
<div class="form-row" v-if="state !== MetadataLoadState.Inactive">
|
||||||
<div class="form-group col-sm-12">
|
<div class="form-group col-sm-12">
|
||||||
<div class="card link-card-mini mb-2 px-0">
|
<div class="card link-card-mini mb-2 px-0">
|
||||||
<div class="row no-gutters">
|
<div v-if="state === MetadataLoadState.Loading" class="row no-gutters">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card-body">
|
||||||
|
<h6 class="card-title text-center font-weight-bold text-info" style="font-size: small;"><span class="oi oi-loop-circular"></span> オカズの情報を読み込んでいます…</h6>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="state === MetadataLoadState.Success" class="row no-gutters">
|
||||||
<div v-if="hasImage" class="col-4 justify-content-center align-items-center">
|
<div v-if="hasImage" class="col-4 justify-content-center align-items-center">
|
||||||
<img :src="metadata.image" alt="Thumbnail" class="card-img-top-to-left bg-secondary">
|
<img :src="metadata.image" alt="Thumbnail" class="card-img-top-to-left bg-secondary">
|
||||||
</div>
|
</div>
|
||||||
@ -20,6 +27,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-else class="row no-gutters">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card-body">
|
||||||
|
<h6 class="card-title text-center font-weight-bold text-danger" style="font-size: small;"><span class="oi oi-circle-x"></span> オカズの情報を読み込めませんでした</h6>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -27,7 +41,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {Vue, Component, Prop} from "vue-property-decorator";
|
import {Vue, Component, Prop} from "vue-property-decorator";
|
||||||
import {bus} from "../checkin";
|
import {bus, MetadataLoadState} from "../checkin";
|
||||||
|
|
||||||
type Metadata = {
|
type Metadata = {
|
||||||
url: string,
|
url: string,
|
||||||
@ -42,8 +56,12 @@
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
export default class MetadataPreview extends Vue {
|
export default class MetadataPreview extends Vue {
|
||||||
|
@Prop() readonly state!: MetadataLoadState;
|
||||||
@Prop() readonly metadata!: Metadata | null;
|
@Prop() readonly metadata!: Metadata | null;
|
||||||
|
|
||||||
|
// for use in v-if
|
||||||
|
private readonly MetadataLoadState = MetadataLoadState;
|
||||||
|
|
||||||
addTag(tag: string) {
|
addTag(tag: string) {
|
||||||
bus.$emit("add-tag", tag);
|
bus.$emit("add-tag", tag);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<metadata-preview :metadata="metadata"></metadata-preview>
|
<metadata-preview :metadata="metadata" :state="metadataLoadState"></metadata-preview>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-sm-12">
|
<div class="form-group col-sm-12">
|
||||||
<label for="note"><span class="oi oi-comment-square"></span> ノート</label>
|
<label for="note"><span class="oi oi-comment-square"></span> ノート</label>
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<metadata-preview :metadata="metadata"></metadata-preview>
|
<metadata-preview :metadata="metadata" :state="metadataLoadState"></metadata-preview>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-sm-12">
|
<div class="form-group col-sm-12">
|
||||||
<label for="note"><span class="oi oi-comment-square"></span> ノート</label>
|
<label for="note"><span class="oi oi-comment-square"></span> ノート</label>
|
||||||
|
Loading…
Reference in New Issue
Block a user