You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/01/15 07:51:44 UTC

(incubator-answer) branch feat/1.2.5/theme created (now 442a0c19)

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a change to branch feat/1.2.5/theme
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


      at 442a0c19 feat(theme): add migration for theme

This branch includes the following new commits:

     new bab5737c feat(theme): add color scheme config
     new 348607f6 Merge remote-tracking branch 'origin/test' into feat/1.2.5/theme
     new 442a0c19 feat(theme): add migration for theme

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(incubator-answer) 03/03: feat(theme): add migration for theme

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.2.5/theme
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 442a0c19b3c3b21615f7e70b45ee905a82988283
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Mon Jan 15 15:51:35 2024 +0800

    feat(theme): add migration for theme
---
 internal/migrations/migrations.go | 2 +-
 internal/migrations/v19.go        | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/internal/migrations/migrations.go b/internal/migrations/migrations.go
index 6fa26088..dbd3acdb 100644
--- a/internal/migrations/migrations.go
+++ b/internal/migrations/migrations.go
@@ -94,7 +94,7 @@ var migrations = []Migration{
 	NewMigration("v1.1.3", "set default user notification config", setDefaultUserNotificationConfig, false),
 	NewMigration("v1.2.0", "add recover answer permission", addRecoverPermission, true),
 	NewMigration("v1.2.1", "add password login control", addPasswordLoginControl, true),
-	NewMigration("v1.2.5", "add notification plugin", addNotificationPlugin, true),
+	NewMigration("v1.2.5", "add notification plugin and theme config", addNotificationPluginAndThemeConfig, true),
 }
 
 func GetMigrations() []Migration {
diff --git a/internal/migrations/v19.go b/internal/migrations/v19.go
index c1505edd..c4478a34 100644
--- a/internal/migrations/v19.go
+++ b/internal/migrations/v19.go
@@ -25,6 +25,10 @@ import (
 	"xorm.io/xorm"
 )
 
-func addNotificationPlugin(ctx context.Context, x *xorm.Engine) error {
-	return x.Context(ctx).Sync(new(entity.PluginUserConfig))
+func addNotificationPluginAndThemeConfig(ctx context.Context, x *xorm.Engine) error {
+	type User struct {
+		ID          string `xorm:"not null pk autoincr BIGINT(20) id"`
+		ColorScheme string `xorm:"not null default '' VARCHAR(100) color_scheme"`
+	}
+	return x.Context(ctx).Sync(new(entity.PluginUserConfig), new(User))
 }


(incubator-answer) 02/03: Merge remote-tracking branch 'origin/test' into feat/1.2.5/theme

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.2.5/theme
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 348607f64bc019efd644b0e370da231e0eb33f3f
Merge: bab5737c c58a2af5
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Mon Jan 15 15:44:39 2024 +0800

    Merge remote-tracking branch 'origin/test' into feat/1.2.5/theme

 cmd/wire_gen.go                                    |  10 +-
 docs/docs.go                                       | 202 ++++++++++---
 docs/swagger.json                                  | 183 ++++++++++--
 docs/swagger.yaml                                  | 132 ++++++---
 i18n/en_US.yaml                                    |  31 +-
 i18n/zh_CN.yaml                                    |  23 +-
 internal/base/middleware/auth.go                   |  41 ++-
 internal/base/server/http.go                       |   7 +-
 internal/controller/controller.go                  |   1 +
 internal/controller/template_controller.go         |   2 +
 internal/controller/user_plugin_controller.go      | 153 ++++++++++
 internal/controller_admin/plugin_controller.go     |  10 +-
 .../entity/plugin_user_config_entity.go            |  24 +-
 internal/migrations/init_data.go                   |   1 +
 internal/migrations/migrations.go                  |   1 +
 .../index.scss => internal/migrations/v19.go       |  21 +-
 internal/repo/plugin_config/plugin_config_repo.go  |   2 +-
 .../repo/plugin_config/plugin_user_config_repo.go  |  99 +++++++
 internal/repo/provider.go                          |   1 +
 .../user_external_login_repo.go                    |  11 +
 internal/router/answer_api_router.go               |  16 +-
 internal/schema/plugin_user_schema.go              | 100 +++++++
 internal/schema/user_notification_schema.go        |  97 ++----
 internal/schema/user_schema.go                     |   1 +
 .../service/notification/external_notification.go  |   8 +
 .../notification/new_comment_notification.go       |   1 -
 .../notification/new_question_notification.go      |  95 +++++-
 .../service/notification_common/notification.go    |  82 ++++++
 .../service/plugin_common/plugin_common_service.go | 151 +++++++---
 internal/service/user_common/user.go               |   1 +
 .../user_external_login_service.go                 |   1 +
 .../user_notification_config_service.go            |  18 +-
 pkg/display/url.go                                 |   5 +
 plugin/notification.go                             |  92 ++++++
 plugin/plugin.go                                   |  14 +
 plugin/user_config.go                              |  52 ++++
 ui/.eslintrc.js                                    |   2 +
 ui/.prettierrc.json                                |   2 +-
 ui/src/common/constants.ts                         |   2 +
 ui/src/common/interface.ts                         |  11 +-
 ui/src/components/FollowingTags/index.tsx          |   1 +
 ui/src/components/TagSelector/index.scss           |  37 +++
 ui/src/components/TagSelector/index.tsx            | 326 ++++++++++++++-------
 ui/src/hooks/useTagModal/index.tsx                 |   7 +-
 ui/src/pages/Admin/Login/index.tsx                 |   2 +-
 ui/src/pages/Questions/Ask/index.tsx               |   2 +
 .../components/InviteToAnswer/PeopleDropdown.scss  |  22 +-
 .../components/InviteToAnswer/PeopleDropdown.tsx   | 148 +++++-----
 .../Detail/components/InviteToAnswer/index.scss    |  13 +
 .../Detail/components/InviteToAnswer/index.tsx     | 123 +++-----
 .../Detail/components/RelatedQuestions/index.tsx   |   2 +-
 ui/src/pages/Questions/Detail/index.tsx            |   2 +-
 ui/src/pages/Questions/EditAnswer/index.tsx        |   1 +
 ui/src/pages/Tags/Create/index.tsx                 |  60 ++++
 ui/src/pages/Tags/Edit/index.tsx                   |  74 ++++-
 ui/src/pages/Users/Settings/Notification/index.tsx |  55 ++--
 ui/src/pages/Users/Settings/Plugins/index.tsx      | 134 +++++++++
 .../pages/Users/Settings/components/Nav/index.tsx  |  14 +
 ui/src/router/routes.ts                            |   4 +
 ui/src/services/client/settings.ts                 |  28 +-
 ui/src/utils/common.ts                             |  38 +--
 ui/template/header.html                            |   1 +
 62 files changed, 2151 insertions(+), 649 deletions(-)



(incubator-answer) 01/03: feat(theme): add color scheme config

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.2.5/theme
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit bab5737c8432e0b62dcd943da996d7328b4bcb3a
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Mon Jan 15 15:44:27 2024 +0800

    feat(theme): add color scheme config
---
 internal/base/constant/site_info.go  |  7 +++++++
 internal/entity/user_entity.go       |  1 +
 internal/repo/user/user_repo.go      |  5 +++--
 internal/schema/siteinfo_schema.go   |  1 +
 internal/schema/user_schema.go       | 20 ++++++++++++++++++++
 internal/service/user_common/user.go |  2 +-
 internal/service/user_service.go     |  9 +--------
 7 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/internal/base/constant/site_info.go b/internal/base/constant/site_info.go
index 94c39f74..de6f4183 100644
--- a/internal/base/constant/site_info.go
+++ b/internal/base/constant/site_info.go
@@ -37,3 +37,10 @@ const (
 	// PermalinkQuestionIDByShortID /questions/11
 	PermalinkQuestionIDByShortID
 )
+
+const (
+	ColorSchemeDefault = "default"
+	ColorSchemeLight   = "light"
+	ColorSchemeDark    = "dark"
+	ColorSchemeSystem  = "system"
+)
diff --git a/internal/entity/user_entity.go b/internal/entity/user_entity.go
index 32821864..cfc2b6c2 100644
--- a/internal/entity/user_entity.go
+++ b/internal/entity/user_entity.go
@@ -65,6 +65,7 @@ type User struct {
 	IPInfo         string    `xorm:"not null default '' VARCHAR(255) ip_info"`
 	IsAdmin        bool      `xorm:"not null default false BOOL is_admin"`
 	Language       string    `xorm:"not null default '' VARCHAR(100) language"`
+	ColorScheme    string    `xorm:"not null default '' VARCHAR(100) color_scheme"`
 }
 
 // TableName user table name
diff --git a/internal/repo/user/user_repo.go b/internal/repo/user/user_repo.go
index deb1427d..628394cf 100644
--- a/internal/repo/user/user_repo.go
+++ b/internal/repo/user/user_repo.go
@@ -155,8 +155,9 @@ func (ur *userRepo) UpdateEmail(ctx context.Context, userID, email string) (err
 	return
 }
 
-func (ur *userRepo) UpdateLanguage(ctx context.Context, userID, language string) (err error) {
-	_, err = ur.data.DB.Context(ctx).Where("id = ?", userID).Update(&entity.User{Language: language})
+func (ur *userRepo) UpdateUserInterface(ctx context.Context, userID, language, colorSchema string) (err error) {
+	session := ur.data.DB.Context(ctx).Where("id = ?", userID)
+	_, err = session.Cols("language", "color_scheme").Update(&entity.User{Language: language, ColorScheme: colorSchema})
 	if err != nil {
 		err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
 	}
diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.go
index fc56bf5a..537a7017 100644
--- a/internal/schema/siteinfo_schema.go
+++ b/internal/schema/siteinfo_schema.go
@@ -136,6 +136,7 @@ type SiteCustomCssHTMLReq struct {
 type SiteThemeReq struct {
 	Theme       string                 `validate:"required,gt=0,lte=255" json:"theme"`
 	ThemeConfig map[string]interface{} `validate:"omitempty" json:"theme_config"`
+	ColorScheme string                 `validate:"omitempty,gt=0,lte=100" json:"color_scheme"`
 }
 
 type SiteSeoReq struct {
diff --git a/internal/schema/user_schema.go b/internal/schema/user_schema.go
index 4906faff..a3b94838 100644
--- a/internal/schema/user_schema.go
+++ b/internal/schema/user_schema.go
@@ -21,6 +21,9 @@ package schema
 
 import (
 	"encoding/json"
+	"github.com/apache/incubator-answer/internal/base/reason"
+	"github.com/apache/incubator-answer/internal/base/translator"
+	"github.com/segmentfault/pacman/errors"
 
 	"github.com/apache/incubator-answer/internal/base/constant"
 	"github.com/apache/incubator-answer/internal/base/validator"
@@ -80,6 +83,8 @@ type UserLoginResp struct {
 	Location string `json:"location"`
 	// language
 	Language string `json:"language"`
+	// Color scheme
+	ColorScheme string `json:"color_scheme"`
 	// access token
 	AccessToken string `json:"access_token"`
 	// role id
@@ -278,10 +283,25 @@ func (req *UpdateInfoRequest) Check() (errFields []*validator.FormErrorField, er
 type UpdateUserInterfaceRequest struct {
 	// language
 	Language string `validate:"required,gt=1,lte=100" json:"language"`
+	// Color scheme
+	ColorScheme string `validate:"required,gt=1,lte=100" json:"color_scheme"`
 	// user id
 	UserId string `json:"-"`
 }
 
+func (req *UpdateUserInterfaceRequest) Check() (errFields []*validator.FormErrorField, err error) {
+	if !translator.CheckLanguageIsValid(req.Language) {
+		return nil, errors.BadRequest(reason.LangNotFound)
+	}
+	if req.ColorScheme != constant.ColorSchemeDefault &&
+		req.ColorScheme != constant.ColorSchemeLight &&
+		req.ColorScheme != constant.ColorSchemeDark &&
+		req.ColorScheme != constant.ColorSchemeSystem {
+		req.ColorScheme = constant.ColorSchemeDefault
+	}
+	return nil, nil
+}
+
 type UserRetrievePassWordRequest struct {
 	Email       string `validate:"required,email,gt=0,lte=500" json:"e_mail"`
 	CaptchaID   string `json:"captcha_id"`
diff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.go
index 75358884..fd04080d 100644
--- a/internal/service/user_common/user.go
+++ b/internal/service/user_common/user.go
@@ -48,7 +48,7 @@ type UserRepo interface {
 	UpdateEmailStatus(ctx context.Context, userID string, emailStatus int) error
 	UpdateNoticeStatus(ctx context.Context, userID string, noticeStatus int) error
 	UpdateEmail(ctx context.Context, userID, email string) error
-	UpdateLanguage(ctx context.Context, userID, language string) error
+	UpdateUserInterface(ctx context.Context, userID, language, colorSchema string) (err error)
 	UpdatePass(ctx context.Context, userID, pass string) error
 	UpdateInfo(ctx context.Context, userInfo *entity.User) (err error)
 	GetByUserID(ctx context.Context, userID string) (userInfo *entity.User, exist bool, err error)
diff --git a/internal/service/user_service.go b/internal/service/user_service.go
index a0e0dbb7..c6d98fc2 100644
--- a/internal/service/user_service.go
+++ b/internal/service/user_service.go
@@ -381,14 +381,7 @@ func (us *UserService) formatUserInfoForUpdateInfo(
 
 // UserUpdateInterface update user interface
 func (us *UserService) UserUpdateInterface(ctx context.Context, req *schema.UpdateUserInterfaceRequest) (err error) {
-	if !translator.CheckLanguageIsValid(req.Language) {
-		return errors.BadRequest(reason.LangNotFound)
-	}
-	err = us.userRepo.UpdateLanguage(ctx, req.UserId, req.Language)
-	if err != nil {
-		return
-	}
-	return nil
+	return us.userRepo.UpdateUserInterface(ctx, req.UserId, req.Language, req.ColorScheme)
 }
 
 // UserRegisterByEmail user register