Skip to content

Commit 5b16c29

Browse files
authored
Merge pull request #48 from daveseah/dev-ds/groupid-plus
FIX: SessionShell Login UI Improvements
2 parents f8fffe5 + 2d7ac58 commit 5b16c29

File tree

3 files changed

+70
-50
lines changed

3 files changed

+70
-50
lines changed

build/app/system/datastore.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,28 @@ DSTOR.Hook("INITIALIZE", () => {
3838
DSTOR.UpdateServerDB(data);
3939
});
4040

41-
UDATA.HandleMessage("GROUPID_CHANGE", function(data) {
42-
DSTOR.SetSessionGroupID(data);
43-
console.log("Handling GROUPID_CHANGE");
41+
UDATA.OnAppStateChange('SESSION', function( decodedData ) {
42+
let { isValid, token } = decodedData;
43+
console.log('Handling SESSION',isValid);
44+
if (isValid) DSTOR.SetSessionGroupID(decodedData);
4445
});
46+
4547
});
4648

49+
4750
/// SESSION ///////////////////////////////////////////////////////////////////
4851
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4952
/*/ datastore needs to set NetMessage GroupID property on behalf of SESSIONS
5053
because SESSION can't include NetMessage (or vice versa)
5154
/*/
52-
DSTOR.SetSessionGroupID = function(token) {
53-
let decoded = SESSION.DecodeToken(token);
54-
if (decoded.isValid) {
55+
DSTOR.SetSessionGroupID = function ( decodedData ) {
56+
let { token, isValid } = decodedData;
57+
if (isValid) {
5558
NetMessage.GlobalSetGroupID(token);
56-
console.log("setting NetMessage group id", token);
59+
console.log('setting NetMessage group id',token);
5760
} else {
58-
console.warn("will not set bad group id:", token);
61+
console.warn('will not set bad group id:',token);
5962
}
60-
UDATA.SetAppState("SESSION", decoded);
6163
};
6264

6365
/// DB INTERFACE //////////////////////////////////////////////////////////////

build/app/unisys/common-session.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SESUTIL.DecodeToken = function(token) {
6363
groupId = 0;
6464
}
6565

66-
// at this point groupId is valid
66+
// at this point groupId is valid (begins with ID, all numeric)
6767
// check for valid subgroupId
6868
if (subId) {
6969
if (
@@ -76,13 +76,13 @@ SESUTIL.DecodeToken = function(token) {
7676
} else {
7777
// subId exists but didn't match subid format
7878
if (DBG) console.log("invalid subId string", subId);
79-
isValid = false;
79+
isValid = false; // groupId is still valid,
8080
subId = 0;
8181
}
8282
}
8383

8484
// if isValid is false, check groupId is 0 or subId is 0, indicating error
85-
let decoded = { isValid, classId, projId, hashedId, groupId, subId };
85+
let decoded = { token, isValid, classId, projId, hashedId, groupId, subId };
8686
return decoded;
8787
};
8888
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

build/app/unisys/component/SessionShell.jsx

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const PROMPTS = require("system/util/prompts");
4141
const SESSION = require("unisys/common-session");
4242
const PR = PROMPTS.Pad("SessionShell");
4343
const ReactStrap = require("reactstrap");
44-
const { Col, FormGroup, FormFeedback, Input, Label } = ReactStrap;
44+
const { InputGroup, InputGroupAddon, Button, Col, Row, Form, FormGroup, FormFeedback, Input, Label } = ReactStrap;
4545
const { Redirect } = require("react-router-dom");
4646
const UNISYS = require("unisys/client");
4747

@@ -50,7 +50,6 @@ const UNISYS = require("unisys/client");
5050
/// these styles are copied from AutoComplete.css
5151
const INPUT_STYLE = {
5252
border: "1px solid #aaa",
53-
borderRadius: "4px",
5453
fontFamily: "Helvetica, sans-serif",
5554
fontWeight: 300,
5655
fontSize: "10px",
@@ -76,14 +75,18 @@ class SessionShell extends UNISYS.Component {
7675
this.renderLogin = this.renderLogin.bind(this);
7776
this.renderLoggedIn = this.renderLoggedIn.bind(this);
7877
this.handleChange = this.handleChange.bind(this);
78+
this.onSubmit = this.onSubmit.bind(this);
7979
this.state = {
80+
token: null,
8081
classId: null,
8182
projId: null,
8283
hashedId: null,
8384
subId: null,
8485
groupId: null,
86+
subId: null,
8587
isValid: false
8688
};
89+
8790
}
8891

8992
/// ROUTE RENDER FUNCTIONS ////////////////////////////////////////////////////
@@ -119,43 +122,49 @@ class SessionShell extends UNISYS.Component {
119122
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120123
/*/ render must login (readonly)
121124
/*/
122-
renderLogin(token) {
123-
let decoded = token ? SESSION.DecodeToken(token) : this.state;
124-
let { classId, projId, groupId, subId, hashedId, isValid } = decoded;
125-
let formFeedback, tip;
126-
if (classId) tip = "keep entering...";
127-
else tip = "enter group ID";
125+
renderLogin() {
126+
let { token, classId, projId, groupId, subId, hashedId, isValid } = this.state;
127+
if (token) token = token.toUpperCase();
128+
let formFeedback, tip, input;
129+
tip = "type group ID";
130+
if (classId) tip = "scanning for valid code...";
131+
if (projId) tip = "waiting for valid code...";
132+
if (groupId) tip = "waiting for extra ID...";
128133
if (hashedId) {
129134
if (hashedId.length >= 3) {
130-
if (!isValid) tip = `'${token}' is an invalid code`;
135+
if (!groupId) tip = `'${token}' is an invalid code`;
136+
else {
137+
if (subId) tip = `login in as GROUP ${groupId} ${subId}`;
138+
else tip = `login as GROUP ${groupId} or add -ID<num>`;
139+
}
131140
}
132141
}
133-
formFeedback = tip ? (
134-
<FormFeedback className="text-right">
135-
<small>{tip}</small>
136-
</FormFeedback>
137-
) : (
138-
undefined
139-
);
142+
if (groupId) {
143+
if (subId===0) {
144+
tip = `e.g. ${classId}-${projId}-${hashedId} followed by -ID<num>`;
145+
input = <Input invalid name="sessionToken" id="sessionToken" bsSize="sm" style={INPUT_STYLE} className="text-right" placeholder="CLASSID-PROJID-CODE" onChange={this.handleChange} />
146+
formFeedback = <FormFeedback className="text-right"><small>{tip}</small></FormFeedback>
147+
} else {
148+
input = <Input valid name="sessionToken" id="sessionToken" bsSize="sm" style={INPUT_STYLE} className="text-right" placeholder="CLASSID-PROJID-CODE" onChange={this.handleChange} />
149+
formFeedback = <FormFeedback valid className="text-right"><small>{tip}</small></FormFeedback>
150+
}
151+
} else {
152+
input = <Input invalid name="sessionToken" id="sessionToken" bsSize="sm" style={INPUT_STYLE} className="text-right" placeholder="CLASSID-PROJID-CODE" onChange={this.handleChange} />
153+
formFeedback = <FormFeedback className="text-right"><small>{tip}</small></FormFeedback>
154+
}
155+
140156
return (
157+
<Form onSubmit={this.onSubmit}>
141158
<FormGroup row>
142-
<Col sm={3}>
143-
<Label className="small text-muted">Login</Label>
144-
</Col>
145-
<Col sm={9}>
146-
<Input
147-
invalid
148-
name="sessionToken"
149-
id="sessionToken"
150-
bsSize="sm"
151-
style={INPUT_STYLE}
152-
className="text-right"
153-
placeholder="CLASS-PROJECT-XYZ"
154-
onChange={this.handleChange}
155-
/>
159+
<Col>
160+
<InputGroup>
161+
<InputGroupAddon addonType="prepend"><Button style={{fontSize:'10px'}} color="secondary" size="sm" disabled={!isValid} onSubmit={this.onSubmit}>LOGIN</Button></InputGroupAddon>
162+
{input}
156163
{formFeedback}
164+
</InputGroup>
157165
</Col>
158166
</FormGroup>
167+
</Form>
159168
);
160169
}
161170
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -196,26 +205,35 @@ class SessionShell extends UNISYS.Component {
196205
// try to decode token
197206
let decoded = SESSION.DecodeToken(token);
198207
if (decoded.isValid) {
199-
this.AppCall("GROUPID_CHANGE", token);
200208
return this.renderLoggedIn(decoded);
209+
} else {
210+
return this.renderLogin(token);
201211
}
202-
// error in decode so render login field
203-
return this.renderLogin(token);
204212
}
205213

206214
/// EVENT HANDLERS ////////////////////////////////////////////////////////////
207215
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
208216
handleChange(event) {
209217
let token = event.target.value;
210218
let decoded = SESSION.DecodeToken(token);
211-
let { classId, projId, hashedId, groupId, subId } = decoded;
219+
let { classId, projId, hashedId, subId, groupId } = decoded;
212220
this.setState(decoded);
213-
this.SetAppState("SESSION", decoded);
214-
if (decoded.groupId) {
221+
}
222+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223+
onSubmit(event) {
224+
event.preventDefault();
225+
const BRUTAL_REDIRECT = true;
226+
if (this.state.isValid) {
215227
// force a page URL change
216-
let redirect = `/edit/${event.target.value}`;
217-
this.props.history.push(redirect);
228+
if (BRUTAL_REDIRECT) {
229+
const redirect = `/#/edit/${this.state.token}`;
230+
window.location=redirect;
231+
} else {
232+
const redirect = `/edit/${this.state.token}`
233+
this.props.history.push(redirect);
234+
}
218235
}
236+
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
219237
}
220238
} // UNISYS.Component SessionShell
221239

0 commit comments

Comments
 (0)