Merge pull request #43 from dklimpel/extend_room_list
Extend the room list with further attributes
This commit is contained in:
commit
2fc75cd6fc
|
@ -1,17 +1,68 @@
|
||||||
import React from "react";
|
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 => (
|
const RoomPagination = props => (
|
||||||
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
<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 => (
|
export const RoomList = props => (
|
||||||
<List {...props} pagination={<RoomPagination />}>
|
<List
|
||||||
|
{...props}
|
||||||
|
pagination={<RoomPagination />}
|
||||||
|
sort={{ field: "name", order: "ASC" }}
|
||||||
|
>
|
||||||
<Datagrid>
|
<Datagrid>
|
||||||
<TextField source="room_id" />
|
<EncryptionField
|
||||||
|
source="is_encrypted"
|
||||||
|
sortBy="encryption"
|
||||||
|
label={<HttpsIcon />}
|
||||||
|
/>
|
||||||
|
<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="federatable" />
|
||||||
|
<BooleanField source="public" />
|
||||||
</Datagrid>
|
</Datagrid>
|
||||||
</List>
|
</List>
|
||||||
);
|
);
|
||||||
|
|
|
@ -56,6 +56,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öderiert",
|
||||||
|
public: "Öffentlich",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
connections: {
|
connections: {
|
||||||
|
|
|
@ -55,6 +55,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: {
|
||||||
|
|
|
@ -50,6 +50,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 => {
|
||||||
|
@ -88,11 +91,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,
|
||||||
|
@ -100,6 +112,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();
|
||||||
|
|
Loading…
Reference in New Issue