Skip to content

Commit 4599ada

Browse files
authored
Merge pull request #16 from PKUHPC/style-notification
style: 更新消息系统 UI
2 parents de3e5f1 + 74312de commit 4599ada

File tree

14 files changed

+77
-49
lines changed

14 files changed

+77
-49
lines changed

.changeset/lazy-garlics-impress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@scow/lib-web": patch
3+
---
4+
5+
修复 navlink 只有图标没有文字是不水平居中的问题

.changeset/silver-yaks-scream.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@scow/notification": patch
3+
"@scow/mis-server": patch
4+
---
5+
6+
修改消息系统 ui

apps/mis-server/src/models/messageType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export enum InternalMessageType {
1616
AccountLowBalance = "AccountLowBalance",
1717
AccountBalance = "AccountBalance",
1818
AccountLocked = "AccountLocked",
19-
AccountRestored = "AccountRestored",
19+
AccountUnblocked = "AccountUnblocked",
2020
JobStarted = "JobStarted",
2121
JobFinished = "JobFinished",
2222
JobAbnormalTermination = "JobAbnormalTermination",

apps/mis-server/src/services/account.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const accountServiceServer = plugin((server) => {
179179
// 发送消息
180180
const ownerAndAdmin = await getAccountOwnerAndAdmin(accountName, logger, em);
181181
await sendMessage({
182-
messageType: InternalMessageType.AccountRestored,
182+
messageType: InternalMessageType.AccountUnblocked,
183183
targetType: TargetType.USER, targetIds: ownerAndAdmin.map((x) => x.userId),
184184
metadata: {
185185
time: (new Date()).toISOString(),
@@ -424,7 +424,7 @@ export const accountServiceServer = plugin((server) => {
424424
// 发送账户解封消息
425425
const ownerAndAdmin = await getAccountOwnerAndAdmin(accountName, logger, em);
426426
await sendMessage({
427-
messageType: InternalMessageType.AccountRestored,
427+
messageType: InternalMessageType.AccountUnblocked,
428428
targetType: TargetType.USER, targetIds: ownerAndAdmin.map((x) => x.userId),
429429
metadata: {
430430
time: (new Date()).toISOString(),

apps/mis-server/src/tasks/fetch.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,17 @@ export async function fetchJobs(
121121

122122
// Determine whether the job can be inserted into the database. If not, skip the job
123123
await em.flush();
124-
124+
125125
await sendMessage({
126126
messageType: InternalMessageType.JobFinished,
127127
targetType: TargetType.USER, targetIds: [job.user],
128128
metadata: {
129129
time: job.endTime!,
130130
jobId: job.jobId.toString(),
131+
jobName: job.name,
132+
cluster: job.cluster,
133+
account: job.account,
134+
price: price.account?.price.toString() ?? "0",
131135
},
132136
}, logger);
133137
} catch (error) {

apps/mis-server/src/utils/sendMessage.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ interface AccountLocked extends BaseMessage {
7070
};
7171
}
7272

73-
interface AccountRestored extends BaseMessage {
74-
messageType: InternalMessageType.AccountRestored;
73+
interface AccountUnblocked extends BaseMessage {
74+
messageType: InternalMessageType.AccountUnblocked;
7575
targetType: TargetType.USER,
7676
metadata: {
7777
time: string;
@@ -85,11 +85,15 @@ interface JobFinished extends BaseMessage {
8585
metadata: {
8686
time: string;
8787
jobId: string;
88+
jobName: string;
89+
cluster: string;
90+
account: string;
91+
price: string;
8892
};
8993
}
9094

9195
type Message = AccountLocked | AccountOverdue | AccountRechargeSuccess
92-
| AccountLowBalance | AccountBalance | AccountRestored
96+
| AccountLowBalance | AccountBalance | AccountUnblocked
9397
| JobFinished;
9498

9599
export const sendMessage = async (message: Message, logger: Logger) => {

apps/notification/src/models/i18n.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export type I18nStringType = string | {
2121
// languageDic for partitionsManagement
2222
export const languageDic = {
2323
zh_cn: {
24+
api: {
25+
notification: "通知",
26+
myMsgs: "我的消息",
27+
msgSub: "消息订阅",
28+
msgConfig: "消息设置",
29+
sendMsg: "发送消息",
30+
createType: "创建自定义消息类型",
31+
},
2432
common: {
2533
default: "默认",
2634
zhCn: "简体中文",
@@ -82,8 +90,8 @@ export const languageDic = {
8290
},
8391
messageConfigModal: {
8492
modifySuccess: "修改成功",
85-
authorization: "授权方式",
86-
dontAllowCancel: "不允许用户取消以下授权方式",
93+
authorization: "订阅设置",
94+
dontAllowCancel: "不允许用户取消订阅以下类型的通知",
8795
inputTitle: "请输入标题",
8896
},
8997
},
@@ -105,7 +113,7 @@ export const languageDic = {
105113
},
106114
},
107115
notification: {
108-
pageTitle: "消息通知",
116+
pageTitle: "我的消息",
109117
markAllReadErrorInfo: "标记全部已读失败",
110118
markAllReadSuccessInfo: "标记全部已读成功",
111119
deleteReadMsgErrorInfo: "删除已读消息失败",
@@ -140,6 +148,14 @@ export const languageDic = {
140148
},
141149
},
142150
en: {
151+
api: {
152+
notification: "Notification",
153+
myMsgs: "My Messages",
154+
msgSub: "Message Subscription",
155+
msgConfig: "Message Config",
156+
sendMsg: "Send Message",
157+
createType: "Create Custom Message Type",
158+
},
143159
common: {
144160
default: "Default",
145161
zhCn: "Simplified Chinese",
@@ -205,8 +221,8 @@ export const languageDic = {
205221
messageConfigModal: {
206222
inputTitle: "Please enter a title",
207223
modifySuccess: "Modification successful",
208-
authorization: "Authorization",
209-
dontAllowCancel: "Do not allow users to cancel the following authorization methods",
224+
authorization: "Subscription Settings",
225+
dontAllowCancel: "Do not allow users to unsubscribe from the following types of notifications.",
210226
},
211227
},
212228
sendMessage: {

apps/notification/src/models/message-type.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export enum InternalMessageType {
3030
AccountLowBalance = "AccountLowBalance",
3131
AccountBalance = "AccountBalance",
3232
AccountLocked = "AccountLocked",
33-
AccountRestored = "AccountRestored",
33+
AccountUnblocked = "AccountUnblocked",
3434
JobStarted = "JobStarted",
3535
JobFinished = "JobFinished",
3636
JobAbnormalTermination = "JobAbnormalTermination",
@@ -160,12 +160,12 @@ export const internalMessageTypesMap = new Map<InternalMessageType, MessageTypeI
160160
zhCn: "账户 {__accountName__} 已于【{__time__}】被封锁,您可以联系管理员申请解封。",
161161
},
162162
}],
163-
[InternalMessageType.AccountRestored, {
164-
type: "AccountRestored",
163+
[InternalMessageType.AccountUnblocked, {
164+
type: "AccountUnblocked",
165165
titleTemplate: {
166-
default: "账户恢复通知",
167-
en: "Account Restored",
168-
zhCn: "账户恢复通知",
166+
default: "账户解封通知",
167+
en: "Account Unblocking",
168+
zhCn: "账户解封通知",
169169
},
170170
category: "Account",
171171
categoryTemplate: {

apps/notification/src/pages/api/mis/navbarLinks.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ import { applyMiddleware } from "../middleware/cors";
1919

2020
async function handler(req: NextApiRequest, res: NextApiResponse) {
2121

22-
const searchParams = req.query;
23-
const scowLangId = searchParams.scowLangId;
24-
25-
const isChinese = scowLangId === "zh_cn";
26-
2722
if (req.method === "POST") {
2823

2924
const cookie = req.headers.cookie;
@@ -47,7 +42,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
4742
const navbarLinks = [
4843
{
4944
path: "/notification",
50-
text: isChinese ? "消息系统" : "Messaging System",
45+
text: "",
5146
icon: { src: svgFilePath },
5247
},
5348
];

apps/notification/src/pages/api/mis/rewriteNavigations.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { NextApiRequest, NextApiResponse } from "next";
1414
import { join } from "path";
1515
import { PlatformRole } from "src/models/user";
1616
import { validateToken } from "src/server/auth/token";
17+
import { getLanguage } from "src/utils/i18n";
1718
import { BASE_PATH } from "src/utils/processEnv";
1819

1920
import { applyMiddleware } from "../middleware/cors";
@@ -37,12 +38,12 @@ interface Request {
3738
}
3839

3940
async function handler(req: NextApiRequest, res: NextApiResponse) {
41+
4042
const body = req.body as Request;
4143

4244
const searchParams = req.query;
43-
const scowLangId = searchParams.scowLangId;
44-
45-
const isChinese = scowLangId === "zh_cn";
45+
const scowLangId = searchParams.scowLangId ?? "zh_cn";
46+
const language = getLanguage(scowLangId as string).api;
4647

4748
const cookie = req.headers.cookie;
4849
// 将 cookie 字符串解析为对象
@@ -63,38 +64,38 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
6364
body.navs.push({
6465
path: "/",
6566
clickToPath: "/notification",
66-
text: isChinese ? "通知" : "Notification",
67+
text: language.notification,
6768
hideIfNotActive: true,
6869
children: [
6970
{
7071
path: "/notification",
7172
clickToPath: undefined,
72-
text: isChinese ? "消息通知" : "Message Notification",
73+
text: language.myMsgs,
7374
icon: { src: join(BASE_PATH, "/icons/notification.svg") },
7475
},
7576
{
7677
path: "/subscription",
7778
clickToPath: undefined,
78-
text: isChinese ? "消息订阅" : "Message Subscription",
79+
text: language.msgSub,
7980
icon: { src: join(BASE_PATH, "/icons/subscription.svg") },
8081
},
8182
...cookie && userInfo?.platformRoles.includes(PlatformRole.PLATFORM_ADMIN) ? [
8283
{
8384
path: "/message-config",
8485
clickToPath: undefined,
85-
text: isChinese ? "消息设置" : "Message Setting",
86+
text: language.msgConfig,
8687
icon: { src: join(BASE_PATH, "/icons/msg-config.svg") },
8788
},
8889
{
8990
path: "/send-message",
9091
clickToPath: undefined,
91-
text: isChinese ? "发送消息" : "Send Message",
92+
text: language.sendMsg,
9293
icon: { src: join(BASE_PATH, "/icons/send-msg.svg") },
9394
},
9495
{
9596
path: "/create-custom-message-type",
9697
clickToPath: undefined,
97-
text: isChinese ? "创建自定义消息类型" : "Create Custom Message Type",
98+
text: language.createType,
9899
icon: { src: join(BASE_PATH, "/icons/create-custom-type.svg") },
99100
},
100101
] : [],

0 commit comments

Comments
 (0)