lollms-webui/web/src/components/ModelEntry.vue

141 lines
4.2 KiB
Vue
Raw Normal View History

2023-05-10 23:33:08 +02:00
<template>
<div class="flex items-center p-4 hover:bg-primary-light rounded-lg mb-2 shadow-lg border-2 cursor-pointer"
@click.stop="toggleSelected" :class="selected ? ' border-primary-light' : 'border-transparent'">
2023-05-11 15:09:35 +02:00
<div class="flex-shrink-0">
2023-05-25 18:14:13 +03:00
<img :src="getImgUrl()" @error="defaultImg($event)" class="w-10 h-10 rounded-lg object-fill text-red-700">
<!-- <i :class="`fas ${icon} text-xl`"></i> -->
2023-05-10 23:33:08 +02:00
</div>
<div v-if="model.isCustomModel">
2023-05-21 22:46:02 +02:00
<h3 class="font-bold font-large text-lg">
2023-05-11 15:09:35 +02:00
{{ title }}
</h3>
</div>
<div class="flex-1" v-if="!model.isCustomModel">
<h3 class="font-bold font-large text-lg">
{{ title }}
</h3>
<div class="flex flex-shrink-0">
<b>Manual download:&nbsp;</b>
<a :href="path" @click.stop class="flex hover:text-secondary duration-75 active:scale-90"
title="Download this manually (faster) and put it in the models/<your backend> folder then refresh">
<i data-feather="link" class="w-5 p-1"></i>
{{ title }}
</a>
</div>
<div class="flex flex-shrink-0">
<b>License:&nbsp;</b>
2023-05-21 22:46:02 +02:00
{{ license }}
</div>
<div class="flex flex-shrink-0">
<b>Owner:&nbsp;</b>
<a :href="owner_link" target="_blank" @click.stop class="flex hover:text-secondary duration-75 active:scale-90"
title="Owner's profile">
<i data-feather="link" class="w-5 p-1"></i>
{{ owner }}
</a>
</div>
<b>Description:&nbsp;</b><br>
<p class="opacity-80">{{ description }}</p>
</div>
<div class="flex-shrink-0" v-if="!model.isCustomModel">
<button class="px-4 py-2 rounded-md text-white font-bold transition-colors duration-300"
:class="[isInstalled ? 'bg-red-500 hover:bg-red-600' : 'bg-green-500 hover:bg-green-600']"
:disabled="installing || uninstalling" @click.stop="toggleInstall">
<template v-if="installing">
<div class="flex items-center space-x-2">
<div class="h-2 w-20 bg-gray-300 rounded">
<div :style="{ width: progress + '%' }" class="h-full bg-red-500 rounded"></div>
</div>
<span>Installing...{{ Math.floor(progress) }}%</span>
2023-05-14 00:24:26 +02:00
</div>
</template>
<template v-else-if="uninstalling">
<div class="flex items-center space-x-2">
<div class="h-2 w-20 bg-gray-300 rounded">
<div :style="{ width: progress + '%' }" class="h-full bg-green-500"></div>
</div>
<span>Uninstalling...</span>
2023-05-14 00:24:26 +02:00
</div>
</template>
<template v-else>
{{ isInstalled ? 'Uninstall' : 'Install' }}
</template>
</button>
</div>
2023-05-11 15:09:35 +02:00
</div>
</template>
<script>
2023-05-19 17:33:31 +03:00
import { nextTick } from 'vue'
import feather from 'feather-icons'
2023-05-25 18:14:13 +03:00
import defaultImgPlaceholder from "../assets/default_model.png"
const bUrl = import.meta.env.VITE_GPT4ALL_API_BASEURL
2023-05-11 15:09:35 +02:00
export default {
props: {
title: String,
icon: String,
path: String,
owner: String,
2023-05-21 22:46:02 +02:00
owner_link: String,
license: String,
2023-05-11 15:09:35 +02:00
description: String,
isInstalled: Boolean,
2023-05-11 21:36:52 +02:00
onInstall: Function,
onUninstall: Function,
2023-05-11 22:27:23 +02:00
onSelected: Function,
selected: Boolean,
model: Object
2023-05-11 21:36:52 +02:00
},
data() {
return {
2023-05-14 13:33:45 +02:00
progress: 0,
2023-05-11 21:36:52 +02:00
installing: false,
2023-05-24 17:44:28 +03:00
uninstalling: false,
failedToLoad:false
2023-05-11 21:36:52 +02:00
};
2023-05-11 15:09:35 +02:00
},
2023-05-19 17:33:31 +03:00
mounted() {
nextTick(() => {
feather.replace()
})
},
2023-05-11 15:09:35 +02:00
methods: {
2023-05-25 18:14:13 +03:00
getImgUrl() {
if (this.icon === '/images/default_model.png'){
return defaultImgPlaceholder
}
return this.icon
},
defaultImg(event) {
event.target.src = defaultImgPlaceholder
},
2023-05-11 15:09:35 +02:00
toggleInstall() {
2023-05-11 21:36:52 +02:00
if (this.isInstalled) {
this.uninstalling = true;
// Simulate uninstallation delay (replace this with your WebSocket logic)
this.onUninstall(this);
} else {
this.installing = true;
this.onInstall(this);
}
2023-05-10 23:33:08 +02:00
},
toggleSelected() {
2023-05-19 17:33:31 +03:00
this.onSelected(this)
},
2023-05-11 15:09:35 +02:00
handleSelection() {
2023-05-11 21:36:52 +02:00
if (this.isInstalled && !this.selected) {
2023-05-14 00:24:26 +02:00
this.onSelected(this);
2023-05-11 15:09:35 +02:00
}
}
}
};
</script>