Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加webdav只读选项 #147

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions public/locales/en-US/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,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",
Expand Down
3 changes: 3 additions & 0 deletions public/locales/zh-CN/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@
"rootFolder": "相对根目录",
"createdAt": "创建日期",
"action": "操作",
"readonlyOn": "开启只读",
"readonlyOff": "关闭只读",
"delete": "删除",
"listEmpty": "没有记录",
"createNewAccount": "创建新账号",
"taskType": "任务类型",
Expand Down
62 changes: 55 additions & 7 deletions src/component/Setting/WebDAV.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ 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";
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: {
Expand Down Expand Up @@ -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", {
Expand All @@ -125,6 +141,7 @@ export default function WebDAV() {
CreatedAt: response.data.created_at,
Name: account.name,
Root: account.path,
Readonly: account.Readonly,
},
...accounts,
]);
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
))}
Expand Down