Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
be8e61f9
Commit
be8e61f9
authored
Jul 24, 2021
by
David Davó
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added DatePicker widget
parent
754b3be8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
4 deletions
+106
-4
Widgets.hs
...-display/ihaskell-widgets/src/IHaskell/Display/Widgets.hs
+2
-1
Common.hs
...y/ihaskell-widgets/src/IHaskell/Display/Widgets/Common.hs
+1
-0
DatePicker.hs
...askell-widgets/src/IHaskell/Display/Widgets/DatePicker.hs
+63
-0
Singletons.hs
...askell-widgets/src/IHaskell/Display/Widgets/Singletons.hs
+1
-0
Types.hs
...ay/ihaskell-widgets/src/IHaskell/Display/Widgets/Types.hs
+39
-3
No files found.
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets.hs
View file @
be8e61f9
...
@@ -2,6 +2,7 @@ module IHaskell.Display.Widgets (module X) where
...
@@ -2,6 +2,7 @@ module IHaskell.Display.Widgets (module X) where
import
IHaskell.Display.Widgets.Button
as
X
import
IHaskell.Display.Widgets.Button
as
X
import
IHaskell.Display.Widgets.ColorPicker
as
X
import
IHaskell.Display.Widgets.ColorPicker
as
X
import
IHaskell.Display.Widgets.DatePicker
as
X
import
IHaskell.Display.Widgets.Box.Box
as
X
import
IHaskell.Display.Widgets.Box.Box
as
X
import
IHaskell.Display.Widgets.Box.SelectionContainer.Accordion
as
X
import
IHaskell.Display.Widgets.Box.SelectionContainer.Accordion
as
X
...
@@ -50,4 +51,4 @@ import IHaskell.Display.Widgets.String.TextArea as X
...
@@ -50,4 +51,4 @@ import IHaskell.Display.Widgets.String.TextArea as X
import
IHaskell.Display.Widgets.Common
as
X
import
IHaskell.Display.Widgets.Common
as
X
import
IHaskell.Display.Widgets.Types
as
X
(
setField
,
getField
,
properties
,
triggerDisplay
,
import
IHaskell.Display.Widgets.Types
as
X
(
setField
,
getField
,
properties
,
triggerDisplay
,
triggerChange
,
triggerClick
,
triggerSelection
,
triggerChange
,
triggerClick
,
triggerSelection
,
triggerSubmit
,
ChildWidget
(
..
))
triggerSubmit
,
ChildWidget
(
..
)
,
Date
(
..
)
)
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets/Common.hs
View file @
be8e61f9
...
@@ -102,6 +102,7 @@ pattern Repeat = S.SRepeat
...
@@ -102,6 +102,7 @@ pattern Repeat = S.SRepeat
pattern
Interval
=
S
.
SInterval
pattern
Interval
=
S
.
SInterval
pattern
ShowRepeat
=
S
.
SShowRepeat
pattern
ShowRepeat
=
S
.
SShowRepeat
pattern
Concise
=
S
.
SConcise
pattern
Concise
=
S
.
SConcise
pattern
DateValue
=
S
.
SDateValue
-- | Close a widget's comm
-- | Close a widget's comm
closeWidget
::
IHaskellWidget
w
=>
w
->
IO
()
closeWidget
::
IHaskellWidget
w
=>
w
->
IO
()
...
...
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets/DatePicker.hs
0 → 100644
View file @
be8e61f9
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module
IHaskell.Display.Widgets.DatePicker
(
-- * The DatePicker Widget
DatePicker
-- * Create a new DatePicker
,
mkDatePicker
)
where
-- To keep `cabal repl` happy when running from the ihaskell repo
import
Prelude
import
Control.Monad
(
void
)
import
Data.Aeson
import
Data.IORef
(
newIORef
)
import
Data.Vinyl
(
Rec
(
..
),
(
<+>
))
import
IHaskell.Display
import
IHaskell.Eval.Widgets
import
IHaskell.IPython.Message.UUID
as
U
import
IHaskell.Display.Widgets.Types
import
IHaskell.Display.Widgets.Common
-- | A 'DatePicker' represents a DatePicker from IPython.html.widgets.
type
DatePicker
=
IPythonWidget
'D
a
tePickerType
-- | Create a new DatePicker
mkDatePicker
::
IO
DatePicker
mkDatePicker
=
do
-- Default properties, with a random uuid
wid
<-
U
.
random
let
ddw
=
defaultDescriptionWidget
"DatePickerView"
"DatePickerModel"
date
=
(
DateValue
=::
defaultDate
)
:&
(
Disabled
=::
False
)
:&
RNil
datePickerState
=
WidgetState
(
ddw
<+>
date
)
stateIO
<-
newIORef
datePickerState
let
datePicker
=
IPythonWidget
wid
stateIO
-- Open a comm for this widget, and store it in the kernel state
widgetSendOpen
datePicker
$
toJSON
datePickerState
-- Return the DatePicker widget
return
datePicker
instance
IHaskellWidget
DatePicker
where
getCommUUID
=
uuid
comm
widget
val
_
=
case
nestedObjectLookup
val
[
"state"
,
"value"
]
of
Just
o
->
case
fromJSON
o
of
Success
date
->
void
$
setField'
widget
DateValue
date
_
->
pure
()
_
->
pure
()
\ No newline at end of file
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets/Singletons.hs
View file @
be8e61f9
...
@@ -108,5 +108,6 @@ singletons
...
@@ -108,5 +108,6 @@ singletons
| Interval
| Interval
| ShowRepeat
| ShowRepeat
| Concise
| Concise
| DateValue
deriving (Eq, Ord, Show)
deriving (Eq, Ord, Show)
|]
|]
ihaskell-display/ihaskell-widgets/src/IHaskell/Display/Widgets/Types.hs
View file @
be8e61f9
...
@@ -63,7 +63,7 @@
...
@@ -63,7 +63,7 @@
-- specification.
-- specification.
module
IHaskell.Display.Widgets.Types
where
module
IHaskell.Display.Widgets.Types
where
import
Control.Monad
(
unless
,
join
,
when
,
void
)
import
Control.Monad
(
unless
,
join
,
when
,
void
,
mzero
)
import
Control.Applicative
((
<$>
))
import
Control.Applicative
((
<$>
))
import
qualified
Control.Exception
as
Ex
import
qualified
Control.Exception
as
Ex
import
Data.Typeable
(
Typeable
,
TypeRep
,
typeOf
)
import
Data.Typeable
(
Typeable
,
TypeRep
,
typeOf
)
...
@@ -247,6 +247,7 @@ type family FieldType (f :: Field) :: * where
...
@@ -247,6 +247,7 @@ type family FieldType (f :: Field) :: * where
FieldType
'S
.
Interval
=
Integer
FieldType
'S
.
Interval
=
Integer
FieldType
'S
.
ShowRepeat
=
Bool
FieldType
'S
.
ShowRepeat
=
Bool
FieldType
'S
.
Concise
=
Bool
FieldType
'S
.
Concise
=
Bool
FieldType
'S
.
DateValue
=
Date
-- | Can be used to put different widgets in a list. Useful for dealing with children widgets.
-- | Can be used to put different widgets in a list. Useful for dealing with children widgets.
data
ChildWidget
=
forall
w
.
RecAll
Attr
(
WidgetFields
w
)
ToPairs
=>
ChildWidget
(
IPythonWidget
w
)
data
ChildWidget
=
forall
w
.
RecAll
Attr
(
WidgetFields
w
)
ToPairs
=>
ChildWidget
(
IPythonWidget
w
)
...
@@ -276,6 +277,7 @@ instance CustomBounded Double where
...
@@ -276,6 +277,7 @@ instance CustomBounded Double where
-- Different types of widgets. Every widget in IPython has a corresponding WidgetType
-- Different types of widgets. Every widget in IPython has a corresponding WidgetType
data
WidgetType
=
ButtonType
data
WidgetType
=
ButtonType
|
ColorPickerType
|
ColorPickerType
|
DatePickerType
|
AudioType
|
AudioType
|
ImageType
|
ImageType
|
VideoType
|
VideoType
...
@@ -319,10 +321,12 @@ type family WidgetFields (w :: WidgetType) :: [Field] where
...
@@ -319,10 +321,12 @@ type family WidgetFields (w :: WidgetType) :: [Field] where
WidgetFields
'B
u
ttonType
=
WidgetFields
'B
u
ttonType
=
DescriptionWidgetClass
:++
DescriptionWidgetClass
:++
[
'S
.
Disabled
,
'S
.
Icon
,
'S
.
ButtonStyle
,
'S
.
ClickHandler
]
[
'S
.
Disabled
,
'S
.
Icon
,
'S
.
ButtonStyle
,
'S
.
ClickHandler
]
WidgetFields
'C
o
lorPickerType
=
WidgetFields
'C
o
lorPickerType
=
DescriptionWidgetClass
:++
DescriptionWidgetClass
:++
[
'S
.
StringValue
,
'S
.
Concise
,
'S
.
Disabled
]
[
'S
.
StringValue
,
'S
.
Concise
,
'S
.
Disabled
]
WidgetFields
'D
a
tePickerType
=
DescriptionWidgetClass
:++
[
'S
.
DateValue
,
'S
.
Disabled
]
WidgetFields
'A
u
dioType
=
WidgetFields
'A
u
dioType
=
MediaClass
:++
[
'S
.
AudioFormat
,
'S
.
AutoPlay
,
'S
.
Loop
,
'S
.
Controls
]
MediaClass
:++
[
'S
.
AudioFormat
,
'S
.
AutoPlay
,
'S
.
Loop
,
'S
.
Controls
]
...
@@ -651,6 +655,9 @@ instance ToPairs (Attr 'S.ShowRepeat) where
...
@@ -651,6 +655,9 @@ instance ToPairs (Attr 'S.ShowRepeat) where
instance
ToPairs
(
Attr
'S
.
Concise
)
where
instance
ToPairs
(
Attr
'S
.
Concise
)
where
toPairs
x
=
[
"concise"
.=
toJSON
x
]
toPairs
x
=
[
"concise"
.=
toJSON
x
]
instance
ToPairs
(
Attr
'S
.
DateValue
)
where
toPairs
x
=
[
"value"
.=
toJSON
x
]
-- | Store the value for a field, as an object parametrized by the Field. No verification is done
-- | Store the value for a field, as an object parametrized by the Field. No verification is done
-- for these values.
-- for these values.
(
=::
)
::
(
SingI
f
,
Typeable
(
FieldType
f
))
=>
Sing
f
->
FieldType
f
->
Attr
f
(
=::
)
::
(
SingI
f
,
Typeable
(
FieldType
f
))
=>
Sing
f
->
FieldType
f
->
Attr
f
...
@@ -980,9 +987,38 @@ instance IHaskellWidget (IPythonWidget w) => IHaskellDisplay (IPythonWidget w) w
...
@@ -980,9 +987,38 @@ instance IHaskellWidget (IPythonWidget w) => IHaskellDisplay (IPythonWidget w) w
display
b
=
do
display
b
=
do
widgetSendView
b
-- Keeping compatibility with classic notebook
widgetSendView
b
-- Keeping compatibility with classic notebook
return
$
Display
[
widgetdisplay
$
unpack
$
decodeUtf8
$
encode
$
object
[
return
$
Display
[
widgetdisplay
$
unpack
$
decodeUtf8
$
encode
$
object
[
"model_id"
.=
getCommUUID
b
,
"model_id"
.=
getCommUUID
b
,
"version_major"
.=
version_major
,
"version_major"
.=
version_major
,
"version_minor"
.=
version_minor
]
]
"version_minor"
.=
version_minor
]
]
where
where
version_major
=
2
::
Int
version_major
=
2
::
Int
version_minor
=
0
::
Int
version_minor
=
0
::
Int
-- | The date class from IPython
data
Date
-- | No date specified. used by default
=
NullDate
-- | Date year month day
|
Date
Integer
Integer
Integer
deriving
(
Eq
,
Ord
)
defaultDate
::
Date
defaultDate
=
NullDate
instance
Show
Date
where
show
NullDate
=
"NullDate"
show
(
Date
y
m
d
)
=
printf
"%04d-%02d-%02d"
y
m
d
instance
ToJSON
Date
where
toJSON
NullDate
=
object
[]
toJSON
(
Date
y
m
d
)
=
object
[
"year"
.=
toJSON
y
,
"month"
.=
toJSON
(
m
-
1
)
-- In the frontend months go from 0 to 11
,
"date"
.=
toJSON
d
]
instance
FromJSON
Date
where
parseJSON
(
Object
v
)
=
Date
<$>
v
.:
"year"
<*>
((
+
1
)
<$>
v
.:
"month"
)
<*>
v
.:
"date"
parseJSON
Null
=
pure
NullDate
parseJSON
_
=
mzero
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment