Files
cloudron-box/dashboard/src/components/CommunityAppDialog.vue
T

85 lines
2.3 KiB
Vue
Raw Normal View History

<script setup>
import { ref, useTemplateRef } from 'vue';
import { Dialog, TextInput, FormGroup } from '@cloudron/pankow';
2026-02-05 21:51:55 +01:00
import CommunityModel from '../models/CommunityModel.js';
const communityModel = CommunityModel.create();
const emit = defineEmits([ 'success' ]);
const dialog = useTemplateRef('dialog');
2026-02-05 21:51:55 +01:00
const form = useTemplateRef('form');
const formError = ref({});
2026-02-05 21:51:55 +01:00
const versionsUrl = ref('');
const busy = ref(false);
const isFormValid = ref(false);
function validateForm() {
isFormValid.value = form.value ? form.value.checkValidity() : false;
}
async function onSubmit() {
if (!form.value.reportValidity()) return;
2026-02-05 21:51:55 +01:00
busy.value = true;
formError.value = {};
2026-02-06 10:19:13 +01:00
const [url, version] = versionsUrl.value.split('@'); // hidden feature that user can input with version
const [error, result] = await communityModel.getApp(url, version || 'latest');
2026-02-05 21:51:55 +01:00
if (error) {
formError.value.generic = error.body ? error.body.message : 'Internal error';
busy.value = false;
return console.error(error);
}
2026-02-06 18:04:47 +01:00
const packageData = {
...result, // { manifest, publishState, creationDate, ts }
versionsUrl: `${url}@${version || 'latest'}`,
iconUrl: result.manifest.iconUrl // compat with app store format
};
2026-02-05 21:51:55 +01:00
emit('success', packageData);
dialog.value.close();
2026-02-05 21:51:55 +01:00
busy.value = false;
}
defineExpose({
open() {
2026-02-05 21:51:55 +01:00
versionsUrl.value = '';
formError.value = {};
dialog.value.open();
}
});
</script>
<template>
<Dialog ref="dialog"
title="Install Community App"
2026-02-05 21:51:55 +01:00
:confirm-label="$t('main.action.add')"
:confirm-busy="busy"
:confirm-active="!busy && isFormValid"
reject-style="secondary"
2026-02-05 21:51:55 +01:00
:reject-label="$t('main.dialog.cancel')"
:reject-active="!busy"
@confirm="onSubmit()"
>
2026-02-05 21:51:55 +01:00
<form @submit.prevent="onSubmit()" autocomplete="off" ref="form" @input="validateForm()">
<fieldset :disabled="busy">
<input type="submit" style="display: none;" />
2026-02-06 22:49:08 +01:00
<div class="warning-label">{{ $t('communityapp.installwarning') }}</div>
2026-02-05 21:51:55 +01:00
<FormGroup>
<label for="urlInput">CloudronVersions.json URL</label>
<TextInput id="urlInput" v-model="versionsUrl" required placeholder="https://example.com/CloudronVersions.json"/>
<div class="error-label" v-if="formError.generic">{{ formError.generic }}</div>
</FormGroup>
</fieldset>
</form>
</Dialog>
</template>