Merge branch 'jochen42-add-not-ready-filter'

This commit is contained in:
Henning Jacobs
2020-07-28 10:13:10 +02:00
2 changed files with 50 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
import Tooltip from './tooltip.js'
import Cluster from './cluster.js'
import {Pod, ALL_PODS, ALL_SORTS} from './pod.js'
import {Pod, ALL_PODS, ALL_SORTS, ALL_STATUS_FILTERS} from './pod.js'
import SelectBox from './selectbox'
import {Theme, ALL_THEMES} from './themes.js'
import {DESATURATION_FILTER} from './filters.js'
@@ -29,6 +29,10 @@ export default class App {
const indexSorterFn = ALL_SORTS.findIndex(obj => obj.text === (localStorage.getItem('sorterFn') || ALL_SORTS[0].text))
this.sorterFn = ALL_SORTS[indexSorterFn].value
// filterFn
const indexStatusFilterFn = ALL_STATUS_FILTERS.findIndex(obj => obj.text === (localStorage.getItem('statusFilterFn') || ALL_STATUS_FILTERS[0].text))
this.statusFilterFn = ALL_STATUS_FILTERS[indexStatusFilterFn].value
this.theme = Theme.get(localStorage.getItem('theme'))
this.eventSource = null
this.connectTime = null
@@ -102,6 +106,7 @@ export default class App {
}
}
filter() {
const searchString = this.filterString
if (this.searchText) {
@@ -124,6 +129,7 @@ export default class App {
}
}
}
filterableElements.forEach(value => {
if (!matchesQuery(value.pod)) {
value.filters = [elementDisplayFilter]
@@ -132,6 +138,12 @@ export default class App {
value.filters = []
}
})
filterableElements.forEach(value => {
if (!this.statusFilterFn(value.pod)) {
value.filters = [elementDisplayFilter]
}
})
}
initialize() {
@@ -356,6 +368,14 @@ export default class App {
themeSelector.y = 3
menuBar.addChild(themeSelector.draw())
const statusFilterBox = new SelectBox(ALL_STATUS_FILTERS, this.statusFilterFn, function (text, value) {
app.changeStatusFilter(text, value)
})
statusFilterBox.x = 585
statusFilterBox.y = 3
menuBar.addChild(statusFilterBox.draw())
this.searchText = searchText
}
@@ -560,6 +580,12 @@ export default class App {
this.update()
}
changeStatusFilter(text, newStatusFilterFunction) {
this.statusFilterFn = newStatusFilterFunction
localStorage.setItem('statusFilterFn', text)
this.update()
}
switchTheme(text, newTheme) {
this.theme = Theme.get(newTheme)
this.draw()

View File

@@ -5,6 +5,27 @@ import {BRIGHTNESS_FILTER} from './filters.js'
const ALL_PODS = {}
const showNotReady = (pod) => {
if (pod.phase == 'Succeeded') {
return false
}
for (let index = 0; index < pod.containers.length; index++) {
if (!pod.containers[index].ready) {
return true
}
}
return false
}
const ALL_STATUS_FILTERS = [
{
text: 'SHOW: All', value: function () { return true }
},
{
text: 'SHOW: NotReady', value: showNotReady
},
]
const sortByName = (a, b) => {
// https://github.com/hjacobs/kube-ops-view/issues/103
// *.name might be undefined
@@ -38,6 +59,7 @@ const sortByStatus = (a, b) => {
return (a.phase).localeCompare(b.phase)
}
const ALL_SORTS = [
{
text: 'SORT: NAME', value: sortByName
@@ -56,7 +78,7 @@ const ALL_SORTS = [
}
]
export {ALL_PODS, ALL_SORTS}
export {ALL_PODS, ALL_SORTS, ALL_STATUS_FILTERS}
export class Pod extends PIXI.Graphics {