SearchView.qml 1.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import "../../../db/Query.js" as Q
Page
{
    contentData: PixGrid
    {
        id: searchResults
        height: parent.height
        width: parent.width
        headerbarExitIcon: "edit-clear"
        headerbarTitle: searchResults.grid.count + qsTr(" results")
        holder.message: "<h2>No results!</h2><p>Try with another query</p>"
        holder.emoji: "qrc:/img/assets/face-sleeping.png"

    }

    footer: ToolBar
    {
        position: ToolBar.Footer

        RowLayout
        {
            anchors.fill: parent
            PixButton
            {
                iconName: "view-filter"
                Layout.alignment: Qt.AlignLeft
            }

            TextField
            {
                id: searchInput
                placeholderText: qsTr("Search...")
                Layout.fillWidth: true
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment:  Text.AlignVCenter
                selectByMouse: !isMobile
                focus: true
                wrapMode: TextEdit.Wrap
                selectionColor: highlightColor
                selectedTextColor: highlightedTextColor
                onAccepted: runSearch(searchInput.text)

            }

            PixButton
            {
                iconName: "edit-clear"
                Layout.alignment: Qt.AlignRight
                onClicked: searchInput.clear()
            }
        }
    }

    function runSearch(query)
    {
        searchResults.clear()
        if(query)
        {
            console.log(query)
            searchResults.headerbarTitle = query

            var queries = query.split(",")
            for(var i in queries)
                populate(pix.get(Q.Query.searchFor_.arg(queries[i])))
        }
    }

    function populate(data)
    {

        if(data.length > 0)
            for(var i in data)
                searchResults.grid.model.append(data[i])
    }
}