Merge branch 'new-ui' of https://github.com/JhumanJ/OpnForm into new-ui

This commit is contained in:
JhumanJ 2022-11-16 11:20:53 +01:00
commit 0ce0a1dcc1
6 changed files with 41 additions and 3 deletions

View File

@ -58,7 +58,8 @@ class FormResource extends JsonResource
'is_closed' => $this->is_closed, 'is_closed' => $this->is_closed,
'is_password_protected' => false, 'is_password_protected' => false,
'has_password' => $this->has_password, 'has_password' => $this->has_password,
'max_number_of_submissions_reached' => $this->max_number_of_submissions_reached 'max_number_of_submissions_reached' => $this->max_number_of_submissions_reached,
'form_pending_submission_key' => $this->form_pending_submission_key
]); ]);
} }

View File

@ -166,6 +166,14 @@ class Form extends Model
return ($this->closes_at && now()->gt($this->closes_at)); return ($this->closes_at && now()->gt($this->closes_at));
} }
public function getFormPendingSubmissionKeyAttribute()
{
if ($this->updated_at?->timestamp) {
return "openform-" . $this->id . "-pending-submission-" . substr($this->updated_at?->timestamp, -6);
}
return null;
}
public function getMaxNumberOfSubmissionsReachedAttribute() public function getMaxNumberOfSubmissionsReachedAttribute()
{ {
return ($this->max_submissions_count && $this->max_submissions_count <= $this->submissions_count); return ($this->max_submissions_count && $this->max_submissions_count <= $this->submissions_count);

View File

@ -29,7 +29,8 @@ class StorageFileNameParser
public function getMovedFileName(): ?string public function getMovedFileName(): ?string
{ {
if ($this->fileName && $this->extension) { if ($this->fileName && $this->extension) {
return substr($this->fileName,0,50).'_'.$this->uuid.'.'.$this->extension; $fileName = substr($this->fileName, 0, 50).'_'.$this->uuid.'.'.$this->extension;
return mb_convert_encoding($fileName, 'UTF-8', 'UTF-8');
} }
return $this->uuid; return $this->uuid;
} }

View File

@ -191,6 +191,9 @@ export default {
workspace_id: this.form.workspace_id, workspace_id: this.form.workspace_id,
form_id: this.form.id form_id: this.form.id
}) })
window.localStorage.removeItem(this.form.form_pending_submission_Key)
if (response.data.redirect && response.data.redirect_url) { if (response.data.redirect && response.data.redirect_url) {
window.location.href = response.data.redirect_url window.location.href = response.data.redirect_url
} }

View File

@ -217,7 +217,15 @@ export default {
handler () { handler () {
this.formVersionId++ this.formVersionId++
} }
},
dataForm: {
deep: true,
handler () {
if(this.isPublicFormPage && this.form && this.dataFormValue){
window.localStorage.setItem(this.form.form_pending_submission_Key, JSON.stringify(this.dataFormValue))
} }
}
},
}, },
mounted () { mounted () {
@ -266,6 +274,14 @@ export default {
} }
}, },
initForm () { initForm () {
if (this.isPublicFormPage) {
const pendingData = window.localStorage.getItem(this.form.form_pending_submission_Key)
if(pendingData !== null && pendingData){
this.dataForm = new Form(JSON.parse(pendingData))
return
}
}
const formData = clonedeep(this.dataForm ? this.dataForm.data() : {}) const formData = clonedeep(this.dataForm ? this.dataForm.data() : {})
let urlPrefill = null let urlPrefill = null
if (this.isPublicFormPage && this.form.is_pro) { if (this.isPublicFormPage && this.form.is_pro) {

View File

@ -25,3 +25,12 @@ it('can parse filenames', function () {
expect($parsedFilename->getMovedFileName())->toBeNull(); expect($parsedFilename->getMovedFileName())->toBeNull();
}); });
it('can handles non-utf characters', function () {
$fileName = 'Образец_для_заполнения_85e16d7b-58ed-43bc-8dce-7d3ff7d69f41.png';
$parsedFilename = \App\Service\Storage\StorageFileNameParser::parse($fileName);
expect($parsedFilename->fileName)->toBe('Образец_для_заполнения');
expect($parsedFilename->uuid)->toBe('85e16d7b-58ed-43bc-8dce-7d3ff7d69f41');
expect($parsedFilename->extension)->toBe('png');
expect($parsedFilename->getMovedFileName())->toBe($fileName);
});