Commit 16251c29 authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Apply feedback from review

* Use getter functions for UserController properties
* Add comment for announce form submit method
parent 28b497b4
......@@ -10,7 +10,7 @@ import { error } from './log';
*/
export default class UserController {
constructor() {
this.sessionCount = 0;
this._sessionCount = 0;
}
/**
......@@ -31,7 +31,7 @@ export default class UserController {
},
})
.then(result => {
this.user = result;
this._user = result;
})
);
promiseList.push(this._loadSessionPage(1));
......@@ -46,11 +46,11 @@ export default class UserController {
*
* @return {Object} `user` object returned by the AMIV API.
*/
get() {
if (typeof this.user === 'undefined') {
get user() {
if (typeof this._user === 'undefined') {
return {};
}
return this.user;
return this._user;
}
/**
......@@ -58,8 +58,8 @@ export default class UserController {
*
* @return {int} number of sessions
*/
getSessionCount() {
return this.sessionCount;
get sessionCount() {
return this._sessionCount;
}
/**
......@@ -77,12 +77,12 @@ export default class UserController {
url: `${apiUrl}/users/${getUserId()}`,
headers: {
Authorization: token || getToken(),
'If-Match': this.user._etag,
'If-Match': this._user._etag,
},
data: options,
})
.then(result => {
this.user = result;
this._user = result;
})
.catch(e => {
error(e.message);
......@@ -94,7 +94,7 @@ export default class UserController {
*/
async clearOtherSessions() {
const sessions = [];
const totalPages = Math.ceil(this.sessionCount / 20);
const totalPages = Math.ceil(this._sessionCount / 20);
let promiseList = [];
let currentPage = 1;
// Load all sessions
......@@ -116,7 +116,7 @@ export default class UserController {
}
});
await Promise.all(promiseList);
this.sessionCount = 1;
this._sessionCount = 1;
}
// helper function to load session page
......@@ -128,7 +128,7 @@ export default class UserController {
Authorization: getToken(),
},
});
this.sessionCount = response._meta.total;
this._sessionCount = response._meta.total;
return response._items;
}
......
......@@ -13,8 +13,9 @@ export default class AnnounceSubscriptionForm {
}
submit() {
const user = this.userController.get();
const { user } = this.userController;
this.busy = true;
// Toggle newsletter subscription
this.userController
.update({ send_newsletter: !user.send_newsletter })
.then(() => {
......@@ -27,7 +28,7 @@ export default class AnnounceSubscriptionForm {
view() {
const buttonArgs = { events: { onclick: () => this.submit() } };
const user = this.userController.get();
const { user } = this.userController;
if (this.busy) {
buttonArgs.disabled = true;
......
......@@ -44,7 +44,7 @@ export default class ChangePasswordForm {
try {
const session = await this.constructor._createSession(
this.userController.get(),
this.userController.user,
this.password_old
);
......@@ -76,7 +76,7 @@ export default class ChangePasswordForm {
}
view() {
const user = this.userController.get();
const { user } = this.userController;
if (user === undefined) return m();
const buttonArgs = {};
......
......@@ -25,7 +25,7 @@ export default class RfidForm {
view() {
const buttonArgs = { events: { onclick: () => this.submit() } };
const user = this.userController.get();
const { user } = this.userController;
if (this.rfid === undefined) this.rfid = user.rfid;
if (!this.valid || this.busy) {
......
......@@ -13,6 +13,7 @@ export default class SessionInfo {
.clearOtherSessions()
.then(() => {
this.busy = false;
m.redraw();
})
.catch(() => {
this.busy = false;
......@@ -20,7 +21,7 @@ export default class SessionInfo {
}
view() {
const sessionCount = this.userController.getSessionCount();
const { sessionCount } = this.userController;
const buttonArgs = { events: { onclick: () => this.submit() } };
if (sessionCount === 0) {
......
......@@ -12,7 +12,7 @@ export default class UserInfo {
}
view() {
const user = this.userController.get();
const { user } = this.userController;
let freeBeerNotice;
if (user.membership !== 'none') {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment