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

Service templates - fix rules #12587

Merged
merged 6 commits into from Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/Models/ServiceTemplate.php
Expand Up @@ -72,19 +72,19 @@ public static function boot()
});

static::saving(function (ServiceTemplate $template) {
if ($template->isDirty('drules')) {
if ($template->dtype == 'dynamic' and $template->isDirty('drules')) {
$template->drules = $template->getDeviceParser()->generateJoins()->toArray();
}
if ($template->isDirty('dgrules')) {
if ($template->dgtype == 'dynamic' and $template->isDirty('dgrules')) {
$template->dgrules = $template->getDeviceGroupParser()->generateJoins()->toArray();
}
});

static::saved(function (ServiceTemplate $template) {
if ($template->isDirty('drules')) {
if ($template->dtype == 'dynamic' and $template->isDirty('drules')) {
$template->updateDevices();
}
if ($template->isDirty('dgrules')) {
if ($template->dgtype == 'dynamic' and $template->isDirty('dgrules')) {
$template->updateGroups();
}
});
Expand All @@ -98,7 +98,7 @@ public static function boot()
public function updateDevices()
{
if ($this->dtype == 'dynamic') {
$this->devices()->sync(QueryBuilderFluentParser::fromJSON($this->rules)->toQuery()
$this->devices()->sync(QueryBuilderFluentParser::fromJSON($this->drules)->toQuery()
->distinct()->pluck('devices.device_id'));
}
}
Expand All @@ -109,7 +109,7 @@ public function updateDevices()
public function updateGroups()
{
if ($this->dgtype == 'dynamic') {
$this->groups()->sync(QueryBuilderFluentParser::fromJSON($this->rules)->toQuery()
$this->groups()->sync(QueryBuilderFluentParser::fromJSON($this->dgrules)->toQuery()
->distinct()->pluck('device_groups.id'));
}
}
Expand Down
8 changes: 2 additions & 6 deletions resources/views/service-template/form.blade.php
Expand Up @@ -253,19 +253,15 @@ function change_st_dgtype(select) {
}
});
$('.service-template-form').submit(function (eventObj) {
if ($('#dtype').val() === 'static') {
return true;
} else {
if ($('#dtype').val() === 'dynamic') {
$('<input type="hidden" name="drules" />')
.attr('value', JSON.stringify(builder.queryBuilder('getRules')))
.appendTo(this);
if (!builder.queryBuilder('validate')) {
return false;
}
}
if ($('#dgtype').val() === 'static') {
return true;
} else {
if ($('#dgtype').val() === 'dynamic') {
$('<input type="hidden" name="dgrules" />')
.attr('value', JSON.stringify(builder2.queryBuilder('getRules')))
.appendTo(this);
Expand Down