Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webapp-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CS-214
ul2024
webapp-lib
Commits
98ce7952
Commit
98ce7952
authored
6 months ago
by
Clément Pit-Claudel
Browse files
Options
Downloads
Patches
Plain Diff
client: Simplify implementation of home page
parent
960ee06b
No related branches found
No related tags found
1 merge request
!38
Customizable homepage + automatic reconnection
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
js/src/main/scala/cs214/webapp/client/Pages.scala
+15
-19
15 additions, 19 deletions
js/src/main/scala/cs214/webapp/client/Pages.scala
with
15 additions
and
19 deletions
js/src/main/scala/cs214/webapp/client/Pages.scala
+
15
−
19
View file @
98ce7952
...
...
@@ -29,7 +29,7 @@ abstract class Page:
List
(
"app"
,
appId
)
case
UIPage
(
appId
,
instanceId
)
=>
List
(
"app"
,
appId
,
instanceId
)
case
JoinPage
Loader
(
appId
,
instanceId
,
uiId
)
=>
case
JoinPage
(
appId
,
instanceId
,
uiId
)
=>
List
(
"app"
,
appId
,
instanceId
,
uiId
)
case
AppPage
(
appId
,
instanceId
,
uiId
,
userId
)
=>
List
(
"app"
,
appId
,
instanceId
,
uiId
,
userId
)
...
...
@@ -55,7 +55,7 @@ object Page:
case
List
(
"app"
,
appId
,
instanceId
)
=>
UIPage
(
appId
,
instanceId
)
case
List
(
"app"
,
appId
,
instanceId
,
uiId
)
=>
JoinPage
Loader
(
appId
,
instanceId
,
uiId
)
JoinPage
(
appId
,
instanceId
,
uiId
)
case
List
(
"app"
,
appId
,
instanceId
,
uiId
,
userId
)
=>
AppPage
(
appId
,
instanceId
,
uiId
,
userId
)
case
_
=>
...
...
@@ -65,18 +65,14 @@ object Page:
object
HomePage
extends
Page
:
val
classList
=
"HomePage"
def
renderInto
(
target
:
Element
)
=
Requests
.
listApps
.
map
:
response
=>
AppSelectionPage
(
response
.
apps
).
renderInto
(
target
)
/** The app selection menu, where the user can create a new app. */
case
class
AppSelectionPage
(
apps
:
Seq
[
AppInfo
])
extends
Page
:
val
classList
=
"AppSelectionPage"
def
selectApp
(
appId
:
AppId
)
:
Unit
=
WebClient
.
navigateTo
(
InstanceCreationPage
(
appId
))
def
renderInto
(
target
:
Element
)
=
replaceChildren
(
target
)
:
def
renderInto
(
target
:
Element
)
=
Requests
.
listApps
.
map
:
resp
=>
doRender
(
resp
.
apps
)(
target
)
private
def
doRender
(
apps
:
Seq
[
AppInfo
])(
target
:
Element
)
=
replaceChildren
(
target
)
:
frag
(
pageHeader
(
"
Select
an
app
"
),
apps.groupBy
(
_
.year
)
.toList.map:
(
year
,
appsOfYear
)
=>
...
...
@@ -138,25 +134,25 @@ case class UIPage(appId: AppId, instanceId: InstanceId) extends Page:
private
val
handleKeyboardEvent
:
Function1
[
dom.KeyboardEvent
,
Unit
]
=
(
e
:
dom.KeyboardEvent
)
=>
if
e
.
keyCode
==
KeyCode
.
Enter
then
e
.
preventDefault
()
joinPage
Loader
()
joinPage
()
private
def
handleFormSubmission
(
e
:
dom.Event
)
:
Unit
=
e
.
preventDefault
()
joinPage
Loader
()
joinPage
()
private
def
getSelected
=
appUIs
.
zipWithIndex
.
find
{
(
ui
,
i
)
=>
getElementById
[
Input
](
cssId
(
i
)).
checked
}.
map
(
_
.
_1
)
private
def
joinPage
Loader
()
:
Unit
=
private
def
joinPage
()
:
Unit
=
getSelected
.
map
:
ui
=>
WebClient
.
navigateTo
(
JoinPage
Loader
(
appId
,
instanceId
,
ui
.
uiId
))
WebClient
.
navigateTo
(
JoinPage
(
appId
,
instanceId
,
ui
.
uiId
))
def
renderInto
(
target
:
Element
)
=
require
(
appUIs
.
nonEmpty
,
f
"No UI found for app with id $appId."
)
if
appUIs
.
size
==
1
then
WebClient
.
navigateTo
(
JoinPage
Loader
(
appId
,
instanceId
,
appUIs
(
0
).
uiId
),
overwriteHistory
=
true
)
WebClient
.
navigateTo
(
JoinPage
(
appId
,
instanceId
,
appUIs
(
0
).
uiId
),
overwriteHistory
=
true
)
else
replaceChildren
(
target
)
:
dom.window.addEventListener
(
"
keydown
"
,
handleKeyboardEvent
)
frag
(
...
...
@@ -183,14 +179,14 @@ case class UIPage(appId: AppId, instanceId: InstanceId) extends Page:
)
/** The pre-connection menu, which fetches the user list. */
case
class
JoinPage
Loader
(
appId
:
AppId
,
instanceId
:
InstanceId
,
uiId
:
UIId
)
extends
Page
:
case
class
JoinPage
(
appId
:
AppId
,
instanceId
:
InstanceId
,
uiId
:
UIId
)
extends
Page
:
val
classList
=
"JoinPageLoader"
def
renderInto
(
target
:
Element
)
=
Requests
.
instanceInfo
(
instanceId
).
map
:
resp
=>
JoinPage
(
appId
,
instanceId
,
uiId
,
resp
.
userIds
).
renderInto
(
target
)
JoinPage
_
(
appId
,
instanceId
,
uiId
,
resp
.
userIds
).
renderInto
(
target
)
/** The connection menu, where a user joins an existing app. */
case
class
JoinPage
(
appId
:
AppId
,
instanceId
:
InstanceId
,
uiId
:
UIId
,
userIds
:
Seq
[
UserId
])
case
class
JoinPage
_
(
appId
:
AppId
,
instanceId
:
InstanceId
,
uiId
:
UIId
,
userIds
:
Seq
[
UserId
])
extends
Page
:
require
(
userIds.size
>
0
)
val
classList
=
"JoinPage"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment