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

169 lines
4.4 KiB
Vue
Raw Normal View History

2023-07-09 19:40:51 +02:00
<template>
2023-07-15 02:12:43 +02:00
<div class="menu relative">
<div class="commands-menu-items-wrapper">
<button
id="commands-menu"
@click.prevent="toggleMenu"
class="menu-button bg-blue-500 text-white dark:bg-blue-200 dark:text-gray-800 rounded-full flex items-center justify-center w-6 h-6 border-none cursor-pointer hover:bg-blue-400 w-8 h-8 rounded-full object-fill text-red-700 border-2 active:scale-90 hover:z-20 hover:-translate-y-2 duration-150 border-gray-300 border-secondary cursor-pointer"
>
<i data-feather="command" class="w-5 h-5"></i>
</button>
<div v-if="showMenu" id="commands-menu-items" class="absolute left-0 mt-4 bg-white border border-gray-300 z-10 w-48 overflow-y-auto custom-scrollbar" :style="{ top: '-200px', maxHeight: '200px' }">
<button
v-for="command in commands"
:key="command.value"
@click.prevent="execute_cmd(command)"
class="menu-button py-2 px-4 w-full text-left cursor-pointer bg-blue-500 text-white dark:bg-blue-200 dark:text-gray-800 hover:bg-blue-400"
:class="{ 'bg-blue-400 text-white': hoveredCommand === command.value }"
:title="command.help"
@mouseover="hoveredCommand = command.value"
@mouseout="hoveredCommand = null"
>
<div class="flex items-center">
<img v-if="command.icon" :src="command.icon" alt="Command Icon" class="w-4 h-4 mr-2" style="width: 25px; height: 25px;">
<div class="flex-grow">
{{ command.name }}
</div>
</div>
2023-07-09 19:40:51 +02:00
</button>
</div>
</div>
2023-07-15 02:12:43 +02:00
</div>
2023-07-09 19:40:51 +02:00
</template>
2023-07-15 02:12:43 +02:00
2023-07-09 19:40:51 +02:00
<style scoped>
2023-07-15 02:12:43 +02:00
.custom-scrollbar::-webkit-scrollbar {
width: 8px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background-color: #f1f1f1;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background-color: #888;
border-radius: 4px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background-color: #555;
}
2023-07-09 19:40:51 +02:00
.menu {
display: flex;
flex-direction: column;
align-items: center;
}
.commands-menu-items-wrapper {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
}
.commands-menu-items-wrapper > #commands-menu-items {
top: calc(-100% - 2rem);
}
</style>
<script>
import feather from 'feather-icons'
2023-07-14 14:02:53 +02:00
import axios from "axios";
2023-07-09 19:40:51 +02:00
export default {
props: {
commandsList: {
type: Array,
required: true,
},
2023-07-09 19:45:43 +02:00
sendCommand:Function
2023-07-09 19:40:51 +02:00
},
data() {
return {
2023-07-15 02:12:43 +02:00
selectedFile: null,
2023-07-09 19:40:51 +02:00
showMenu: false,
showHelpText: false,
helpText: '',
commands: [],
};
},
2023-07-10 22:01:20 +02:00
async mounted() {
//this.fileSize = await this.getFileSize(this.model.path)
//console.log('model path', this.model.path)
nextTick(() => {
feather.replace()
})
},
2023-07-09 19:40:51 +02:00
methods: {
2023-07-15 02:12:43 +02:00
selectFile(next) {
2023-07-14 14:02:53 +02:00
const input = document.createElement('input');
input.type = 'file';
input.accept = 'application/pdf'; // Specify the file type you want to accept
input.onchange = (e) => {
this.selectedFile = e.target.files[0];
2023-07-15 02:12:43 +02:00
next()
2023-07-14 14:02:53 +02:00
};
input.click();
},
uploadFile() {
const formData = new FormData();
formData.append('file', this.selectedFile);
axios.post('/send_file', formData)
.then(response => {
// Handle the server response if needed
console.log(response.data);
})
.catch(error => {
// Handle any errors that occur during the upload
console.error(error);
});
},
2023-07-10 22:01:20 +02:00
async constructor() {
nextTick(() => {
feather.replace()
})
},
2023-07-09 19:40:51 +02:00
toggleMenu() {
this.showMenu = !this.showMenu;
},
execute_cmd(cmd) {
2023-07-14 14:02:53 +02:00
this.showMenu = !this.showMenu;
if (cmd.hasOwnProperty('is_file')) {
console.log("Need to send a file.");
2023-07-15 02:12:43 +02:00
this.selectFile(()=>{
if(this.selectedFile!=null){
this.uploadFile()
}
});
2023-07-14 14:02:53 +02:00
} else {
this.sendCommand(cmd);
}
2023-07-09 19:40:51 +02:00
},
2023-07-10 22:01:20 +02:00
2023-07-09 19:40:51 +02:00
handleClickOutside(event) {
const menuElement = this.$el.querySelector('.commands-menu-items-wrapper');
if (menuElement && !menuElement.contains(event.target)) {
this.showMenu = false;
}
},
},
mounted() {
// Example commands data
this.commands = this.commandsList;
document.addEventListener('click', this.handleClickOutside);
},
beforeUnmount() {
document.removeEventListener('click', this.handleClickOutside);
},
};
</script>