2021-11-16 17:14:30 +01:00
|
|
|
import '@maicol07/mwc-card';
|
2021-11-12 14:09:29 +01:00
|
|
|
import '@maicol07/mwc-layout-grid';
|
2021-08-06 12:47:31 +02:00
|
|
|
import '@material/mwc-button';
|
|
|
|
import '@material/mwc-checkbox';
|
|
|
|
import '@material/mwc-fab';
|
|
|
|
import '@material/mwc-formfield';
|
|
|
|
import '@material/mwc-list/mwc-list-item';
|
|
|
|
import '@material/mwc-select';
|
|
|
|
import '@material/mwc-textarea';
|
2021-10-12 23:38:26 +02:00
|
|
|
import '../WebComponents/TextField';
|
2021-11-30 13:17:14 +01:00
|
|
|
import '../WebComponents/Select';
|
2021-09-07 13:28:20 +02:00
|
|
|
|
|
|
|
import collect from 'collect.js';
|
2021-08-06 12:47:31 +02:00
|
|
|
import LocaleCode from 'locale-code';
|
|
|
|
import Mithril from 'mithril';
|
2021-11-11 18:32:07 +01:00
|
|
|
import redaxios from 'redaxios';
|
2021-08-06 12:47:31 +02:00
|
|
|
|
2021-10-09 17:15:15 +02:00
|
|
|
// eslint-disable-next-line import/no-absolute-path
|
|
|
|
import logoUrl from '/images/logo_completo.png';
|
2021-09-07 13:28:20 +02:00
|
|
|
|
2021-11-11 18:32:07 +01:00
|
|
|
import {Alert} from '../Components';
|
2021-09-29 15:32:31 +02:00
|
|
|
import Mdi from '../Components/Mdi.jsx';
|
|
|
|
import Page from '../Components/Page.jsx';
|
2021-11-12 16:59:04 +01:00
|
|
|
import {
|
|
|
|
getFormData,
|
|
|
|
showSnackbar
|
|
|
|
} from '../utils';
|
2021-07-30 22:56:43 +02:00
|
|
|
|
2021-11-30 13:17:14 +01:00
|
|
|
function getFlag(language: string, slot: string = 'graphic', styles: {...} = {}) {
|
2021-12-01 18:27:09 +01:00
|
|
|
if (!styles.display) {
|
|
|
|
styles.display = 'flex';
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:17:14 +01:00
|
|
|
return (
|
|
|
|
<div slot={slot} style={styles}>
|
|
|
|
<img style="border-radius: 4px;"
|
|
|
|
src={`https://flagicons.lipis.dev/flags/4x3/${LocaleCode.getCountryCode(language)
|
|
|
|
.toLowerCase()}.svg`}
|
|
|
|
alt={LocaleCode.getLanguageNativeName(language)}/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:16:10 +02:00
|
|
|
export default class SetupPage extends Page {
|
2021-09-09 23:31:37 +02:00
|
|
|
languages() {
|
2021-11-30 14:47:35 +01:00
|
|
|
const listItems: Mithril.Vnode[] = [];
|
2021-08-06 12:47:31 +02:00
|
|
|
|
2021-09-07 13:28:20 +02:00
|
|
|
for (const lang of this.page.props.languages) {
|
|
|
|
const attributes = {
|
2021-08-06 12:47:31 +02:00
|
|
|
selected: this.page.props.locale === lang
|
|
|
|
};
|
|
|
|
const langCode = lang.replace('_', '-');
|
|
|
|
listItems.push(
|
2021-09-07 13:28:20 +02:00
|
|
|
<mwc-list-item graphic="icon" value={lang} {...attributes}>
|
2021-11-30 13:17:14 +01:00
|
|
|
{getFlag(langCode)}
|
2021-09-09 23:31:37 +02:00
|
|
|
<span>{LocaleCode.getLanguageNativeName(langCode)}</span>
|
|
|
|
</mwc-list-item>
|
2021-08-06 12:47:31 +02:00
|
|
|
);
|
2021-11-30 13:17:14 +01:00
|
|
|
|
|
|
|
if (attributes.selected) {
|
|
|
|
listItems.push(getFlag(langCode, 'icon', {display: 'block', width: '24px', lineHeight: '22px'}));
|
|
|
|
}
|
2021-09-07 13:28:20 +02:00
|
|
|
}
|
|
|
|
|
2021-09-09 23:31:37 +02:00
|
|
|
return listItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
view(vnode) {
|
2021-09-07 13:28:20 +02:00
|
|
|
const examplesTexts = collect();
|
|
|
|
for (const example of ['localhost', 'root', 'mysql', 'openstamanager']) {
|
2021-11-09 10:14:08 +01:00
|
|
|
examplesTexts.put(example, __('Esempio: :example', {example}));
|
2021-09-07 13:28:20 +02:00
|
|
|
}
|
2021-08-06 12:47:31 +02:00
|
|
|
|
2021-08-02 13:16:10 +02:00
|
|
|
return (
|
|
|
|
<>
|
2021-11-16 17:14:30 +01:00
|
|
|
<mwc-card outlined className="center" style="width: 95%;">
|
2021-11-10 17:20:20 +01:00
|
|
|
<form id="setup">
|
2021-11-09 10:14:08 +01:00
|
|
|
<img src={logoUrl} className="center" alt={__('OpenSTAManager')} />
|
2021-11-11 18:32:07 +01:00
|
|
|
<mwc-layout-grid>
|
|
|
|
<mwc-layout-grid-cell span-desktop="8">
|
2021-11-09 10:14:08 +01:00
|
|
|
<h2>{__('Benvenuto in :name!', {name: <strong>{__('OpenSTAManager')}</strong>})}</h2>
|
|
|
|
<p>{__('Puoi procedere alla configurazione tecnica del software attraverso i '
|
2021-08-06 12:47:31 +02:00
|
|
|
+ 'parametri seguenti, che potranno essere corretti secondo necessità tramite il file .env.')}<br/>
|
2021-11-09 10:14:08 +01:00
|
|
|
{__("Se necessiti supporto puoi contattarci tramite l':contactLink o tramite il nostro :forumLink.", {
|
2021-09-07 13:28:20 +02:00
|
|
|
// eslint-disable-next-line no-secrets/no-secrets
|
2021-11-09 10:14:08 +01:00
|
|
|
contactLink: <a href="https://www.openstamanager.com/contattaci/?subject=Assistenza%20installazione%20OSM">{__('assistenza ufficiale')}</a>,
|
|
|
|
forumLink: <a href="https://forum.openstamanager.com">{__('forum')}</a>
|
2021-08-06 12:47:31 +02:00
|
|
|
})}</p>
|
2021-11-09 10:14:08 +01:00
|
|
|
<h4>{__('Formato date')}</h4>
|
2021-11-11 19:06:29 +01:00
|
|
|
<p className="mdc-typography--subtitle2" style="font-size: small;">
|
2021-11-09 10:14:08 +01:00
|
|
|
{__('I formati sono impostabili attraverso lo standard previsto da :link.',
|
2021-08-06 12:47:31 +02:00
|
|
|
{link: <a href="https://www.php.net/manual/en/function.date.php#refsect1-function.date-parameters">PHP</a>})
|
|
|
|
}
|
2021-11-11 19:06:29 +01:00
|
|
|
</p>
|
|
|
|
<mwc-layout-grid inner>
|
|
|
|
<mwc-layout-grid-cell>
|
2021-11-09 10:14:08 +01:00
|
|
|
<text-field name="timestamp_format" label={__('Formato data lunga')}
|
2021-10-12 23:38:26 +02:00
|
|
|
required value="d/m/Y H:i">
|
|
|
|
<Mdi icon="calendar-clock" slot="icon"/>
|
|
|
|
</text-field>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
2021-11-11 19:06:29 +01:00
|
|
|
<mwc-layout-grid-cell>
|
2021-11-09 10:14:08 +01:00
|
|
|
<text-field name="date_format" label={__('Formato data corta')}
|
2021-10-12 23:38:26 +02:00
|
|
|
required value="d/m/Y">
|
|
|
|
<Mdi icon="calendar-month-outline" slot="icon"/>
|
|
|
|
</text-field>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
2021-11-11 19:06:29 +01:00
|
|
|
<mwc-layout-grid-cell>
|
2021-11-09 10:14:08 +01:00
|
|
|
<text-field name="time_format" label={__('Formato orario')} required
|
2021-10-12 23:38:26 +02:00
|
|
|
value="H:i">
|
|
|
|
<Mdi icon="clock-outline" slot="icon"/>
|
|
|
|
</text-field>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
</mwc-layout-grid>
|
2021-08-06 12:47:31 +02:00
|
|
|
<hr/>
|
2021-11-09 10:14:08 +01:00
|
|
|
<h4>{__('Database')}</h4>
|
2021-11-11 18:32:07 +01:00
|
|
|
<mwc-layout-grid inner>
|
|
|
|
<mwc-layout-grid-cell span="4">
|
2021-11-09 10:14:08 +01:00
|
|
|
<text-field name="host" label={__('Host')} required
|
2021-10-12 23:38:26 +02:00
|
|
|
helper={examplesTexts.get('localhost')}>
|
|
|
|
<Mdi icon="server-network" slot="icon"/>
|
|
|
|
</text-field>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
<mwc-layout-grid-cell span="4">
|
2021-11-09 10:14:08 +01:00
|
|
|
<text-field name="username" label={__('Nome utente')} required
|
2021-10-12 23:38:26 +02:00
|
|
|
helper={examplesTexts.get('root')}>
|
|
|
|
<Mdi icon="account-outline" slot="icon"/>
|
|
|
|
</text-field>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
<mwc-layout-grid-cell span="4">
|
2021-11-10 17:18:19 +01:00
|
|
|
<text-field name="password" label={__('Password')}
|
2021-10-12 23:38:26 +02:00
|
|
|
helper={examplesTexts.get('mysql')}>
|
|
|
|
<Mdi icon="lock-outline" slot="icon"/>
|
|
|
|
</text-field>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
<mwc-layout-grid-cell span="4">
|
2021-11-09 10:14:08 +01:00
|
|
|
<text-field name="database_name" label={__('Nome database')} required
|
2021-10-12 23:38:26 +02:00
|
|
|
helper={examplesTexts.get('openstamanager')}>
|
|
|
|
<Mdi icon="database-outline" slot="icon"/>
|
|
|
|
</text-field>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
</mwc-layout-grid>
|
2021-08-06 12:47:31 +02:00
|
|
|
<hr/>
|
2021-11-11 18:32:07 +01:00
|
|
|
<mwc-layout-grid inner>
|
2021-11-11 19:06:29 +01:00
|
|
|
<mwc-layout-grid-cell>
|
2021-11-09 10:14:08 +01:00
|
|
|
<small>{__('* Campi obbligatori')}</small>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
2021-11-11 19:06:29 +01:00
|
|
|
<mwc-layout-grid-cell>
|
2021-11-10 17:20:20 +01:00
|
|
|
<mwc-button id="save-install" raised label={__('Salva e installa')} onclick={this.onSaveButtonClicked.bind(this)}>
|
2021-09-19 12:28:21 +02:00
|
|
|
<Mdi icon="check" slot="icon"/>
|
2021-08-06 12:47:31 +02:00
|
|
|
</mwc-button>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
2021-11-11 19:06:29 +01:00
|
|
|
<mwc-layout-grid-cell>
|
2021-11-10 17:20:20 +01:00
|
|
|
<mwc-button id="test-db" outlined label={__('Testa il database')} onclick={this.onTestButtonClicked.bind(this)}>
|
2021-09-19 12:28:21 +02:00
|
|
|
<Mdi icon="test-tube" slot="icon"/>
|
2021-08-06 12:47:31 +02:00
|
|
|
</mwc-button>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
</mwc-layout-grid>
|
|
|
|
</mwc-layout-grid-cell>
|
2021-11-11 19:06:29 +01:00
|
|
|
<mwc-layout-grid-cell>
|
2021-11-09 10:14:08 +01:00
|
|
|
<h4>{__('Lingua')}</h4>
|
2021-11-30 13:17:14 +01:00
|
|
|
<material-select id="language-select" name="locale">
|
2021-09-09 23:31:37 +02:00
|
|
|
{this.languages()}
|
2021-11-30 13:17:14 +01:00
|
|
|
</material-select>
|
2021-08-06 12:47:31 +02:00
|
|
|
<hr />
|
2021-11-09 10:14:08 +01:00
|
|
|
<h4>{__('Licenza')}</h4>
|
|
|
|
<p>{__('OpenSTAManager è tutelato dalla licenza GPL 3.0, da accettare obbligatoriamente per poter utilizzare il gestionale.')}</p>
|
2021-11-11 19:06:29 +01:00
|
|
|
<mwc-textarea value={this.page.props.license} rows="15" cols="40" disabled style="margin-bottom: 8px;"/>
|
|
|
|
<mwc-layout-grid inner>
|
2021-11-11 18:32:07 +01:00
|
|
|
<mwc-layout-grid-cell span-desktop="8" span-tablet="8">
|
2021-11-09 10:14:08 +01:00
|
|
|
<mwc-formfield label={__('Ho visionato e accetto la licenza')}>
|
2021-09-19 12:28:21 +02:00
|
|
|
<mwc-checkbox name="license_agreement"/>
|
2021-08-06 12:47:31 +02:00
|
|
|
</mwc-formfield>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
2021-11-11 19:06:29 +01:00
|
|
|
<mwc-layout-grid-cell>
|
2021-08-06 12:47:31 +02:00
|
|
|
<a href="https://www.gnu.org/licenses/translations.en.html#GPL" target="_blank">
|
2021-11-09 10:14:08 +01:00
|
|
|
<mwc-button label={__('Versioni tradotte')}>
|
2021-09-19 12:28:21 +02:00
|
|
|
<Mdi icon="license" slot="icon"/>
|
2021-08-06 12:47:31 +02:00
|
|
|
</mwc-button>
|
|
|
|
</a>
|
2021-11-11 18:32:07 +01:00
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
</mwc-layout-grid>
|
|
|
|
</mwc-layout-grid-cell>
|
|
|
|
</mwc-layout-grid>
|
2021-11-10 17:20:20 +01:00
|
|
|
</form>
|
2021-11-16 17:14:30 +01:00
|
|
|
</mwc-card>
|
2021-09-19 12:28:21 +02:00
|
|
|
<mwc-fab id="contrast-switcher" className="sticky contrast-light"
|
2021-11-09 10:14:08 +01:00
|
|
|
label={__('Attiva/disattiva contrasto elevato')}>
|
2021-09-07 13:28:20 +02:00
|
|
|
<Mdi icon="contrast-circle" slot="icon" className="light-bg"/>
|
2021-08-06 12:47:31 +02:00
|
|
|
</mwc-fab>
|
2021-11-10 17:20:20 +01:00
|
|
|
<Alert id="test-connection-alert-error" icon="error"/>
|
|
|
|
<Alert id="test-connection-alert-success" icon="success">
|
|
|
|
<p>{__('Connessione al database riuscita')}</p>
|
|
|
|
</Alert>
|
2021-08-02 13:16:10 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2021-08-06 12:47:31 +02:00
|
|
|
|
|
|
|
oncreate(vnode: Mithril.VnodeDOM) {
|
|
|
|
super.oncreate(vnode);
|
|
|
|
|
2021-10-12 23:38:26 +02:00
|
|
|
$('mwc-fab#contrast-switcher')
|
|
|
|
.on('click', function () {
|
|
|
|
$(this)
|
|
|
|
.toggleClass('contrast-light')
|
|
|
|
.toggleClass('contrast-dark');
|
|
|
|
$('body')
|
|
|
|
.toggleClass('mdc-high-contrast');
|
|
|
|
});
|
|
|
|
|
2021-12-01 18:28:54 +01:00
|
|
|
$('#language-select').on('action', this.onLanguageSelected);
|
2021-11-10 18:41:25 +01:00
|
|
|
|
2021-10-12 23:38:26 +02:00
|
|
|
// Fix for mwc button inside <a> tags
|
|
|
|
$('a')
|
|
|
|
.has('mwc-button')
|
|
|
|
.css('text-decoration', 'none');
|
2021-08-06 12:47:31 +02:00
|
|
|
}
|
2021-11-10 17:20:20 +01:00
|
|
|
|
|
|
|
onTestButtonClicked(event: Event) {
|
|
|
|
this.testDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
onSaveButtonClicked(event: Event) {
|
|
|
|
const form = $(event.target).closest('form');
|
2021-11-12 16:59:04 +01:00
|
|
|
this.save(getFormData(form));
|
2021-11-10 17:20:20 +01:00
|
|
|
}
|
|
|
|
|
2021-11-10 18:41:25 +01:00
|
|
|
onLanguageSelected(event: Event) {
|
2021-12-01 18:28:54 +01:00
|
|
|
const {detail, target: select} = event;
|
|
|
|
const selected = $(select).find(`mwc-list-item:nth-child(${detail.index + 1}) [slot="graphic"] img`);
|
|
|
|
$(select).find('[slot="icon"] img').attr('src', selected.attr('src'));
|
|
|
|
window.location.href = window.route('app.language', {language: select.value});
|
2021-11-10 18:41:25 +01:00
|
|
|
}
|
|
|
|
|
2021-11-12 14:08:12 +01:00
|
|
|
async testDatabase(silentSuccess = false, silentError = false): boolean {
|
2021-11-10 17:20:20 +01:00
|
|
|
const form = $('form');
|
|
|
|
|
|
|
|
try {
|
2021-11-12 14:08:12 +01:00
|
|
|
await redaxios.options(window.route('setup.test'), {data: getFormData(form)});
|
2021-11-10 17:20:20 +01:00
|
|
|
} catch (error) {
|
2021-11-12 14:08:12 +01:00
|
|
|
if (!silentError) {
|
2021-11-10 17:20:20 +01:00
|
|
|
const alert = $('#test-connection-alert-error');
|
|
|
|
alert.find('.content').text(__('Si è verificato un errore durante la connessione al'
|
|
|
|
+ ' database: :error', {error: error.data.error}));
|
|
|
|
alert.get(0).show();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-11-12 14:08:12 +01:00
|
|
|
if (!silentSuccess) {
|
|
|
|
document.querySelector('#test-connection-alert-success')
|
|
|
|
.show();
|
2021-11-10 17:20:20 +01:00
|
|
|
}
|
2021-11-12 14:08:12 +01:00
|
|
|
return true;
|
2021-11-10 17:20:20 +01:00
|
|
|
}
|
2021-11-12 16:59:04 +01:00
|
|
|
|
|
|
|
async save(data: {...}) {
|
|
|
|
const test = this.testDatabase(true);
|
|
|
|
if (!test) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await redaxios.put(window.route('setup.save'), data);
|
|
|
|
} catch (error) {
|
|
|
|
await showSnackbar(error.data.error_description);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await showSnackbar(__('Impostazioni salvate correttamente'));
|
|
|
|
window.location.href = window.route('auth.login');
|
|
|
|
}
|
2021-08-02 13:16:10 +02:00
|
|
|
}
|