Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 10cb62b4 authored by ROSPARS Benoit's avatar ROSPARS Benoit
Browse files

improvement: Add plugin file upload with template

parent 9f5dcd52
Branches
Tags
No related merge requests found
Pipeline #899659 passed
......@@ -249,11 +249,11 @@ const writeEpocData = async function (workdir, data) {
* Copy the imported file to the workdir
* @param {string} workdir
* @param {string} filepath
* @param {boolean} isIcon
* @param {string} targetDirectory the path where to copy the file
* @return {string} the path of the copied file
*/
const copyFileToWorkdir = async function (workdir, filepath, isIcon) {
const pathEnd = isIcon ? path.join('assets', 'icons') : 'assets';
const copyFileToWorkdir = async function (workdir, filepath, targetDirectory) {
const pathEnd = targetDirectory ? path.join(...(targetDirectory.split('/'))) : 'assets';
const assetsPath = path.join(workdir, pathEnd);
if(!fs.existsSync(assetsPath)) fs.mkdirSync(assetsPath, {recursive: true});
......
......@@ -106,8 +106,8 @@ const setupIpcListener = function (targetWindow) {
ipcMain.on('importFile', async (event, data) => {
if(event.sender !== targetWindow.webContents) return;
const { filepath, isIcon } = data;
sendToFrontend(event.sender, 'fileImported', await copyFileToWorkdir(store.state.projects[targetWindow.id].workdir, filepath, isIcon));
const { filepath, targetDirectory } = data;
sendToFrontend(event.sender, 'fileImported', await copyFileToWorkdir(store.state.projects[targetWindow.id].workdir, filepath, targetDirectory));
});
ipcMain.on('graphCopy', async (event, data) => {
......
......@@ -9,6 +9,7 @@ const props = defineProps<{
label: string;
accept: string;
placeholder: string;
targetDirectory?: string
}>();
const emit = defineEmits<{
......@@ -34,7 +35,7 @@ async function changeImage(e: Event) {
const file = target.files[0];
if (!file) return;
fileInput.value.value = '';
url.value = await graphService.importFile(file.path);
url.value = await graphService.importFile(file.path, props.targetDirectory);
emit('input', url.value);
emit('saveGivenState', savedState);
......
......@@ -80,6 +80,7 @@ const inputId = computed(() => {
:accept="input.accept"
:input-value="inputValue as string"
:placeholder="input.placeholder"
:target-directory="input.targetDirectory"
@input="emit('input', $event)"
@save-given-state="emit('saveGivenState', $event)"
/>
......
......@@ -303,6 +303,7 @@ export const epocForm: Form = {
type: 'file',
label: 'Fichier de plugin',
placeholder: 'Ajouter un plugin',
targetDirectory: 'plugins',
value: '',
accept: '.js'
}
......@@ -310,6 +311,28 @@ export const epocForm: Form = {
}
]
},
{
name: 'Plugins templates',
inputs: [
{
id: 'templates',
label: 'Plugin templates',
type: 'repeat',
value: [],
inputs: [
{
id: '',
type: 'file',
label: 'Template html de plugin',
placeholder: 'Ajouter un template',
targetDirectory: 'plugins',
value: '',
accept: '.html'
}
]
}
]
},
{
name: 'Licence',
inputs: [
......
......@@ -10,4 +10,5 @@ export interface Input {
addButton?: boolean;
options?: string[];
linkedOptions?: string;
targetDirectory?: string
}
\ No newline at end of file
......@@ -38,8 +38,8 @@ function writeProjectData(): void {
});
}
function importFile(filepath: string, isIcon?: boolean): Promise<string> {
api.send('importFile', { filepath, isIcon: Boolean(isIcon) });
function importFile(filepath: string, targetDirectory?: string): Promise<string> {
api.send('importFile', { filepath, targetDirectory });
return new Promise((resolve) => {
api.receiveOnce('fileImported', (data) => {
......@@ -62,8 +62,6 @@ function createContentJSON() : EpocV1 {
const validBadges = getValidBadges();
const ePocValues = ePocNode.data.formValues;
console.log('epocValues', ePocValues);
const epoc = new EpocV1(
ePocValues.id || 'E000XX',
......
......@@ -205,7 +205,7 @@ export function addNewBadge() {
export async function saveCustomIcon(icon: string) {
const projectStore = useProjectStore();
const iconPath = await graphService.importFile(icon, true);
const iconPath = await graphService.importFile(icon, 'assets/icons');
projectStore.addCustomIcon(iconPath);
return iconPath;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment