Add cancel button to restore previously saved rule

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-11-19 09:53:56 +01:00
parent ce6aed8667
commit caad94142f
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
1 changed files with 15 additions and 4 deletions

View File

@ -36,10 +36,10 @@
@click="saveRule"> @click="saveRule">
{{ ruleStatus.title }} {{ ruleStatus.title }}
</button> </button>
<button v-if="rule.id < -1" @click="cancelRule"> <button v-if="rule.id < -1 || dirty" @click="cancelRule">
{{ t('workflowengine', 'Cancel') }} {{ t('workflowengine', 'Cancel') }}
</button> </button>
<button v-else @click="deleteRule"> <button v-else-if="!dirty" @click="deleteRule">
{{ t('workflowengine', 'Delete') }} {{ t('workflowengine', 'Delete') }}
</button> </button>
</div> </div>
@ -75,7 +75,8 @@ export default {
checks: [], checks: [],
error: null, error: null,
dirty: this.rule.id < 0, dirty: this.rule.id < 0,
checking: false checking: false,
originalRule: null
} }
}, },
computed: { computed: {
@ -101,6 +102,9 @@ export default {
return typeof lastCheck === 'undefined' || lastCheck.class !== null return typeof lastCheck === 'undefined' || lastCheck.class !== null
} }
}, },
mounted() {
this.originalRule = JSON.parse(JSON.stringify(this.rule))
},
methods: { methods: {
async updateOperation(operation) { async updateOperation(operation) {
this.$set(this.rule, 'operation', operation) this.$set(this.rule, 'operation', operation)
@ -128,6 +132,7 @@ export default {
await this.$store.dispatch('pushUpdateRule', this.rule) await this.$store.dispatch('pushUpdateRule', this.rule)
this.dirty = false this.dirty = false
this.error = null this.error = null
this.originalRule = JSON.parse(JSON.stringify(this.rule))
} catch (e) { } catch (e) {
console.error('Failed to save operation') console.error('Failed to save operation')
this.error = e.response.data.ocs.meta.message this.error = e.response.data.ocs.meta.message
@ -142,7 +147,13 @@ export default {
} }
}, },
cancelRule() { cancelRule() {
this.$store.dispatch('removeRule', this.rule) if (this.rule.id < 0) {
this.$store.dispatch('removeRule', this.rule)
} else {
this.$store.dispatch('updateRule', this.originalRule)
this.originalRule = JSON.parse(JSON.stringify(this.rule))
this.dirty = false
}
}, },
async removeCheck(check) { async removeCheck(check) {
const index = this.rule.checks.findIndex(item => item === check) const index = this.rule.checks.findIndex(item => item === check)