mirror of
https://github.com/UA-Fediland/synapse-admin.git
synced 2024-11-08 15:54:51 +00:00
Merge pull request #43 from dklimpel/extend_room_list
Extend the room list with further attributes
This commit is contained in:
commit
2fc75cd6fc
4 changed files with 80 additions and 3 deletions
|
@ -1,17 +1,68 @@
|
|||
import React from "react";
|
||||
import { Datagrid, List, TextField, Pagination } from "react-admin";
|
||||
import {
|
||||
Datagrid,
|
||||
List,
|
||||
TextField,
|
||||
Pagination,
|
||||
BooleanField,
|
||||
useTranslate,
|
||||
} from "react-admin";
|
||||
import get from "lodash/get";
|
||||
import { Tooltip, Typography } from "@material-ui/core";
|
||||
import HttpsIcon from "@material-ui/icons/Https";
|
||||
import NoEncryptionIcon from "@material-ui/icons/NoEncryption";
|
||||
|
||||
const RoomPagination = props => (
|
||||
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||
);
|
||||
|
||||
const EncryptionField = ({ source, record = {}, emptyText }) => {
|
||||
const translate = useTranslate();
|
||||
const value = get(record, source);
|
||||
let ariaLabel = value === false ? "ra.boolean.false" : "ra.boolean.true";
|
||||
|
||||
if (value === false || value === true) {
|
||||
return (
|
||||
<Typography component="span" variant="body2">
|
||||
<Tooltip title={translate(ariaLabel, { _: ariaLabel })}>
|
||||
{value === true ? (
|
||||
<HttpsIcon data-testid="true" htmlColor="limegreen" />
|
||||
) : (
|
||||
<NoEncryptionIcon data-testid="false" color="error" />
|
||||
)}
|
||||
</Tooltip>
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Typography component="span" variant="body2">
|
||||
{emptyText}
|
||||
</Typography>
|
||||
);
|
||||
};
|
||||
|
||||
export const RoomList = props => (
|
||||
<List {...props} pagination={<RoomPagination />}>
|
||||
<List
|
||||
{...props}
|
||||
pagination={<RoomPagination />}
|
||||
sort={{ field: "name", order: "ASC" }}
|
||||
>
|
||||
<Datagrid>
|
||||
<TextField source="room_id" />
|
||||
<EncryptionField
|
||||
source="is_encrypted"
|
||||
sortBy="encryption"
|
||||
label={<HttpsIcon />}
|
||||
/>
|
||||
<TextField source="room_id" sortable={false} />
|
||||
<TextField source="name" />
|
||||
<TextField source="canonical_alias" />
|
||||
<TextField source="joined_members" />
|
||||
<TextField source="joined_local_members" />
|
||||
<TextField source="state_events" />
|
||||
<TextField source="version" />
|
||||
<BooleanField source="federatable" />
|
||||
<BooleanField source="public" />
|
||||
</Datagrid>
|
||||
</List>
|
||||
);
|
||||
|
|
|
@ -56,6 +56,12 @@ export default {
|
|||
name: "Name",
|
||||
canonical_alias: "Alias",
|
||||
joined_members: "Mitglieder",
|
||||
joined_local_members: "lokale Mitglieder",
|
||||
state_events: "Ereignisse",
|
||||
version: "Version",
|
||||
is_encrypted: "Verschlüsselt",
|
||||
federatable: "Föderiert",
|
||||
public: "Öffentlich",
|
||||
},
|
||||
},
|
||||
connections: {
|
||||
|
|
|
@ -55,6 +55,12 @@ export default {
|
|||
name: "Name",
|
||||
canonical_alias: "Alias",
|
||||
joined_members: "Members",
|
||||
joined_local_members: "local members",
|
||||
state_events: "State events",
|
||||
version: "Version",
|
||||
is_encrypted: "Encrypted",
|
||||
federatable: "Federatable",
|
||||
public: "Public",
|
||||
},
|
||||
},
|
||||
connections: {
|
||||
|
|
|
@ -50,6 +50,9 @@ const resourceMap = {
|
|||
id: r.room_id,
|
||||
alias: r.canonical_alias,
|
||||
members: r.joined_members,
|
||||
is_encrypted: !!r.encryption,
|
||||
federatable: !!r.federatable,
|
||||
public: !!r.public,
|
||||
}),
|
||||
data: "rooms",
|
||||
total: json => {
|
||||
|
@ -88,11 +91,20 @@ function filterNullValues(key, value) {
|
|||
return value;
|
||||
}
|
||||
|
||||
function getSearchOrder(order) {
|
||||
if (order === "DESC") {
|
||||
return "b";
|
||||
} else {
|
||||
return "f";
|
||||
}
|
||||
}
|
||||
|
||||
const dataProvider = {
|
||||
getList: (resource, params) => {
|
||||
console.log("getList " + resource);
|
||||
const { user_id, guests, deactivated } = params.filter;
|
||||
const { page, perPage } = params.pagination;
|
||||
const { field, order } = params.sort;
|
||||
const from = (page - 1) * perPage;
|
||||
const query = {
|
||||
from: from,
|
||||
|
@ -100,6 +112,8 @@ const dataProvider = {
|
|||
user_id: user_id,
|
||||
guests: guests,
|
||||
deactivated: deactivated,
|
||||
order_by: field,
|
||||
dir: getSearchOrder(order),
|
||||
};
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
|
Loading…
Reference in a new issue