1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
import { observable, runInAction, action, computed } from "mobx";
import * as React from "react";
import MainViewModal from "../views/MainViewModal";
import { observer } from "mobx-react";
import { library } from '@fortawesome/fontawesome-svg-core';
import * as fa from '@fortawesome/free-solid-svg-icons';
import { SelectionManager } from "./SelectionManager";
import "./SettingsManager.scss";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Networking } from "../Network";
import { CurrentUserUtils } from "./CurrentUserUtils";
import { Utils, addStyleSheet, addStyleSheetRule, removeStyleSheetRule } from "../../Utils";
import { Doc } from "../../fields/Doc";
import GroupManager from "./GroupManager";
import GoogleAuthenticationManager from "../apis/GoogleAuthenticationManager";
import { DocServer } from "../DocServer";
import { BoolCast, StrCast, NumCast } from "../../fields/Types";
import { undoBatch } from "./UndoManager";
import { ColorState, SketchPicker } from "react-color";
const higflyout = require("@hig/flyout");
export const { anchorPoints } = higflyout;
export const Flyout = higflyout.default;
library.add(fa.faTimes);
@observer
export default class SettingsManager extends React.Component<{}> {
public static Instance: SettingsManager;
static _settingsStyle = addStyleSheet();
@observable private isOpen = false;
@observable private dialogueBoxOpacity = 1;
@observable private overlayOpacity = 0.4;
@observable private settingsContent = "password";
@observable private errorText = "";
@observable private successText = "";
@observable private playgroundMode = false;
private curr_password_ref = React.createRef<HTMLInputElement>();
private new_password_ref = React.createRef<HTMLInputElement>();
private new_confirm_ref = React.createRef<HTMLInputElement>();
@computed get backgroundColor() { return Doc.UserDoc().defaultColor; }
public open = action(() => {
SelectionManager.DeselectAll();
this.isOpen = true;
});
public close = action(() => {
this.isOpen = false;
});
constructor(props: {}) {
super(props);
SettingsManager.Instance = this;
}
@action
private dispatchRequest = async () => {
const curr_pass = this.curr_password_ref.current?.value;
const new_pass = this.new_password_ref.current?.value;
const new_confirm = this.new_confirm_ref.current?.value;
if (!(curr_pass && new_pass && new_confirm)) {
this.changeAlertText("Hey, we're missing some fields!", "");
return;
}
const passwordBundle = {
curr_pass,
new_pass,
new_confirm
};
const { error } = await Networking.PostToServer('/internalResetPassword', passwordBundle);
if (error) {
this.changeAlertText("Uh oh! " + error[0].msg + "...", "");
return;
}
this.changeAlertText("", "Password successfully updated!");
}
@action
private changeAlertText = (errortxt: string, successtxt: string) => {
this.errorText = errortxt;
this.successText = successtxt;
}
@action
onClick = (event: any) => {
this.settingsContent = event.currentTarget.value;
this.errorText = "";
this.successText = "";
}
@action
noviceToggle = (event: any) => {
Doc.UserDoc().noviceMode = !Doc.UserDoc().noviceMode;
}
@action
googleAuthorize = (event: any) => {
GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(true);
}
@action
togglePlaygroundMode = () => {
this.playgroundMode = !this.playgroundMode;
if (this.playgroundMode) DocServer.Control.makeReadOnly();
else DocServer.Control.makeEditable();
addStyleSheetRule(SettingsManager._settingsStyle, "lm_header", { background: "pink !important" });
}
@action
changeMode = (e: any) => {
if (e.currentTarget.value === "Novice") {
Doc.UserDoc().noviceMode = true;
} else {
Doc.UserDoc().noviceMode = false;
}
}
@action
changeFontFamily = (e: any) => {
Doc.UserDoc().fontFamily = e.currentTarget.value;
}
@action
changeFontSize = (e: any) => {
Doc.UserDoc().fontSize = e.currentTarget.value;
}
@action @undoBatch
switchColor = (color: ColorState) => {
const val = String(color.hex);
Doc.UserDoc().defaultColor = val;
return true;
}
private get settingsInterface() {
const passwordContent = <div className="password-content">
<div className="password-content-inputs">
<input className="password-inputs" type="password" placeholder="current password" ref={this.curr_password_ref} />
<input className="password-inputs" type="password" placeholder="new password" ref={this.new_password_ref} />
<input className="password-inputs" type="password" placeholder="confirm new password" ref={this.new_confirm_ref} />
</div>
<div className="password-content-buttons">
{this.errorText ? <div className="error-text">{this.errorText}</div> : undefined}
{this.successText ? <div className="success-text">{this.successText}</div> : undefined}
<button className="password-submit" onClick={this.dispatchRequest}>submit</button>
<a className="password-forgot" style={{ marginLeft: 65, marginTop: -20 }}
href="/forgotPassword">forgot password?</a>
</div>
</div>;
const modesContent = <div className="modes-content">
<select className="modes-select"
onChange={e => this.changeMode(e)}>
<option key={"Novice"} value={"Novice"} selected={BoolCast(Doc.UserDoc().noviceMode)}>
Novice
</option>
<option key={"Developer"} value={"Developer"} selected={!BoolCast(Doc.UserDoc().noviceMode)}>
Developer
</option>
</select>
<div className="modes-playground">
<input className="playground-check" type="checkbox"
checked={this.playgroundMode}
onChange={undoBatch(action(() => this.togglePlaygroundMode()))}
/><div className="playground-text">Playground Mode</div>
</div>
</div>;
const accountsContent = <div className="accounts-content">
<button onClick={this.googleAuthorize} value="data">{`Link to Google`}</button>
<button onClick={() => GroupManager.Instance.open()}>Manage groups</button>
</div>;
const colorBox = <SketchPicker onChange={this.switchColor}
presetColors={['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505',
'#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B',
'#FFFFFF', '#f1efeb', 'transparent']}
color={StrCast(this.backgroundColor)} />;
const colorFlyout = <div className="colorFlyout">
<Flyout anchorPoint={anchorPoints.LEFT_TOP}
content={colorBox}>
<div>
<div className="colorFlyout-button" style={{ backgroundColor: StrCast(this.backgroundColor) }}
onPointerDown={e => e.stopPropagation()} >
<FontAwesomeIcon icon="palette" size="sm" color={StrCast(this.backgroundColor)} />
</div>
</div>
</Flyout>
</div>;
const fontFamilies: string[] = ["Times New Roman", "Arial", "Georgia", "Comic Sans MS", "Tahoma", "Impact", "Crimson Text"];
const fontSizes: string[] = ["7pt", "8pt", "9pt", "10pt", "12pt", "14pt", "16pt", "18pt", "20pt", "24pt", "32pt", "48pt", "72pt"];
const preferencesContent = <div className="preferences-content">
<div className="preferences-color">
<div className="preferences-color-text">Background Color</div> {colorFlyout}
</div>
<div className="preferences-font">
<div className="preferences-font-text">Default Font</div>
<select className="font-select"
onChange={e => this.changeFontFamily(e)}>
{fontFamilies.map((font) => {
return <option key={font} value={font} selected={StrCast(Doc.UserDoc().fontFamily) === font}>
{font}
</option>;
})}
</select>
<select className="size-select"
onChange={e => this.changeFontSize(e)}>
{fontSizes.map((size) => {
return <option key={size} value={size} selected={StrCast(Doc.UserDoc().fontSize) === size}>
{size}
</option>;
})}
</select>
</div>
</div>;
return (<div className="settings-interface">
<div className="settings-top">
<div className="settings-title">Settings</div>
<div className="settings-username">{Doc.CurrentUserEmail}</div>
<button onClick={() => window.location.assign(Utils.prepend("/logout"))}
style={{ right: 35, position: "absolute" }} >
{CurrentUserUtils.GuestWorkspace ? "Exit" : "Log Out"}
</button>
<div className="close-button" onClick={this.close}>
<FontAwesomeIcon icon={fa.faTimes} color="black" size={"lg"} />
</div>
</div>
<div className="settings-content">
<div className="settings-section">
<div className="settings-section-title">Password</div>
<div className="settings-section-context">{passwordContent}</div>
</div>
<div className="settings-section">
<div className="settings-section-title">Modes</div>
<div className="settings-section-context">{modesContent}</div>
</div>
<div className="settings-section">
<div className="settings-section-title">Accounts</div>
<div className="settings-section-context">{accountsContent}</div>
</div>
<div className="settings-section" style={{ paddingBottom: 4 }}>
<div className="settings-section-title">Preferences</div>
<div className="settings-section-context">{preferencesContent}</div>
</div>
</div>
</div>);
}
render() {
return (
<MainViewModal
contents={this.settingsInterface}
isDisplayed={this.isOpen}
interactive={true}
closeOnExternalClick={this.close}
dialogueBoxStyle={{ width: "600px", height: "340px" }}
/>
);
}
}
|