automatic rule creation

This commit is contained in:
vabene1111 2021-09-15 14:58:55 +02:00
parent 19d1e2d456
commit dbfa27e4b9
4 changed files with 49 additions and 8 deletions

View File

@ -97,6 +97,7 @@ import GenericInfiniteCards from "@/components/GenericInfiniteCards";
import GenericHorizontalCard from "@/components/GenericHorizontalCard";
import GenericModalForm from "@/components/Modals/GenericModalForm";
import ModelMenu from "@/components/ModelMenu";
import {ApiApiFactory} from "@/utils/openapi/api";
Vue.use(BootstrapVue)
@ -179,9 +180,18 @@ export default {
this.this_action = this.Actions.MERGE
this.show_modal = true
} else {
this.mergeThis(e.source.id, e.target.id)
this.mergeThis(e.source, e.target, false)
}
break;
case 'merge-automate':
if (target == null) {
this.this_item = e.source
this.this_action = this.Actions.MERGE
this.show_modal = true
} else {
this.mergeThis(e.source, e.target, true)
}
break
case 'get-children':
if (source.show_children) {
Vue.set(source, 'show_children', false)
@ -219,7 +229,7 @@ export default {
this.saveThis(update)
break;
case this.Actions.MERGE:
this.mergeThis(this.this_item.id, e.form_data.target.id)
this.mergeThis(this.this_item, e.form_data.target, false)
break;
case this.Actions.MOVE:
this.moveThis(this.this_item.id, e.form_data.target.id)
@ -305,7 +315,9 @@ export default {
this.makeToast(this.$t('Error'), err.bodyText, 'danger')
})
},
mergeThis: function (source_id, target_id) {
mergeThis: function (source, target, automate) {
let source_id = source.id
let target_id = target.id
if (source_id === target_id) {
this.makeToast(this.$t('Error'), this.$t('Cannot merge item with itself'), 'danger')
this.clearState()
@ -331,6 +343,28 @@ export default {
this.makeToast(this.$t('Error'), err.bodyText, 'danger')
})
if (automate){
let apiClient = new ApiApiFactory()
let automation = {
name: `Merge ${source.name} with ${target.name}`,
param_1: source.name,
param_2: target.id
}
if (this.this_model === this.Models.FOOD){
automation.type = 'FOOD_ALIAS'
}
if (this.this_model === this.Models.UNIT){
automation.type = 'UNIT_ALIAS'
}
if (this.this_model === this.Models.KEYWORD){
automation.type = 'KEYWORD_ALIAS'
}
apiClient.createAutomation(automation)
}
},
getChildren: function (col, item) {
let parent = {}

View File

@ -1,6 +1,6 @@
<template>
<span>
<b-dropdown variant="link" toggle-class="text-decoration-none" no-caret style="boundary:window">
<b-dropdown variant="link" toggle-class="text-decoration-none" right no-caret style="boundary:window">
<template #button-content>
<i class="fas fa-ellipsis-v" ></i>
</template>
@ -20,6 +20,10 @@
<i class="fas fa-compress-arrows-alt fa-fw"></i> {{ $t('Merge') }}
</b-dropdown-item>
<b-dropdown-item v-if="show_merge" v-on:click="$emit('item-action', 'merge-automate')">
<i class="fas fa-robot fa-fw"></i> {{$t('Merge')}} & {{$t('Automate')}}
</b-dropdown-item>
</b-dropdown>
</span>
</template>

View File

@ -80,13 +80,16 @@
<!-- this should be made a generic component, would also require mixin for functions that generate the popup and put in parent container-->
<b-list-group ref="tooltip" variant="light" v-show="show_menu" v-on-clickaway="closeMenu" style="z-index:9999; cursor:pointer">
<b-list-group-item v-if="useMove" action v-on:click="$emit('item-action',{'action': 'move', 'target': item, 'source': source}); closeMenu()">
<i class="fas fa-expand-arrows-alt fa-fw"></i> {{$t('Move')}}: {{$t('move_confirmation', {'child': source.name,'parent':item.name})}}
<i class="fas fa-expand-arrows-alt fa-fw"></i> <b>{{$t('Move')}}</b>: <span v-html="$t('move_confirmation', {'child': source.name,'parent':item.name})"></span>
</b-list-group-item>
<b-list-group-item v-if="useMerge" action v-on:click="$emit('item-action',{'action': 'merge', 'target': item, 'source': source}); closeMenu()">
<i class="fas fa-compress-arrows-alt fa-fw"></i> {{$t('Merge')}}: {{ $t('merge_confirmation', {'source': source.name,'target':item.name}) }}
<i class="fas fa-compress-arrows-alt fa-fw"></i> <b>{{$t('Merge')}}</b>: <span v-html="$t('merge_confirmation', {'source': source.name,'target':item.name})"></span>
</b-list-group-item>
<b-list-group-item v-if="useMerge" action v-on:click="$emit('item-action',{'action': 'merge-automate', 'target': item, 'source': source}); closeMenu()">
<i class="fas fa-robot fa-fw"></i> <b>{{$t('Merge')}} & {{$t('Automate')}}</b>: <span v-html="$t('merge_confirmation', {'source': source.name,'target':item.name})"></span> {{$t('create_rule')}}
</b-list-group-item>
<b-list-group-item action v-on:click="closeMenu()">
{{$t('Cancel')}}
<i class="fas fa-times fa-fw"></i> <b>{{$t('Cancel')}}</b>
</b-list-group-item>
<!-- TODO add to shopping list -->
<!-- TODO add to and/or manage pantry -->

View File

@ -27,7 +27,7 @@
</b-dropdown-item>
<b-dropdown-item :href="resolveDjangoUrl('list_automation')">
<i class="fas fa-cogs fa-fw"></i> {{ Models['AUTOMATION'].name }}
<i class="fas fa-robot fa-fw"></i> {{ Models['AUTOMATION'].name }}
</b-dropdown-item>
</b-dropdown>