aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/src/components/model/Metarule.vue
blob: 1cb266bd982b3524b51d10b74ded96415a5716d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
  <div class="">
    <template v-if="edit">
      <form>
        <div class="form-group">
          <label for="metaruleName">Name</label>
          <input
            type="text"
            name="name"
            v-model="metaruleEdit.name"
            v-validate="'alpha_dash|required|min:3'"
            class="form-control"
            id="metaruleName"
          >
        </div>
        <div class="form-group">
          <label for="modelDescription">Description</label>
          <textarea
            name="description"
            v-model="metaruleEdit.description"
            v-validate="'required|min:3'"
            class="form-control"
          ></textarea>
        </div>
        <ul>
          <li v-for="error in errors.all()" :key="error.id">{{ error }}</li>
        </ul>
        <button type="button" class="btn btn-secondary" @click="edit = false">Cancel</button>
        <span>&nbsp;</span>
        <button type="button" :disabled="errors.any()" class="btn btn-primary" @click="updateMetarule()">Update</button>
      </form>
    </template>
    <template v-else>
      <h3 class="list-group-item-heading inline">{{ metarule.name }}</h3>
      <div class="pull-right">
        <button
          type="button"
          class="fa fa-trash btn btn-dark btn-sm"
          @click="removeMetarule()"
          title="Remove Meta Rule"
        ></button>
        <button
          type="button"
          class="fa fa-edit btn btn-dark btn-sm"
          @click="updatingMetarule()"
          title="Edit Meta Rule"
        ></button>
      </div>
      <p class="list-group-item-text">{{ metarule.description }}</p>
      <p class="list-group-item-text"></p>
      <table class="table categories">
        <thead>
          <tr>
            <th>
              <span>Subjects</span>
              <i class="fa fa-question-circle" style="margin-left: 2%" v-if="metaruleHelpStrings.subject" data-toggle="tooltip"  :title="metaruleHelpStrings.subject"></i>
              <button
                type="button"
                class="fa fa-plus pull-right btn btn-dark btn-sm"
                @click="addSubjectCategory = true"
                title="Add Subject"
              ></button>
            </th>
            <th>
              <span>Objects</span>
              <i class="fa fa-question-circle" style="margin-left: 2%" v-if="metaruleHelpStrings.object" data-toggle="tooltip"  :title="metaruleHelpStrings.object"></i>
              <button
                type="button"
                class="fa fa-plus pull-right btn btn-dark btn-sm"
                @click="addObjectCategory = true"
                title="Add Object"
              ></button>
            </th>
            <th>
              <span>Actions</span>
              <i class="fa fa-question-circle" style="margin-left: 2%" v-if="metaruleHelpStrings.action" data-toggle="tooltip"  :title="metaruleHelpStrings.action"></i>
              <button
                type="button"
                class="fa fa-plus pull-right btn btn-dark btn-sm"
                @click="addActionCategory = true"
                title="Add Action"
              ></button>
            </th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>
              <AddCategory v-if="addSubjectCategory" :metarule="metarule" type="subject" @close="addSubjectCategory = false"></AddCategory>
              <Category v-else v-for="category in metarule.subject_categories" :key="category.id" :category="category" :metarule="metarule" :attributes="metarule.subjectAttributes" type="subject"></Category>
            </td>
            <td>
              <AddCategory v-if="addObjectCategory" :metarule="metarule" type="object" @close="addObjectCategory = false"></AddCategory>
              <Category v-else v-for="category in metarule.object_categories" :key="category.id" :category="category" :metarule="metarule" :attributes="metarule.objectAttributes" type="object"></Category>
            </td>
            <td>
              <AddCategory v-if="addActionCategory" :metarule="metarule" type="action" @close="addActionCategory = false"></AddCategory>
              <Category v-else v-for="category in metarule.action_categories" :key="category.id" :category="category" :metarule="metarule" :attributes="metarule.actionAttributes" type="action"></Category>
            </td>
          </tr>
        </tbody>
      </table>
    </template>
  </div>
</template>

<script>
import Category from './Category.vue'
import AddCategory from './AddCategory.vue'
import ModelService from "./../../services/Model.service.js";
import util from "./../../services/Util.service.js";
import helpstrings from "../../helpstrings";

export default {
  name: "metarule",
  data: function() {
    return {
      edit: false,
      metaruleEdit: {},
      addSubjectCategory: false,
      addObjectCategory: false,
      addActionCategory: false,
      metaruleHelpStrings: {}
    };
  },
  components: {
    Category, 
    AddCategory
  },
  props: {
    metarule: Object,
    model: Object,
  },
  mounted() {
    this.metaruleHelpStrings = helpstrings.metarule;
  },
  methods: {
    updatingMetarule() {
      this.metaruleEdit = util.clone(this.metarule);
      this.edit = true;
    },
    updateMetarule() {
      this.edit = false;
      ModelService.updateMetaRule(this.metaruleEdit);
    },
    removeMetarule() {
      if (confirm('Are you sure to remove this Meta Rule from model?')) {
        var modelCopy = util.clone(this.model);
        modelCopy.meta_rules.splice(modelCopy.meta_rules.indexOf(this.metarule), 1);
        ModelService.updateModel(modelCopy);
      }
    }
  }
};
</script>