Skip to content

Commit

Permalink
Merge pull request #123 from devaslanphp/dev
Browse files Browse the repository at this point in the history
Project - Company integration
  • Loading branch information
heloufir authored Sep 30, 2022
2 parents e08af44 + f49470c commit b59c085
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 14 deletions.
16 changes: 12 additions & 4 deletions app/Http/Livewire/Kanban.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ protected function records(): Collection
if (auth()->user()->can('View own tickets') && !auth()->user()->can('View all tickets')) {
$query->where(function ($query) {
$query->where('owner_id', auth()->user()->id)
->orWhere('responsible_id', auth()->user()->id);
->orWhere('responsible_id', auth()->user()->id)
->orWhereHas('project', function ($query) {
$query->whereHas('company', function ($query) {
$query->whereIn('companies.id', auth()->user()->ownCompanies->pluck('id')->toArray());
});
});
});
}
return $query->get()
Expand All @@ -55,15 +60,18 @@ protected function records(): Collection
<div class="w-full flex items-center gap-2">
' . ($type ? '
<div title="' . $type['title'] . '"
class="text-xs rounded-full w-6 h-6 flex items-center justify-center text-center"
style="color: ' . $type->text_color . '; background-color: ' . $type->bg_color . ';"
class="text-xs rounded-full w-6 h-6 flex items-center
justify-center text-center"
style="color: ' . $type->text_color . ';
background-color: ' . $type->bg_color . ';"
>
<i class="fa ' . $type['icon'] . '"></i>
</div>
' : '') . '
' . ($priority ? '
<div title="' . $priority['title'] . '"
class="text-xs rounded-full w-6 h-6 flex items-center justify-center text-center"
class="text-xs rounded-full w-6 h-6 flex items-center
justify-center text-center"
style="
color: ' . $priority->text_color . ';
background-color: ' . $priority->bg_color . ';
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Livewire/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class="' . $btnClass . '"
UserColumn::make('owner')
->label(__('Owner')),

TextColumn::make('company.name')
->label(__('Company'))
->sortable()
->searchable(),

TextColumn::make('tickets_count')
->label(__('Tickets'))
->sortable(),
Expand Down
47 changes: 40 additions & 7 deletions app/Http/Livewire/ProjectsDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace App\Http\Livewire;

use App\Core\CrudDialogHelper;
use App\Models\Company;
use App\Models\Project;
use App\Models\User;
use App\Notifications\ProjectCreatedNotification;
use Closure;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;
use Livewire\Component;

Expand All @@ -32,6 +33,7 @@ public function mount(): void
'ticket_prefix' => $this->project->ticket_prefix,
'description' => $this->project->description,
'owner_id' => $this->project->owner_id ?? auth()->user()->id,
'company_id' => $this->project->company_id
]);
}

Expand All @@ -48,11 +50,40 @@ public function render()
protected function getFormSchema(): array
{
return [
Select::make('owner_id')
->label(__('Owner'))
->required()
->searchable()
->options(User::all()->pluck('name', 'id')),
Grid::make()
->schema([
Select::make('owner_id')
->label(__('Owner'))
->required()
->searchable()
->reactive()
->options(function () {
$query = User::query();
if (auth()->user()->can('View company users') && !auth()->user()->can('View all users')) {
$query->whereHas(
'companies',
fn($query) => $query->whereIn(
'companies.id',
auth()->user()->ownCompanies->pluck('id')->toArray()
)
)->orWhere('id', auth()->user()->id);
}
return $query->get()->pluck('name', 'id')->toArray();
}),

Select::make('company_id')
->label(__('Company'))
->searchable()
->options(function (Closure $get) {
$query = Company::query();
if ($get('owner_id')) {
$query->where('responsible_id', $get('owner_id'));
} elseif (auth()->user()->can('View own companies')) {
$query->where('responsible_id', auth()->user()->id);
}
return $query->get()->pluck('name', 'id')->toArray();
}),
]),

Grid::make(3)
->schema([
Expand Down Expand Up @@ -92,7 +123,8 @@ public function save(): void
'name' => $data['name'],
'description' => $data['description'],
'owner_id' => $data['owner_id'],
'ticket_prefix' => $data['ticket_prefix']
'ticket_prefix' => $data['ticket_prefix'],
'company_id' => $data['company_id'],
]);
Notification::make()
->success()
Expand All @@ -103,6 +135,7 @@ public function save(): void
$this->project->name = $data['name'];
$this->project->description = $data['description'];
$this->project->owner_id = $data['owner_id'];
$this->project->company_id = $data['company_id'];
$this->project->ticket_prefix = $data['ticket_prefix'];
$this->project->save();
Notification::make()
Expand Down
7 changes: 6 additions & 1 deletion app/Http/Livewire/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ public function render()
if (auth()->user()->can('View own tickets') && !auth()->user()->can('View all tickets')) {
$query->where(function ($query) {
$query->where('owner_id', auth()->user()->id)
->orWhere('responsible_id', auth()->user()->id);
->orWhere('responsible_id', auth()->user()->id)
->orWhereHas('project', function ($query) {
$query->whereHas('company', function ($query) {
$query->whereIn('companies.id', auth()->user()->ownCompanies->pluck('id')->toArray());
});
});
});
}
if ($this->activeMenu === 'Unassigned') {
Expand Down
8 changes: 7 additions & 1 deletion app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Project extends Model implements HasLogsActivity
'name',
'description',
'owner_id',
'ticket_prefix'
'ticket_prefix',
'company_id'
];

protected static function boot()
Expand All @@ -36,6 +37,11 @@ public function owner(): BelongsTo
return $this->belongsTo(User::class, 'owner_id')->withTrashed();
}

public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}

public function tickets(): HasMany
{
return $this->hasMany(Ticket::class);
Expand Down
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('projects', function (Blueprint $table) {
$table->foreignId('company_id')->nullable()->constrained('companies');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('projects', function (Blueprint $table) {
$table->dropForeign(['company_id']);
$table->dropColumn('company_id');
});
}
};
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Help Desk is a Laravel based project, that let you manage your support tickets a

> Help Desk is based on the latest version of Laravel and any other Open Source packages and technologies.
- **Current version:** *v1.4.6*
- **Current version:** *v1.4.7*
- **Last update:** *30 September, 2022*

## Features
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

See what's new added, changed, fixed, improved or updated in the latest versions.

- **Version 1.4.7** *(30 September, 2022)*
- Project - Company integration

- **Version 1.4.6** *(30 September, 2022)*
- Bug-fix: assign all roles

Expand Down
1 change: 1 addition & 0 deletions lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"Type a message..": "Tapez un message..",
"Send": "Envoyer",
"No messages yet!": "Aucun message pour le moment !",
"Company": "Entreprise",
"Company name": "Nom de l'entreprise",
"Logo": "Logo",
"Companies": "Entreprises",
Expand Down

0 comments on commit b59c085

Please sign in to comment.