Edit submissions file issue (#373)

* Edit submissions file issue fixed

* handleCompValChange with loader

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala 2024-04-15 18:42:36 +05:30 committed by GitHub
parent 4f4f7128fa
commit e1faba8239
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 82 additions and 54 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Forms;
use App\Http\Controllers\Controller;
use App\Http\Requests\AnswerFormRequest;
use App\Http\Resources\FormResource;
use App\Http\Resources\FormSubmissionResource;
use App\Jobs\Form\StoreFormSubmissionJob;
use App\Models\Forms\Form;
use App\Models\Forms\FormSubmission;
@ -112,7 +113,8 @@ class PublicFormController extends Controller
]);
}
$submission = FormSubmission::findOrFail($submissionId);
$submission = new FormSubmissionResource(FormSubmission::findOrFail($submissionId));
$submission->publiclyAccessed();
if ($submission->form_id != $form->id) {
return $this->error([
@ -120,6 +122,6 @@ class PublicFormController extends Controller
], 403);
}
return $this->success(['data' => ($submission) ? $submission->data : []]);
return $this->success($submission->toArray($request));
}
}

View File

@ -6,6 +6,8 @@ use Illuminate\Http\Resources\Json\JsonResource;
class FormSubmissionResource extends JsonResource
{
public bool $publiclyAccessed = false;
/**
* Transform the resource into an array.
*
@ -15,13 +17,23 @@ class FormSubmissionResource extends JsonResource
public function toArray($request)
{
$this->generateFileLinks();
$this->addExtraData();
return [
'data' => $this->data,
if (!$this->publiclyAccessed) {
$this->addExtraData();
}
return array_merge([
'data' => $this->data
], ($this->publiclyAccessed) ? [] : [
'form_id' => $this->form_id,
'id' => $this->id,
];
'id' => $this->id
]);
}
public function publiclyAccessed($publiclyAccessed = true)
{
$this->publiclyAccessed = $publiclyAccessed;
return $this;
}
private function addExtraData()

View File

@ -121,7 +121,8 @@ class StoreFormSubmissionJob implements ShouldQueue
if (
($field['type'] == 'url' && isset($field['file_upload']) && $field['file_upload'])
|| $field['type'] == 'files') {
|| $field['type'] == 'files'
) {
if (is_array($answerValue)) {
$finalData[$field['id']] = [];
foreach ($answerValue as $file) {
@ -179,7 +180,7 @@ class StoreFormSubmissionJob implements ShouldQueue
}
if (filter_var($value, FILTER_VALIDATE_URL) !== false && str_contains($value, parse_url(config('app.url'))['host'])) { // In case of prefill we have full url so convert to s3
$fileName = basename($value);
$fileName = explode('?', basename($value))[0];
$path = FormController::ASSETS_UPLOAD_PATH . '/' . $fileName;
$newPath = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $this->form->id);
Storage::move($path, $newPath . '/' . $fileName);

View File

@ -129,10 +129,24 @@ export default {
handler(files) {
this.compVal = files.map((file) => file.url)
}
},
'compVal': {
deep: true,
handler(newVal, oldVal) {
if (!oldVal) {
this.handleCompValChange();
}
}
}
},
async created() {
mounted() {
this.handleCompValChange();
},
methods: {
async handleCompValChange() {
this.loading = true
if (typeof this.compVal === 'string' || this.compVal instanceof String) {
await this.getFileFromUrl(this.compVal).then((fileObj) => {
this.files = [{
@ -147,16 +161,15 @@ export default {
await this.getFileFromUrl(this.compVal[i]).then((fileObj) => {
tmpFiles.push({
file: fileObj,
url: this.compVal[i],
url: (typeof this.compVal[i] === 'object') ? this.compVal[i]?.file_url : this.compVal[i],
src: this.getFileSrc(fileObj)
})
})
}
this.files = tmpFiles
}
this.loading = false
},
methods: {
clearAll() {
this.files = []
},