Skip to content

Commit

Permalink
Filter(js): Add hour, minute & second filters (#174)
Browse files Browse the repository at this point in the history
Add hour, minute & second filters for recent bans table
  • Loading branch information
VerifiedJoseph authored Oct 1, 2023
1 parent 5de8206 commit a8b1219
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 9 deletions.
94 changes: 90 additions & 4 deletions frontend/js/class/Dialog/FilterAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ export class FilterAddDialog extends Dialog {
name: 'Date',
chart: false,
table: true
},
{
value: 'hour',
name: 'Time / Hour',
chart: false,
table: true
},
{
value: 'minute',
name: 'Time / Minute',
chart: false,
table: true
},
{
value: 'second',
name: 'Time / Second',
chart: false,
table: true
}
]

Expand All @@ -84,6 +102,9 @@ export class FilterAddDialog extends Dialog {
this.#disableFilter('address')
this.#disableFilter('jail')
this.#disableFilter('date')
this.#disableFilter('hour')
this.#disableFilter('minute')
this.#disableFilter('second')

if (Helper.getTableType() === 'address') {
this.#setSelectedFilter('version')
Expand Down Expand Up @@ -204,15 +225,20 @@ export class FilterAddDialog extends Dialog {
valueName = 'name'
textValueName = 'name'
break
case 'date':
valueName = 'date'
textValueName = 'date'
break
default:
valueName = type
textValueName = type
}

let data = []
if (type === 'version') {
data = [{ number: 4 }, { number: 6 }]
} else if (type === 'hour') {
data = this.#getHourList()
} else if (type === 'minute') {
data = this.#getMinuteList()
} else if (type === 'second') {
data = this.#getSecondList()
} else {
data = this.#iaData.getList(type)
}
Expand Down Expand Up @@ -267,4 +293,64 @@ export class FilterAddDialog extends Dialog {
#getId (name) {
return `${this.viewType}-${name}`
}

/**
* Get list of hours in 24 hour format
* @returns {array}
*/
#getHourList () {
const hours = []

for (let i = 0; i <= 23; i++) {
let value = i.toString()

if (i <= 9) {
value = `0${i}`
}

hours.push({ hour: value })
}

return hours
}

/**
* @returns Get list of minutes (00 to 60)
* @returns {array}
*/
#getMinuteList () {
const minutes = []

for (let i = 0; i <= 60; i++) {
let value = i.toString()

if (i <= 9) {
value = `0${i}`
}

minutes.push({ minute: value })
}

return minutes
}

/**
* @returns Get list of seconds (00 to 60)
* @returns {array}
*/
#getSecondList () {
const minutes = []

for (let i = 0; i <= 60; i++) {
let value = i.toString()

if (i <= 9) {
value = `0${i}`
}

minutes.push({ second: value })
}

return minutes
}
}
35 changes: 31 additions & 4 deletions frontend/js/class/Filter/Filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export class Filter {

_getFilteredData (data) {
const filtered = []
const timestampFilterTypes = ['date', 'hour', 'minute', 'second']

data.forEach(item => {
const addStatus = []

for (let index = 0; index < this.settings.length; index++) {
const filter = this.settings[index]

let value
if (filter.type === 'date') {
const parts = item.timestamp.split(' ')
value = parts[0]

if (timestampFilterTypes.includes(filter.type) === true) {
value = this.#getTimestampPart(item.timestamp, filter.type)
} else {
value = item[filter.type].toString()
}
Expand Down Expand Up @@ -235,4 +235,31 @@ export class Filter {

return false
}

/**
* Get part of a timestamp
* @param {string} timestamp Timestamp
* @param {string} part Timestamp part (date, hour, minutes or seconds)
* @returns {string}
*/
#getTimestampPart (timestamp, part) {
const parts = timestamp.split(' ')
const timeParts = parts[1].split(':')

if (part === 'date') {
return parts[0]
}

if (part === 'hour') {
return timeParts[0]
}

if (part === 'minute') {
return timeParts[1]
}

if (part === 'second') {
return timeParts[2]
}
}
}
5 changes: 4 additions & 1 deletion frontend/js/class/FilterChip.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export class FilterChip {
country: 'Country',
continent: 'Continent',
jail: 'Jail',
date: 'Date'
date: 'Date',
hour: 'Hour',
minute: 'Minute',
second: 'Second'
}

constructor (viewGroup, iaData) {
Expand Down

0 comments on commit a8b1219

Please # to comment.