feat(webdav): add read-only option (#147)

This commit is contained in:
WeidiDeng 2023-02-07 19:38:23 +08:00 committed by GitHub
parent 0d6a560cd6
commit e4b6e583d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 7 deletions

View File

@ -447,6 +447,9 @@
"rootFolder": "Relative root folder",
"createdAt": "Created at",
"action": "Action",
"readonlyOn": "Turn on readonly",
"readonlyOff": "Turn off readonly",
"delete": "Delete",
"listEmpty": "No records.",
"createNewAccount": "Create new account",
"taskType": "Task type",

View File

@ -446,6 +446,9 @@
"rootFolder": "相对根目录",
"createdAt": "创建日期",
"action": "操作",
"readonlyOn": "开启只读",
"readonlyOff": "关闭只读",
"delete": "删除",
"listEmpty": "没有记录",
"createNewAccount": "创建新账号",
"taskType": "任务类型",

View File

@ -15,7 +15,7 @@ import Alert from "@material-ui/lab/Alert";
import Auth from "../../middleware/Auth";
import API from "../../middleware/Api";
import IconButton from "@material-ui/core/IconButton";
import { Delete } from "@material-ui/icons";
import { Delete, ToggleOff, ToggleOn } from "@material-ui/icons";
import CreateWebDAVAccount from "../Modals/CreateWebDAVAccount";
import TimeAgo from "timeago-react";
import Link from "@material-ui/core/Link";
@ -23,6 +23,8 @@ import { toggleSnackbar } from "../../redux/explorer";
import Nothing from "../Placeholder/Nothing";
import { useTranslation } from "react-i18next";
import AppPromotion from "./AppPromotion";
import Tooltip from "@material-ui/core/Tooltip";
import ToggleIcon from "material-ui-toggle-icon";
const useStyles = makeStyles((theme) => ({
layout: {
@ -111,6 +113,20 @@ export default function WebDAV() {
});
};
const toggleAccountReadonly = (id) => {
const account = accounts[id];
API.patch("/webdav/accounts", {
id: account.ID,
readonly: !account.Readonly,
}).then((response) => {
account.Readonly = response.data.readonly;
const accountCopy = [...accounts];
setAccounts(accountCopy);
}).catch((error) => {
ToggleSnackbar("top", "right", error.message, "error");
});
};
const addAccount = (account) => {
setCreate(false);
API.post("/webdav/accounts", {
@ -125,6 +141,7 @@ export default function WebDAV() {
CreatedAt: response.data.created_at,
Name: account.name,
Root: account.path,
Readonly: account.Readonly,
},
...accounts,
]);
@ -186,7 +203,7 @@ export default function WebDAV() {
<TableCell align="right">
{t("setting.createdAt")}
</TableCell>
<TableCell align="right">
<TableCell align="center">
{t("setting.action")}
</TableCell>
</TableRow>
@ -230,15 +247,46 @@ export default function WebDAV() {
)}
/>
</TableCell>
<TableCell align="right">
<IconButton
size={"small"}
<TableCell align="center">
<Tooltip
placement="top"
title={
row.Readonly
? t("setting.readonlyOff")
: t("setting.readonlyOn")
}
onClick={() =>
toggleAccountReadonly(id)
}>
<IconButton>
<ToggleIcon
on={row.Readonly}
onIcon={
<ToggleOn
fontSize={"small"}
/>
}
offIcon={
<ToggleOff
fontSize={"small"}
/>
}
/>
</IconButton>
</Tooltip>
<Tooltip
placement="top"
title={t("setting.delete")}
onClick={() =>
deleteAccount(id)
}
>
<Delete />
</IconButton>
<IconButton
fontSize={"small"}
>
<Delete />
</IconButton>
</Tooltip>
</TableCell>
</TableRow>
))}