Skip to content

Commit

Permalink
sort switches by description in Nodes sidebar, fixes #8368
Browse files Browse the repository at this point in the history
  • Loading branch information
satkunas committed Nov 19, 2024
1 parent 7b9c943 commit 5cd3dd9
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions html/pfappserver/root/src/views/Nodes/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,30 @@ const setup = (props, context) => {
return {
name: switchGroup.id || i18n.t('Default'),
collapsable: true,
items: switchGroup.members.map(switchGroupMember => {
let conditionAdvanced
if ((/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2})$/.exec(switchGroupMember.id))) { // CIDR
const [start, end] = network.cidrToRange(switchGroupMember.id)
conditionAdvanced = { op: 'and', values: [
{ op: 'or', values: [{ field: 'locationlog.switch_ip', op: 'greater_than_equals', value: start }] },
{ op: 'or', values: [{ field: 'locationlog.switch_ip', op: 'less_than_equals', value: end }] }
] }
}
else if ((/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/.exec(switchGroupMember.id))) { // IPv4
conditionAdvanced = { op: 'and', values: [{ op: 'or', values: [{ field: 'locationlog.switch_ip', op: 'equals', value: switchGroupMember.id }] }] }
}
else { // non-CIDR
conditionAdvanced = { op: 'and', values: [{ op: 'or', values: [{ field: 'locationlog.switch', op: 'equals', value: switchGroupMember.id }] }] }
}
return {
name: switchGroupMember.id,
caption: switchGroupMember.description,
path: { name: 'nodeSearch', query: { conditionAdvanced: JSON.stringify(conditionAdvanced) } }
}
})
}
items: switchGroup.members
.sort((a, b) => (a.description||a.id).localeCompare(b.description||b.id))
.map(switchGroupMember => {
let conditionAdvanced
if ((/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2})$/.exec(switchGroupMember.id))) { // CIDR
const [start, end] = network.cidrToRange(switchGroupMember.id)
conditionAdvanced = { op: 'and', values: [
{ op: 'or', values: [{ field: 'locationlog.switch_ip', op: 'greater_than_equals', value: start }] },
{ op: 'or', values: [{ field: 'locationlog.switch_ip', op: 'less_than_equals', value: end }] }
] }
}
else if ((/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/.exec(switchGroupMember.id))) { // IPv4
conditionAdvanced = { op: 'and', values: [{ op: 'or', values: [{ field: 'locationlog.switch_ip', op: 'equals', value: switchGroupMember.id }] }] }
}
else { // non-CIDR
conditionAdvanced = { op: 'and', values: [{ op: 'or', values: [{ field: 'locationlog.switch', op: 'equals', value: switchGroupMember.id }] }] }
}
return {
name: switchGroupMember.id,
caption: switchGroupMember.description,
path: { name: 'nodeSearch', query: { conditionAdvanced: JSON.stringify(conditionAdvanced) } }
}
})
}
})
}
]))
Expand Down

0 comments on commit 5cd3dd9

Please sign in to comment.