Allow to search by folders

This commit is contained in:
Eike Kettner
2020-07-11 16:52:13 +02:00
parent 86443e10a6
commit 0df541f30a
5 changed files with 81 additions and 7 deletions

View File

@ -21,7 +21,6 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Markdown
import Ports
import Util.List
import Util.String
import Util.Time
@ -125,6 +124,10 @@ viewItem settings item =
|> List.intersperse ", "
|> String.concat
folder =
Maybe.map .name item.folder
|> Maybe.withDefault ""
dueDate =
Maybe.map Util.Time.formatDateShort item.dueDate
|> Maybe.withDefault ""
@ -212,6 +215,14 @@ viewItem settings item =
, text " "
, Util.String.withDefault "-" conc |> text
]
, div
[ class "item"
, title "Folder"
]
[ Icons.folderIcon ""
, text " "
, Util.String.withDefault "-" folder |> text
]
]
, div [ class "right floated meta" ]
[ div [ class "ui horizontal list" ]

View File

@ -11,6 +11,7 @@ module Comp.SearchMenu exposing
import Api
import Api.Model.Equipment exposing (Equipment)
import Api.Model.EquipmentList exposing (EquipmentList)
import Api.Model.FolderList exposing (FolderList)
import Api.Model.IdName exposing (IdName)
import Api.Model.ItemSearch exposing (ItemSearch)
import Api.Model.ReferenceList exposing (ReferenceList)
@ -45,6 +46,7 @@ type alias Model =
, corrPersonModel : Comp.Dropdown.Model IdName
, concPersonModel : Comp.Dropdown.Model IdName
, concEquipmentModel : Comp.Dropdown.Model Equipment
, folderModel : Comp.Dropdown.Model IdName
, inboxCheckbox : Bool
, fromDateModel : DatePicker
, fromDate : Maybe Int
@ -103,6 +105,14 @@ init =
, labelColor = \_ -> \_ -> ""
, placeholder = "Choose an equipment"
}
, folderModel =
Comp.Dropdown.makeModel
{ multiple = False
, searchable = \n -> n > 5
, makeOption = \e -> { value = e.id, text = e.name }
, labelColor = \_ -> \_ -> ""
, placeholder = "Only items in folder"
}
, inboxCheckbox = False
, fromDateModel = Comp.DatePicker.emptyModel
, fromDate = Nothing
@ -144,6 +154,8 @@ type Msg
| ResetForm
| KeyUpMsg (Maybe KeyCode)
| ToggleNameHelp
| FolderMsg (Comp.Dropdown.Msg IdName)
| GetFolderResp (Result Http.Error FolderList)
getDirection : Model -> Maybe Direction
@ -184,6 +196,7 @@ getItemSearch model =
, corrOrg = Comp.Dropdown.getSelected model.orgModel |> List.map .id |> List.head
, concPerson = Comp.Dropdown.getSelected model.concPersonModel |> List.map .id |> List.head
, concEquip = Comp.Dropdown.getSelected model.concEquipmentModel |> List.map .id |> List.head
, folder = Comp.Dropdown.getSelected model.folderModel |> List.map .id |> List.head
, direction = Comp.Dropdown.getSelected model.directionModel |> List.head |> Maybe.map Data.Direction.toString
, inbox = model.inboxCheckbox
, dateFrom = model.fromDate
@ -250,6 +263,7 @@ update flags settings msg model =
, Api.getOrgLight flags GetOrgResp
, Api.getEquipments flags "" GetEquipResp
, Api.getPersonsLight flags GetPersonResp
, Api.getFolders flags "" False GetFolderResp
, cdp
]
)
@ -513,6 +527,29 @@ update flags settings msg model =
ToggleNameHelp ->
NextState ( { model | showNameHelp = not model.showNameHelp }, Cmd.none ) False
GetFolderResp (Ok fs) ->
let
opts =
List.filter .isMember fs.items
|> List.map (\e -> IdName e.id e.name)
|> Comp.Dropdown.SetOptions
in
update flags settings (FolderMsg opts) model
GetFolderResp (Err _) ->
noChange ( model, Cmd.none )
FolderMsg lm ->
let
( m2, c2 ) =
Comp.Dropdown.update lm model.folderModel
in
NextState
( { model | folderModel = m2 }
, Cmd.map FolderMsg c2
)
(isDropdownChangeMsg lm)
-- View
@ -629,6 +666,11 @@ view flags settings model =
[ text "Looks in item name only."
]
]
, formHeader (Icons.folderIcon "") "Folder"
, div [ class "field" ]
[ label [] [ text "Folder" ]
, Html.map FolderMsg (Comp.Dropdown.view settings model.folderModel)
]
, formHeader (Icons.tagsIcon "") "Tags"
, div [ class "field" ]
[ label [] [ text "Include (and)" ]