Skip to content

Commit

Permalink
Merge pull request Silvanite#63 from SGS-Optimisation/main
Browse files Browse the repository at this point in the history
rule filter fixes and tag sorting in pm section
  • Loading branch information
yayann authored Jul 14, 2021
2 parents 59e3956 + 80015dd commit d6f9386
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ yarn-error.log
.phpstorm.meta.php
_ide_helper.php
ERD.png
.DS_Store
12 changes: 10 additions & 2 deletions app/Http/Controllers/OPs/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public function show(Request $request, $jobNumber)
}

return $request->wantsJson() ?
new JsonResponse(['rules' => $rules, 'job' => $job], 200)
new JsonResponse([
'rules' => $rules,
'job' => $job,
'processing_mysgs' => $job->metadata->processing_mysgs,
'error_mysgs' => $job->metadata->error_mysgs,
], 200)
: Jetstream::inertia()->render($request, 'OP/JobRules', [
'team' => $request->user()->currentTeam,
'jobNumber' => $jobNumber,
Expand All @@ -44,7 +49,10 @@ public function status(Request $request, $jobNumber)
{
$job = JobRepository::findByJobNumber($jobNumber);

return new JsonResponse(['processing_mysgs' => $job->metadata->processing_mysgs] );
return new JsonResponse([
'processing_mysgs' => $job->metadata->processing_mysgs,
'error_mysgs' => $job->metadata->error_mysgs,
]);
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function boot()
'createRules', 'updateRules', 'deleteRules', 'publishRules',
'createClientAccounts', 'updateClientAccounts', 'deleteClientAccounts',
'accessPM',
'accessBackend',
'viewTaxonomies', 'manageTaxonomies',
'viewTerms', 'manageTerms',
'viewFieldMappings', 'manageFieldMappings',
Expand Down
14 changes: 11 additions & 3 deletions app/Repositories/JobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Events\Jobs\NewJobSearched;
use App\Listeners\Jobs\LoadMySgsData;
use App\Models\Job;
use Carbon\Carbon;

class JobRepository
{
Expand All @@ -31,10 +32,17 @@ public static function findByJobNumber($job_number)

if (!$job) {
$job = static::createFromJobNumber($job_number);
// TODO: check if not better to dispatch loading of data instead of using of queued events
event(new NewJobSearched($job));

} elseif ($job->metadata->processing_mysgs) {
}
elseif ($job->metadata->error_mysgs
&& $job->created_at->lessThan(Carbon::now()->subMinute())
) {
logger($job_number . ' was in error, should prune and recreate');
$job->delete();
$job = static::createFromJobNumber($job_number);
event(new NewJobSearched($job));
}
elseif ($job->metadata->processing_mysgs) {
logger($job_number . ' still processing');
}

Expand Down
13 changes: 8 additions & 5 deletions app/Services/Rule/RuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ function ($job, $mapping) {
$term->taxonomy->name, $termValue, print_r($mysgsValue_single, true))
);*/
if (!(Str::is($termValue, Str::lower($mysgsValue_single))
|| (isset($term->config['aliases'])
&& in_array( Str::lower($mysgsValue_single),
array_map('Str::lower', $term->config['aliases']))
|| (
isset($term->config['aliases'])
&& in_array(
Str::lower($mysgsValue_single),
array_map('Str::lower', $term->config['aliases'])
)
)
)) {
/*logger(sprintf('rule %s dropped, term %s did not match with %s',
Expand All @@ -133,9 +136,9 @@ function ($job, $mapping) {
}
}

$taxonomyMatch = true;
$taxonomyMatch = false;
foreach ($matchedTaxonomies as $taxonomy => $state) {
$taxonomyMatch &= $state;
$taxonomyMatch |= $state;
}

if ($matched || $taxonomyMatch) {
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=4752df63d0f7559df6dc",
"/js/app.js": "/js/app.js?id=922b7a912e769ab9037b",
"/css/app.css": "/css/app.css?id=407231647b0a43e928b4"
}
5 changes: 4 additions & 1 deletion resources/js/Components/PM/Rules/RuleTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
export default {
name: "RuleTag",
props: [
'taxonomy',
'terms',
],
data: function () {
Expand All @@ -53,6 +52,10 @@ export default {
computed: {
taxonomy() {
return this.terms[0].taxonomy.name;
},
shouldTruncate() {
return this.terms.length > 4;
},
Expand Down
38 changes: 34 additions & 4 deletions resources/js/Components/PM/Rules/RuleTags.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
<template>
<div class="flex flex-wrap">
<div v-for="(taxonomyTerms, taxonomy) in _.groupBy(rule.terms, function(item){
return item.taxonomy ? item.taxonomy.name : 'ERROR';
})">
<div v-for="taxonomyTerms in sortedTaxonomyTerms">

<rule-tag :terms="taxonomyTerms" :taxonomy="taxonomy"/>
<rule-tag :terms="taxonomyTerms"/>

</div>
</div>
</template>

<script>
import RuleTag from "@/Components/PM/Rules/RuleTag";
export default {
name: "RuleTags",
components: {RuleTag},
props: ['rule'],
data: function () {
return {}
},
computed: {
termsByTaxonomy() {
return _.groupBy(this.rule.terms, function (item) {
return item.taxonomy ? item.taxonomy.name : 'ERROR';
})
},
taxonomyTerms() {
return _.values(this.termsByTaxonomy);
},
sortedTaxonomyTerms() {
return _.orderBy(
this.taxonomyTerms,
[
(termLists) => termLists[0].taxonomy.parent.name,
(termLists) => termLists.length,
(termLists) => termLists[0].taxonomy.name,
],
[
'desc',
'asc',
'asc'
]
)
}
}
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion resources/js/Layouts/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
:href="route('pm.landing')" :active="route().current('pm.landing')">
Project Manager
</jet-nav-link>
<a v-if="$page.user_permissions.viewNova"
<a v-if="$page.user_permissions.accessBackend"
class="inline-flex items-center px-1 pt-1 border-b-2 border-transparent text-sm font-medium leading-5 text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300 transition duration-150 ease-in-out"
href="/admin">Admin</a>
</div>
Expand Down
10 changes: 8 additions & 2 deletions resources/js/Pages/OP/JobRules.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,20 @@ export default {
axios.get(route('job.rules', this.jobNumber))
.then(({data}) => {
console.log(data);
if (!data.job.metadata.processing_mysgs) {
if (!data.job.metadata.processing_mysgs && !data.job.metadata.error_mysgs) {
clearTimeout(this.timeOut);
this.currentJob = data.job;
this.currentRules = data.rules;
this.newRulesLoaded();
this.initRulesParsing();
} else {
} else if(data.job.metadata.error_mysgs){
this.currentJob = data.job;
this.currentJob.metadata.error_mysgs = data.job.metadata.error_mysgs;
console.log('mysgs error, halt');
clearTimeout(this.timeOut);
}
else{
this.waitMode();
}
})
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"viewNova": "Access Admin",
"viewNova": "View Backoffice [required for file uploads]",
"viewRoles": "View Roles",
"manageRoles": "Manage Roles",
"assignRoles": "Assign Roles",
Expand All @@ -17,6 +17,7 @@
"deleteClientAccounts": "Delete Client Accounts",

"accessPM": "Access Project Manager Section",
"accessBackend": "Manage Resources in Backend",
"manageFieldMappings": "Manage Field Mappings",
"manageSettings": "Manage Settings",
"manageTaxonomies": "Manage Taxonomies",
Expand Down

0 comments on commit d6f9386

Please sign in to comment.