Skip to content

Commit

Permalink
Merge pull request #16 from PKUHPC/style-notification
Browse files Browse the repository at this point in the history
style: 更新消息系统 UI
  • Loading branch information
ddadaal authored Sep 19, 2024
2 parents de3e5f1 + 74312de commit 4599ada
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-garlics-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/lib-web": patch
---

修复 navlink 只有图标没有文字是不水平居中的问题
6 changes: 6 additions & 0 deletions .changeset/silver-yaks-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@scow/notification": patch
"@scow/mis-server": patch
---

修改消息系统 ui
2 changes: 1 addition & 1 deletion apps/mis-server/src/models/messageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum InternalMessageType {
AccountLowBalance = "AccountLowBalance",
AccountBalance = "AccountBalance",
AccountLocked = "AccountLocked",
AccountRestored = "AccountRestored",
AccountUnblocked = "AccountUnblocked",
JobStarted = "JobStarted",
JobFinished = "JobFinished",
JobAbnormalTermination = "JobAbnormalTermination",
Expand Down
4 changes: 2 additions & 2 deletions apps/mis-server/src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const accountServiceServer = plugin((server) => {
// 发送消息
const ownerAndAdmin = await getAccountOwnerAndAdmin(accountName, logger, em);
await sendMessage({
messageType: InternalMessageType.AccountRestored,
messageType: InternalMessageType.AccountUnblocked,
targetType: TargetType.USER, targetIds: ownerAndAdmin.map((x) => x.userId),
metadata: {
time: (new Date()).toISOString(),
Expand Down Expand Up @@ -424,7 +424,7 @@ export const accountServiceServer = plugin((server) => {
// 发送账户解封消息
const ownerAndAdmin = await getAccountOwnerAndAdmin(accountName, logger, em);
await sendMessage({
messageType: InternalMessageType.AccountRestored,
messageType: InternalMessageType.AccountUnblocked,
targetType: TargetType.USER, targetIds: ownerAndAdmin.map((x) => x.userId),
metadata: {
time: (new Date()).toISOString(),
Expand Down
6 changes: 5 additions & 1 deletion apps/mis-server/src/tasks/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ export async function fetchJobs(

// Determine whether the job can be inserted into the database. If not, skip the job
await em.flush();

await sendMessage({
messageType: InternalMessageType.JobFinished,
targetType: TargetType.USER, targetIds: [job.user],
metadata: {
time: job.endTime!,
jobId: job.jobId.toString(),
jobName: job.name,
cluster: job.cluster,
account: job.account,
price: price.account?.price.toString() ?? "0",
},
}, logger);
} catch (error) {
Expand Down
10 changes: 7 additions & 3 deletions apps/mis-server/src/utils/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ interface AccountLocked extends BaseMessage {
};
}

interface AccountRestored extends BaseMessage {
messageType: InternalMessageType.AccountRestored;
interface AccountUnblocked extends BaseMessage {
messageType: InternalMessageType.AccountUnblocked;
targetType: TargetType.USER,
metadata: {
time: string;
Expand All @@ -85,11 +85,15 @@ interface JobFinished extends BaseMessage {
metadata: {
time: string;
jobId: string;
jobName: string;
cluster: string;
account: string;
price: string;
};
}

type Message = AccountLocked | AccountOverdue | AccountRechargeSuccess
| AccountLowBalance | AccountBalance | AccountRestored
| AccountLowBalance | AccountBalance | AccountUnblocked
| JobFinished;

export const sendMessage = async (message: Message, logger: Logger) => {
Expand Down
26 changes: 21 additions & 5 deletions apps/notification/src/models/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export type I18nStringType = string | {
// languageDic for partitionsManagement
export const languageDic = {
zh_cn: {
api: {
notification: "通知",
myMsgs: "我的消息",
msgSub: "消息订阅",
msgConfig: "消息设置",
sendMsg: "发送消息",
createType: "创建自定义消息类型",
},
common: {
default: "默认",
zhCn: "简体中文",
Expand Down Expand Up @@ -82,8 +90,8 @@ export const languageDic = {
},
messageConfigModal: {
modifySuccess: "修改成功",
authorization: "授权方式",
dontAllowCancel: "不允许用户取消以下授权方式",
authorization: "订阅设置",
dontAllowCancel: "不允许用户取消订阅以下类型的通知",
inputTitle: "请输入标题",
},
},
Expand All @@ -105,7 +113,7 @@ export const languageDic = {
},
},
notification: {
pageTitle: "消息通知",
pageTitle: "我的消息",
markAllReadErrorInfo: "标记全部已读失败",
markAllReadSuccessInfo: "标记全部已读成功",
deleteReadMsgErrorInfo: "删除已读消息失败",
Expand Down Expand Up @@ -140,6 +148,14 @@ export const languageDic = {
},
},
en: {
api: {
notification: "Notification",
myMsgs: "My Messages",
msgSub: "Message Subscription",
msgConfig: "Message Config",
sendMsg: "Send Message",
createType: "Create Custom Message Type",
},
common: {
default: "Default",
zhCn: "Simplified Chinese",
Expand Down Expand Up @@ -205,8 +221,8 @@ export const languageDic = {
messageConfigModal: {
inputTitle: "Please enter a title",
modifySuccess: "Modification successful",
authorization: "Authorization",
dontAllowCancel: "Do not allow users to cancel the following authorization methods",
authorization: "Subscription Settings",
dontAllowCancel: "Do not allow users to unsubscribe from the following types of notifications.",
},
},
sendMessage: {
Expand Down
12 changes: 6 additions & 6 deletions apps/notification/src/models/message-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export enum InternalMessageType {
AccountLowBalance = "AccountLowBalance",
AccountBalance = "AccountBalance",
AccountLocked = "AccountLocked",
AccountRestored = "AccountRestored",
AccountUnblocked = "AccountUnblocked",
JobStarted = "JobStarted",
JobFinished = "JobFinished",
JobAbnormalTermination = "JobAbnormalTermination",
Expand Down Expand Up @@ -160,12 +160,12 @@ export const internalMessageTypesMap = new Map<InternalMessageType, MessageTypeI
zhCn: "账户 {__accountName__} 已于【{__time__}】被封锁,您可以联系管理员申请解封。",
},
}],
[InternalMessageType.AccountRestored, {
type: "AccountRestored",
[InternalMessageType.AccountUnblocked, {
type: "AccountUnblocked",
titleTemplate: {
default: "账户恢复通知",
en: "Account Restored",
zhCn: "账户恢复通知",
default: "账户解封通知",
en: "Account Unblocking",
zhCn: "账户解封通知",
},
category: "Account",
categoryTemplate: {
Expand Down
7 changes: 1 addition & 6 deletions apps/notification/src/pages/api/mis/navbarLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import { applyMiddleware } from "../middleware/cors";

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

const searchParams = req.query;
const scowLangId = searchParams.scowLangId;

const isChinese = scowLangId === "zh_cn";

if (req.method === "POST") {

const cookie = req.headers.cookie;
Expand All @@ -47,7 +42,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const navbarLinks = [
{
path: "/notification",
text: isChinese ? "消息系统" : "Messaging System",
text: "",
icon: { src: svgFilePath },
},
];
Expand Down
19 changes: 10 additions & 9 deletions apps/notification/src/pages/api/mis/rewriteNavigations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { NextApiRequest, NextApiResponse } from "next";
import { join } from "path";
import { PlatformRole } from "src/models/user";
import { validateToken } from "src/server/auth/token";
import { getLanguage } from "src/utils/i18n";
import { BASE_PATH } from "src/utils/processEnv";

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

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

const body = req.body as Request;

const searchParams = req.query;
const scowLangId = searchParams.scowLangId;

const isChinese = scowLangId === "zh_cn";
const scowLangId = searchParams.scowLangId ?? "zh_cn";
const language = getLanguage(scowLangId as string).api;

const cookie = req.headers.cookie;
// 将 cookie 字符串解析为对象
Expand All @@ -63,38 +64,38 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
body.navs.push({
path: "/",
clickToPath: "/notification",
text: isChinese ? "通知" : "Notification",
text: language.notification,
hideIfNotActive: true,
children: [
{
path: "/notification",
clickToPath: undefined,
text: isChinese ? "消息通知" : "Message Notification",
text: language.myMsgs,
icon: { src: join(BASE_PATH, "/icons/notification.svg") },
},
{
path: "/subscription",
clickToPath: undefined,
text: isChinese ? "消息订阅" : "Message Subscription",
text: language.msgSub,
icon: { src: join(BASE_PATH, "/icons/subscription.svg") },
},
...cookie && userInfo?.platformRoles.includes(PlatformRole.PLATFORM_ADMIN) ? [
{
path: "/message-config",
clickToPath: undefined,
text: isChinese ? "消息设置" : "Message Setting",
text: language.msgConfig,
icon: { src: join(BASE_PATH, "/icons/msg-config.svg") },
},
{
path: "/send-message",
clickToPath: undefined,
text: isChinese ? "发送消息" : "Send Message",
text: language.sendMsg,
icon: { src: join(BASE_PATH, "/icons/send-msg.svg") },
},
{
path: "/create-custom-message-type",
clickToPath: undefined,
text: isChinese ? "创建自定义消息类型" : "Create Custom Message Type",
text: language.createType,
icon: { src: join(BASE_PATH, "/icons/create-custom-type.svg") },
},
] : [],
Expand Down
7 changes: 1 addition & 6 deletions apps/notification/src/pages/api/portal/navbarLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import { applyMiddleware } from "../middleware/cors";

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

const searchParams = req.query;
const scowLangId = searchParams.scowLangId;

const isChinese = scowLangId === "zh_cn";

if (req.method === "POST") {

const cookie = req.headers.cookie;
Expand All @@ -47,7 +42,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const navbarLinks = [
{
path: "/notification",
text: isChinese ? "消息系统" : "Messaging System",
text: "",
icon: { src: svgFilePath },
},
];
Expand Down
19 changes: 10 additions & 9 deletions apps/notification/src/pages/api/portal/rewriteNavigations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { NextApiRequest, NextApiResponse } from "next";
import { join } from "path";
import { PlatformRole } from "src/models/user";
import { validateToken } from "src/server/auth/token";
import { getLanguage } from "src/utils/i18n";
import { BASE_PATH } from "src/utils/processEnv";

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

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

const body = req.body as Request;

const searchParams = req.query;
const scowLangId = searchParams.scowLangId;

const isChinese = scowLangId === "zh_cn";
const scowLangId = searchParams.scowLangId ?? "zh_cn";
const language = getLanguage(scowLangId as string).api;

const cookie = req.headers.cookie;
// 将 cookie 字符串解析为对象
Expand All @@ -63,38 +64,38 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
body.navs.push({
path: "/",
clickToPath: "/notification",
text: isChinese ? "通知" : "Notification",
text: language.notification,
hideIfNotActive: true,
children: [
{
path: "/notification",
clickToPath: undefined,
text: isChinese ? "消息通知" : "Message Notification",
text: language.myMsgs,
icon: { src: join(BASE_PATH, "/icons/notification.svg") },
},
{
path: "/subscription",
clickToPath: undefined,
text: isChinese ? "消息订阅" : "Message Subscription",
text: language.msgSub,
icon: { src: join(BASE_PATH, "/icons/subscription.svg") },
},
...cookie && userInfo?.platformRoles.includes(PlatformRole.PLATFORM_ADMIN) ? [
{
path: "/message-config",
clickToPath: undefined,
text: isChinese ? "消息设置" : "Message Setting",
text: language.msgConfig,
icon: { src: join(BASE_PATH, "/icons/msg-config.svg") },
},
{
path: "/send-message",
clickToPath: undefined,
text: isChinese ? "发送消息" : "Send Message",
text: language.sendMsg,
icon: { src: join(BASE_PATH, "/icons/send-msg.svg") },
},
{
path: "/create-custom-message-type",
clickToPath: undefined,
text: isChinese ? "创建自定义消息类型" : "Create Custom Message Type",
text: language.createType,
icon: { src: join(BASE_PATH, "/icons/create-custom-type.svg") },
},
] : [],
Expand Down
2 changes: 1 addition & 1 deletion dev/vagrant/config/notification/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ redis:
port: 6379

scow:
misServerUrl: http://localhost:5004
misServerUrl: localhost:5004

noticeType:
siteMessage:
Expand Down
1 change: 1 addition & 0 deletions libs/web/src/layouts/base/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const MenuPartPlaceholder = styled.div`
const LinksPart = styled.div`
display: flex;
flex-direction: row;
align-items: center;
`;

const RightContentPart = styled.div`
Expand Down

0 comments on commit 4599ada

Please sign in to comment.