aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/src/components/pdp/Pdp.vue
blob: 3aba3fed23d8e3d97a8f7db5c31796ecc8b157f0 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<template>
  <div class="">
    <template v-if="edit">
      <form>
        <div class="form-group">
          <label for="pdpName">Name</label>
          <input
            type="text"
            name="name"
            v-model="pdpEdit.name"
            v-validate="'alpha_dash|required|min:3'"
            class="form-control"
            id="pdpName"
          >
        </div>
        <div class="form-group">
          <label for="pdpDescription">Description</label>
          <textarea
            name="description"
            v-model="pdpEdit.description"
            v-validate="'required|min:3'"
            class="form-control"
            id="pdpDescription"
          ></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="updatePdp()">Update</button>
      </form>
    </template>
    <template v-else>
      <div>
        <h3 class="list-group-item-heading inline">{{ pdp.name }}</h3>
        <div class="pull-right">
          <button
            type="button"
            class="fa fa-trash btn btn-dark btn-sm"
            @click="removePdp(pdp)"
            title="Remove PDP"
          ></button>
          <button
            type="button"
            class="fa fa-edit btn btn-dark btn-sm"
            @click="updatingPdp(pdp)"
            title="Edit PDP"
          ></button>
        </div>
        <p class="list-group-item-text">{{ pdp.description }}</p>
        <h4 class="list-group-item-text">
          <div v-if="!changeProject">
            Project: {{ pdp.project ? pdp.project : 'none' }}
            <button
              type="button"
              class="fa fa-edit btn btn-dark btn-sm"
              @click="changingProject()"
              title="Change project"
            ></button>
          </div>
          <form class="form-inline" v-else>
            <label for="projectId">Project ID: </label>
            &nbsp;
            <input
              type="text"
              name="id"
              v-model="project"
              class="form-control"
              id="projectId"
            >
            &nbsp;
            <button type="button" class="btn btn-secondary" @click="changeProject = false">Cancel</button>
            <span>&nbsp;</span>
            <button
              type="button"
              class="btn btn-primary"
              @click="setProject()"
            >OK</button>
          </form>
        </h4>

        <UpdatePolicy v-if="updatePolicy" :pdp="pdp" @close="updatePolicy = false"></UpdatePolicy>
        <details class="list-group-item-text" v-else>
          <summary>
            <h4 class="inline">
              {{ pdp.security_pipeline.length }} {{ (pdp.security_pipeline.length > 1) ? "policies" : "policy"}}
            </h4>
            <button
              type="button"
              class="fa fa-edit  btn btn-dark btn-sm"
              @click="updatePolicy = true"
              title="Change Policy"
            ></button>
          </summary>
          <div class="list-group">
            <div
              v-for="policy in pdp.security_pipeline" :key="policy.id"
            >
              <h3 class="list-group-item-heading inline">{{ policy.name }}</h3>
             <!--<button
                type="button"
                class="fa fa-trash pull-right btn btn-dark btn-sm"
                @click="removePolicyFromPdp(policy)"
                title="Remove Policy"
              ></button>-->
              <p class="list-group-item-text">{{ policy.description }}</p>
            </div>
          </div>
        </details>
      </div>
    </template>
    <hr>
  </div>
</template>

<script>
import PdpService from './../../services/Pdp.service.js';
//import AddPolicy from "./AddPolicy.vue";
import UpdatePolicy from "./UpdatePolicy";
import util from "./../../services/Util.service.js";

export default {
  name: "pdp",
  data: function() {
    return {
      edit: false,
      updatePolicy: false,
      changeProject: false,
      project: "",
      pdpEdit: {}
    };
  },
  props: {
    pdp: Object
  },
  components: {
    //AddPolicy
    UpdatePolicy
  },
  methods: {
    changingProject() {
      this.project = this.pdp.project;
      this.changeProject = true;
    },
    removePdp() {
      if (confirm('Are you sure to delete this PDP?'))
        PdpService.removePdp(this.pdp);
    },
    updatingPdp() {
      this.pdpEdit = util.clone(this.pdp);
      this.edit = true;
    },
    updatePdp() {
      this.edit = false;
      PdpService.updatePdp(this.pdpEdit);
    },
    removePolicyFromPdp(policy) {
      if (confirm('Are you sure to remove this Policy from PDP?')) {
        //var pdpCopy = util.clone(this.pdp);
        this.pdp.security_pipeline.splice(this.pdp.security_pipeline.indexOf(policy), 1);
        PdpService.updatePdp(this.pdp);
      }
    },
    setProject() {
      var pdpCopy = util.clone(this.pdp);
      pdpCopy.project = this.project;
      PdpService.updatePdp(pdpCopy);
      this.changeProject = false;
    }
  }
};
</script>