2020-08-05 18:38:55 +02:00
|
|
|
/*
|
|
|
|
Copyright 2020 Bruno Windels <bruno@windels.cloud>
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2019-09-08 10:19:16 +02:00
|
|
|
import {SortedArray} from "../observable/index.js";
|
2022-02-14 17:53:59 +01:00
|
|
|
import {ViewModel} from "./ViewModel";
|
2020-08-14 14:34:39 +02:00
|
|
|
import {avatarInitials, getIdentifierColorNumber} from "./avatar.js";
|
2019-10-12 21:16:48 +02:00
|
|
|
|
2020-05-04 19:23:11 +02:00
|
|
|
class SessionItemViewModel extends ViewModel {
|
2020-10-09 17:02:53 +02:00
|
|
|
constructor(options, pickerVM) {
|
|
|
|
super(options);
|
2019-10-12 21:16:48 +02:00
|
|
|
this._pickerVM = pickerVM;
|
2020-10-09 17:02:53 +02:00
|
|
|
this._sessionInfo = options.sessionInfo;
|
2019-10-12 21:16:48 +02:00
|
|
|
this._isDeleting = false;
|
2019-10-13 07:48:49 +02:00
|
|
|
this._isClearing = false;
|
2019-10-12 21:16:48 +02:00
|
|
|
this._error = null;
|
2019-12-14 18:29:35 +01:00
|
|
|
this._exportDataUrl = null;
|
2019-10-12 21:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get error() {
|
|
|
|
return this._error && this._error.message;
|
|
|
|
}
|
|
|
|
|
|
|
|
get id() {
|
|
|
|
return this._sessionInfo.id;
|
|
|
|
}
|
|
|
|
|
2020-10-09 17:02:53 +02:00
|
|
|
get openUrl() {
|
2020-10-16 13:02:21 +02:00
|
|
|
return this.urlCreator.urlForSegment("session", this.id);
|
2020-10-09 17:02:53 +02:00
|
|
|
}
|
|
|
|
|
2019-12-14 18:29:35 +01:00
|
|
|
get label() {
|
|
|
|
const {userId, comment} = this._sessionInfo;
|
|
|
|
if (comment) {
|
|
|
|
return `${userId} (${comment})`;
|
|
|
|
} else {
|
|
|
|
return userId;
|
|
|
|
}
|
2019-10-12 21:16:48 +02:00
|
|
|
}
|
2019-10-12 22:18:08 +02:00
|
|
|
|
|
|
|
get sessionInfo() {
|
|
|
|
return this._sessionInfo;
|
2019-10-12 21:16:48 +02:00
|
|
|
}
|
2019-10-13 08:29:23 +02:00
|
|
|
|
2019-12-14 18:29:35 +01:00
|
|
|
get exportDataUrl() {
|
|
|
|
return this._exportDataUrl;
|
|
|
|
}
|
|
|
|
|
2020-08-14 14:34:39 +02:00
|
|
|
get avatarColorNumber() {
|
|
|
|
return getIdentifierColorNumber(this._sessionInfo.userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
get avatarInitials() {
|
|
|
|
return avatarInitials(this._sessionInfo.userId);
|
|
|
|
}
|
2019-10-12 21:16:48 +02:00
|
|
|
}
|
2019-07-29 22:39:56 +02:00
|
|
|
|
2020-04-22 21:53:55 +02:00
|
|
|
|
2020-05-04 19:23:11 +02:00
|
|
|
export class SessionPickerViewModel extends ViewModel {
|
2020-05-05 23:14:58 +02:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2019-10-13 08:16:08 +02:00
|
|
|
this._sessions = new SortedArray((s1, s2) => s1.id.localeCompare(s2.id));
|
2020-04-22 21:53:55 +02:00
|
|
|
this._loadViewModel = null;
|
|
|
|
this._error = null;
|
2019-07-29 22:39:56 +02:00
|
|
|
}
|
|
|
|
|
2020-04-20 22:49:14 +02:00
|
|
|
// this loads all the sessions
|
2019-07-29 22:39:56 +02:00
|
|
|
async load() {
|
2020-10-26 15:44:11 +01:00
|
|
|
const sessions = await this.platform.sessionInfoStorage.getAll();
|
2020-10-09 17:02:53 +02:00
|
|
|
this._sessions.setManyUnsorted(sessions.map(s => {
|
|
|
|
return new SessionItemViewModel(this.childOptions({sessionInfo: s}), this);
|
|
|
|
}));
|
2019-07-29 22:39:56 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 21:53:55 +02:00
|
|
|
// for the loading of 1 picked session
|
|
|
|
get loadViewModel() {
|
|
|
|
return this._loadViewModel;
|
2020-04-20 22:49:14 +02:00
|
|
|
}
|
|
|
|
|
2019-07-29 22:39:56 +02:00
|
|
|
get sessions() {
|
|
|
|
return this._sessions;
|
|
|
|
}
|
|
|
|
|
2020-10-09 17:02:53 +02:00
|
|
|
get cancelUrl() {
|
2020-10-16 13:02:21 +02:00
|
|
|
return this.urlCreator.urlForSegment("login");
|
2019-07-29 22:39:56 +02:00
|
|
|
}
|
|
|
|
}
|