Skip to content

Commit

Permalink
Dropzone form post edited
Browse files Browse the repository at this point in the history
  • Loading branch information
brkcvn committed May 26, 2021
1 parent 7adb8c9 commit 93ba76e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 49 deletions.
10 changes: 3 additions & 7 deletions app/Http/Controllers/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Settings extends Controller
{
use DateTime, Uploads;

public $skip_keys = ['company_id', '_method', '_token', '_prefix'];
public $skip_keys = ['company_id', '_method', '_token', '_prefix', 'uploaded_logo'];

public $file_keys = ['company.logo', 'invoice.logo'];

Expand Down Expand Up @@ -113,10 +113,6 @@ public function update(Request $request)
}

if ($real_key == 'default.locale') {
if (!in_array($value, config('language.allowed'))) {
continue;
}

user()->setAttribute('locale', $value)->save();
}

Expand Down Expand Up @@ -160,10 +156,10 @@ protected function oneCompany($real_key, $value)
Installer::updateEnv(['MAIL_FROM_NAME' => '"' . $value . '"']);
break;
case 'company.email':
Installer::updateEnv(['MAIL_FROM_ADDRESS' => '"' . $value . '"']);
Installer::updateEnv(['MAIL_FROM_ADDRESS' => $value]);
break;
case 'default.locale':
Installer::updateEnv(['APP_LOCALE' => '"' . $value . '"']);
Installer::updateEnv(['APP_LOCALE' => $value]);
break;
case 'schedule.time':
Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']);
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Wizard/Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function update(Request $request)

$fields = $request->all();

$skip_keys = ['company_id', '_method', '_token'];
$skip_keys = ['company_id', '_method', '_token', 'uploaded_logo'];
$file_keys = ['company.logo'];

foreach ($fields as $key => $value) {
Expand All @@ -70,13 +70,13 @@ public function update(Request $request)
$real_key = 'company.' . $key;
}

// Process file uploads
if (in_array($real_key, $file_keys)) {
// Process file uploads
if (in_array($real_key, $file_keys)) {
// Upload attachment
if ($request->file($key)) {
$media = $this->getMedia($request->file($key), 'settings');

$company->attachMedia($media, Str::snake($key));
$company->attachMedia($media, Str::snake($real_key));

$value = $media->id;
}
Expand All @@ -87,7 +87,7 @@ public function update(Request $request)
}
}

setting()->set($real_key, $value);
setting()->set($real_key, $value);
}

// Save all settings
Expand Down
2 changes: 1 addition & 1 deletion resources/assets/js/mixins/spa-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default {
file = this.$refs.dropzoneWizard.files[0];
}
}

if(plus_data == 'logo') {
Object.assign(data, {
['logo']: file
Expand Down
62 changes: 27 additions & 35 deletions resources/assets/js/views/wizard/Company.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@
</div>
<div class="col-6">
<base-input :label="translations.company.logo">
<akaunting-dropzone-file-upload
ref="dropzoneWizard"
preview-classes="single"
:attachments="logo"
>
</akaunting-dropzone-file-upload>
<akaunting-dropzone-file-upload
ref="dropzoneWizard"
preview-classes="single"
:attachments="logo"
>
</akaunting-dropzone-file-upload>
</base-input>
</div>
</div>
Expand Down Expand Up @@ -127,52 +127,44 @@ export default {
return {
active: 0,
logo: [],
real_date: ''
};
real_date: "",
};
},
mounted() {
let company_data = this.company;
setTimeout(() => {
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;
}
this.dataWatch(company_data);
}, 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.dataWatch(company);
},
},
methods: {
dataWatch(company) {
if(Object.keys(company).length) {
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: {
next() {
if (this.active++ > 2);
this.$router.push("/wizard/currencies");
},
onEditSave() {
this.onEditEvent("PATCH", url + "/wizard/company", "logo", "", "");
this.onEditEvent("PATCH", url + "/wizard/companies", "logo", "", "");
this.$router.push("/wizard/currencies");
},
},
Expand Down
2 changes: 1 addition & 1 deletion routes/wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Route::get('data', 'Wizard\Data@index')->name('data.index');

Route::get('companies', 'Wizard\Companies@edit')->name('companies.edit');
Route::patch('companies', 'Wizard\Companies@update')->name('companies.update');
Route::patch('companies', 'Wizard\Companies@update')->middleware('dropzone')->name('companies.update');

Route::get('currencies/{currency}/enable', 'Settings\Currencies@enable')->name('currencies.enable');
Route::get('currencies/{currency}/disable', 'Settings\Currencies@disable')->name('currencies.disable');
Expand Down

0 comments on commit 93ba76e

Please sign in to comment.