Skip to content

Commit

Permalink
feat(app):
Browse files Browse the repository at this point in the history
- add delete msg box and wait delete
- add total node count
  • Loading branch information
MorvanZhou committed May 24, 2024
1 parent 9a293ed commit 670d2c0
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 70 deletions.
14 changes: 7 additions & 7 deletions src/retk/controllers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

from retk import config, const, safety
from retk.controllers import schemas
from retk.controllers.utils import json_exception
from retk.controllers.utils import json_exception, get_user_info_response_from_u_dict
from retk.core import account, user, statistic
from retk.models.tps import AuthedUser, UserMeta
from retk.utils import get_token, jwt_encode, jwt_decode


def set_cookie_response(
async def set_cookie_response(
u: Union[UserMeta, Dict[str, str]],
req_id: str,
status_code: int,
Expand All @@ -26,7 +26,7 @@ def set_cookie_response(
log_msg="user id not found",
)
if len(u) > 1:
content = schemas.user.get_user_info_response_from_u_dict(u, request_id=req_id).model_dump()
content = (await get_user_info_response_from_u_dict(u, request_id=req_id)).model_dump()
else:
content = {"requestId": req_id}
resp = JSONResponse(
Expand Down Expand Up @@ -97,7 +97,7 @@ async def signup(
uid=new_user["id"],
language=req.language,
)
return set_cookie_response(
return await set_cookie_response(
u=new_user,
req_id=req_id,
status_code=201,
Expand Down Expand Up @@ -146,7 +146,7 @@ async def login(
type_=const.UserBehaviorTypeEnum.LOGIN,
remark="",
)
return set_cookie_response(
return await set_cookie_response(
u=u,
req_id=req_id,
status_code=200,
Expand All @@ -171,7 +171,7 @@ async def auto_login(
u, code = await user.get(uid=payload["uid"], disabled=False)
if code != const.CodeEnum.OK:
return r
return schemas.user.get_user_info_response_from_u_dict(u, request_id=req_id)
return await get_user_info_response_from_u_dict(u, request_id=req_id)


async def logout(
Expand Down Expand Up @@ -325,7 +325,7 @@ async def get_new_access_token(
"language": au.language,
},
)
return set_cookie_response(
return await set_cookie_response(
u={"id": au.u.id},
req_id=au.request_id,
status_code=200,
Expand Down
4 changes: 2 additions & 2 deletions src/retk/controllers/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def provider_callback(provider_name: str, req: Request) -> JSONResponse:
language=u["settings"]["language"],
)

return set_cookie_response(
return await set_cookie_response(
u=u,
req_id="",
status_code=200,
Expand Down Expand Up @@ -128,7 +128,7 @@ async def provider_callback(provider_name: str, req: Request) -> JSONResponse:
uid=u["id"],
language=language,
)
return set_cookie_response(
return await set_cookie_response(
u=u,
req_id="",
status_code=201,
Expand Down
43 changes: 2 additions & 41 deletions src/retk/controllers/schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

from pydantic import BaseModel, NonNegativeInt, Field, NonNegativeFloat

from retk import config
from retk.const import settings, LanguageEnum, app, NodeDisplaySortKeyEnum, USER_TYPE
from retk.models import tps
from retk.utils import datetime2str
from retk.const import settings, LanguageEnum, app, NodeDisplaySortKeyEnum


class UserInfoResponse(BaseModel):
Expand All @@ -33,6 +30,7 @@ class Settings(BaseModel):
maxSpace: NonNegativeInt = 0
lastState: LastState
settings: Settings
totalNodes: NonNegativeInt = 0

requestId: str
user: User = None
Expand Down Expand Up @@ -65,43 +63,6 @@ class UpdatePasswordRequest(BaseModel):
newPassword: str = Field(max_length=settings.PASSWORD_MAX_LENGTH)


def get_user_info_response_from_u_dict(
u: tps.UserMeta,
request_id: str,
) -> UserInfoResponse:
if config.is_local_db():
max_space = 0
else:
max_space = USER_TYPE.id2config(u["type"]).max_store_space
last_state = u["lastState"]
u_settings = u["settings"]
return UserInfoResponse(
requestId=request_id,
user=UserInfoResponse.User(
email=u["email"],
nickname=u["nickname"],
avatar=u["avatar"],
source=u["source"],
createdAt=datetime2str(u["_id"].generation_time),
usedSpace=u["usedSpace"],
maxSpace=max_space,
lastState=UserInfoResponse.User.LastState(
nodeDisplayMethod=last_state["nodeDisplayMethod"],
nodeDisplaySortKey=last_state["nodeDisplaySortKey"],
),
settings=UserInfoResponse.User.Settings(
language=u_settings["language"],
theme=u_settings["theme"],
editorMode=u_settings["editorMode"],
editorFontSize=u_settings["editorFontSize"],
editorCodeTheme=u_settings["editorCodeTheme"],
editorSepRightWidth=u_settings.get("editorSepRightWidth", 200),
editorSideCurrentToolId=u_settings.get("editorSideCurrentToolId", ""),
),
),
)


class NotificationResponse(BaseModel):
class System(BaseModel):
class Notice(BaseModel):
Expand Down
5 changes: 3 additions & 2 deletions src/retk/controllers/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from retk import const, core, config
from retk.controllers import schemas
from retk.controllers.utils import maybe_raise_json_exception
from retk.controllers.utils import maybe_raise_json_exception, get_user_info_response_from_u_dict
from retk.core import account, notice
from retk.core.user import reset_password
from retk.models.tps import AuthedUser
Expand Down Expand Up @@ -38,6 +38,7 @@ async def get_user(
editorSepRightWidth=au.u.settings.editor_sep_right_width,
editorSideCurrentToolId=au.u.settings.editor_side_current_tool_id,
),
totalNodes=await core.user.get_user_nodes_count(uid=au.u.id, disabled=False, in_trash=False),
),
)

Expand All @@ -53,7 +54,7 @@ async def patch_user(
maybe_raise_json_exception(au=au, code=code)

u["email"] = mask_email(u["email"])
return schemas.user.get_user_info_response_from_u_dict(u=u, request_id=au.request_id)
return await get_user_info_response_from_u_dict(u=u, request_id=au.request_id)


async def update_password(
Expand Down
45 changes: 43 additions & 2 deletions src/retk/controllers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

from fastapi import HTTPException

from retk import const
from retk import const, config
from retk.controllers.schemas.user import UserInfoResponse
from retk.core.user import get_user_nodes_count
from retk.logger import logger
from retk.models.tps import AuthedUser
from retk.models.tps import AuthedUser, UserMeta
from retk.utils import datetime2str


def is_allowed_mime_type(data_url, allowed_mime_types: Sequence[str]):
Expand Down Expand Up @@ -71,3 +74,41 @@ def maybe_raise_json_exception(
code=code,
language=au.language,
)


async def get_user_info_response_from_u_dict(
u: UserMeta,
request_id: str,
) -> UserInfoResponse:
if config.is_local_db():
max_space = 0
else:
max_space = const.USER_TYPE.id2config(u["type"]).max_store_space
last_state = u["lastState"]
u_settings = u["settings"]
return UserInfoResponse(
requestId=request_id,
user=UserInfoResponse.User(
email=u["email"],
nickname=u["nickname"],
avatar=u["avatar"],
source=u["source"],
createdAt=datetime2str(u["_id"].generation_time),
usedSpace=u["usedSpace"],
maxSpace=max_space,
lastState=UserInfoResponse.User.LastState(
nodeDisplayMethod=last_state["nodeDisplayMethod"],
nodeDisplaySortKey=last_state["nodeDisplaySortKey"],
),
settings=UserInfoResponse.User.Settings(
language=u_settings["language"],
theme=u_settings["theme"],
editorMode=u_settings["editorMode"],
editorFontSize=u_settings["editorFontSize"],
editorCodeTheme=u_settings["editorCodeTheme"],
editorSepRightWidth=u_settings.get("editorSepRightWidth", 200),
editorSideCurrentToolId=u_settings.get("editorSideCurrentToolId", ""),
),
totalNodes=await get_user_nodes_count(uid=u["id"], disabled=False, in_trash=False),
),
)
4 changes: 4 additions & 0 deletions src/retk/core/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@ async def reset_password(uid: str, hashed: str) -> const.CodeEnum:
{"$set": {"hashed": hashed}}
)
return const.CodeEnum.OK if res.acknowledged == 1 else const.CodeEnum.OPERATION_FAILED


async def get_user_nodes_count(uid: str, disabled: bool = False, in_trash: bool = False) -> int:
return await client.coll.nodes.count_documents({"uid": uid, "disabled": disabled, "inTrash": in_trash})
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ body,
}

.white-font {
color: #f1f1f1;
color: #f6f6f6;
}

.hover-node-bg:hover {
Expand Down Expand Up @@ -466,6 +466,28 @@ em.match {
overflow-y: auto;
}

@keyframes blink {
0% {
opacity: 1;
}
25% {
opacity: 0.25;
}
50% {
opacity: 1;
}
75% {
opacity: 0.25;
}
100% {
opacity: 1;
}
}

.blink {
animation: blink 0.6s;
}

/*!********************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/css-loader/dist/cjs.js??clonedRuleSet-12.use[1]!./node_modules/vue-loader/dist/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-12.use[2]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/App.vue?vue&type=style&index=0&id=7ba5bd90&scoped=true&lang=css ***!
\********************************************************************************************************************************************************************************************************************************************************************************************************************************/
Expand Down Expand Up @@ -526,6 +548,29 @@ em.match {
.left-side-items[data-v-9c8cfb28] {
margin-top: 1em;
}
.static[data-v-9c8cfb28] {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-around;
margin-bottom: 1em;
}
.value[data-v-9c8cfb28] {
display: flex;
flex-direction: column;
align-items: center;
color: #606060;
}
.number[data-v-9c8cfb28] {
font-size: 1.5em;
font-weight: 600;
}
.sm-number[data-v-9c8cfb28] {
font-size: 1em;
}
.title[data-v-9c8cfb28] {
font-size: 0.8em;
}
.left-side-item[data-v-9c8cfb28] {
padding: 10px 20px;
cursor: pointer;
Expand Down Expand Up @@ -5578,3 +5623,23 @@ li[data-v-314222b0] {
}


/*!**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/css-loader/dist/cjs.js??clonedRuleSet-12.use[1]!./node_modules/vue-loader/dist/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-12.use[2]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/messageBox/DeleteConfirmMsgBox.vue?vue&type=style&index=0&id=0753a324&scoped=true&lang=css ***!
\**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/

.del-btn[data-v-0753a324] {
padding: 10px 20px;
border-radius: 5px;
margin-left: 15px;
border: none;
color: #f2f2f2;
background-color: #ff3333;
cursor: pointer;
}
.del-btn[data-v-0753a324]:hover {
color: #ffffff;
}
.deleting[data-v-0753a324] {
background-color: #ff6666;
}

2 changes: 1 addition & 1 deletion src/retk/dist-local/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script async src="/r/js/highlight.min.js"></script>
<title>rethink</title>

<script defer src="/r/js/chunk-vendors.js"></script><script defer src="/r/js/app.js"></script><link href="/r/css/app.8910a837.css" rel="stylesheet"></head>
<script defer src="/r/js/chunk-vendors.js"></script><script defer src="/r/js/app.js"></script><link href="/r/css/app.0cb61b64.css" rel="stylesheet"></head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
Expand Down
Loading

0 comments on commit 670d2c0

Please sign in to comment.