Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0] fix: Issue #1691 fixed. #1717

Open
wants to merge 2 commits into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/Webkul/Activity/src/Models/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +18,8 @@ class ActivityController extends Controller
*/
public function __construct(
protected ActivityRepository $activityRepository,
protected EmailRepository $emailRepository
protected EmailRepository $emailRepository,
protected AttachmentRepository $attachmentRepository
) {}

/**
Expand All @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class="cursor-pointer font-medium hover:underline dark:text-white"

<div class="flex w-full items-center justify-between">
<label
class="icon-attachment cursor-pointer rounded-md p-1 text-2xl transition-all hover:bg-gray-200"
class="icon-attachment cursor-pointer p-1 text-2xl hover:rounded-md hover:bg-gray-100 dark:hover:bg-gray-950"
for="file-upload"
></label>

Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
:placeholder="$attribute->name"
:url="$url"
:allow-edit="$allowEdit"
:value-label="$lookUpEntity?->name ?? '--'"
/>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<x-admin::form.control-group.controls.inline.text
type="inline"
::name="'{{ $attribute->code }}'"
:value="$value"
:value="$value ?? ''"
:value-label="$value == '' ? '--' : $value"
position="left"
rules="required"
:label="$attribute->name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,32 @@ class="icon-edit rounded-md p-1 text-2xl transition-all hover:bg-gray-100 dark:h

@if ($person->organization->address)
<div class="flex flex-col gap-0.5 dark:text-white">
<span>
{{ $person->organization->address['address'] }}
</span>
@isset($person->organization->address['address'])
<span>
{{ $person->organization->address['address'] }}
</span>
@endisset

<span>
{{ $person->organization->address['postcode'] . ' ' . $person->organization->address['city'] }}
</span>
@if(
isset($person->organization->address['postcode'])
&& isset($person->organization->address['city'])
)
<span>
{{ $person->organization->address['postcode'] . ' ' . $person->organization->address['city'] }}
</span>
@endif

<span>
{{ core()->state_name($person->organization->address['state']) }}
</span>
@isset($person->organization->address['state'])
<span>
{{ core()->state_name($person->organization->address['state']) }}
</span>
@endisset

<span>
{{ core()->country_name($person->organization->address['country']) }}
</span>
@isset($person->organization->address['country'])
<span>
{{ core()->country_name($person->organization->address['country']) }}
</span>
@endisset
</div>
@endif

Expand Down
29 changes: 29 additions & 0 deletions packages/Webkul/Email/src/Models/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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();
}
}
Loading