-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathRulePacks.vue
209 lines (199 loc) · 5.57 KB
/
RulePacks.vue
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
<div>
<!-- Page Title -->
<div class="col-md-2 pt-2 text-left page-title">
<h3><small class="text-nowrap">RULEPACKS</small></h3>
</div>
<!-- Spinner -->
<Spinner :active="spinnerActive" />
<div class="ml-3">
<!-- Import button to upload rulepack -->
<b-button
class="float-left mt-2 mb-2"
variant="prime"
size="sm"
@click="showRulePackUploadModal()"
>IMPORT</b-button
>
<!-- RulePackUpload Modal -->
<RulePackUploadModal
ref="rulePackUploadModal"
@on-file-upload-suceess="onRulePackUploadSuccess"
/>
</div>
<!--Rule Packs Table -->
<div v-if="!hasRecords" class="text-center cursor-default">
<br />
<br />No Record Found...
</div>
<div class="p-3" v-if="hasRecords">
<b-table
id="rule-packs-table"
sticky-header="85vh"
:items="rulePackList"
:fields="fields"
:current-page="currentPage"
:per-page="0"
primary-key="version"
v-model="currentItems"
responsive
small
head-variant="light"
>
<!-- Version Column -->
<template #cell(version)="data">
{{ data.item.version }}
</template>
<!-- Active Column -->
<template #cell(active)="data">
<font-awesome-icon
v-if="data.item.active"
icon="check-circle"
:style="{ color: 'green' }"
/>
<font-awesome-icon v-if="!data.item.active" icon="check-circle" class="disabled-button" />
</template>
<!-- Download Column -->
<template #cell(download)="data">
<font-awesome-icon
icon="download"
class="download-button"
@click="downloadRulePack(data.item.version)"
/>
</template>
</b-table>
<!-- Pagination -->
<Pagination
:currentPage="currentPage"
:perPage="perPage"
:totalRows="totalRows"
:pageSizes="pageSizes"
:requestedPageNumber="requestedPageNumber"
@page-click="handlePageClick"
@page-size-change="handlePageSizeChange"
></Pagination>
</div>
</div>
</template>
<script>
import AxiosConfig from '@/configuration/axios-config.js';
import Config from '@/configuration/config';
import DateUtils from '@/utils/date-utils';
import Spinner from '@/components/Common/Spinner.vue';
import RulePackUploadModal from '@/components/RulePack/RulePackUploadModal.vue';
import Pagination from '@/components/Common/Pagination.vue';
import RulePackService from '@/services/rule-pack-service';
import spinnerMixin from '@/mixins/spinner.js';
export default {
name: 'RulePacks',
mixins: [spinnerMixin],
data() {
return {
rulePackList: [],
currentItems: [],
totalRows: 0,
currentPage: 1,
perPage: Number(`${Config.value('defaultPageSize')}`),
pageSizes: [20, 50, 100],
requestedPageNumber: 1,
fields: [
{
key: 'version',
sortable: true,
label: 'Version',
class: 'text-left position-sticky',
thStyle: { borderTop: '0px' },
},
{
key: 'active',
sortable: true,
label: 'Active',
class: 'text-left position-sticky',
thStyle: { borderTop: '0px' },
},
{
key: 'created',
sortable: true,
label: 'Created',
class: 'text-left position-sticky',
thStyle: { borderTop: '0px' },
formatter: 'formatDate',
},
{
key: 'download',
sortable: false,
label: 'Download',
class: 'text-left position-sticky',
thStyle: { borderTop: '0px' },
},
],
};
},
computed: {
hasRecords() {
return this.rulePackList.length > 0;
},
},
methods: {
handlePageClick(page) {
this.currentPage = page;
this.fetchPaginatedRulePacks();
},
handlePageSizeChange(pageSize) {
this.perPage = Number(pageSize);
this.currentPage = 1;
this.fetchPaginatedRulePacks();
},
showRulePackUploadModal() {
this.$refs.rulePackUploadModal.show();
},
onRulePackUploadSuccess() {
this.fetchPaginatedRulePacks();
},
fetchPaginatedRulePacks() {
this.showSpinner();
RulePackService.getRulePackVersions()
.then((response) => {
this.rulePackList = response.data.data;
this.totalRows = response.data.total;
this.hideSpinner();
})
.catch((error) => {
AxiosConfig.handleError(error);
});
},
forceFileDownload(response, title) {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', title);
document.body.appendChild(link);
link.click();
},
downloadRulePack(rulePackVersion) {
this.showSpinner();
const title = `RESC-SECRETS-RULE_v${rulePackVersion}.TOML`;
RulePackService.downloadRulePack(rulePackVersion)
.then((response) => {
this.forceFileDownload(response, title);
this.hideSpinner();
})
.catch((error) => {
AxiosConfig.handleError(error);
});
},
formatDate(timestamp) {
const date = DateUtils.formatDate(timestamp);
return timestamp ? date : 'Not Scanned';
},
},
created() {
this.fetchPaginatedRulePacks();
},
components: {
Pagination,
RulePackUploadModal,
Spinner,
},
};
</script>