Skip to content

Commit

Permalink
Merge pull request Silvanite#38 from SGS-Optimisation/feature/job-search
Browse files Browse the repository at this point in the history
Feature/job search
  • Loading branch information
yayann authored Mar 30, 2021
2 parents 5580d27 + 09528cd commit 4ef4202
Show file tree
Hide file tree
Showing 26 changed files with 781 additions and 239 deletions.
41 changes: 41 additions & 0 deletions app/Events/Jobs/NewJobSearched.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Events\Jobs;

use App\Models\Job;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class NewJobSearched
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* @var Job
*/
public $mysgs_job;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Job $mysgs_job)
{
$this->mysgs_job = $mysgs_job;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
24 changes: 24 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Controllers;

use App\Services\Job\JobApiHandler;
use App\Services\Rule\RuleFilter;
use Illuminate\Http\Request;
use Laravel\Jetstream\Jetstream;

class HomeController extends Controller
{
/**
* Display a listing of the resource.
*
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Inertia\Response
*/
public function index(Request $request)
{
return Jetstream::inertia()->render($request, 'Dashboard', [
'team' => $request->user()->currentTeam,
]);
}
}
62 changes: 33 additions & 29 deletions app/Http/Controllers/OPs/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,60 @@
namespace App\Http\Controllers\OPs;

use App\Http\Controllers\Controller;
use App\Repositories\JobRepository;
use App\Services\Job\JobApiHandler;
use App\Services\Rule\RuleFilter;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Laravel\Jetstream\Jetstream;

class JobController extends Controller
{

/**
* Display a listing of the resource.
* Display rules relevant for a job.
*
* @param Request $request
* @param null $jobNumber
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Inertia\Response
* @param Request $request
* @param null $jobNumber
* @return JsonResponse|\Inertia\Response
*/
public function show(Request $request, $jobNumber = null)
public function show(Request $request, $jobNumber)
{
$rules = [];
$job = null;

if($jobNumber){
$job = JobApiHandler::handle($jobNumber, 'basicDetails');
if ($job) {
$rules = RuleFilter::handle($job);
}
//$job = JobApiHandler::handle($jobNumber, 'basicDetails');

$job = JobRepository::findByJobNumber($jobNumber);

if (!$job->metadata->processing_mysgs) {
logger('already loaded mysgs data');
$rules = RuleFilter::handle($job);
}
return Jetstream::inertia()->render($request, ($job ? 'OP/JobRules' : 'Dashboard'), [
'team' => $request->user()->currentTeam,
'jobNumber' => $jobNumber,
'job' => $job,
'rules' => $rules
]);



return $request->wantsJson() ?
new JsonResponse(['rules' => $rules, 'job' => $job], 200)
: Jetstream::inertia()->render($request, 'OP/JobRules', [
'team' => $request->user()->currentTeam,
'jobNumber' => $jobNumber,
'job' => $job,
'rules' => $rules
]);
}

/**
* Display a listing of the resource.
* Helper to redirect to show.
*
* @param Request $request
* @param null $jobNumber
* @return \Illuminate\Http\JsonResponse
* @param Request $request
* @param null $jobNumber
* @return RedirectResponse
*/
public function search(Request $request, $jobNumber)
{
$rules = [];
if($jobNumber) {
$job = JobApiHandler::handle($jobNumber, 'basicDetails');
if ($job) {
$rules = RuleFilter::handle($job);
}
}
return response()->json($rules);
return \Redirect::route('job.rules', [$jobNumber]);
}
}
75 changes: 75 additions & 0 deletions app/Listeners/Jobs/LoadMySgsData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace App\Listeners\Jobs;

use App\Events\Jobs\NewJobSearched;
use App\Models\Job;
use App\Services\MySgs\DataLoader;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class LoadMySgsData implements ShouldQueue, ShouldBeUnique
{

use InteractsWithQueue, Queueable;

/**
* @var Job
*/
public $mysgs_job;

/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{

}

/**
* Handle the event.
*
* @param NewJobSearched $event
* @return void
*/
public function handle($event)
{
$this->mysgs_job = $event->mysgs_job;

logger('handling job '.$this->mysgs_job->job_number);

DataLoader::handle($this->mysgs_job);
}

/**
* The unique ID of the job.
*
* @return string
*/
public function uniqueId()
{
return $this->mysgs_job->id;
}

/**
* @param $event
* @param \Exception|null $exception
*/
public function failed($event, $exception)
{
\Log::error('loading mysgs data failed');
\Log::error($exception->getMessage());
\Log::error($exception->getTraceAsString());
$job_metadata = $event->mysgs_job->metadata;
$job_metadata->error_mysgs = true;
$event->mysgs_job->metadata = $job_metadata;

$event->mysgs_job->save();
}
}
4 changes: 4 additions & 0 deletions app/Models/ClientAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
* @method static \Illuminate\Database\Eloquent\Builder|ClientAccount whereLegacyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ClientAccount whereUpdatedAt($value)
* @mixin \Eloquent
* @property string|null $legacy_id
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Rule[] $rules
* @property-read int|null $rules_count
* @property-read \App\Models\Team|null $team
*/
class ClientAccount extends Model
{
Expand Down
23 changes: 23 additions & 0 deletions app/Models/FieldMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,31 @@

/**
* Class FieldMapping
*
* @package App\Models
* @mixin \Eloquent
* @property int $id
* @property string $api_name
* @property string|null $api_version
* @property string $api_action
* @property string $field_path
* @property string|null $resolver_name
* @property int $taxonomy_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Taxonomy $taxonomy
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping query()
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereApiAction($value)
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereApiName($value)
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereApiVersion($value)
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereFieldPath($value)
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereResolverName($value)
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereTaxonomyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|FieldMapping whereUpdatedAt($value)
*/
class FieldMapping extends Model
{
Expand Down
22 changes: 22 additions & 0 deletions app/Models/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
* App\Models\Job
*
* @property int $id
* @property string $job_number
* @property string|null $designation
* @property object|null $metadata
* @property string|null $deleted_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|Job newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Job newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Job query()
* @method static \Illuminate\Database\Eloquent\Builder|Job whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Job whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Job whereDesignation($value)
* @method static \Illuminate\Database\Eloquent\Builder|Job whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Job whereJobNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|Job whereMetadata($value)
* @method static \Illuminate\Database\Eloquent\Builder|Job whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Job extends Model
{
use HasFactory;
Expand Down
18 changes: 18 additions & 0 deletions app/Models/MysgsClientAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
* App\Models\MysgsClientAccount
*
* @property int $id
* @property string $name
* @property string|null $alias
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|MysgsClientAccount newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|MysgsClientAccount newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|MysgsClientAccount query()
* @method static \Illuminate\Database\Eloquent\Builder|MysgsClientAccount whereAlias($value)
* @method static \Illuminate\Database\Eloquent\Builder|MysgsClientAccount whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|MysgsClientAccount whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|MysgsClientAccount whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|MysgsClientAccount whereUpdatedAt($value)
* @mixin \Eloquent
*/
class MysgsClientAccount extends Model
{
use HasFactory;
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
* @method static \Illuminate\Database\Query\Builder|Rule withTrashed()
* @method static \Illuminate\Database\Query\Builder|Rule withoutTrashed()
* @mixin \Eloquent
* @property-read \Illuminate\Database\Eloquent\Collection|\OwenIt\Auditing\Models\Audit[] $audits
* @property-read int|null $audits_count
*/
class Rule extends Model implements Auditable
{
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
* @method static \Illuminate\Database\Query\Builder|Taxonomy withTrashed()
* @method static \Illuminate\Database\Query\Builder|Taxonomy withoutTrashed()
* @mixin \Eloquent
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ClientAccount[] $client_accounts
* @property-read \App\Models\FieldMapping|null $mapping
*/
class Taxonomy extends Model
{
Expand All @@ -63,6 +65,8 @@ class Taxonomy extends Model

protected $with = ['parent'];

protected $appends = ['requiresMapping'];


/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
Expand Down Expand Up @@ -103,4 +107,9 @@ public function mapping()
{
return $this->hasOne(FieldMapping::class);
}

public function getRequiresMappingAttribute()
{
return $this->parent && $this->parent->name == 'Account Structure';
}
}
4 changes: 4 additions & 0 deletions app/Models/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
* @method static \Illuminate\Database\Eloquent\Builder|Term whereTaxonomyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Term whereUpdatedAt($value)
* @mixin \Eloquent
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Rule[] $rules
* @property-read int|null $rules_count
* @method static \Illuminate\Database\Eloquent\Builder|Term whereDeletedAt($value)
*/
class Term extends Model
{
Expand Down
7 changes: 7 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
* @method static \Illuminate\Database\Eloquent\Builder|User whereTwoFactorSecret($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
* @mixin \Eloquent
* @property string|null $azure_id
* @property-read \Illuminate\Database\Eloquent\Collection|\OwenIt\Auditing\Models\Audit[] $audits
* @property-read int|null $audits_count
* @property-read \Illuminate\Database\Eloquent\Collection|\Silvanite\Brandenburg\Role[] $roles
* @property-read int|null $roles_count
* @method static \Illuminate\Database\Eloquent\Builder|User whereAzureId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User withRoles()
*/
class User extends Authenticatable implements Auditable
{
Expand Down
Loading

0 comments on commit 4ef4202

Please sign in to comment.