1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Test PDF abilites in setup

This commit is contained in:
Benjamin Beganovic 2020-07-02 13:58:39 +02:00
parent 7f90d8d45b
commit 605069f05b
8 changed files with 87 additions and 40 deletions

View File

@ -19,7 +19,11 @@ use App\Models\Account;
use App\Utils\SystemHealth;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
use Spatie\Browsershot\Browsershot;
/**
* Class SetupController.
@ -113,6 +117,10 @@ class SetupController extends Controller
Artisan::call('migrate', ['--force' => true]);
Artisan::call('db:seed', ['--force' => true]);
File::delete(
public_path('test.pdf')
);
/* Create the first account. */
if (Account::count() == 0) {
$account = CreateAccount::dispatchNow($request->all());
@ -179,4 +187,19 @@ class SetupController extends Controller
return false;
}
public function checkPdf(Request $request)
{
try {
Browsershot::html('If you see this text, generating PDF works! Thanks for using Invoice Ninja!')->savePdf(
public_path('test.pdf')
);
return response(['url' => asset('test.pdf')], 200);
} catch (\Exception $e) {
info($e->getMessage());
return response([], 500);
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,6 @@
"/js/clients/quotes/action-selectors.js": "/js/clients/quotes/action-selectors.js?id=b6b33ab51b58b51e1212",
"/js/clients/quotes/approve.js": "/js/clients/quotes/approve.js?id=1c5d76fb5f98bd49f6c8",
"/js/clients/shared/pdf.js": "/js/clients/shared/pdf.js?id=ba1182244cda0e0ffbeb",
"/js/setup/setup.js": "/js/setup/setup.js?id=87653cfb4084aadea7a2",
"/js/setup/setup.js": "/js/setup/setup.js?id=045266c33610abf0dbd0",
"/css/card-js.min.css": "/css/card-js.min.css?id=62afeb675235451543ad"
}

View File

@ -8,75 +8,89 @@
* @license https://opensource.org/licenses/AAL
*/
import Axios from "axios";
import Axios from 'axios';
class Setup {
constructor() {
this.checkDbButton = document.getElementById("test-db-connection");
this.checkDbAlert = document.getElementById("database-response");
this.checkDbEndpoint = document.querySelector(
'meta[name="test-db-endpoint"]'
).content;
this.checkDbButton = document.getElementById('test-db-connection');
this.checkDbAlert = document.getElementById('database-response');
this.checkSmtpButton = document.getElementById("test-smtp-connection");
this.checkSmtpAlert = document.getElementById("smtp-response");
this.checkSmtpEndpoint = document.querySelector(
'meta[name="test-smtp-endpoint"]'
).content;
this.checkSmtpButton = document.getElementById('test-smtp-connection');
this.checkSmtpAlert = document.getElementById('smtp-response');
this.checkPdfButton = document.getElementById('test-pdf');
this.checkPdfAlert = document.getElementById('test-pdf-response');
}
handleDatabaseCheck() {
let data = {
host: document.querySelector('input[name="host"]').value,
database: document.querySelector('input[name="database"]').value,
username: document.querySelector('input[name="db_username"]').value,
password: document.querySelector('input[name="db_password"]').value,
}
};
Axios.post(this.checkDbEndpoint, data)
.then(response => this.handleSuccess(this.checkDbAlert))
.catch(e => this.handleFailure(this.checkDbAlert));
Axios.post('/setup/check_db', data)
.then((response) => this.handleSuccess(this.checkDbAlert))
.catch((e) => this.handleFailure(this.checkDbAlert));
}
handleSmtpCheck() {
let data = {
driver: document.querySelector('select[name="mail_driver"]').value,
from_name: document.querySelector('input[name="mail_name"]').value,
from_address: document.querySelector('input[name="mail_address"]').value,
username: document.querySelector('input[name="mail_username"]').value,
from_address: document.querySelector('input[name="mail_address"]')
.value,
username: document.querySelector('input[name="mail_username"]')
.value,
host: document.querySelector('input[name="mail_host"]').value,
port: document.querySelector('input[name="mail_port"]').value,
encryption: document.querySelector('select[name="encryption"]').value,
password: document.querySelector('input[name="mail_password"]').value,
}
encryption: document.querySelector('select[name="encryption"]')
.value,
password: document.querySelector('input[name="mail_password"]')
.value,
};
Axios.post(this.checkSmtpEndpoint, data)
.then(response => this.handleSuccess(this.checkSmtpAlert))
.catch(e => this.handleFailure(this.checkSmtpAlert));
Axios.post('/setup/check_mail', data)
.then((response) => this.handleSuccess(this.checkSmtpAlert))
.catch((e) => this.handleFailure(this.checkSmtpAlert));
}
handleTestPdfCheck() {
Axios.post('/setup/check_pdf', {})
.then((response) => {
let win = window.open(response.data.url, '_blank');
win.focus();
return this.handleSuccess(this.checkPdfAlert);
})
.catch((error) => this.handleFailure(this.checkPdfAlert));
}
handleSuccess(element) {
element.classList.remove("alert-failure");
element.innerText = "Success!";
element.classList.add("alert-success");
element.classList.remove('alert-failure');
element.innerText = 'Success!';
element.classList.add('alert-success');
}
handleFailure(element) {
element.classList.remove("alert-success");
element.classList.remove('alert-success');
element.innerText = "Oops, looks like something isn't correct!";
element.classList.add("alert-failure");
element.classList.add('alert-failure');
}
handle() {
this.checkDbButton.addEventListener("click", () =>
this.checkDbButton.addEventListener('click', () =>
this.handleDatabaseCheck()
);
this.checkSmtpButton.addEventListener("click", () =>
this.checkSmtpButton.addEventListener('click', () =>
this.handleSmtpCheck()
);
this.checkPdfButton.addEventListener('click', () =>
this.handleTestPdfCheck()
);
}
}

View File

@ -3232,4 +3232,6 @@ return [
'application_settings_label' => 'Let\'s store basic information about your Invoice Ninja!',
'recommended_in_production' => 'Recommended in production',
'enable_only_for_development' => 'Enable only for development',
'test_pdf' => 'Test PDF',
];

View File

@ -47,6 +47,16 @@
<a class="button-link mt-1 block" href="https://www.invoiceninja.com/privacy-policy/">Read more about how we use this.</a>
</dd>
</div>
<div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6 sm:flex sm:items-center">
<dt class="text-sm leading-5 font-medium text-gray-500">
<button type="button" class="button button-primary py-2 px-3 text-xs" id="test-pdf">
{{ ctrans('texts.test_pdf') }}
</button>
</dt>
<dd class="text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
<div class="alert py-2 bg-gray-50" id="test-pdf-response"></div>
</dd>
</div>
</dl>
</div>
</div>

View File

@ -1,11 +1,6 @@
@extends('portal.ninja2020.layout.clean')
@section('meta_title', ctrans('texts.setup'))
@push('head')
<meta name="test-db-endpoint" content="{{ url('/setup/check_db') }}">
<meta name="test-smtp-endpoint" content="{{ url('/setup/check_mail') }}">
@endpush
@section('body')
<div class="container mx-auto mb-10 mt-4">
<form action="{{ url('/setup') }}" method="post">

View File

@ -3,10 +3,13 @@
use Illuminate\Support\Facades\Route;
Route::get('/', 'BaseController@flutterRoute')->middleware('guest');
Route::get('setup', 'SetupController@index')->middleware('guest');
Route::post('setup', 'SetupController@doSetup')->middleware('guest');
Route::post('setup/check_db', 'SetupController@checkDB')->middleware('guest');
Route::post('setup/check_mail', 'SetupController@checkMail')->middleware('guest');
Route::post('setup', 'SetupController@doSetup')->middleware('guest');
Route::post('setup/check_pdf', 'SetupController@checkPdf')->middleware('guest');
Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');