Skip to content

Commit

Permalink
Filter by assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
ciukstar committed Sep 30, 2023
1 parent 28b93de commit c6a82ab
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 97 deletions.
1 change: 1 addition & 0 deletions messages/en.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FromCoworkers: From coworkers
DemoUserAccounts: Demo user accounts
WithoutAssignee: Without assignee
AssignedToMe: Assigned to me
Expand Down
1 change: 1 addition & 0 deletions messages/fr.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FromCoworkers: Des collègues
DemoUserAccounts: Comptes utilisateurs démo
WithoutAssignee: Sans exécuteur
AssignedToMe: Assigné à moi
Expand Down
5 changes: 3 additions & 2 deletions messages/ro.msg
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FromCoworkers: De la colegi
DemoUserAccounts: Conturi de utilizator Demo
WithoutAssignee: Fără executor
AssignedToMe: Atribuite mie
Assignee: Desemnatul
ShowAll: Arată tot
Approve: Aprobă
Request: Solicitare
Request: Solicitare de programare
LoginToSeeTheRequests: Vă rugăm să vă conectați pentru a vedea solicitările
NoRequestsFound: Nu s-au găsit solicitări
NoPendingRequestsYet: Nu există încă cereri de aprobare
Expand All @@ -29,7 +30,7 @@ Nullify: Anulează
Reschedule: Reprogramează
Calendar: Calendar
BookingCalendar: Calendar de rezervari
Requests: Solicitări
Requests: Solicitări de programare
BookingRequests: Cereri de rezervare
NoOffersYet: Nu există încă oferte
ChoosePhoto: Alege foto
Expand Down
9 changes: 5 additions & 4 deletions messages/ru.msg
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FromCoworkers: От коллег
DemoUserAccounts: Демо-аккаунты
WithoutAssignee: Без исполнителя
AssignedToMe: Назначенные мне
Assignee: Исполнитель
ShowAll: Показать всё
Approve: Утвердить
Request: Запрос
Request: Запрос на приём
LoginToSeeTheRequests: Пожалуйста, войдите, чтобы увидеть запросы
NoRequestsFound: Запросы не найдены
NoPendingRequestsYet: Запросов на одобрение пока нет
Expand All @@ -29,7 +30,7 @@ Nullify: Аннулировать
Reschedule: Перенести
Calendar: Календарь
BookingCalendar: Календарь бронирования
Requests: Запросы
Requests: Запросы на приём
BookingRequests: Запросы на бронирование
NoOffersYet: Предложений пока нет
ChoosePhoto: Выбрать фото
Expand Down Expand Up @@ -61,7 +62,7 @@ CancelAppointment: Аннулировать
Appointment: Запись
NoAppointmentsYet: У вас еще нет записей
LoginToSeeYourAppointments: Пожалуйста, войдите, чтобы увидеть ваши записи
MyAppointments: Мои записи
MyAppointments: Мои записи на приём
Time: Время
Day: День
NotYourAccount: Не ваша учетная запись
Expand Down Expand Up @@ -135,7 +136,7 @@ Ratings: Рейтинги
Rating: Рейтинг
AddRole: Добавить роль
NoRolesYes: Ролей пока нет
BookAppointment: Записаться на прием
BookAppointment: Записаться на приём
EmployeeAlreadyInTheList: Сотрудник уже в списке
Mobile: Мобильный
Phone: Телефон
Expand Down
47 changes: 28 additions & 19 deletions src/Demo/DemoDataEN.hs
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,18 @@ We will continue to offer the latest treatments, the most innovative techniques
}

insert_ $ Role { roleStaff = e1
, roleService = s11
, roleName = "Makeup artist"
, roleRating = Just 5
}
, roleService = s11
, roleName = "Makeup artist"
, roleRating = Just 5
}

insert_ $ Offer { offerService = s11
, offerName = "Price"
, offerPrice = 26
, offerPrefix = Just "$"
, offerSuffix = Nothing
, offerDescr = Nothing
}
o111 <- insert $ Offer { offerService = s11
, offerName = "Price"
, offerPrice = 26
, offerPrefix = Just "$"
, offerSuffix = Nothing
, offerDescr = Nothing
}

insert_ $ Thumbnail { thumbnailService = s11
, thumbnailPhoto = $(embedFile "static/img/men-haircuts.avif")
Expand Down Expand Up @@ -452,13 +452,13 @@ We will continue to offer the latest treatments, the most innovative techniques
, serviceGroup = Just s1
}

insert_ $ Offer { offerService = s14
, offerName = "Price"
, offerPrice = 16
, offerPrefix = Just "$"
, offerSuffix = Just "-$20 (depending on the length of their hair)"
, offerDescr = Nothing
}
o141 <- insert $ Offer { offerService = s14
, offerName = "Price"
, offerPrice = 16
, offerPrefix = Just "$"
, offerSuffix = Just "-$20 (depending on the length of their hair)"
, offerDescr = Nothing
}

insert_ $ Thumbnail { thumbnailService = s14
, thumbnailPhoto = $(embedFile "static/img/children-hair-cuts.avif")
Expand Down Expand Up @@ -1001,7 +1001,7 @@ We will continue to offer the latest treatments, the most innovative techniques
, bookStatus = BookStatusRequest
}

insert_ $ Book { bookOffer = o121
insert_ $ Book { bookOffer = o111
, bookRole = Just r51511
, bookUser = u2
, bookDay = addDays 2 today
Expand All @@ -1010,6 +1010,15 @@ We will continue to offer the latest treatments, the most innovative techniques
, bookStatus = BookStatusRequest
}

insert_ $ Book { bookOffer = o141
, bookRole = Nothing
, bookUser = u2
, bookDay = addDays 3 today
, bookTime = time
, bookTz = utc
, bookStatus = BookStatusRequest
}

return ()
where
duration :: String -> Maybe DiffTime
Expand Down
121 changes: 82 additions & 39 deletions src/Handler/Requests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import Yesod.Core
)
import Yesod.Core.Widget (setTitleI)
import Yesod.Auth ( Route(LoginR, LogoutR), maybeAuth )
import Yesod.Form.Fields (Textarea(unTextarea, Textarea), searchField)
import Yesod.Form.Fields (Textarea(unTextarea, Textarea), searchField, intField)
import Yesod.Form.Types (MForm, FormResult (FormSuccess))
import Yesod.Form.Functions (generateFormPost)
import Yesod.Form.Input (runInputGet, iopt)
import Settings (widgetFile)

import Foundation
Expand All @@ -44,15 +45,17 @@ import Foundation
, MsgService, MsgMeetingTime, MsgAcquaintance, MsgAppoinmentStatus
, MsgDuration, MsgApprove, MsgNoPendingRequestsYet, MsgShowAll
, MsgAssignedToMe, MsgWithoutAssignee, MsgSearch, MsgNoRequestsFound
, MsgFromCoworkers
)
)

import Database.Persist (Entity (Entity))
import Database.Persist.Sql (fromSqlKey, toSqlKey)
import Yesod.Persist.Core (YesodPersist(runDB))
import Database.Esqueleto.Experimental
( select, from, table, innerJoin, leftJoin, on, where_, val
, (:&)((:&)), (==.), (^.), (?.), (%), (++.), (||.)
, orderBy, desc, just, selectOne, valList, in_, upper_, like
, (:&)((:&)), (==.), (^.), (?.), (%), (++.), (||.), (&&.)
, orderBy, desc, just, selectOne, valList, in_, upper_, like, isNothing_, not_
)

import Model
Expand All @@ -62,24 +65,23 @@ import Model
( BookStatusRequest, BookStatusApproved, BookStatusCancelled
, BookStatusPaid
)
, Assignees (AssigneesMe, AssigneesNone, AssigneesOthers)
, EntityField
( BookOffer, OfferId, OfferService, ServiceId, BookDay, BookTime
, BookRole, RoleId, RoleStaff, StaffId, StaffUser, ContentsSection, BookId
, ThumbnailService, BookUser, UserId, BookStatus, ServiceName, ServiceDescr
, ServiceOverview, RoleName, OfferName, OfferPrefix, OfferSuffix, OfferDescr
, StaffName, StaffPhone, StaffMobile, StaffEmail, UserName, UserFullName, UserEmail
, StaffName, StaffPhone, StaffMobile, StaffEmail, UserName, UserFullName
, UserEmail
)
)

import Menu (menu)
import Handler.Contacts (section)
import Yesod.Form.Input (runInputGet, iopt)


getRequestsSearchR :: Handler Html
getRequestsSearchR = do
q <- runInputGet $ iopt (searchField True) "q"
stati <- filter ((== "status") . fst) . reqGetParams <$> getRequest
user <- maybeAuth
setUltDestCurrent
msgs <- getMessages
Expand All @@ -90,41 +92,57 @@ getRequestsSearchR = do
Just (Entity uid _) -> do
formSearch <- newIdent
dlgStatusList <- newIdent
let statusList = [ (BookStatusRequest, MsgRequest)
, (BookStatusApproved, MsgApproved)
, (BookStatusCancelled, MsgCancelled)
, (BookStatusPaid, MsgPaid)
]
q <- runInputGet $ iopt (searchField True) "q"
stati <- filter ((== "status") . fst) . reqGetParams <$> getRequest
let states = mapMaybe (readMaybe . unpack . snd) stati
owners <- filter ((== "assignee") . fst) . reqGetParams <$> getRequest
let assignees = mapMaybe (readMaybe . unpack . snd) owners
dlgAssignee <- newIdent
requests <- runDB $ select $ do
x :& o :& s :& r :& e :& c <- from $ table @Book
`innerJoin` table @Offer `on` (\(x :& o) -> x ^. BookOffer ==. o ^. OfferId)
`innerJoin` table @Service `on` (\(_ :& o :& s) -> o ^. OfferService ==. s ^. ServiceId)
`innerJoin` table @Role `on` (\(x :& _ :& _ :& r) -> x ^. BookRole ==. just (r ^. RoleId))
`innerJoin` table @Staff `on` (\(_ :& _ :& _ :& r :& e) -> r ^. RoleStaff ==. e ^. StaffId)
`innerJoin` table @User `on` (\(_ :& _ :& _ :& _ :& e :& c) -> e ^. StaffUser ==. just (c ^. UserId))
where_ $ e ^. StaffUser ==. just (val uid)
`leftJoin` table @Role `on` (\(x :& _ :& _ :& r) -> x ^. BookRole ==. r ?. RoleId)
`leftJoin` table @Staff `on` (\(_ :& _ :& _ :& r :& e) -> r ?. RoleStaff ==. e ?. StaffId)
`leftJoin` table @User `on` (\(_ :& _ :& _ :& _ :& e :& c) -> e ?. StaffUser ==. just (c ?. UserId))

case q of
Just query -> where_ $ (upper_ (s ^. ServiceName) `like` ((%) ++. upper_ (val query) ++. (%)))
||. (upper_ (s ^. ServiceOverview) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (s ^. ServiceDescr) `like` ((%) ++. upper_ (just (val (Textarea query))) ++. (%)))
||. (upper_ (r ^. RoleName) `like` ((%) ++. upper_ (val query) ++. (%)))
||. (upper_ (r ?. RoleName) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (o ^. OfferName) `like` ((%) ++. upper_ (val query) ++. (%)))
||. (upper_ (o ^. OfferPrefix) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (o ^. OfferSuffix) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (o ^. OfferDescr) `like` ((%) ++. upper_ (just (val (Textarea query))) ++. (%)))
||. (upper_ (e ^. StaffName) `like` ((%) ++. upper_ (val query) ++. (%)))
||. (upper_ (e ^. StaffPhone) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (e ^. StaffMobile) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (e ^. StaffEmail) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (c ^. UserName) `like` ((%) ++. upper_ (val query) ++. (%)))
||. (upper_ (c ^. UserFullName) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (c ^. UserEmail) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (e ?. StaffName) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (e ?. StaffPhone) `like` ((%) ++. upper_ (just (just (val query))) ++. (%)))
||. (upper_ (e ?. StaffMobile) `like` ((%) ++. upper_ (just (just (val query))) ++. (%)))
||. (upper_ (e ?. StaffEmail) `like` ((%) ++. upper_ (just (just (val query))) ++. (%)))
||. (upper_ (c ?. UserName) `like` ((%) ++. upper_ (just (val query)) ++. (%)))
||. (upper_ (c ?. UserFullName) `like` ((%) ++. upper_ (just (just (val query))) ++. (%)))
||. (upper_ (c ?. UserEmail) `like` ((%) ++. upper_ (just (just (val query))) ++. (%)))
Nothing -> return ()

case states of
[] -> return ()
xs -> where_ $ x ^. BookStatus `in_` valList xs

let ors = [ ( AssigneesMe `elem` assignees
, e ?. StaffUser ==. just (just (val uid))
)
, ( AssigneesNone `elem` assignees
, isNothing_ $ e ?. StaffUser
)
, ( AssigneesOthers `elem` assignees
, not_ (isNothing_ $ e ?. StaffUser) &&. not_ (e ?. StaffUser ==. just (just (val uid)))
)
]

case snd <$> filter fst ors of
[] -> return ()
xs -> where_ $ foldr (||.) (val False) xs

orderBy [desc (x ^. BookDay), desc (x ^. BookTime)]
return (x,s)
defaultLayout $ do
Expand All @@ -134,10 +152,9 @@ getRequestsSearchR = do

getRequestR :: BookId -> Handler Html
getRequestR bid = do
stati <- filter ((== "status") . fst) . reqGetParams <$> getRequest
stati <- reqGetParams <$> getRequest
app <- getYesod
langs <- languages
user <- maybeAuth
location <- runDB $ selectOne $ do
x <- from $ table @Contents
where_ $ x ^. ContentsSection ==. val section
Expand All @@ -147,13 +164,10 @@ getRequestR bid = do
`innerJoin` table @Offer `on` (\(x :& o) -> x ^. BookOffer ==. o ^. OfferId)
`innerJoin` table @Service `on` (\(_ :& o :& s) -> o ^. OfferService ==. s ^. ServiceId)
`leftJoin` table @Thumbnail `on` (\(_ :& _ :& s :& t) -> just (s ^. ServiceId) ==. t ?. ThumbnailService)
`innerJoin` table @Role `on` (\(x :& _ :& _ :& _ :& r) -> x ^. BookRole ==. just (r ^. RoleId))
`innerJoin` table @Staff `on` (\(_ :& _ :& _ :& _ :& r :& e) -> r ^. RoleStaff ==. e ^. StaffId)
`leftJoin` table @Role `on` (\(x :& _ :& _ :& _ :& r) -> x ^. BookRole ==. r ?. RoleId)
`leftJoin` table @Staff `on` (\(_ :& _ :& _ :& _ :& r :& e) -> r ?. RoleStaff ==. e ?. StaffId)
`innerJoin` table @User `on` (\(x :& _ :& _ :& _ :& _ :& _ :& c) -> x ^. BookUser ==. c ^. UserId)
where_ $ x ^. BookId ==. val bid
case user of
Just (Entity uid _) -> where_ $ e ^. StaffUser ==. just (val uid)
Nothing -> where_ $ val False
return (x,o,s,t,r,e,c)
msgs <- getMessages
(fw,et) <- generateFormPost formCancel
Expand All @@ -168,6 +182,7 @@ formCancel extra = return (FormSuccess (),[whamlet|#{extra}|])

getRequestsR :: Handler Html
getRequestsR = do
mbid <- (toSqlKey <$>) <$> runInputGet (iopt intField "bid")
stati <- filter ((== "status") . fst) . reqGetParams <$> getRequest
user <- maybeAuth
setUltDestCurrent
Expand All @@ -177,31 +192,59 @@ getRequestsR = do
setTitleI MsgLogin
$(widgetFile "requests/login")
Just (Entity uid _) -> do
formSearch <- newIdent
dlgStatusList <- newIdent
let statusList = [ (BookStatusRequest, MsgRequest)
, (BookStatusApproved, MsgApproved)
, (BookStatusCancelled, MsgCancelled)
, (BookStatusPaid, MsgPaid)
]
let states = mapMaybe (readMaybe . unpack . snd) stati
owners <- filter ((== "assignee") . fst) . reqGetParams <$> getRequest
let assignees = mapMaybe (readMaybe . unpack . snd) owners
dlgAssignee <- newIdent
requests <- runDB $ select $ do
x :& _ :& s :& _ :& e <- from $ table @Book
`innerJoin` table @Offer `on` (\(x :& o) -> x ^. BookOffer ==. o ^. OfferId)
`innerJoin` table @Service `on` (\(_ :& o :& s) -> o ^. OfferService ==. s ^. ServiceId)
`innerJoin` table @Role `on` (\(x :& _ :& _ :& r) -> x ^. BookRole ==. just (r ^. RoleId))
`innerJoin` table @Staff `on` (\(_ :& _ :& _ :& r :& e) -> r ^. RoleStaff ==. e ^. StaffId)
where_ $ e ^. StaffUser ==. just (val uid)
`leftJoin` table @Role `on` (\(x :& _ :& _ :& r) -> x ^. BookRole ==. r ?. RoleId)
`leftJoin` table @Staff `on` (\(_ :& _ :& _ :& r :& e) -> r ?. RoleStaff ==. e ?. StaffId)
case states of
[] -> return ()
xs -> where_ $ x ^. BookStatus `in_` valList xs

let ors = [ ( AssigneesMe `elem` assignees
, e ?. StaffUser ==. just (just (val uid))
)
, ( AssigneesNone `elem` assignees
, isNothing_ $ e ?. StaffUser
)
, ( AssigneesOthers `elem` assignees
, not_ (isNothing_ $ e ?. StaffUser) &&. not_ (e ?. StaffUser ==. just (just (val uid)))
)
]

case snd <$> filter fst ors of
[] -> return ()
xs -> where_ $ foldr (||.) (val False) xs

orderBy [desc (x ^. BookDay), desc (x ^. BookTime)]
return (x,s)
defaultLayout $ do
setTitleI MsgRequests
$(widgetFile "requests/requests")


statusList :: [(BookStatus, AppMessage)]
statusList = [ (BookStatusRequest, MsgRequest)
, (BookStatusApproved, MsgApproved)
, (BookStatusCancelled, MsgCancelled)
, (BookStatusPaid, MsgPaid)
]

assigneeList :: [(Assignees, AppMessage)]
assigneeList = [ (AssigneesMe,MsgAssignedToMe)
, (AssigneesNone,MsgWithoutAssignee)
, (AssigneesOthers,MsgFromCoworkers)
]


resolve :: BookStatus -> (Text, Text, AppMessage)
resolve BookStatusRequest = ("orange", "hourglass_top", MsgAwaitingApproval)
resolve BookStatusApproved = ("green", "verified", MsgApproved)
Expand Down
2 changes: 1 addition & 1 deletion src/Menu.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Foundation
)
)

import Model (BookStatus (BookStatusRequest), Services (Services))
import Model (BookStatus (BookStatusRequest), Services (Services), Assignees (AssigneesMe))

import Settings (widgetFile)
import Settings.StaticFiles (img_salon_svg)
Expand Down
Loading

0 comments on commit c6a82ab

Please sign in to comment.