aboutsummaryrefslogtreecommitdiff
path: root/src/components/TileInfoModal.vue
blob: 275dd085aac023db5d77a633f1c786f25e78d344 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<script lang="ts">
import {defineComponent, PropType} from 'vue';
import CloseIcon from './icon/CloseIcon.vue';
import {LayoutNode} from '../layout';
import type {TolMap} from '../tol';
import {TolNode} from '../tol';
import {capitalizeWords} from '../util';

// Displays information about a tree-of-life node
export default defineComponent({
	data(){
		return {
			desc: null as null | string,
			fromRedirect: false,
			imgInfo: null as null | {eolId: string, sourceUrl: string, license: string, copyrightOwner: string},
		};
	},
	props: {
		node: {type: Object as PropType<LayoutNode>, required: true},
		tolMap: {type: Object as PropType<TolMap>, required: true},
		uiOpts: {type: Object, required: true},
	},
	computed: {
		tolNode(): TolNode {
			return this.tolMap.get(this.node.name)!;
		},
		displayName(): string {
			if (this.tolNode.commonName == null){
				return capitalizeWords(this.node.name);
			} else {
				return `${capitalizeWords(this.tolNode.commonName)} (aka ${capitalizeWords(this.node.name)})`;
			}
		},
		imgStyles(): Record<string,string> {
			return {
				backgroundImage: this.tolNode.imgName != null ?
					'linear-gradient(to bottom, rgba(0,0,0,0.4), #0000 40%, #0000 60%, rgba(0,0,0,0.4) 100%),' +
						'url(\'/img/' + this.tolNode.imgName.replaceAll('\'', '\\\'') + '\')' :
					'none',
				backgroundColor: '#1c1917',
				width: this.uiOpts.infoModalImgSz + 'px',
				height: this.uiOpts.infoModalImgSz + 'px',
				backgroundSize: 'cover',
				borderRadius: this.uiOpts.borderRadius + 'px',
			};
		},
	},
	methods: {
		onCloseClick(evt: Event){
			if (evt.target == this.$el || (this.$refs.closeIcon as typeof CloseIcon).$el.contains(evt.target)){
				this.$emit('info-modal-close');
			}
		},
	},
	created(){
		let url = new URL(window.location.href);
		url.pathname = '/data/info';
		url.search = '?name=' + encodeURIComponent(this.node.name);
		fetch(url.toString())
			.then(response => response.json())
			.then(obj => {
				if (obj != null){
					if (obj.desc != null){
						this.desc = obj.desc.text;
						this.fromRedirect = obj.desc.fromRedirect;
					}
					this.imgInfo = obj.imgInfo;
				}
			});
	},
	components: {CloseIcon, },
	emits: ['info-modal-close', ],
});
</script>

<template>
<div class="fixed left-0 top-0 w-full h-full bg-black/40" @click="onCloseClick">
	<div class="absolute left-1/2 -translate-x-1/2 w-4/5 top-1/2 -translate-y-1/2 p-4
		bg-stone-50 rounded-md shadow shadow-black">
		<close-icon @click.stop="onCloseClick" ref="closeIcon"
			class="block absolute top-2 right-2 w-6 h-6 hover:cursor-pointer"/>
		<h1 class="text-center text-xl font-bold mb-2">{{displayName}}</h1>
		<hr class="mb-4 border-stone-400"/>
		<div class="flex">
			<div>
				<div :style="imgStyles" class="mr-4" alt="an image"></div>
				<div v-if="imgInfo != null">
					<ul>
						<li>License: {{imgInfo.license}}</li>
						<li><a :href="imgInfo.sourceUrl" class="underline">Source URL</a></li>
						<li>Copyright Owner: {{imgInfo.copyrightOwner}}</li>
					</ul>
				</div>
			</div>
			<div v-if="desc != null">
				<div>
					Redirected: {{fromRedirect}}
				</div>
				<div>
					{{desc}}
				</div>
			</div>
			<div v-else>
				(No description found)
			</div>
		</div>
		
	</div>
</div>
</template>