Skip to content

Commit

Permalink
Refactored auth token progress indicator page
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarashev committed Feb 28, 2019
1 parent 9369951 commit d0421d7
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 14 deletions.
4 changes: 4 additions & 0 deletions ganttproject/data/resources/language/i18n.properties
Expand Up @@ -51,6 +51,10 @@ choosePublicHoliday=Choose a public holidays calendar
chooseRoleSets=Choose role sets
chooseWeekend=Choose weekend
close=Close
cloud.authPane.expirationMsg=Your access will expire in {0}
cloud.authPane.expirationValue_hm={0}h {1}m
cloud.authPane.expirationValue_m={0} minutes
cloud.authPane.progressLabel=Verifying access token...
cloud.historyPane.btnGet=Get selected verion
cloud.historyPane.title=Project History
cloud.historyPane.titleHelp=You can replace current project contents with any version from the history
Expand Down
Expand Up @@ -252,7 +252,7 @@ class BrowserPaneBuilder(
installEventHandlers()
rootPane.apply {
vbox.prefWidth = 400.0
addTitle(i18n.create("${this@BrowserPaneBuilder.mode.name.toLowerCase()}.title")).also {
addTitle(this@BrowserPaneBuilder.i18n.create("${this@BrowserPaneBuilder.mode.name.toLowerCase()}.title")).also {
it.styleClass.add("title-integrated")
}
add(VBox().also {
Expand Down
Expand Up @@ -292,6 +292,7 @@ class DocPropertiesUi(val errorUi: ErrorUi, val busyUi: BusyUi) {
fun showDialog(document: GPCloudDocument) {
Platform.runLater {
Dialog<Unit>().also {
it.isResizable = true
it.dialogPane.apply {
content = buildPane(document, {})
styleClass.addAll("dlg-lock", "dlg-cloud-file-options")
Expand All @@ -303,6 +304,9 @@ class DocPropertiesUi(val errorUi: ErrorUi, val busyUi: BusyUi) {
}
scene.accelerators[KeyCombination.keyCombination("ESC")] = Runnable { window.hide() }
}
it.onShown = EventHandler { _ ->
it.dialogPane.scene.window.sizeToScene()
}
it.show()
}
}
Expand Down
Expand Up @@ -124,6 +124,9 @@ class GPCloudSignupPane(
unauthenticated.accept("ACCESS_TOKEN_EXPIRED")
return
}

pageSwitcher(createTokenVerificationProgressUi())

GlobalScope.launch {
try {
callAuthCheck(success, unauthenticated)
Expand Down Expand Up @@ -202,24 +205,64 @@ class GPCloudSignupPane(
}
}

val progressIndicator: Pane by lazy {
val paneBuilder = VBoxBuilder("pane-service-contents")
paneBuilder.addTitle("Signing into GanttProject Cloud")
if (GPCloudOptions.authToken.value != "") {
fun createTokenVerificationProgressUi(): Pane {
val i18nSignin = DefaultLocalizer("cloud.authPane", i18n)
val vboxBuilder = VBoxBuilder("dlg-lock")
vboxBuilder.addTitle(i18nSignin.formatText("title"))

val expirationValue = {
val expirationInstant = Instant.ofEpochSecond(GPCloudOptions.validity.value.toLongOrNull() ?: 0)
val remainingDuration = Duration.between(Instant.now(), expirationInstant)
if (!remainingDuration.isNegative) {
val hours = remainingDuration.toHours()
val minutes = remainingDuration.minusMinutes(hours * 60).toMinutes()
val expirationLabel = if (hours > 0) {
"${hours}h ${minutes}m"
if (hours > 0) {
i18nSignin.formatText("expirationValue_hm", hours, minutes)
} else {
"${minutes}m"
i18nSignin.formatText("expirationValue_m", minutes)
}
paneBuilder.add(Label("Your access token expires in $expirationLabel"), Pos.BASELINE_LEFT, Priority.NEVER)
}
} else ""
}()

vboxBuilder.add(Label(i18nSignin.formatText("expirationMsg", expirationValue)).apply {
this.styleClass.add("help")
})
vboxBuilder.add(ProgressIndicator(-1.0).also {
it.maxWidth = Double.MAX_VALUE
it.maxHeight = Double.MAX_VALUE
}, Pos.CENTER, Priority.ALWAYS)
vboxBuilder.add(Label(i18nSignin.formatText("progressLabel")), Pos.CENTER, Priority.NEVER).also {
it.styleClass.add("medskip")
}

return DialogPane().also {
it.styleClass.addAll("dlg-lock", "signup-pane")
it.stylesheets.add("/biz/ganttproject/storage/cloud/GPCloudStorage.css")
it.graphic = ImageView(Image(
this.javaClass.getResourceAsStream("/icons/ganttproject-logo-512.png"),
64.0, 64.0, false, true))
it.content = vboxBuilder.vbox
}
paneBuilder.add(ProgressIndicator(-1.0), null, Priority.ALWAYS)
paneBuilder.vbox
}

// val progressIndicator: Pane by lazy {
// val paneBuilder = VBoxBuilder("pane-service-contents")
// paneBuilder.addTitle("Signing into GanttProject Cloud")
// if (GPCloudOptions.authToken.value != "") {
// val expirationInstant = Instant.ofEpochSecond(GPCloudOptions.validity.value.toLongOrNull() ?: 0)
// val remainingDuration = Duration.between(Instant.now(), expirationInstant)
// if (!remainingDuration.isNegative) {
// val hours = remainingDuration.toHours()
// val minutes = remainingDuration.minusMinutes(hours * 60).toMinutes()
// val expirationLabel = if (hours > 0) {
// "${hours}h ${minutes}m"
// } else {
// "${minutes}m"
// }
// paneBuilder.add(Label("Your access token expires in $expirationLabel"), Pos.BASELINE_LEFT, Priority.NEVER)
// }
// }
// paneBuilder.add(ProgressIndicator(-1.0), null, Priority.ALWAYS)
// paneBuilder.vbox
// }
}
10 changes: 10 additions & 0 deletions ganttproject/src/biz/ganttproject/storage/cloud/GPCloudStorage.css
Expand Up @@ -6,6 +6,8 @@
-fx-pref-height: 100%;
-fx-fill-width: 1;
-fx-fill-height: 1;
-fx-min-width: 400;
-fx-min-height: 400;
}

.dlg-lock .btn-option {
Expand Down Expand Up @@ -140,3 +142,11 @@ Label.h2 {
.signup-pane .signup-body {
-fx-padding: 2ex 1em;
}

.progress-indicator {
-fx-pref-width: 100%;
-fx-pref-height: 100%;
-fx-fill-height: 1;
-fx-fill-width: 1;
-fx-padding: 20px;
}
Expand Up @@ -73,8 +73,6 @@ class GPCloudStorage(
}

fun start() {
sceneChanger(signupPane.progressIndicator)

signupPane.tryAccessToken(
success = Consumer {
webSocket.start()
Expand Down

0 comments on commit d0421d7

Please sign in to comment.