Code refactoring

This commit is contained in:
Burak Civan 2021-05-25 19:52:39 +03:00
parent 5bac50274a
commit 32894e7151
16 changed files with 190 additions and 253 deletions

View File

@ -93,19 +93,12 @@ class Companies extends Controller
// Save all settings // Save all settings
setting()->save(); setting()->save();
$message = trans('messages.success.updated', ['type' => trans_choice('general.companies', 2)]); return response()->json([
$response = [
'status' => null, 'status' => null,
'success' => true, 'success' => true,
'error' => false, 'error' => false,
'message' => $message, 'message' => trans('messages.success.updated', ['type' => trans_choice('general.companies', 2)]),
'data' => null, 'data' => null,
'redirect' => route('wizard.currencies.index'), ]);
];
flash($message)->success();
return response()->json($response);
} }
} }

View File

@ -58,17 +58,10 @@ class Currencies extends Controller
{ {
$response = $this->ajaxDispatch(new CreateCurrency($request)); $response = $this->ajaxDispatch(new CreateCurrency($request));
//$response['redirect'] = route('wizard.currencies.index');
if ($response['success']) { if ($response['success']) {
$message = trans('messages.success.added', ['type' => trans_choice('general.currencies', 1)]); $message = trans('messages.success.added', ['type' => trans_choice('general.currencies', 1)]);
//flash($message)->success();
} else { } else {
$message = $response['message']; $message = $response['message'];
//flash($message)->error()->important();
} }
$response['message'] = $message; $response['message'] = $message;
@ -88,16 +81,10 @@ class Currencies extends Controller
{ {
$response = $this->ajaxDispatch(new UpdateCurrency($currency, $request)); $response = $this->ajaxDispatch(new UpdateCurrency($currency, $request));
// $response['redirect'] = route('wizard.currencies.index');
if ($response['success']) { if ($response['success']) {
$message = trans('messages.success.updated', ['type' => $currency->name]); $message = trans('messages.success.updated', ['type' => $currency->name]);
// flash($message)->success();
} else { } else {
$message = $response['message']; $message = $response['message'];
// flash($message)->error()->important();
} }
$response['message'] = $message; $response['message'] = $message;

View File

@ -34,7 +34,7 @@ class Data extends Controller
public function index() public function index()
{ {
$translations = [ $translations = [
'companies' => [ 'company' => [
'title' => trans_choice('general.companies', 1), 'title' => trans_choice('general.companies', 1),
'api_key' => trans('modules.api_key'), 'api_key' => trans('modules.api_key'),
'form_enter' => trans('general.form.enter'), 'form_enter' => trans('general.form.enter'),
@ -112,28 +112,37 @@ class Data extends Controller
} }
$taxes = Tax::collect(); $taxes = Tax::collect();
$data = [ $modules = $this->getFeaturedModules([
'query' => [ 'query' => [
'limit' => 4 'limit' => 4
] ]
]; ]);
$modules = $this->getFeaturedModules($data); $company = company();
$company = Company::find(company_id()); $company->api_key = setting('apps.api_key');
$company->financial_start = setting('localisation.financial_start');
if ($company->logo) {
$logo = \Plank\Mediable\Media::find($company->logo);
$logo->path = route('uploads.get', $logo->id);
$company->logo = $logo;
}
return response()->json([ return response()->json([
'success' => true, 'success' => true,
'errors' => false, 'errors' => false,
'message' => 'Get languages text..', 'message' => 'Get all data...',
'data' => [ 'data' => [
'translations' => $translations,
'company' => $company,
'currencies' => $currencies, 'currencies' => $currencies,
'currency_codes' => $codes, 'currency_codes' => $codes,
'taxes' => $taxes, 'taxes' => $taxes,
'modules' => $modules, 'modules' => $modules,
'translations' => $translations,
'companies' => $company,
], ],
]); ]);
} }

View File

@ -46,17 +46,12 @@ class Taxes extends Controller
{ {
$response = $this->ajaxDispatch(new CreateTax($request)); $response = $this->ajaxDispatch(new CreateTax($request));
// $response['redirect'] = route('wizard.taxes.index');
if ($response['success']) { if ($response['success']) {
$message = trans('messages.success.added', ['type' => trans_choice('general.taxes', 1)]); $message = trans('messages.success.added', ['type' => trans_choice('general.taxes', 1)]);
// flash($message)->success();
} else { } else {
$message = $response['message']; $message = $response['message'];
// flash($message)->error()->important();
} }
$response['message'] = $message; $response['message'] = $message;
return response()->json($response); return response()->json($response);
@ -74,16 +69,10 @@ class Taxes extends Controller
{ {
$response = $this->ajaxDispatch(new UpdateTax($tax, $request)); $response = $this->ajaxDispatch(new UpdateTax($tax, $request));
// $response['redirect'] = route('wizard.taxes.index');
if ($response['success']) { if ($response['success']) {
$message = trans('messages.success.updated', ['type' => $tax->name]); $message = trans('messages.success.updated', ['type' => $tax->name]);
// flash($message)->success();
} else { } else {
$message = $response['message']; $message = $response['message'];
// flash($message)->error()->important();
} }
$response['message'] = $message; $response['message'] = $message;
@ -104,17 +93,12 @@ class Taxes extends Controller
$response = $this->ajaxDispatch(new DeleteTax($tax)); $response = $this->ajaxDispatch(new DeleteTax($tax));
// $response['redirect'] = route('wizard.taxes.index');
if ($response['success']) { if ($response['success']) {
$message = trans('messages.success.deleted', ['type' => $tax->name]); $message = trans('messages.success.deleted', ['type' => $tax->name]);
// flash($message)->success();
} else { } else {
$message = $response['message']; $message = $response['message'];
// flash($message)->error()->important();
} }
$response['tax_id'] = $tax_id; $response['tax_id'] = $tax_id;
$response['message'] = $message; $response['message'] = $message;

View File

@ -1,102 +0,0 @@
<?php
namespace App\Http\Controllers\Wizard;
use App\Abstracts\Http\Controller;
class Translations extends Controller
{
/**
* Instantiate a new controller instance.
*/
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-common-companies')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-common-companies')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-common-companies')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-common-companies')->only('destroy');
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function index()
{
$translations = [
'companies' => [
'title' => trans_choice('general.companies', 1),
'api_key' => trans('modules.api_key'),
'form_enter' => trans('general.form.enter'),
'get_api_key' => trans('modules.get_api_key'),
'tax_number' => trans('general.tax_number'),
'financial_start' => trans('settings.localisation.financial_start'),
'address' => trans('settings.company.address'),
'logo' => trans('settings.company.logo'),
'skip' => trans('general.skip'),
'save' => trans('general.save'),
],
'currencies' => [
'title' => trans_choice('general.currencies', 2),
'add_new' => trans('general.add_new'),
'name' => trans('general.name'),
'code' => trans('currencies.code'),
'rate' => trans('currencies.rate'),
'enabled' => trans('general.enabled'),
'actions' => trans('general.actions') ,
'yes' => trans('general.yes'),
'no' => trans('general.no'),
'edit' => trans('general.edit'),
'delete' => trans('general.delete'),
'save' => trans('general.save'),
'precision' => trans('currencies.precision'),
'symbol' => trans('currencies.symbol.symbol'),
'position' => trans('currencies.symbol.position'),
'decimal_mark' => trans('currencies.decimal_mark'),
'thousands_separator' => trans('currencies.thousands_separator'),
'previous' => trans('pagination.previous'),
'next' => trans('pagination.next'),
'delete_confirm' => trans('general.delete_confirm'),
'cancel' => trans('general.cancel'),
],
'taxes' => [
'title' => trans_choice('general.taxes', 2),
'add_new' => trans('general.add_new'),
'name' => trans('general.name'),
'rate_percent' => trans('taxes.rate_percent'),
'enabled' => trans('general.enabled'),
'actions' => trans('general.actions'),
'yes' => trans('general.yes'),
'no' => trans('general.no'),
'edit' => trans('general.edit'),
'delete' => trans('general.delete'),
'name' => trans('general.name'),
'rate' => trans('currencies.rate'),
'enabled' => trans('general.enabled'),
'save' => trans('general.save'),
'previous' => trans('pagination.previous'),
'next' => trans('pagination.next'),
'cancel' => trans('general.cancel'),
],
'finish' => [
'title' => trans_choice('general.finish', 1),
'recommended_apps' => trans('modules.recommended_apps'),
'no_apps' => trans('modules.no_apps'),
'developer' => trans('modules.developer'),
'previous' => trans('pagination.previous'),
'go_to_dashboard' => trans('general.go_to_dashboard'),
]
];
return response()->json([
'success' => true,
'errors' => false,
'message' => 'Get languages text..',
'data' => $translations,
]);
}
}

View File

@ -5,14 +5,18 @@
:taxes="taxes" :taxes="taxes"
:modules="modules.data" :modules="modules.data"
:currency_codes="currency_codes" :currency_codes="currency_codes"
:companies="companies" :company="company"
></router-view> ></router-view>
</template> </template>
<script> <script>
export default { export default {
name: 'Wizard', name: 'Wizard',
data: function () {
return {
page_loaded: true,
}
},
created() { created() {
let self = this; let self = this;
@ -31,6 +35,10 @@ export default {
Object.keys(data.currency_codes).map((key) => { Object.keys(data.currency_codes).map((key) => {
return data.currency_codes[key]; return data.currency_codes[key];
}); });
setTimeout(function() {
self.page_loaded = false;
}.bind(self), 800);
}); });
}, },
@ -40,9 +48,9 @@ export default {
currency_codes: [], currency_codes: [],
taxes: [], taxes: [],
modules: {}, modules: {},
companies: {}, company: {},
translations: { translations: {
companies: {}, company: {},
currencies: {}, currencies: {},
taxes: {}, taxes: {},
finish: {}, finish: {},
@ -94,6 +102,11 @@ export default {
border-right:1px solid; border-right:1px solid;
} }
.el-step__icon {
-webkit-transition: unset;
transition: unset;
}
@media screen and (max-width: 991px) { @media screen and (max-width: 991px) {
.form-container .has-error { .form-container .has-error {
position: relative; position: relative;

View File

@ -12,7 +12,7 @@
:disabled="disabled" :disabled="disabled"
> >
<flat-picker slot-scope="{focus, blur}" <flat-picker slot-scope="{focus, blur}"
:name="title" :name="dataName"
@on-open="focus" @on-open="focus"
@on-close="blur" @on-close="blur"
:config="dateConfig" :config="dateConfig"
@ -42,6 +42,11 @@ export default {
default: '', default: '',
description: "Modal header title" description: "Modal header title"
}, },
dataName: {
type: String,
default: '',
description: "Modal header title"
},
placeholder: { placeholder: {
type: String, type: String,
default: '', default: '',
@ -93,7 +98,7 @@ export default {
data() { data() {
return { return {
real_model: this.model, real_model: '',
} }
}, },
@ -121,6 +126,13 @@ export default {
this.$emit('change', this.real_model); this.$emit('change', this.real_model);
} }
},
watch: {
real_model: function(val) {
this.real_model = val;
this.$emit('interface', this.real_model);
}
} }
} }
</script> </script>

View File

@ -231,6 +231,42 @@ export default {
async mounted() { async mounted() {
this.initDropzone(); this.initDropzone();
}, },
watch: {
attachments: function (attachments) {
attachments.forEach((attachment) => {
var mockFile = {
id: attachment[0].id,
name: attachment[0].name,
size: attachment[0].size,
type: attachment[0].type,
download: attachment[0].downloadPath,
dropzone: 'edit',
};
this.dropzone.emit("addedfile", mockFile);
this.dropzone.options.thumbnail.call(this.dropzone, mockFile, attachment[0].path);
// Make sure that there is no progress bar, etc...
this.dropzone.emit("complete", mockFile);
}, this);
this.files.forEach(async (attachment) => {
if (attachment.download) {
attachment.previewElement.querySelector("[data-dz-download]").href = attachment.download;
attachment.previewElement.querySelector("[data-dz-download]").classList.remove("d-none");
}
});
if (this.preview == 'single' && attachments.length == 1) {
this.$nextTick(() => {
document.querySelector("#dropzone-" + this._uid).classList.add("dz-max-files-reached");
});
}
},
},
} }
</script> </script>

View File

@ -1,51 +1,51 @@
<template> <template>
<div> <div>
<h1 class="text-white">{{ translations.companies.title }}</h1> <h1 class="text-white">
{{ translations.company.title }}
</h1>
<div class="card"> <div class="card">
<div class="card-header wizard-header p-3"> <div class="card-header wizard-header p-3">
<el-steps :active="active" finish-status="success" align-center> <el-steps :active="active" finish-status="success" align-center>
<el-step :title="translations.companies.title"></el-step> <el-step :title="translations.company.title"></el-step>
<el-step :title="translations.currencies.title"></el-step> <el-step :title="translations.currencies.title"></el-step>
<el-step :title="translations.taxes.title"></el-step> <el-step :title="translations.taxes.title"></el-step>
<el-step :title="translations.finish.title"></el-step> <el-step :title="translations.finish.title"></el-step>
</el-steps> </el-steps>
</div> </div>
<form <form ref="form" class="w-100">
ref="form"
class="w-100"
>
<div class="card-body"> <div class="card-body">
<div class="row mb-4"> <div class="row mb-4">
<div class="col-12 mb-4"> <div class="col-12 mb-4">
<base-input <base-input
:label="translations.companies.api_key" :label="translations.company.api_key"
name="api_key" name="api_key"
data-name="api_key" data-name="api_key"
:placeholder="translations.companies.api_key" :placeholder="translations.company.api_key"
prepend-icon="fas fa-key" prepend-icon="fas fa-key"
v-model="model.apiKey" v-model="company.api_key"
/> />
<p class="mb-0 mt--3"> <p class="mb-0 mt--3">
<small> <small>
<div v-html="translations.companies.get_api_key"></div> <div v-html="translations.company.get_api_key"></div>
</small> </small>
</p> </p>
</div> </div>
<div class="col-6 mb-4"> <div class="col-6 mb-4">
<base-input <base-input
type="text" type="text"
:label="translations.companies.tax_number" :label="translations.company.tax_number"
name="tax_number" name="tax_number"
data-name="tax_number" data-name="tax_number"
:placeholder="translations.companies.tax_number" :placeholder="translations.company.tax_number"
prepend-icon="fas fa-percent" prepend-icon="fas fa-percent"
v-model="companies.tax_number" v-model="company.tax_number"
/> />
</div> </div>
<div class="col-6 mb-4"> <div class="col-6 mb-4">
<akaunting-date <akaunting-date
:title="translations.companies.financial_start" :title="translations.company.financial_start"
:placeholder="translations.companies.financial_start" data-name="financial_start"
:placeholder="translations.company.financial_start"
prepend-icon="fas fa-calendar" prepend-icon="fas fa-calendar"
:date-config="{ :date-config="{
dateFormat: 'd-m', dateFormat: 'd-m',
@ -53,27 +53,30 @@
altInput: true, altInput: true,
altFormat: 'j F', altFormat: 'j F',
}" }"
v-model="model.date" v-model="company.financial_start"
></akaunting-date> ></akaunting-date>
</div> </div>
<div class="col-12 mb-4"> <div class="col-12 mb-4">
<base-input :label="translations.companies.address"> <base-input :label="translations.company.address">
<textarea <textarea
class="form-control" class="form-control"
name="address" name="address"
data-name="address" data-name="address"
rows="3" rows="3"
:placeholder="translations.companies.address" :placeholder="translations.company.address"
v-model="companies.address" v-model="company.address"
></textarea> ></textarea>
</base-input> </base-input>
</div> </div>
<div class="col-6"> <div class="col-6">
<base-input :label="translations.companies.logo"> <base-input :label="translations.company.logo">
<akaunting-dropzone-file-upload <keep-alive>
preview-classes="single" <akaunting-dropzone-file-upload
> preview-classes="single"
</akaunting-dropzone-file-upload> :attachments="logo"
>
</akaunting-dropzone-file-upload>
</keep-alive>
</base-input> </base-input>
</div> </div>
</div> </div>
@ -81,11 +84,14 @@
<div class="card-footer"> <div class="card-footer">
<div class="row"> <div class="row">
<div class="col-md-12 text-right"> <div class="col-md-12 text-right">
<base-button type="success" native-type="button" @click="onEditSave()">{{ <base-button
translations.companies.save type="success"
}}</base-button> native-type="button"
@click="onEditSave()"
>{{ translations.company.save }}</base-button
>
<base-button type="white" native-type="submit" @click="next()">{{ <base-button type="white" native-type="submit" @click="next()">{{
translations.companies.skip translations.company.skip
}}</base-button> }}</base-button>
</div> </div>
</div> </div>
@ -111,7 +117,7 @@ export default {
AkauntingDate, AkauntingDate,
}, },
props: { props: {
companies: { company: {
type: [Object, Array], type: [Object, Array],
}, },
translations: { translations: {
@ -121,23 +127,56 @@ export default {
data() { data() {
return { return {
active: 0, active: 0,
model: { logo: [],
apiKey: "503df039-d0bc-4f74-aba8-a6f1d38c645b", real_date: ''
taxNumber: "", };
address: "", },
date: "01.01", mounted() {
}, setTimeout(() => {
}; debugger;
if (this.company != undefined) {
let logo_arr = [
{
id: this.company.logo.id,
name:this.company.logo.filename + "." + this.company.logo.extension,
path: this.company.logo.path,
type: this.company.logo.mime_type,
size: this.company.logo.size,
downloadPath: false,
},
];
this.logo.push(logo_arr);
this.real_date = this.company.financial_start;
}
}, 500);
},
watch: {
company: function (company) {
let logo_arr = [
{
id: company.logo.id,
name: company.logo.filename + "." + company.logo.extension,
path: company.logo.path,
type: company.logo.mime_type,
size: company.logo.size,
downloadPath: false,
},
];
this.logo.push(logo_arr);
this.real_date = company.financial_start;
},
}, },
methods: { methods: {
next() { next() {
if (this.active++ > 2); if (this.active++ > 2);
this.$router.push("/wizard/currencies"); this.$router.push("/wizard/currencies");
}, },
onEditSave() { onEditSave() {
this.onEditEvent("PATCH", url + "/wizard/companies", '', '', ''); this.onEditEvent("PATCH", url + "/wizard/company", "", "", "");
this.$router.push("/wizard/currencies"); this.$router.push("/wizard/currencies");
} },
}, },
}; };
</script> </script>

View File

@ -7,7 +7,7 @@
<div class="card"> <div class="card">
<div class="card-header wizard-header p-3"> <div class="card-header wizard-header p-3">
<el-steps :active="active" finish-status="success" align-center> <el-steps :active="active" finish-status="success" align-center>
<el-step :title="translations.companies.title"></el-step> <el-step :title="translations.company.title"></el-step>
<el-step :title="translations.currencies.title"></el-step> <el-step :title="translations.currencies.title"></el-step>
<el-step :title="translations.taxes.title"></el-step> <el-step :title="translations.taxes.title"></el-step>
<el-step :title="translations.finish.title"></el-step> <el-step :title="translations.finish.title"></el-step>

View File

@ -4,7 +4,7 @@
<div class="card"> <div class="card">
<div class="card-header wizard-header p-3"> <div class="card-header wizard-header p-3">
<el-steps :active="active" finish-status="success" align-center> <el-steps :active="active" finish-status="success" align-center>
<el-step :title="translations.companies.title"></el-step> <el-step :title="translations.company.title"></el-step>
<el-step :title="translations.currencies.title"></el-step> <el-step :title="translations.currencies.title"></el-step>
<el-step :title="translations.taxes.title"></el-step> <el-step :title="translations.taxes.title"></el-step>
<el-step :title="translations.finish.title"></el-step> <el-step :title="translations.finish.title"></el-step>

View File

@ -4,7 +4,7 @@
<div class="card"> <div class="card">
<div class="card-header wizard-header p-3"> <div class="card-header wizard-header p-3">
<el-steps :active="active" finish-status="success" align-center> <el-steps :active="active" finish-status="success" align-center>
<el-step :title="translations.companies.title"></el-step> <el-step :title="translations.company.title"></el-step>
<el-step :title="translations.currencies.title"></el-step> <el-step :title="translations.currencies.title"></el-step>
<el-step :title="translations.taxes.title"></el-step> <el-step :title="translations.taxes.title"></el-step>
<el-step :title="translations.finish.title"></el-step> <el-step :title="translations.finish.title"></el-step>

View File

@ -1,25 +1,28 @@
<html> <html>
@include('partials.wizard.head') @include('partials.wizard.head')
<body class="wizard-page"> <body class="wizard-page">
<div class="container mt--5"> <div class="container mt--5">
@stack('body_start') @stack('body_start')
<div id="app"> <div id="app">
<div class="card-body"> <div class="card-body">
<div class="document-loading" v-if="!page_loaded"> <div class="document-loading" v-if="!page_loaded">
<div><i class="fas fa-spinner fa-pulse fa-7x"></i></div> <div>
</div> <i class="fas fa-spinner fa-pulse fa-7x"></i>
@include('flash::message') </div>
</div>
@yield('content') @include('flash::message')
</div>
</div>
</div> @yield('content')
</div>
</div>
@include('partials.wizard.scripts') </div>
</body>
@include('partials.wizard.scripts')
</body>
</html> </html>

View File

@ -1,22 +0,0 @@
@stack('content_start')
@stack('content_header_start')
<h1 class="text-white">
@yield('title')
@yield('new_button')
</h1>
@stack('content_header_end')
@stack('content_content_start')
@yield('content')
@stack('content_content_end')
<notifications></notifications>
<form id="form-dynamic-component" method="POST" action="#"></form>
<component v-bind:is="component"></component>
@stack('content_end')

View File

@ -1,14 +0,0 @@
@stack('pagination_start')
@if ($items->firstItem())
<div class="pull-left">
<small>{{ trans('pagination.showing', ['first' => $items->firstItem(), 'last' => $items->lastItem(), 'total' => $items->total(), 'type' => strtolower(trans_choice('general.' . $type, 2))]) }}</small>
</div>
<div class="pull-right">
{!! $items->withPath(request()->url())->withQueryString()->links() !!}
</div>
@else
<div class="pull-left">
<small>{{ trans('general.no_records') }}</small>
</div>
@endif
@stack('pagination_end')

View File

@ -10,7 +10,6 @@ use Illuminate\Support\Facades\Route;
Route::group(['as' => 'wizard.'], function () { Route::group(['as' => 'wizard.'], function () {
Route::get('data', 'Wizard\Data@index')->name('data.index'); Route::get('data', 'Wizard\Data@index')->name('data.index');
Route::get('translations', 'Wizard\Translations@index')->name('translations.index');
Route::get('companies', 'Wizard\Companies@edit')->name('companies.edit'); Route::get('companies', 'Wizard\Companies@edit')->name('companies.edit');
Route::patch('companies', 'Wizard\Companies@update')->name('companies.update'); Route::patch('companies', 'Wizard\Companies@update')->name('companies.update');