Extend the room list with further attributes

Add further attributes:
- is_encrypted
- federatable
- public
- state_events
- version
- joined_local_members

Also add the ability to sort.

API was added by synapse v1.13.0.
This commit is contained in:
dklimpel 2020-05-23 17:43:33 +02:00
parent 009ce803e2
commit 3884c50012
4 changed files with 45 additions and 3 deletions

View File

@ -1,17 +1,33 @@
import React from "react"; import React from "react";
import { Datagrid, List, TextField, Pagination } from "react-admin"; import {
Datagrid,
List,
TextField,
Pagination,
BooleanField,
} from "react-admin";
const RoomPagination = props => ( const RoomPagination = props => (
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} /> <Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
); );
export const RoomList = props => ( export const RoomList = props => (
<List {...props} pagination={<RoomPagination />}> <List
{...props}
pagination={<RoomPagination />}
sort={{ field: "name", order: "ASC" }}
>
<Datagrid> <Datagrid>
<TextField source="room_id" /> <TextField source="room_id" sortable={false} />
<TextField source="name" /> <TextField source="name" />
<TextField source="canonical_alias" /> <TextField source="canonical_alias" />
<TextField source="joined_members" /> <TextField source="joined_members" />
<TextField source="joined_local_members" />
<TextField source="state_events" />
<TextField source="version" />
<BooleanField source="is_encrypted" />
<BooleanField source="federatable" />
<BooleanField source="public" />
</Datagrid> </Datagrid>
</List> </List>
); );

View File

@ -53,6 +53,12 @@ export default {
name: "Name", name: "Name",
canonical_alias: "Alias", canonical_alias: "Alias",
joined_members: "Mitglieder", joined_members: "Mitglieder",
joined_local_members: "lokale Mitglieder",
state_events: "Ereignisse",
version: "Version",
is_encrypted: "Verschlüsselt",
federatable: "Fö­de­riert",
public: "Öffentlich",
}, },
}, },
connections: { connections: {

View File

@ -53,6 +53,12 @@ export default {
name: "Name", name: "Name",
canonical_alias: "Alias", canonical_alias: "Alias",
joined_members: "Members", joined_members: "Members",
joined_local_members: "local members",
state_events: "State events",
version: "Version",
is_encrypted: "Encrypted",
federatable: "Federatable",
public: "Public",
}, },
}, },
connections: { connections: {

View File

@ -48,6 +48,9 @@ const resourceMap = {
id: r.room_id, id: r.room_id,
alias: r.canonical_alias, alias: r.canonical_alias,
members: r.joined_members, members: r.joined_members,
is_encrypted: !!r.encryption,
federatable: !!r.federatable,
public: !!r.public,
}), }),
data: "rooms", data: "rooms",
total: json => { total: json => {
@ -86,11 +89,20 @@ function filterNullValues(key, value) {
return value; return value;
} }
function getSearchOrder(order) {
if (order === "DESC") {
return "b";
} else {
return "f";
}
}
const dataProvider = { const dataProvider = {
getList: (resource, params) => { getList: (resource, params) => {
console.log("getList " + resource); console.log("getList " + resource);
const { user_id, guests, deactivated } = params.filter; const { user_id, guests, deactivated } = params.filter;
const { page, perPage } = params.pagination; const { page, perPage } = params.pagination;
const { field, order } = params.sort;
const from = (page - 1) * perPage; const from = (page - 1) * perPage;
const query = { const query = {
from: from, from: from,
@ -98,6 +110,8 @@ const dataProvider = {
user_id: user_id, user_id: user_id,
guests: guests, guests: guests,
deactivated: deactivated, deactivated: deactivated,
order_by: field,
dir: getSearchOrder(order),
}; };
const homeserver = localStorage.getItem("base_url"); const homeserver = localStorage.getItem("base_url");
if (!homeserver || !(resource in resourceMap)) return Promise.reject(); if (!homeserver || !(resource in resourceMap)) return Promise.reject();