Working filter field for room members
This commit is contained in:
parent
1af8c97734
commit
47327c64cf
|
@ -2,6 +2,7 @@ import QtQuick 2.7
|
|||
import QtQuick.Layouts 1.3
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../../Base"
|
||||
import "../../utils.js" as Utils
|
||||
|
||||
HColumnLayout {
|
||||
property bool collapsed: false
|
||||
|
@ -29,6 +30,13 @@ HColumnLayout {
|
|||
sorters: StringSorter {
|
||||
roleName: "displayName"
|
||||
}
|
||||
|
||||
filters: ExpressionFilter {
|
||||
function filterIt(filter, text) {
|
||||
return Utils.filterMatches(filter, text)
|
||||
}
|
||||
expression: filterIt(filterField.text, displayName)
|
||||
}
|
||||
}
|
||||
|
||||
delegate: MemberDelegate {}
|
||||
|
@ -43,17 +51,6 @@ HColumnLayout {
|
|||
placeholderText: qsTr("Filter members")
|
||||
backgroundColor: theme.sidePane.filterRooms.background
|
||||
|
||||
// Without this, if the user types in the field, changes of room, then
|
||||
// comes back, the field will be empty but the filter still applied.
|
||||
//Component.onCompleted:
|
||||
//text = Backend.clients.get(chatPage.userId).getMemberFilter(
|
||||
//chatPage.category, chatPage.roomId
|
||||
//)
|
||||
|
||||
//onTextChanged: Backend.clients.get(chatPage.userId).setMemberFilter(
|
||||
//chatPage.category, chatPage.roomId, text
|
||||
//)
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: theme.bottomElementsHeight
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import QtQuick 2.7
|
|||
import QtQuick.Layouts 1.3
|
||||
import SortFilterProxyModel 0.2
|
||||
import "../Base"
|
||||
import "../utils.js" as Utils
|
||||
|
||||
HListView {
|
||||
property string userId: ""
|
||||
|
@ -24,18 +25,11 @@ HListView {
|
|||
}
|
||||
|
||||
ExpressionFilter {
|
||||
expression: {
|
||||
var filter = paneToolBar.roomFilter.toLowerCase()
|
||||
var words = filter.split(" ")
|
||||
var room_name = displayName.toLowerCase()
|
||||
|
||||
for (var i = 0; i < words.length; i++) {
|
||||
if (words[i] && room_name.indexOf(words[i]) == -1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
// Utils... won't work directly in expression?
|
||||
function filterIt(filter, text) {
|
||||
return Utils.filterMatches(filter, text)
|
||||
}
|
||||
expression: filterIt(paneToolBar.roomFilter, displayName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,3 +88,18 @@ function translatedEventContent(ev) {
|
|||
}
|
||||
return text
|
||||
}
|
||||
|
||||
|
||||
function filterMatches(filter, text) {
|
||||
filter = filter.toLowerCase()
|
||||
text = text.toLowerCase()
|
||||
|
||||
var words = filter.split(" ")
|
||||
|
||||
for (var i = 0; i < words.length; i++) {
|
||||
if (words[i] && text.indexOf(words[i]) == -1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user