Skip to content

Commit

Permalink
feat: implement week start day setting
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Aug 18, 2024
1 parent 06c460b commit 3c5aa41
Show file tree
Hide file tree
Showing 15 changed files with 346 additions and 289 deletions.
4 changes: 2 additions & 2 deletions bin/memos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ var (
)

func init() {
viper.SetDefault("mode", "demo")
viper.SetDefault("mode", "dev")
viper.SetDefault("driver", "sqlite")
viper.SetDefault("port", 8081)
viper.SetDefault("password-auth", true)

rootCmd.PersistentFlags().String("mode", "demo", `mode of server, can be "prod" or "dev" or "demo"`)
rootCmd.PersistentFlags().String("mode", "dev", `mode of server, can be "prod" or "dev" or "demo"`)
rootCmd.PersistentFlags().String("addr", "", "address of server")
rootCmd.PersistentFlags().Int("port", 8081, "port of server")
rootCmd.PersistentFlags().String("data", "", "data directory")
Expand Down
7 changes: 7 additions & 0 deletions docs/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,13 @@ definitions:
customProfile:
$ref: '#/definitions/apiv1WorkspaceCustomProfile'
description: custom_profile is the custom profile.
weekStartDayOffset:
type: integer
format: int32
description: |-
week_start_day_offset is the week start day offset from Sunday.
0: Sunday, 1: Monday, 2: Tuesday, 3: Wednesday, 4: Thursday, 5: Friday, 6: Saturday
Default is Sunday.
apiv1WorkspaceMemoRelatedSetting:
type: object
properties:
Expand Down
4 changes: 4 additions & 0 deletions proto/api/v1/workspace_setting_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ message WorkspaceGeneralSetting {
string additional_style = 4;
// custom_profile is the custom profile.
WorkspaceCustomProfile custom_profile = 5;
// week_start_day_offset is the week start day offset from Sunday.
// 0: Sunday, 1: Monday, 2: Tuesday, 3: Wednesday, 4: Thursday, 5: Friday, 6: Saturday
// Default is Sunday.
int32 week_start_day_offset = 6;
}

message WorkspaceCustomProfile {
Expand Down
230 changes: 122 additions & 108 deletions proto/gen/api/v1/workspace_setting_service.pb.go

Large diffs are not rendered by default.

196 changes: 105 additions & 91 deletions proto/gen/store/workspace_setting.pb.go

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions proto/store/workspace_setting.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ message WorkspaceBasicSetting {

message WorkspaceGeneralSetting {
// additional_script is the additional script.
string additional_script = 3;
string additional_script = 1;
// additional_style is the additional style.
string additional_style = 4;
string additional_style = 2;
// custom_profile is the custom profile.
WorkspaceCustomProfile custom_profile = 5;
WorkspaceCustomProfile custom_profile = 3;
// week_start_day_offset is the week start day offset from Sunday.
// 0: Sunday, 1: Monday, 2: Tuesday, 3: Wednesday, 4: Thursday, 5: Friday, 6: Saturday
// Default is Sunday.
int32 week_start_day_offset = 4;
}

message WorkspaceCustomProfile {
Expand Down
1 change: 1 addition & 0 deletions server/router/api/v1/workspace_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (s *APIV1Service) GetWorkspaceProfile(ctx context.Context, _ *v1pb.GetWorks
PasswordAuth: s.Profile.PasswordAuth,
InstanceUrl: s.Profile.InstanceURL,
}
println("workspaceProfile: ", workspaceProfile.Mode)
owner, err := s.GetInstanceOwner(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get instance owner: %v", err)
Expand Down
10 changes: 6 additions & 4 deletions server/router/api/v1/workspace_setting_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ func convertWorkspaceGeneralSettingFromStore(setting *storepb.WorkspaceGeneralSe
return nil
}
generalSetting := &v1pb.WorkspaceGeneralSetting{
AdditionalScript: setting.AdditionalScript,
AdditionalStyle: setting.AdditionalStyle,
AdditionalScript: setting.AdditionalScript,
AdditionalStyle: setting.AdditionalStyle,
WeekStartDayOffset: setting.WeekStartDayOffset,
}
if setting.CustomProfile != nil {
generalSetting.CustomProfile = &v1pb.WorkspaceCustomProfile{
Expand All @@ -152,8 +153,9 @@ func convertWorkspaceGeneralSettingToStore(setting *v1pb.WorkspaceGeneralSetting
return nil
}
generalSetting := &storepb.WorkspaceGeneralSetting{
AdditionalScript: setting.AdditionalScript,
AdditionalStyle: setting.AdditionalStyle,
AdditionalScript: setting.AdditionalScript,
AdditionalStyle: setting.AdditionalStyle,
WeekStartDayOffset: setting.WeekStartDayOffset,
}
if setting.CustomProfile != nil {
generalSetting.CustomProfile = &storepb.WorkspaceCustomProfile{
Expand Down
28 changes: 19 additions & 9 deletions web/src/components/ActivityCalendar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Tooltip } from "@mui/joy";
import clsx from "clsx";
import dayjs from "dayjs";
import { useWorkspaceSettingStore } from "@/store/v1";
import { WorkspaceGeneralSetting } from "@/types/proto/api/v1/workspace_setting_service";
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
import { useTranslate } from "@/utils/i18n";

const WEEK_DAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];

interface Props {
// Format: 2021-1
month: string;
Expand All @@ -29,11 +34,16 @@ const getCellAdditionalStyles = (count: number, maxCount: number) => {
const ActivityCalendar = (props: Props) => {
const t = useTranslate();
const { month: monthStr, data, onClick } = props;
const workspaceSettingStore = useWorkspaceSettingStore();
const weekStartDayOffset = (
workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.GENERAL).generalSetting || WorkspaceGeneralSetting.fromPartial({})
).weekStartDayOffset;
const year = dayjs(monthStr).toDate().getFullYear();
const month = dayjs(monthStr).toDate().getMonth() + 1;
const dayInMonth = new Date(year, month, 0).getDate();
const firstDay = new Date(year, month - 1, 1).getDay();
const lastDay = new Date(year, month - 1, dayInMonth).getDay();
const firstDay = new Date(year, month - 1, 1).getDay() - weekStartDayOffset;
const lastDay = new Date(year, month - 1, dayInMonth).getDay() - weekStartDayOffset;
const weekDays = WEEK_DAYS.slice(weekStartDayOffset).concat(WEEK_DAYS.slice(0, weekStartDayOffset));
const maxCount = Math.max(...Object.values(data));
const days = [];

Expand All @@ -49,13 +59,13 @@ const ActivityCalendar = (props: Props) => {

return (
<div className={clsx("w-full h-auto shrink-0 grid grid-cols-7 grid-flow-row gap-1")}>
<div className={clsx("w-6 h-5 text-xs flex justify-center items-center cursor-default opacity-60")}>Su</div>
<div className={clsx("w-6 h-5 text-xs flex justify-center items-center cursor-default opacity-60")}>Mo</div>
<div className={clsx("w-6 h-5 text-xs flex justify-center items-center cursor-default opacity-60")}>Tu</div>
<div className={clsx("w-6 h-5 text-xs flex justify-center items-center cursor-default opacity-60")}>We</div>
<div className={clsx("w-6 h-5 text-xs flex justify-center items-center cursor-default opacity-60")}>Th</div>
<div className={clsx("w-6 h-5 text-xs flex justify-center items-center cursor-default opacity-60")}>Fr</div>
<div className={clsx("w-6 h-5 text-xs flex justify-center items-center cursor-default opacity-60")}>Sa</div>
{weekDays.map((day, index) => {
return (
<div key={index} className={clsx("w-6 h-5 text-xs flex justify-center items-center cursor-default opacity-60")}>
{day}
</div>
);
})}
{days.map((day, index) => {
const date = dayjs(`${year}-${month}-${day}`).format("YYYY-MM-DD");
const count = data[date] || 0;
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/ChangePasswordDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const ChangePasswordDialog: React.FC<Props> = ({ destroy }: Props) => {
toast.success(t("message.password-changed"));
handleCloseBtnClick();
} catch (error: any) {
toast.error(error.details);
console.error(error);
toast.error(error.response.data.message);
}
};

Expand Down
2 changes: 1 addition & 1 deletion web/src/components/CreateAccessTokenDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ const CreateAccessTokenDialog: React.FC<Props> = (props: Props) => {
onConfirm();
destroy();
} catch (error: any) {
toast.error(error.details);
console.error(error);
toast.error(error.response.data.message);
}
};

Expand Down
2 changes: 1 addition & 1 deletion web/src/components/CreateIdentityProviderDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ const CreateIdentityProviderDialog: React.FC<Props> = (props: Props) => {
toast.success(t("setting.sso-section.sso-updated", { name: basicInfo.title }));
}
} catch (error: any) {
toast.error(error.details);
console.error(error);
toast.error(error.response.data.message);
}
if (confirmCallback) {
confirmCallback();
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/MemoActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const MemoActionMenu = (props: Props) => {
toast.success(t("message.archived-successfully"));
}
} catch (error: any) {
toast.error(error.details);
console.error(error);
toast.error(error.response.data.message);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const AddMemoRelationPopover = (props: Props) => {
});
setFetchedMemos(memos);
} catch (error: any) {
toast.error(error.details);
console.error(error);
toast.error(error.response.data.message);
}
setIsFetching(false);
},
Expand Down
135 changes: 68 additions & 67 deletions web/src/components/Settings/WorkspaceSection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Textarea } from "@mui/joy";
import { Button, Select, Textarea, Option, Divider } from "@mui/joy";
import { useState } from "react";
import { toast } from "react-hot-toast";
import { Link } from "react-router-dom";
Expand All @@ -25,27 +25,15 @@ const WorkspaceSection = () => {
setWorkspaceGeneralSetting({ ...workspaceGeneralSetting, additionalStyle: value });
};

const handleSaveAdditionalStyle = async () => {
try {
await workspaceSettingServiceClient.setWorkspaceSetting({
setting: {
name: `${workspaceSettingNamePrefix}${WorkspaceSettingKey.GENERAL}`,
generalSetting: workspaceGeneralSetting,
},
});
} catch (error: any) {
toast.error(error.response.data.message);
console.error(error);
return;
}
toast.success(t("message.update-succeed"));
};

const handleAdditionalScriptChanged = (value: string) => {
setWorkspaceGeneralSetting({ ...workspaceGeneralSetting, additionalScript: value });
};

const handleSaveAdditionalScript = async () => {
const handleWeekStartDayOffsetChanged = (value: number) => {
setWorkspaceGeneralSetting({ ...workspaceGeneralSetting, weekStartDayOffset: value });
};

const handleSaveGeneralSetting = async () => {
try {
await workspaceSettingServiceClient.setWorkspaceSetting({
setting: {
Expand All @@ -54,7 +42,7 @@ const WorkspaceSection = () => {
},
});
} catch (error: any) {
toast.error(error.response.data.message);
toast.error(error.details);
console.error(error);
return;
}
Expand All @@ -69,57 +57,70 @@ const WorkspaceSection = () => {
{t("setting.system-section.server-name")}:{" "}
<span className="font-mono font-bold">{workspaceGeneralSetting.customProfile?.title || "Memos"}</span>
</div>
<Button onClick={handleUpdateCustomizedProfileButtonClick}>{t("common.edit")}</Button>
<Button variant="outlined" color="neutral" onClick={handleUpdateCustomizedProfileButtonClick}>
{t("common.edit")}
</Button>
</div>
<Divider />
<p className="font-medium text-gray-700 dark:text-gray-500">General</p>
<div className="space-y-2 border rounded-md py-2 px-3 dark:border-zinc-700">
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.additional-style")}</span>
<Button variant="outlined" color="neutral" onClick={handleSaveAdditionalStyle}>
{t("common.save")}
</Button>
</div>
<Textarea
className="w-full"
sx={{
fontFamily: "monospace",
fontSize: "14px",
}}
minRows={2}
maxRows={4}
placeholder={t("setting.system-section.additional-style-placeholder")}
value={workspaceGeneralSetting.additionalStyle}
onChange={(event) => handleAdditionalStyleChanged(event.target.value)}
/>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.additional-script")}</span>
<Button variant="outlined" color="neutral" onClick={handleSaveAdditionalScript}>
{t("common.save")}
</Button>
</div>
<Textarea
className="w-full"
color="neutral"
sx={{
fontFamily: "monospace",
fontSize: "14px",
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.additional-style")}</span>
</div>
<Textarea
className="w-full"
sx={{
fontFamily: "monospace",
fontSize: "14px",
}}
minRows={2}
maxRows={4}
placeholder={t("setting.system-section.additional-style-placeholder")}
value={workspaceGeneralSetting.additionalStyle}
onChange={(event) => handleAdditionalStyleChanged(event.target.value)}
/>
<div className="w-full flex flex-row justify-between items-center">
<span>{t("setting.system-section.additional-script")}</span>
</div>
<Textarea
className="w-full"
color="neutral"
sx={{
fontFamily: "monospace",
fontSize: "14px",
}}
minRows={2}
maxRows={4}
placeholder={t("setting.system-section.additional-script-placeholder")}
value={workspaceGeneralSetting.additionalScript}
onChange={(event) => handleAdditionalScriptChanged(event.target.value)}
/>
<div className="w-full">
<Link
className="text-gray-500 text-sm flex flex-row justify-start items-center hover:underline hover:text-blue-600"
to="https://usememos.com/docs/advanced-settings/custom-style-and-script"
target="_blank"
>
{t("common.learn-more")}
<Icon.ExternalLink className="inline w-4 h-auto ml-1" />
</Link>
</div>
<div className="w-full flex flex-row justify-between items-center">
<span className="truncate">{t("setting.preference-section.default-memo-visibility")}</span>
<Select
className="!min-w-fit"
value={workspaceGeneralSetting.weekStartDayOffset}
onChange={(_, weekStartDayOffset) => {
handleWeekStartDayOffsetChanged(weekStartDayOffset || 0);
}}
minRows={2}
maxRows={4}
placeholder={t("setting.system-section.additional-script-placeholder")}
value={workspaceGeneralSetting.additionalScript}
onChange={(event) => handleAdditionalScriptChanged(event.target.value)}
/>
<div className="w-full">
<Link
className="text-gray-500 text-sm flex flex-row justify-start items-center hover:underline hover:text-blue-600"
to="https://usememos.com/docs/advanced-settings/custom-style-and-script"
target="_blank"
>
{t("common.learn-more")}
<Icon.ExternalLink className="inline w-4 h-auto ml-1" />
</Link>
</div>
>
<Option value={0}>Sunday</Option>
<Option value={1}>Monday</Option>
</Select>
</div>
<div>
<Button variant="outlined" color="neutral" onClick={handleSaveGeneralSetting}>
{t("common.save")}
</Button>
</div>
</div>
);
Expand Down

0 comments on commit 3c5aa41

Please sign in to comment.