/
PageBlocked.vue
122 lines (120 loc) · 3.8 KB
/
PageBlocked.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
<template>
<div v-if="incidents === null"><i class="fas fa-sync fa-spin"></i> Loading incidents...</div>
<div v-else-if="incidents.length > 0">
<div class="row align-items-center">
<div class="col-auto my-1">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="checkbox" v-model="groupFlavors" />
<label class="form-check-label" for="checkbox"> Group Flavors</label>
</div>
</div>
</div>
<table class="table">
<thead>
<tr>
<th>
Incident
<input
v-model="matchText"
type="text"
class="form-control"
id="inlineSearchIncidents"
title="Partial incident# or package name are matched"
placeholder="Search for incident/package"
/>
</th>
<th>
Groups
<input
v-model="groupNames"
type="text"
class="form-control"
id="inlineSearchGroups"
title="Comma separated, job group names are matched, supports regex syntax"
placeholder="Search for group names"
/>
</th>
</tr>
</thead>
<tbody>
<BlockedIncident
v-for="incident in matchedIncidents"
:key="incident.incident.number"
:incident="incident.incident"
:incident-results="incident.incident_results"
:update-results="incident.update_results"
:group-flavors="groupFlavors"
:group-names="groupNames"
/>
</tbody>
</table>
</div>
<div v-else>No active incidents, maybe take a look at <a :href="smelt">Smelt</a>.</div>
</template>
<script>
import BlockedIncident from './BlockedIncident.vue';
import * as filtering from '../helpers/filtering.js';
import Refresh from '../mixins/refresh.js';
export default {
name: 'PageBlocked',
mixins: [Refresh],
components: {BlockedIncident},
data() {
return {
incidents: null,
groupFlavors: this.$route.query.group_flavors !== '0',
matchText: this.$route.query.incident || '',
groupNames: this.$route.query.group_names || '',
refreshUrl: '/app/api/blocked'
};
},
computed: {
matchedIncidents() {
const url = new URL(location);
const searchParams = url.searchParams;
let results = this.incidents;
if (this.matchText) {
searchParams.set('incident', this.matchText);
results = this.incidents.filter(incident => {
if (String(incident.incident.number).includes(this.matchText)) return true;
for (const pack of incident.incident.packages) {
if (pack.includes(this.matchText)) return true;
}
return false;
});
} else {
searchParams.delete('incident');
}
if (this.groupNames) {
url.searchParams.set('group_names', this.groupNames);
const filters = filtering.makeGroupNamesFilters(this.groupNames);
results = results.filter(
incident =>
filtering.checkResults(incident.update_results, filters) ||
filtering.checkResults(incident.incident_results, filters)
);
} else {
searchParams.delete('group_names');
}
history.pushState({}, '', url);
return results.sort((a, b) => (b.incident.priority || 0) - (a.incident.priority || 0));
},
smelt() {
return this.appConfig.smeltUrl;
}
},
methods: {
refreshData(data) {
this.incidents = data.blocked;
}
},
watch: {
groupFlavors: function (enabled) {
const url = new URL(location);
const params = url.searchParams;
enabled ? params.delete('group_flavors') : params.set('group_flavors', '0');
history.pushState({}, '', url);
}
}
};
</script>