Skip to content

Commit

Permalink
Add some more resilience and refactor views (#1363)
Browse files Browse the repository at this point in the history
  • Loading branch information
herpaderpaldent authored Apr 5, 2023
1 parent e03ef36 commit 396b7b9
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 114 deletions.
118 changes: 5 additions & 113 deletions resources/js/Shared/Components/Assets/ItemList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,21 @@
v-if="compact"
:items="uniqueItems"
/>
<WideListElement
v-for="asset in uniqueItems"
<WideAssetListComponent
v-else
:key="asset.item_id"
:url="url(asset)"
>
<template #avatar>
<span class="inline-block relative">
<EveImage
:tailwind_class="'h-12 w-12 rounded-full text-white shadow-solid bg-white'"
:object="asset.type"
:size="128"
/>
<span
v-if="asset.quantity > 1"
class="absolute bottom-0 right-0 inline-flex items-center justify-center h-3 w-3 rounded-full text-white shadow-solid bg-gray-400"
>
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 bg-indigo-200 text-indigo-600">{{ asset.quantity }}</span>
</span>
</span>
<EveImage
v-if="hasOwnerPicture"
:tailwind_class="'-ml-1 inline-block h-12 w-12 rounded-full text-white shadow-solid'"
:object="asset.owner"
:size="128"
/>
</template>

<template #upper_left>
{{ asset.name }}
</template>

<template #lower_left>
<svg
class="shrink-0 mr-1.5 h-5 w-5 text-gray-400"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
fill-rule="evenodd"
d="M17.707 9.293a1 1 0 010 1.414l-7 7a1 1 0 01-1.414 0l-7-7A.997.997 0 012 10V5a3 3 0 013-3h5c.256 0 .512.098.707.293l7 7zM5 6a1 1 0 100-2 1 1 0 000 2z"
clip-rule="evenodd"
/>
</svg>

<span class="truncate">{{ asset.type.name }}</span>
</template>

<template #upper_right>
{{ asset.type.group.name }} <span
v-if="!asset.is_singleton"
class="text-info"
>(packaged)</span>
</template>

<template #lower_right>
<svg
class="shrink-0 mr-1.5 h-5 w-5"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
fill-rule="evenodd"
d="M10 2a1 1 0 011 1v1.323l3.954 1.582 1.599-.8a1 1 0 01.894 1.79l-1.233.616 1.738 5.42a1 1 0 01-.285 1.05A3.989 3.989 0 0115 15a3.989 3.989 0 01-2.667-1.019 1 1 0 01-.285-1.05l1.715-5.349L11 6.477V16h2a1 1 0 110 2H7a1 1 0 110-2h2V6.477L6.237 7.582l1.715 5.349a1 1 0 01-.285 1.05A3.989 3.989 0 015 15a3.989 3.989 0 01-2.667-1.019 1 1 0 01-.285-1.05l1.738-5.42-1.233-.617a1 1 0 01.894-1.788l1.599.799L9 4.323V3a1 1 0 011-1zm-5 8.274l-.818 2.552c.25.112.526.174.818.174.292 0 .569-.062.818-.174L5 10.274zm10 0l-.818 2.552c.25.112.526.174.818.174.292 0 .569-.062.818-.174L15 10.274z"
clip-rule="evenodd"
/>
</svg>
{{ getMetricPrefix(asset.quantity * asset.type.volume) }}
</template>

<template #navigation>
<Link
v-if="asset.content[0]"
:href="route('character.item', {item_id: asset.item_id, character_id: asset.owner.character_id})"
preserve-state
preserve-scroll
>
<svg
:class="[{'text-gray-400' : asset.content[0], 'text-transparent' : !asset.content[0]},'h-5 w-5']"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
fill-rule="evenodd"
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
clip-rule="evenodd"
/>
</svg>
</Link>
</template>
</WideListElement>
:items="uniqueItems"
/>
</div>
</template>

<script>
import EveImage from "@/Shared/EveImage.vue"
import { prefix } from 'metric-prefix'
import WideListElement from "@/Shared//WideListElement.vue";
import CompactAssetListComponent from "./CompactAssetListComponent.vue";
import { Link } from '@inertiajs/vue3';
import WideAssetListComponent from "./WideAssetListComponent.vue";
export default {
name: "ItemList",
components: {CompactAssetListComponent, WideListElement, EveImage, Link},
components: {CompactAssetListComponent, WideAssetListComponent},
props: {
compact: {
required: true,
Expand All @@ -124,25 +34,7 @@
uniqueItems() {
return _.uniqBy(this.items, 'item_id')
},
hasOwnerPicture() {
let selectedCharacterIds = _.get(route().params, 'character_ids', null)
if (_.size(selectedCharacterIds) > 1)
return true
return !selectedCharacterIds && this.$page.props.user.data.characters.length > 1;
}
},
methods: {
getMetricPrefix(numeric_value) {
return prefix(numeric_value, {precision: 3, unit: ''})
},
url(asset) {
return asset.content[0] ? route('character.item', {item_id: asset.item_id, character_id: asset.owner.character_id}) : ''
},
}
}
</script>

Expand Down
3 changes: 2 additions & 1 deletion resources/js/Shared/Components/Assets/LocationComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ import {prefix} from "metric-prefix";
export default {
name: "LocationComponent",
components: {CompleteLoadingHelper, AddManualLocationModal, ItemList, LocationName, WideLists},
components: {
CompleteLoadingHelper, AddManualLocationModal, ItemList, LocationName, WideLists},
props: {
location: {
required: true,
Expand Down
138 changes: 138 additions & 0 deletions resources/js/Shared/Components/Assets/WideAssetListComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<template>
<WideListElement
v-for="asset in props.items"
:key="asset.item_id"
:url="url(asset)"
>
<template #avatar>
<span class="inline-block relative">
<EveImage
v-if="asset.type"
:tailwind_class="'h-12 w-12 rounded-full text-white shadow-solid bg-white'"
:object="asset.type"
:size="128"
/>
<div v-else>
<span class="inline-flex items-center justify-center h-12 w-12 shrink-0 mx-auto rounded-full bg-gray-500">
<span class="text-xl font-medium leading-none text-white">N/A</span>
</span>
</div>
<span
v-if="asset.quantity > 1"
class="absolute bottom-0 right-0 inline-flex items-center justify-center h-3 w-3 rounded-full text-white shadow-solid bg-gray-400"
>
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 bg-indigo-200 text-indigo-600">{{ asset.quantity }}</span>
</span>
</span>
<EveImage
v-if="hasOwnerPicture"
:tailwind_class="'-ml-1 inline-block h-12 w-12 rounded-full text-white shadow-solid'"
:object="asset.owner"
:size="128"
/>
</template>

<template #upper_left>
{{ asset.name }}
</template>

<template #lower_left>
<TagIcon class="shrink-0 mr-1.5 h-5 w-5 text-gray-400" />

<span class="truncate">{{ getType(asset).name }}</span>
</template>

<template #upper_right>
{{ getType(asset).group.name }} <span
v-if="!asset.is_singleton"
class="text-info"
>(packaged)</span>
</template>

<template #lower_right>
<ScaleIcon class="shrink-0 mr-1.5 h-5 w-5" />
<span v-if="asset.type">{{ getMetricPrefix(asset.quantity * asset.type.volume) }}</span>
<span v-else>N/A</span>
</template>

<template #navigation>
<Link
v-if="asset.content[0]"
:href="route('character.item', {item_id: asset.item_id, character_id: asset.owner.character_id})"
preserve-state
preserve-scroll
>
<svg
:class="[{'text-gray-400' : asset.content[0], 'text-transparent' : !asset.content[0]},'h-5 w-5']"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
fill-rule="evenodd"
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
clip-rule="evenodd"
/>
</svg>
</Link>
</template>
</WideListElement>
</template>

<script setup>
import WideListElement from "@/Shared/WideListElement.vue";
import EveImage from "@/Shared/EveImage.vue";
import {Link, usePage} from '@inertiajs/vue3';
import { prefix } from 'metric-prefix'
import {computed} from "vue";
import {TagIcon, ScaleIcon} from "@heroicons/vue/20/solid";
const props = defineProps({
items: {
type: Array,
required: true,
},
});
const hasOwnerPicture = computed(() => {
let selectedCharacterIds = _.get(route().params, 'character_ids', null)
if (_.size(selectedCharacterIds) > 1)
return true
return !selectedCharacterIds && usePage().props.user.data.characters.length > 1;
})
const getMetricPrefix = function (numeric_value) {
return prefix(numeric_value, {precision: 3, unit: ''})
}
const url = function (asset) {
return asset.content[0] ? route('character.item', {item_id: asset.item_id, character_id: asset.owner.character_id}) : ''
}
const getType = function (asset) {
let type = asset.type
// if type is not set we createa a dummy type
if (!type) {
type = {
name: 'Unknown',
group: {
name: 'Unknown'
}
}
}
return type
}
</script>

<style scoped>
</style>

0 comments on commit 396b7b9

Please sign in to comment.