Skip to content

Commit

Permalink
feat: adding search in service view (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmriBarZik authored Jun 18, 2021
1 parent d3efbf8 commit f997bd5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/widgetsTemplates/list.widget.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class myWidget extends baseWidget(EventEmitter) {
searchInput.on('keypress', (data) => {
this.filterList(data)
})

searchInput.on('exitSearch', () => {
this.focus()
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion widgets/searchInput.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class myWidget extends baseWidget(EventEmitter) {
this.widget.clearValue()
this.inputValue = []
this.widget.destroy()
this.widgetsRepo.get('containerList').focus()
this.emit('exitSearch')
} else {
this.emit('keypress', this.captureText(key))
}
Expand Down
31 changes: 31 additions & 0 deletions widgets/services/servicesList.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
const ListWidget = require('../../src/widgetsTemplates/list.widget.template')

class myWidget extends ListWidget {
constructor ({ blessed = {}, contrib = {}, screen = {}, grid = {} }) {
super({ blessed, contrib, screen, grid })
this.servicesListData = []
}

getLabel () {
return 'Services'
}
Expand All @@ -23,6 +28,30 @@ class myWidget extends ListWidget {
this.utilsRepo.get('docker').listServices(cb)
}

filterList (data) {
let filteredContainersList = this.servicesListData[0]
let serviceList = this.servicesListData.slice(1)
let filteredServices = []

if (data) {
filteredServices = serviceList.filter((service) => {
const serviceName = service[1]
const serviceImageName = service[2]

if ((serviceName.indexOf(data) !== -1) || (serviceImageName.indexOf(data) !== -1)) {
return true
}
})
}

if (filteredServices.length > 0) {
filteredServices.unshift(filteredContainersList)
this.update(filteredServices)
} else {
this.update(this.servicesListData)
}
}

formatList (services) {
const list = []

Expand All @@ -39,6 +68,8 @@ class myWidget extends ListWidget {

list.unshift(['Id', 'Name', 'Image', 'Replicas'])

this.servicesListData = list

return list
}

Expand Down
4 changes: 4 additions & 0 deletions widgets/toolbar.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class myWidget extends baseWidget(EventEmitter) {
'copy id': {
keys: ['c'],
callback: () => { this.emit('key', 'c') }
},
'search': {
keys: ['/'],
callback: () => { this.emit('key', '/') }
}
}

Expand Down

0 comments on commit f997bd5

Please sign in to comment.