-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close: #7952 Co-authored-by: ivk <[email protected]>
- Loading branch information
Showing
8 changed files
with
214 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { MailboxDetail } from "../../../common/mailFunctionality/MailboxModel" | ||
import Stream from "mithril/stream" | ||
import stream from "mithril/stream" | ||
|
||
export type MailExportState = | ||
| { type: "idle"; lastExport: Date | null } | ||
| { type: "exporting"; mailbox: MailboxDetail; progress: number; exportedMails: number } | ||
| { | ||
type: "finished" | ||
mailbox: MailboxDetail | ||
exportedMails: number | ||
} | ||
|
||
export class MailExportController { | ||
private _state: Stream<MailExportState> = stream({ type: "idle", lastExport: new Date() }) | ||
private progressTimeout: number | null = null | ||
|
||
get state(): Stream<MailExportState> { | ||
return this._state | ||
} | ||
|
||
startExport(mailbox: MailboxDetail) { | ||
this._state({ type: "exporting", mailbox: mailbox, progress: 0, exportedMails: 0 }) | ||
this.progressTimeout = window.setInterval(() => { | ||
const oldState = this._state() | ||
if (oldState.type === "exporting") { | ||
if (oldState.progress >= 0.9) { | ||
this._state({ type: "finished", mailbox: mailbox, exportedMails: oldState.exportedMails }) | ||
} else { | ||
this._state({ | ||
...oldState, | ||
progress: oldState.progress + 0.1, | ||
exportedMails: oldState.exportedMails + 100, | ||
}) | ||
} | ||
} | ||
}, 1000) | ||
} | ||
|
||
cancelExport() { | ||
if (this.progressTimeout) { | ||
clearInterval(this.progressTimeout) | ||
this.progressTimeout = null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import m, { Children, Component, Vnode } from "mithril" | ||
import { lang } from "../../common/misc/LanguageViewModel" | ||
import { theme } from "../../common/gui/theme" | ||
import { px } from "../../common/gui/size" | ||
import { ProgressBar } from "../../common/gui/base/ProgressBar" | ||
import { DropDownSelector, type DropDownSelectorAttrs } from "../../common/gui/base/DropDownSelector" | ||
import { MailboxDetail } from "../../common/mailFunctionality/MailboxModel" | ||
import { getMailboxName } from "../../common/mailFunctionality/SharedMailUtils" | ||
import { mailLocator } from "../mailLocator" | ||
import { first } from "@tutao/tutanota-utils" | ||
import { LoginController } from "../../common/api/main/LoginController" | ||
import { Button, ButtonType } from "../../common/gui/base/Button" | ||
import { MailExportController } from "../mail/model/MailExportController" | ||
import { formatDate } from "../../common/misc/Formatter" | ||
import Stream from "mithril/stream" | ||
|
||
interface MailExportSettingsAttrs { | ||
mailboxDetails: MailboxDetail[] | ||
logins: LoginController | ||
mailExportController: MailExportController | ||
} | ||
|
||
export class MailExportSettings implements Component<MailExportSettingsAttrs> { | ||
private selectedMailbox: MailboxDetail | null = null | ||
private controllerSubscription: Stream<void> | null = null | ||
|
||
oncreate(vnode: Vnode<MailExportSettingsAttrs>) { | ||
this.controllerSubscription = vnode.attrs.mailExportController.state.map(m.redraw) | ||
} | ||
|
||
onremove() { | ||
if (this.controllerSubscription) { | ||
this.controllerSubscription.end() | ||
this.controllerSubscription = null | ||
} | ||
} | ||
|
||
view(vnode: Vnode<MailExportSettingsAttrs>): Children { | ||
const { mailboxDetails } = vnode.attrs | ||
this.selectedMailbox = this.selectedMailbox ?? first(mailboxDetails) | ||
const state = vnode.attrs.mailExportController.state() | ||
return [ | ||
m(DropDownSelector, { | ||
label: "mailboxToExport_label", | ||
items: mailboxDetails.map((mailboxDetail) => { | ||
return { name: getMailboxName(mailLocator.logins, mailboxDetail), value: mailboxDetail } | ||
}), | ||
selectedValue: this.selectedMailbox, | ||
selectionChangedHandler: (selectedMailbox) => { | ||
this.selectedMailbox = selectedMailbox | ||
}, | ||
dropdownWidth: 300, | ||
disabled: state.type === "exporting", | ||
} satisfies DropDownSelectorAttrs<MailboxDetail>), | ||
state.type === "exporting" | ||
? [ | ||
m(".flex-space-between.items-center.mt.mb-s", [ | ||
m(".flex-grow.mr", [ | ||
m( | ||
"small.noselect", | ||
lang.get("exportingEmails_label", { | ||
"{count}": state.exportedMails, | ||
}), | ||
), | ||
m( | ||
".rel.full-width.mt-s", | ||
{ | ||
style: { | ||
"background-color": theme.content_border, | ||
height: px(2), | ||
}, | ||
}, | ||
m(ProgressBar, { progress: state.progress }), | ||
), | ||
]), | ||
m(Button, { | ||
label: "cancel_action", | ||
type: ButtonType.Secondary, | ||
click: () => { | ||
vnode.attrs.mailExportController.cancelExport() | ||
}, | ||
}), | ||
]), | ||
] | ||
: state.type === "idle" | ||
? [ | ||
m(".flex-space-between.items-center.mt.mb-s", [ | ||
m( | ||
"small.noselect", | ||
state.lastExport | ||
? lang.get("lastExportTime_Label", { | ||
"{date}": formatDate(state.lastExport), | ||
}) | ||
: null, | ||
), | ||
m(Button, { | ||
label: "export_action", | ||
click: () => { | ||
if (this.selectedMailbox) { | ||
vnode.attrs.mailExportController.startExport(this.selectedMailbox) | ||
} | ||
}, | ||
type: ButtonType.Secondary, | ||
}), | ||
]), | ||
] | ||
: [ | ||
m(".flex-space-between.items-center.mt.mb-s", [ | ||
m( | ||
"small.noselect", | ||
lang.get("mailsExported_label", { | ||
"{numbers}": state.exportedMails, | ||
}), | ||
), | ||
m(Button, { | ||
label: "open_action", | ||
click: () => {}, | ||
type: ButtonType.Secondary, | ||
}), | ||
]), | ||
], | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters