mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Load theme as a user setting; allow the user to change it; update tests.
This commit is contained in:
@@ -330,7 +330,7 @@ module.exports = ProjectController =
|
|||||||
}
|
}
|
||||||
userSettings: {
|
userSettings: {
|
||||||
mode : user.ace.mode
|
mode : user.ace.mode
|
||||||
theme : user.ace.theme
|
editorTheme : user.ace.theme
|
||||||
fontSize : user.ace.fontSize
|
fontSize : user.ace.fontSize
|
||||||
autoComplete: user.ace.autoComplete
|
autoComplete: user.ace.autoComplete
|
||||||
autoPairDelimiters: user.ace.autoPairDelimiters
|
autoPairDelimiters: user.ace.autoPairDelimiters
|
||||||
@@ -338,6 +338,7 @@ module.exports = ProjectController =
|
|||||||
syntaxValidation: user.ace.syntaxValidation
|
syntaxValidation: user.ace.syntaxValidation
|
||||||
fontFamily: user.ace.fontFamily
|
fontFamily: user.ace.fontFamily
|
||||||
lineHeight: user.ace.lineHeight
|
lineHeight: user.ace.lineHeight
|
||||||
|
overallTheme: user.overallTheme
|
||||||
}
|
}
|
||||||
trackChangesState: project.track_changes
|
trackChangesState: project.track_changes
|
||||||
privilegeLevel: privilegeLevel
|
privilegeLevel: privilegeLevel
|
||||||
@@ -346,7 +347,7 @@ module.exports = ProjectController =
|
|||||||
anonymousAccessToken: req._anonymousAccessToken
|
anonymousAccessToken: req._anonymousAccessToken
|
||||||
isTokenMember: isTokenMember
|
isTokenMember: isTokenMember
|
||||||
languages: Settings.languages
|
languages: Settings.languages
|
||||||
themes: THEME_LIST
|
editorThemes: THEME_LIST
|
||||||
maxDocLength: Settings.max_doc_length
|
maxDocLength: Settings.max_doc_length
|
||||||
useV2History: !!project.overleaf?.history?.display
|
useV2History: !!project.overleaf?.history?.display
|
||||||
richTextEnabled: Features.hasFeature('rich-text')
|
richTextEnabled: Features.hasFeature('rich-text')
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ module.exports = UserController =
|
|||||||
user.institution = req.body.institution.trim()
|
user.institution = req.body.institution.trim()
|
||||||
if req.body.mode?
|
if req.body.mode?
|
||||||
user.ace.mode = req.body.mode
|
user.ace.mode = req.body.mode
|
||||||
if req.body.theme?
|
if req.body.editorTheme?
|
||||||
user.ace.theme = req.body.theme
|
user.ace.theme = req.body.editorTheme
|
||||||
if req.body.fontSize?
|
if req.body.fontSize?
|
||||||
user.ace.fontSize = req.body.fontSize
|
user.ace.fontSize = req.body.fontSize
|
||||||
if req.body.autoComplete?
|
if req.body.autoComplete?
|
||||||
@@ -86,6 +86,8 @@ module.exports = UserController =
|
|||||||
user.ace.fontFamily = req.body.fontFamily
|
user.ace.fontFamily = req.body.fontFamily
|
||||||
if req.body.lineHeight?
|
if req.body.lineHeight?
|
||||||
user.ace.lineHeight = req.body.lineHeight
|
user.ace.lineHeight = req.body.lineHeight
|
||||||
|
if req.body.overallTheme?
|
||||||
|
user.overallTheme = req.body.overallTheme
|
||||||
|
|
||||||
user.save (err)->
|
user.save (err)->
|
||||||
newEmail = req.body.email?.trim().toLowerCase()
|
newEmail = req.body.email?.trim().toLowerCase()
|
||||||
|
|||||||
@@ -163,6 +163,12 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
|
|||||||
return Url.resolve(staticFilesBase, hashedPath)
|
return Url.resolve(staticFilesBase, hashedPath)
|
||||||
return Url.resolve(staticFilesBase, path)
|
return Url.resolve(staticFilesBase, path)
|
||||||
|
|
||||||
|
res.locals.buildCssFileName = (userSettings) ->
|
||||||
|
themeModifier = ""
|
||||||
|
if userSettings?.overallTheme? and Settings.overleaf?
|
||||||
|
themeModifier = userSettings.overallTheme
|
||||||
|
return "/" + Settings.brandPrefix + themeModifier + "style.css"
|
||||||
|
|
||||||
res.locals.buildImgPath = (imgFile)->
|
res.locals.buildImgPath = (imgFile)->
|
||||||
path = Path.join("/img/", imgFile)
|
path = Path.join("/img/", imgFile)
|
||||||
return Url.resolve(staticFilesBase, path)
|
return Url.resolve(staticFilesBase, path)
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ UserSchema = new Schema
|
|||||||
id: { type: Number }
|
id: { type: Number }
|
||||||
accessToken: { type: String }
|
accessToken: { type: String }
|
||||||
refreshToken: { type: String }
|
refreshToken: { type: String }
|
||||||
|
overallTheme: { type: String, default: "" }
|
||||||
awareOfV2: { type:Boolean, default: false }
|
awareOfV2: { type:Boolean, default: false }
|
||||||
|
|
||||||
conn = mongoose.createConnection(Settings.mongo.url, {
|
conn = mongoose.createConnection(Settings.mongo.url, {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ html(itemscope, itemtype='http://schema.org/Product')
|
|||||||
link(rel="mask-icon", href="/" + settings.brandPrefix + "mask-favicon.svg", color=settings.brandPrefix === 'ol-' ? "#4f9c45" : "#a93529")
|
link(rel="mask-icon", href="/" + settings.brandPrefix + "mask-favicon.svg", color=settings.brandPrefix === 'ol-' ? "#4f9c45" : "#a93529")
|
||||||
|
|
||||||
//- Stylesheet
|
//- Stylesheet
|
||||||
link(rel='stylesheet', href=buildCssPath("/" + settings.brandPrefix + (settings.themeModifier != null ? settings.themeModifier : "") + "style.css", {hashedPath:true}))
|
link(rel='stylesheet', href=buildCssPath(buildCssFileName(userSettings), {hashedPath:true}))
|
||||||
|
|
||||||
block _headLinks
|
block _headLinks
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ div.full-size(
|
|||||||
ng-if="!editor.showRichText",
|
ng-if="!editor.showRichText",
|
||||||
ng-show="!!editor.sharejs_doc && !editor.opening",
|
ng-show="!!editor.sharejs_doc && !editor.opening",
|
||||||
style=richTextEnabled ? "top: 32px" : "",
|
style=richTextEnabled ? "top: 32px" : "",
|
||||||
theme="settings.theme",
|
theme="settings.editorTheme",
|
||||||
keybindings="settings.mode",
|
keybindings="settings.mode",
|
||||||
font-size="settings.fontSize",
|
font-size="settings.fontSize",
|
||||||
auto-complete="settings.autoComplete",
|
auto-complete="settings.autoComplete",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
) #{translate("restore_to_before_these_changes")}
|
) #{translate("restore_to_before_these_changes")}
|
||||||
.diff-editor.hide-ace-cursor(
|
.diff-editor.hide-ace-cursor(
|
||||||
ace-editor="history",
|
ace-editor="history",
|
||||||
theme="settings.theme",
|
theme="settings.editorTheme",
|
||||||
font-size="settings.fontSize",
|
font-size="settings.fontSize",
|
||||||
text="history.diff.text",
|
text="history.diff.text",
|
||||||
highlights="history.diff.highlights",
|
highlights="history.diff.highlights",
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
.diff-editor.hide-ace-cursor(
|
.diff-editor.hide-ace-cursor(
|
||||||
ng-if="!history.diff.binary"
|
ng-if="!history.diff.binary"
|
||||||
ace-editor="history",
|
ace-editor="history",
|
||||||
theme="settings.theme",
|
theme="settings.editorTheme",
|
||||||
font-size="settings.fontSize",
|
font-size="settings.fontSize",
|
||||||
text="history.diff.text",
|
text="history.diff.text",
|
||||||
highlights="history.diff.highlights",
|
highlights="history.diff.highlights",
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
.hide-ace-cursor(
|
.hide-ace-cursor(
|
||||||
ng-if="!history.selectedFile.binary"
|
ng-if="!history.selectedFile.binary"
|
||||||
ace-editor="history-pointintime",
|
ace-editor="history-pointintime",
|
||||||
theme="settings.theme",
|
theme="settings.editorTheme",
|
||||||
font-size="settings.fontSize",
|
font-size="settings.fontSize",
|
||||||
text="history.selectedFile.text",
|
text="history.selectedFile.text",
|
||||||
read-only="true",
|
read-only="true",
|
||||||
|
|||||||
@@ -131,13 +131,22 @@ aside#left-menu.full-size(
|
|||||||
)
|
)
|
||||||
|
|
||||||
.form-controls
|
.form-controls
|
||||||
label(for="theme") #{translate("theme")}
|
label(for="editorTheme") #{translate("theme")}
|
||||||
select(
|
select(
|
||||||
name="theme"
|
name="editorTheme"
|
||||||
ng-model="settings.theme"
|
ng-model="settings.editorTheme"
|
||||||
|
)
|
||||||
|
each editorTheme in editorThemes
|
||||||
|
option(value=editorTheme) #{editorTheme.replace(/_/g, ' ')}
|
||||||
|
|
||||||
|
- if (settings.overleaf != null)
|
||||||
|
.form-controls
|
||||||
|
label(for="overallTheme") overall theme
|
||||||
|
select(
|
||||||
|
name="overallTheme"
|
||||||
|
ng-model="settings.overallTheme"
|
||||||
|
ng-options="o.v as o.n for o in [{ n: 'Default', v: '' }, { n: 'Light', v: 'light-' }]"
|
||||||
)
|
)
|
||||||
each theme in themes
|
|
||||||
option(value=theme) #{theme.replace(/_/g, ' ')}
|
|
||||||
|
|
||||||
.form-controls(ng-show="!anonymous")
|
.form-controls(ng-show="!anonymous")
|
||||||
label(for="mode") #{translate("keybindings")}
|
label(for="mode") #{translate("keybindings")}
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ define [
|
|||||||
"twilight", "vibrant_ink"
|
"twilight", "vibrant_ink"
|
||||||
]
|
]
|
||||||
$scope.darkTheme = false
|
$scope.darkTheme = false
|
||||||
$scope.$watch "settings.theme", (theme) ->
|
$scope.$watch "settings.editorTheme", (theme) ->
|
||||||
if theme in DARK_THEMES
|
if theme in DARK_THEMES
|
||||||
$scope.darkTheme = true
|
$scope.darkTheme = true
|
||||||
else
|
else
|
||||||
|
|||||||
+1
@@ -28,6 +28,7 @@ define [
|
|||||||
@redrawAnnotations()
|
@redrawAnnotations()
|
||||||
|
|
||||||
@$scope.$watch "theme", (value) =>
|
@$scope.$watch "theme", (value) =>
|
||||||
|
console.log value
|
||||||
@redrawAnnotations()
|
@redrawAnnotations()
|
||||||
|
|
||||||
@editor.on "mousemove", (e) =>
|
@editor.on "mousemove", (e) =>
|
||||||
|
|||||||
@@ -19,9 +19,13 @@ define [
|
|||||||
$scope.settings.fontSize = newVal
|
$scope.settings.fontSize = newVal
|
||||||
return $scope.settings.fontSize.toString()
|
return $scope.settings.fontSize.toString()
|
||||||
|
|
||||||
$scope.$watch "settings.theme", (theme, oldTheme) =>
|
$scope.$watch "settings.editorTheme", (editorTheme, oldEditorTheme) =>
|
||||||
if theme != oldTheme
|
if editorTheme != oldEditorTheme
|
||||||
settings.saveSettings({theme: theme})
|
settings.saveSettings({editorTheme})
|
||||||
|
|
||||||
|
$scope.$watch "settings.overallTheme", (overallTheme, oldOverallTheme) =>
|
||||||
|
if overallTheme != oldOverallTheme
|
||||||
|
settings.saveSettings({overallTheme})
|
||||||
|
|
||||||
$scope.$watch "settings.fontSize", (fontSize, oldFontSize) =>
|
$scope.$watch "settings.fontSize", (fontSize, oldFontSize) =>
|
||||||
if fontSize != oldFontSize
|
if fontSize != oldFontSize
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ describe "ProjectController", ->
|
|||||||
it "should add on userSettings", (done)->
|
it "should add on userSettings", (done)->
|
||||||
@res.render = (pageName, opts)=>
|
@res.render = (pageName, opts)=>
|
||||||
opts.userSettings.fontSize.should.equal @user.ace.fontSize
|
opts.userSettings.fontSize.should.equal @user.ace.fontSize
|
||||||
opts.userSettings.theme.should.equal @user.ace.theme
|
opts.userSettings.editorTheme.should.equal @user.ace.theme
|
||||||
done()
|
done()
|
||||||
@ProjectController.loadEditor @req, @res
|
@ProjectController.loadEditor @req, @res
|
||||||
|
|
||||||
|
|||||||
@@ -224,12 +224,20 @@ describe "UserController", ->
|
|||||||
|
|
||||||
it "should set some props on ace", (done)->
|
it "should set some props on ace", (done)->
|
||||||
@req.body =
|
@req.body =
|
||||||
theme: "something"
|
editorTheme: "something"
|
||||||
@res.sendStatus = (code)=>
|
@res.sendStatus = (code)=>
|
||||||
@user.ace.theme.should.equal "something"
|
@user.ace.theme.should.equal "something"
|
||||||
done()
|
done()
|
||||||
@UserController.updateUserSettings @req, @res
|
@UserController.updateUserSettings @req, @res
|
||||||
|
|
||||||
|
it "should set the overall theme", (done)->
|
||||||
|
@req.body =
|
||||||
|
overallTheme: "green-ish"
|
||||||
|
@res.sendStatus = (code)=>
|
||||||
|
@user.overallTheme.should.equal "green-ish"
|
||||||
|
done()
|
||||||
|
@UserController.updateUserSettings @req, @res
|
||||||
|
|
||||||
it "should send an error if the email is 0 len", (done)->
|
it "should send an error if the email is 0 len", (done)->
|
||||||
@req.body.email = ""
|
@req.body.email = ""
|
||||||
@res.sendStatus = (code)->
|
@res.sendStatus = (code)->
|
||||||
|
|||||||
Reference in New Issue
Block a user