From 6f09bd97b6ffb0ea7e0206094f8e29a6f156e867 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 20 Oct 2020 12:10:41 +0200 Subject: [PATCH] move setting view models in own dir / file --- src/domain/session/SessionViewModel.js | 2 +- .../SessionBackupViewModel.js} | 59 +-------------- .../session/settings/SettingsViewModel.js | 74 +++++++++++++++++++ 3 files changed, 77 insertions(+), 58 deletions(-) rename src/domain/session/{SettingsViewModel.js => settings/SessionBackupViewModel.js} (60%) create mode 100644 src/domain/session/settings/SettingsViewModel.js diff --git a/src/domain/session/SessionViewModel.js b/src/domain/session/SessionViewModel.js index b9b6def1..081e9f16 100644 --- a/src/domain/session/SessionViewModel.js +++ b/src/domain/session/SessionViewModel.js @@ -19,7 +19,7 @@ import {LeftPanelViewModel} from "./leftpanel/LeftPanelViewModel.js"; import {RoomViewModel} from "./room/RoomViewModel.js"; import {SessionStatusViewModel} from "./SessionStatusViewModel.js"; import {RoomGridViewModel} from "./RoomGridViewModel.js"; -import {SettingsViewModel} from "./SettingsViewModel.js"; +import {SettingsViewModel} from "./settings/SettingsViewModel.js"; import {ViewModel} from "../ViewModel.js"; export class SessionViewModel extends ViewModel { diff --git a/src/domain/session/SettingsViewModel.js b/src/domain/session/settings/SessionBackupViewModel.js similarity index 60% rename from src/domain/session/SettingsViewModel.js rename to src/domain/session/settings/SessionBackupViewModel.js index aaf31e37..c617e504 100644 --- a/src/domain/session/SettingsViewModel.js +++ b/src/domain/session/settings/SessionBackupViewModel.js @@ -1,5 +1,4 @@ /* -Copyright 2020 Bruno Windels Copyright 2020 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,63 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {ViewModel} from "../ViewModel.js"; +import {ViewModel} from "../../ViewModel.js"; -export class SettingsViewModel extends ViewModel { - constructor(options) { - super(options); - this._updateService = options.updateService; - const session = options.session; - this._session = session; - this._sessionBackupViewModel = this.track(new SessionBackupViewModel(this.childOptions({session}))); - this._closeUrl = this.urlCreator.urlUntilSegment("session"); - } - - get closeUrl() { - return this._closeUrl; - } - - get fingerprintKey() { - const key = this._session.fingerprintKey; - const partLength = 4; - const partCount = Math.ceil(key.length / partLength); - let formattedKey = ""; - for (let i = 0; i < partCount; i += 1) { - formattedKey += (formattedKey.length ? " " : "") + key.slice(i * partLength, (i + 1) * partLength); - } - return formattedKey; - } - - get deviceId() { - return this._session.deviceId; - } - - get userId() { - return this._session.userId; - } - - get version() { - if (this._updateService) { - return `${this._updateService.version} (${this._updateService.buildHash})`; - } - return this.i18n`development version`; - } - - checkForUpdate() { - this._updateService?.checkForUpdate(); - } - - get showUpdateButton() { - return !!this._updateService; - } - - get sessionBackupViewModel() { - return this._sessionBackupViewModel; - } -} - - -class SessionBackupViewModel extends ViewModel { +export class SessionBackupViewModel extends ViewModel { constructor(options) { super(options); this._session = options.session; diff --git a/src/domain/session/settings/SettingsViewModel.js b/src/domain/session/settings/SettingsViewModel.js new file mode 100644 index 00000000..76931884 --- /dev/null +++ b/src/domain/session/settings/SettingsViewModel.js @@ -0,0 +1,74 @@ +/* +Copyright 2020 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import {ViewModel} from "../../ViewModel.js"; +import {SessionBackupViewModel} from "./SessionBackupViewModel.js"; + +function formatKey(key) { + const partLength = 4; + const partCount = Math.ceil(key.length / partLength); + let formattedKey = ""; + for (let i = 0; i < partCount; i += 1) { + formattedKey += (formattedKey.length ? " " : "") + key.slice(i * partLength, (i + 1) * partLength); + } + return formattedKey; +} + +export class SettingsViewModel extends ViewModel { + constructor(options) { + super(options); + this._updateService = options.updateService; + const session = options.session; + this._session = session; + this._sessionBackupViewModel = this.track(new SessionBackupViewModel(this.childOptions({session}))); + this._closeUrl = this.urlCreator.urlUntilSegment("session"); + } + + get closeUrl() { + return this._closeUrl; + } + + get fingerprintKey() { + return formatKey(this._session.fingerprintKey); + } + + get deviceId() { + return this._session.deviceId; + } + + get userId() { + return this._session.userId; + } + + get version() { + if (this._updateService) { + return `${this._updateService.version} (${this._updateService.buildHash})`; + } + return this.i18n`development version`; + } + + checkForUpdate() { + this._updateService?.checkForUpdate(); + } + + get showUpdateButton() { + return !!this._updateService; + } + + get sessionBackupViewModel() { + return this._sessionBackupViewModel; + } +}