implement client list filtering

This commit is contained in:
Bruno Windels 2020-12-02 09:43:54 +01:00
parent 517a5ccbea
commit 1957277463
1 changed files with 24 additions and 5 deletions

View File

@ -15,6 +15,7 @@ limitations under the License.
*/
import {isWebPlatform, Platform} from "./Platform.js";
import {Maturity} from "./types.js";
import {ClientViewModel} from "./ClientViewModel.js";
import {ViewModel} from "../utils/ViewModel.js";
@ -22,17 +23,35 @@ export class ClientListViewModel extends ViewModel {
constructor(options) {
super(options);
const {clients, client, link} = options;
this.clientList = clients.map(client => new ClientViewModel(this.childOptions({
client,
link,
pickClient: client => this._pickClient(client)
})));
this._clients = clients;
this._link = link;
this.clientList = null;
this._showExperimental = true;
this._showUnsupportedPlatform = true;
this._filterClients();
this.clientViewModel = null;
if (client) {
this._pickClient(client);
}
}
_filterClients() {
this.clientList = this._clients.filter(client => {
if (!this._showExperimental && !this.platforms.map(p => client.getMaturity(p)).includes(Maturity.Stable)) {
return false;
}
if (!this._showUnsupportedPlatform && !client.platforms.some(p => this.platforms.includes(p))) {
return false;
}
return true;
}).map(client => new ClientViewModel(this.childOptions({
client,
link: this._link,
pickClient: client => this._pickClient(client)
})));
this.emitChange();
}
_pickClient(client) {
this.clientViewModel = this.clientList.find(vm => vm.clientId === client.id);
this.emitChange();