From 7b163998e2d2bf78751340567047e9334dc3c9e7 Mon Sep 17 00:00:00 2001 From: Suraj Kashyap Date: Thu, 7 Nov 2024 17:00:43 +0530 Subject: [PATCH] Issue #1691 fixed. --- packages/Webkul/Activity/src/Models/File.php | 12 +++++ .../Contact/Persons/ActivityController.php | 51 +++++++++++++++++-- .../Controllers/Lead/ActivityController.php | 1 + .../Http/Controllers/Mail/EmailController.php | 5 +- .../Resources/EmailAttachmentResource.php | 1 + .../activities/actions/mail.blade.php | 4 +- .../attributes/view/lookup.blade.php | 1 + .../components/attributes/view/text.blade.php | 3 +- .../persons/view/organization.blade.php | 35 ++++++++----- .../Webkul/Email/src/Models/Attachment.php | 29 +++++++++++ 10 files changed, 122 insertions(+), 20 deletions(-) diff --git a/packages/Webkul/Activity/src/Models/File.php b/packages/Webkul/Activity/src/Models/File.php index 7d1db3127..27a87fa82 100644 --- a/packages/Webkul/Activity/src/Models/File.php +++ b/packages/Webkul/Activity/src/Models/File.php @@ -8,8 +8,20 @@ class File extends Model implements FileContract { + /** + * The table associated with the model. + * + * @var string + */ protected $table = 'activity_files'; + /** + * The attributes that should be appended to the model. + * + * @var array + */ + protected $appends = ['url']; + /** * The attributes that are mass assignable. * diff --git a/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php b/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php index 66822141c..49292c5e8 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/ActivityController.php @@ -2,9 +2,11 @@ namespace Webkul\Admin\Http\Controllers\Contact\Persons; +use Illuminate\Support\Facades\DB; use Webkul\Activity\Repositories\ActivityRepository; use Webkul\Admin\Http\Controllers\Controller; use Webkul\Admin\Http\Resources\ActivityResource; +use Webkul\Email\Repositories\AttachmentRepository; use Webkul\Email\Repositories\EmailRepository; class ActivityController extends Controller @@ -16,7 +18,8 @@ class ActivityController extends Controller */ public function __construct( protected ActivityRepository $activityRepository, - protected EmailRepository $emailRepository + protected EmailRepository $emailRepository, + protected AttachmentRepository $attachmentRepository ) {} /** @@ -32,14 +35,54 @@ public function index($id) ->where('person_activities.person_id', $id) ->get(); - return ActivityResource::collection($this->concatEmail($activities)); + return ActivityResource::collection($this->concatEmailAsActivities($id, $activities)); } /** * Store a newly created resource in storage. */ - public function concatEmail($activities) + public function concatEmailAsActivities($personId, $activities) { - return $activities->sortByDesc('id')->sortByDesc('created_at'); + $emails = DB::table('emails as child') + ->select('child.*') + ->join('emails as parent', 'child.parent_id', '=', 'parent.id') + ->where('parent.person_id', $personId) + ->union(DB::table('emails as parent')->where('parent.person_id', $personId)) + ->get(); + + return $activities->concat($emails->map(function ($email) { + return (object) [ + 'id' => $email->id, + 'parent_id' => $email->parent_id, + 'title' => $email->subject, + 'type' => 'email', + 'is_done' => 1, + 'comment' => $email->reply, + 'schedule_from' => null, + 'schedule_to' => null, + 'user' => auth()->guard('user')->user(), + 'participants' => [], + 'location' => null, + 'additional' => [ + 'folders' => json_decode($email->folders), + 'from' => json_decode($email->from), + 'to' => json_decode($email->reply_to), + 'cc' => json_decode($email->cc), + 'bcc' => json_decode($email->bcc), + ], + 'files' => $this->attachmentRepository->findWhere(['email_id' => $email->id])->map(function ($attachment) { + return (object) [ + 'id' => $attachment->id, + 'name' => $attachment->name, + 'path' => $attachment->path, + 'url' => $attachment->url, + 'created_at' => $attachment->created_at, + 'updated_at' => $attachment->updated_at, + ]; + }), + 'created_at' => $email->created_at, + 'updated_at' => $email->updated_at, + ]; + }))->sortByDesc('id')->sortByDesc('created_at'); } } diff --git a/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php b/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php index 107225118..f12e14440 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Lead/ActivityController.php @@ -75,6 +75,7 @@ public function concatEmailAsActivities($leadId, $activities) 'id' => $attachment->id, 'name' => $attachment->name, 'path' => $attachment->path, + 'url' => $attachment->url, 'created_at' => $attachment->created_at, 'updated_at' => $attachment->updated_at, ]; diff --git a/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php b/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php index 2c0008b07..8a30dc88c 100644 --- a/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Mail/EmailController.php @@ -101,8 +101,9 @@ public function view() public function store() { $this->validate(request(), [ - 'reply_to' => 'required|array|min:1', - 'reply' => 'required', + 'reply_to' => 'required|array|min:1', + 'reply_to.*' => 'email', + 'reply' => 'required', ]); Event::dispatch('email.create.before'); diff --git a/packages/Webkul/Admin/src/Http/Resources/EmailAttachmentResource.php b/packages/Webkul/Admin/src/Http/Resources/EmailAttachmentResource.php index ee736275e..85d73c194 100644 --- a/packages/Webkul/Admin/src/Http/Resources/EmailAttachmentResource.php +++ b/packages/Webkul/Admin/src/Http/Resources/EmailAttachmentResource.php @@ -18,6 +18,7 @@ public function toArray($request) 'id' => $this->id, 'name' => $this->name, 'path' => $this->path, + 'url' => $this->url, 'size' => $this->size, 'content_type' => $this->content_type, 'content_id' => $this->content_id, diff --git a/packages/Webkul/Admin/src/Resources/views/components/activities/actions/mail.blade.php b/packages/Webkul/Admin/src/Resources/views/components/activities/actions/mail.blade.php index 96083861e..34451d68f 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/activities/actions/mail.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/activities/actions/mail.blade.php @@ -199,7 +199,7 @@ class="cursor-pointer font-medium hover:underline dark:text-white"
@@ -257,6 +257,8 @@ class="primary-button" }, save(params, { resetForm, setErrors }) { + this.isStoring = true; + let formData = new FormData(this.$refs.mailActionForm); this.$axios.post("{{ route('admin.leads.emails.store', 'replaceLeadId') }}".replace('replaceLeadId', this.entity.id), formData, { diff --git a/packages/Webkul/Admin/src/Resources/views/components/attributes/view/lookup.blade.php b/packages/Webkul/Admin/src/Resources/views/components/attributes/view/lookup.blade.php index 399ca7188..9fa70cb6c 100644 --- a/packages/Webkul/Admin/src/Resources/views/components/attributes/view/lookup.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/attributes/view/lookup.blade.php @@ -12,4 +12,5 @@ :placeholder="$attribute->name" :url="$url" :allow-edit="$allowEdit" + :value-label="$lookUpEntity?->name ?? '--'" /> diff --git a/packages/Webkul/Admin/src/Resources/views/components/attributes/view/text.blade.php b/packages/Webkul/Admin/src/Resources/views/components/attributes/view/text.blade.php index b66f5b87a..7c514d146 100755 --- a/packages/Webkul/Admin/src/Resources/views/components/attributes/view/text.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/components/attributes/view/text.blade.php @@ -1,7 +1,8 @@ - - {{ $person->organization->address['address'] }} - + @isset($person->organization->address['address']) + + {{ $person->organization->address['address'] }} + + @endisset - - {{ $person->organization->address['postcode'] . ' ' . $person->organization->address['city'] }} - + @if( + isset($person->organization->address['postcode']) + && isset($person->organization->address['city']) + ) + + {{ $person->organization->address['postcode'] . ' ' . $person->organization->address['city'] }} + + @endif - - {{ core()->state_name($person->organization->address['state']) }} - + @isset($person->organization->address['state']) + + {{ core()->state_name($person->organization->address['state']) }} + + @endisset - - {{ core()->country_name($person->organization->address['country']) }} - + @isset($person->organization->address['country']) + + {{ core()->country_name($person->organization->address['country']) }} + + @endisset
@endif diff --git a/packages/Webkul/Email/src/Models/Attachment.php b/packages/Webkul/Email/src/Models/Attachment.php index 8a87dd536..c3831a49f 100644 --- a/packages/Webkul/Email/src/Models/Attachment.php +++ b/packages/Webkul/Email/src/Models/Attachment.php @@ -3,12 +3,25 @@ namespace Webkul\Email\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Storage; use Webkul\Email\Contracts\Attachment as AttachmentContract; class Attachment extends Model implements AttachmentContract { + /** + * The attributes that are mass assignable. + * + * @var string + */ protected $table = 'email_attachments'; + /** + * The attributes that are appended. + * + * @var array + */ + protected $appends = ['url']; + /** * The attributes that are mass assignable. * @@ -30,4 +43,20 @@ public function email() { return $this->belongsTo(EmailProxy::modelClass()); } + + /** + * Get image url for the product image. + */ + public function url() + { + return Storage::url($this->path); + } + + /** + * Accessor for the 'url' attribute. + */ + public function getUrlAttribute() + { + return $this->url(); + } }