2026-02-05 13:20:00 +01:00
|
|
|
<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();
|
2026-02-05 13:20:00 +01:00
|
|
|
|
|
|
|
|
const emit = defineEmits([ 'success' ]);
|
|
|
|
|
|
|
|
|
|
const dialog = useTemplateRef('dialog');
|
2026-02-05 21:51:55 +01:00
|
|
|
const form = useTemplateRef('form');
|
2026-02-05 13:20:00 +01:00
|
|
|
|
|
|
|
|
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 13:20:00 +01:00
|
|
|
|
2026-02-05 21:51:55 +01:00
|
|
|
busy.value = true;
|
2026-02-05 13:20:00 +01:00
|
|
|
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-05 13:20:00 +01:00
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
2026-02-05 13:20:00 +01:00
|
|
|
dialog.value.close();
|
2026-02-05 21:51:55 +01:00
|
|
|
busy.value = false;
|
2026-02-05 13:20:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
|
open() {
|
2026-02-05 21:51:55 +01:00
|
|
|
versionsUrl.value = '';
|
2026-02-05 13:20:00 +01:00
|
|
|
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"
|
2026-02-05 13:20:00 +01:00
|
|
|
reject-style="secondary"
|
2026-02-05 21:51:55 +01:00
|
|
|
:reject-label="$t('main.dialog.cancel')"
|
|
|
|
|
:reject-active="!busy"
|
2026-02-05 13:20:00 +01:00
|
|
|
@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-05 13:20:00 +01:00
|
|
|
|
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>
|
2026-02-05 13:20:00 +01:00
|
|
|
</form>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</template>
|