Skip to content

Commit

Permalink
Added Migrations and added API for search.
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-webkul committed Jan 2, 2025
1 parent bc6fadc commit c97c7f8
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('activity_participants', function (Blueprint $table) {
$table->string('organization_id')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('activity_participants', function (Blueprint $table) {
$table->dropColumn('organization_id');
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public function create(array $data)
]);
}

foreach ($data['participants']['organizations'] ?? [] as $userId) {
$activity->participants()->create([
'user_id' => $userId,
]);
}

return $activity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Prettus\Repository\Criteria\RequestCriteria;
use Webkul\Admin\DataGrids\Contact\OrganizationDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\AttributeForm;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Resources\OrganizationResource;
use Webkul\Contact\Repositories\OrganizationRepository;

class OrganizationController extends Controller
Expand Down Expand Up @@ -96,6 +99,24 @@ public function update(AttributeForm $request, int $id): RedirectResponse
return redirect()->route('admin.contacts.organizations.index');
}

/**
* Search person results.
*/
public function search(): JsonResource
{
if ($userIds = bouncer()->getAuthorizedUserIds()) {
$organization = $this->organizationRepository
->pushCriteria(app(RequestCriteria::class))
->findWhereIn('user_id', $userIds);
} else {
$organization = $this->organizationRepository
->pushCriteria(app(RequestCriteria::class))
->all();
}

return OrganizationResource::collection($organization);
}

/**
* Remove the specified resource from storage.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class="flex h-[74px] w-[84px] flex-col items-center justify-center gap-1 rounded
{!! view_render_event('admin.components.activities.actions.activity.after') !!}
</div>


@pushOnce('scripts')
<script type="text/x-template" id="v-activity-template">
<Teleport to="body">
Expand Down Expand Up @@ -129,7 +128,8 @@ class="flex h-[74px] w-[84px] flex-col items-center justify-center gap-1 rounded
@lang('admin::app.components.activities.actions.activity.participants.title')
</x-admin::form.control-group.label>

<x-admin::activities.actions.activity.participants />
<x-admin::activities.actions.activity.participants :entity="$entity->getTable()" />

</x-admin::form.control-group>

<!-- Schedule Date -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{!! view_render_event('admin.components.activities.actions.activity.participants.before') !!}

<!-- Participants Vue Component -->
<v-activity-participants></v-activity-participants>
<v-activity-participants :entity='@json($entity)'></v-activity-participants>

{!! view_render_event('admin.components.activities.actions.activity.participants.after') !!}

Expand All @@ -14,7 +14,7 @@ class="relative rounded border border-gray-200 px-2 py-1 hover:border-gray-400 f
role="button"
>
<ul class="flex flex-wrap items-center gap-1">
<template v-for="userType in ['users', 'persons']">
<template v-for="userType in ['users', 'persons', 'organizations']">
{!! view_render_event('admin.components.activities.actions.activity.participants.user_type.before') !!}

<li
Expand Down Expand Up @@ -59,7 +59,7 @@ class="w-full px-1 py-1 dark:bg-gray-900 dark:text-gray-300"
</ul>

<div>
<template v-if="! isSearching.users && ! isSearching.persons">
<template v-if="! isSearching.users && ! isSearching.persons && ! isSearching.organizations">
<span
class="absolute right-1.5 top-1.5 text-2xl"
:class="[searchTerm.length >= 2 ? 'icon-up-arrow' : 'icon-down-arrow']"
Expand All @@ -80,10 +80,10 @@ class="absolute z-10 w-full rounded bg-white shadow-[0px_10px_20px_0px_#0000001F
v-if="searchTerm.length >= 2"
>
<ul class="flex flex-col gap-1 p-2">
<!-- Users -->
<!-- Users, Persons, and Organizations -->
<li
class="flex flex-col gap-2"
v-for="userType in ['users', 'persons']"
v-for="userType in ['users', 'persons', 'organizations']"
>
{!! view_render_event('admin.components.activities.actions.activity.participants.dropdown.user_type.before') !!}

Expand All @@ -92,6 +92,10 @@ class="flex flex-col gap-2"
@lang('admin::app.components.activities.actions.activity.participants.users')
</template>

<template v-else-if="userType === 'organizations'">
@lang('admin::app.components.activities.actions.activity.participants.organizations')
</template>

<template v-else>
@lang('admin::app.components.activities.actions.activity.participants.persons')
</template>
Expand Down Expand Up @@ -140,8 +144,15 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
users: [],
persons: [],
organizations: [],
})
}
},
entity: {
type: String,
default: '',
},
},
data: function () {
Expand All @@ -150,6 +161,8 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
users: false,
persons: false,
organizations: false,
},
searchTerm: '',
Expand All @@ -158,18 +171,24 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
users: [],
persons: [],
organizations: [],
},
searchedParticipants: {
users: [],
persons: [],
organizations: [],
},
searchEnpoints: {
users: "{{ route('admin.settings.users.search') }}",
persons: "{{ route('admin.contacts.persons.search') }}",
organizations: "{{ route('admin.contacts.organizations.search') }}",
},
}
},
Expand All @@ -179,6 +198,8 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
this.search('users');
this.search('persons');
this.search('organizations');
},
},
Expand All @@ -199,16 +220,16 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
this.isSearching[userType] = true;
let self = this;
this.$axios.get(this.searchEnpoints[userType], {
params: {
search: 'name:' + this.searchTerm,
searchFields: 'name:like',
}
})
.then (function(response) {
self.addedParticipants[userType].forEach(function(addedParticipant) {
response.data.data = response.data.data.filter(function(participant) {
.then(function (response) {
self.addedParticipants[userType].forEach(function (addedParticipant) {
response.data.data = response.data.data.filter(function (participant) {
return participant.id !== addedParticipant.id;
});
});
Expand All @@ -217,7 +238,7 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
self.isSearching[userType] = false;
})
.catch (function (error) {
.catch(function (error) {
self.isSearching[userType] = false;
});
},
Expand All @@ -229,17 +250,17 @@ class="cursor-pointer rounded-sm px-3 py-2 text-sm text-gray-800 hover:bg-gray-1
this.searchedParticipants = {
users: [],
persons: [],
organizations: [],
};
},
remove(userType, participant) {
this.addedParticipants[userType] = this.addedParticipants[userType].filter(function(addedParticipant) {
this.addedParticipants[userType] = this.addedParticipants[userType].filter(function (addedParticipant) {
return addedParticipant.id !== participant.id;
});
},
},
}
});
</script>
@endPushOnce
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,6 @@
<div class="flex flex-wrap gap-2">
{!! view_render_event('admin.contact.organizations.view.actions.before', ['organization' => $organization]) !!}

<!-- Mail Activity Action -->
<x-admin::activities.actions.mail
:entity="$organization"
entity-control-name="organization_id"
/>

<!-- File Activity Action -->
<x-admin::activities.actions.file
:entity="$organization"
entity-control-name="organization_id"
/>

<!-- Note Activity Action -->
<x-admin::activities.actions.note
:entity="$organization"
entity-control-name="organization_id"
/>

<!-- Activity Action -->
<x-admin::activities.actions.activity
:entity="$organization"
Expand All @@ -77,7 +59,13 @@
{!! view_render_event('admin.contact.organizations.view.right.before', ['organization' => $organization]) !!}

<!-- Stages Navigation -->
<x-admin::activities :endpoint="route('admin.contacts.organizations.activities.index', $organization->id)" />
<x-admin::activities
:endpoint="route('admin.contacts.organizations.activities.index', $organization->id)"
:types="[
['name' => 'all', 'label' => trans('admin::app.products.view.all')],
['name' => 'system', 'label' => trans('admin::app.products.view.change-logs')],
]"
></x-admin::activities>

{!! view_render_event('admin.contact.organizations.view.right.after', ['organization' => $organization]) !!}
</div>
Expand Down
2 changes: 2 additions & 0 deletions packages/Webkul/Admin/src/Routes/Admin/contacts-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

Route::delete('{id}', 'destroy')->name('admin.contacts.organizations.delete');

Route::get('search', 'search')->name('admin.contacts.organizations.search');

Route::put('mass-destroy', 'massDestroy')->name('admin.contacts.organizations.mass_delete');

/**
Expand Down

0 comments on commit c97c7f8

Please sign in to comment.