Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/assets/i18n-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"RANKING": {
"DETAIL": "Ranking Details",
"ME": "Me",
"MONTHLYPOINTS": "Points(Monthly)",
"PAGETITLE": "Leaderboard",
"TOTALPOINTS": "Points(Total)"
"MONTHLYPOINTS": "Points (Monthly)",
"PAGETITLE": "Ranking (Monthly)",
"TOTALPOINTS": "Points (Total)"
},
"RESETPASSWORD": {
"PAGETITLE": "Reset Password"
Expand Down
22 changes: 14 additions & 8 deletions src/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@
<ion-list-header>
{{ 'SETTINGS.PROFILE' | translate }} <span *ngIf="getUserEmail()">({{ getUserEmail() }})</span>
</ion-list-header>

<ion-item>
<ion-toggle [(ngModel)]="hideName" (ionChange)="triggerHideName()"></ion-toggle>
<ion-label>
Hide name in rankings
</ion-label>
</ion-item>
</ion-list>
<ion-list no-lines>
<ion-list-header>
{{ 'SETTINGS.SUPPORT' | translate }}
</ion-list-header>
<button ion-item (click)="goToTutorial()">
<ion-icon name="medkit" item-left></ion-icon> {{ 'SETTINGS.TUTORIAL' | translate }}
</button>
<button ion-item (click)="goToTermConditions()">
<ion-icon name="clipboard" item-left></ion-icon> {{ 'SETTINGS.TERMS' | translate }}
</button>
<!-- <button ion-item (click)="goLeaderBoardSettings()">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @imkven, do we need to remove this commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has removed, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kven, I just found that those code seems to be removed already in actual codebase. Thats great, thx bro.

<ion-icon name="swap" item-left></ion-icon> {{ 'SETTINGS.LEADERBOARD' | translate }}
</button> -->
</ion-list>
<ion-list no-lines>
<ion-list-header>
{{ 'SETTINGS.SUPPORT' | translate }}
</ion-list-header>
<a ion-item href="mailto:{{helpline}}?Subject=Tech%20Support%20Request" target="_blank">
<ion-icon name="mail" item-left></ion-icon> {{ 'SETTINGS.HELP' | translate }}
</a>
</ion-list>
<ion-list no-lines>
<button ion-item (click)="logout()">
<ion-icon name="exit" item-left></ion-icon> {{ 'SETTINGS.LOGOUT' | translate }}
</button>
Expand Down
106 changes: 96 additions & 10 deletions src/pages/settings/settings.page.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,136 @@
import { Component } from '@angular/core';
import { App, NavController, MenuController, LoadingController } from 'ionic-angular';
import { App, NavController, MenuController, LoadingController, AlertController } from 'ionic-angular';
// services
import { CacheService } from '../../shared/cache/cache.service';
import { GameService } from '../../services/game.service';
// pages
import { LeaderboardSettingsPage } from '../settings/leaderboard/leaderboard-settings.page';
import { LoginPage } from '../../pages/login/login';
import { TutorialPage } from '../settings/tutorial/tutorial.page';
import { TermsConditionsPage } from '../registration/terms-conditions/terms-conditions.page';
// Others
import { TranslationService } from '../../shared/translation/translation.service';
import { loadingMessages, errMessages } from '../../app/messages';
import { loadingMessages } from '../../app/messages';

@Component({
selector: 'settings-page',
templateUrl: 'settings.html'
})
export class SettingsPage {
helpline: string = "help@practera.com";
hideName: boolean = false;
logoutMessage: any = loadingMessages.Logout.logout;
settings: any = [];
isLock: boolean = false;
pageLoad: boolean = true;
constructor(
public appCtrl: App,
public alertCtrl: AlertController,
public cacheService: CacheService,
public gameService: GameService,
public loadingCtrl: LoadingController,
public menuCtrl: MenuController,
public navCtrl: NavController,
public cache: CacheService,
public translationService: TranslationService) {}
getUserEmail() {
return this.cache.getLocal('email') || '';
public translationService: TranslationService,
) {}

ionViewWillEnter(){
this.pageLoad = true;
this.preload();
}
goLeaderBoardSettings(){
this.navCtrl.push(LeaderboardSettingsPage);

preload() {
const loading = this.loadingCtrl.create({
content: 'Loading'
});
loading.present();

let gameId = this.cacheService.getLocal('game_id');
this.gameService.getCharacters(gameId)
.subscribe((characters) => {
let me = characters.Characters[0];
if (me.meta == null) {
this.hideName = false;
}
if (me.meta != null){
if (me.meta.private === 0) {
this.hideName = false;
} else {
this.hideName = true;
}
}
loading.dismiss();
}, (err) => {
loading.dismiss();
});
}

triggerHideName() {
if (this.pageLoad) {
this.pageLoad = false;
return false;
}

if (this.isLock) {
this.isLock = false;
} else {
const showAlert = (msg) => {
let alert = this.alertCtrl.create({
subTitle: msg,
buttons: ['OK']
});
alert.present();
}

const loader = this.loadingCtrl.create({
content: 'Updating'
});

loader.present().then(() => {
this.isLock = true;
this.gameService.postCharacter({
Character: {
id: this.cacheService.getLocal('character_id'),
meta: {
private: (this.hideName) ? 1 : 0
}
}
})
.subscribe((result) => {
this.isLock = false;
loader.dismiss();
let msg = 'You name will now be hidden if in the ranking';
if (!this.hideName) {
msg = 'Your name will now be displayed if in the ranking';
}
showAlert(msg);
}, (err) => {
this.hideName = !this.hideName;
showAlert('Unabled to change your privacy setting.');
loader.dismiss();
});
});
}
}

getUserEmail() {
return this.cacheService.getLocal('email') || '';
}

goToTutorial() {
this.navCtrl.push(TutorialPage);
}

goToTermConditions() {
this.navCtrl.push(TermsConditionsPage);
}

logout() {
let loader = this.loadingCtrl.create({
spinner: 'hide',
content: this.logoutMessage
});
loader.present().then(() => {
this.cache.clear().then(() => {
this.cacheService.clear().then(() => {
loader.dismiss();
this.navCtrl.push(LoginPage);
localStorage.clear();
Expand Down
4 changes: 1 addition & 3 deletions src/services/assessment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ export class AssessmentService {
}

post(assessmentAnswer: Submission) {
return this.request.post('api/assessment_submissions.json', assessmentAnswer, {
'Content-Type': 'application/json'
});
return this.request.post('api/assessment_submissions.json', assessmentAnswer);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export class AuthService {
public request: RequestService,
) {}
private postRequest(type, body) {
return this.request.post(AUTH_ENDPOINT + type, body);
return this.request.post(AUTH_ENDPOINT + type, body, {
'Content-Type': 'application/x-www-form-urlencoded'
});
}
verifyRegistration(data) {
let email = data.email;
Expand All @@ -38,7 +40,9 @@ export class AuthService {
return this.postRequest('reset_password', { key, email, password, verify_password });
}
magicLinkLogin(auth_token) {
return this.request.post('api/auths.json', { auth_token });
return this.request.post('api/auths.json', { auth_token }, {
'Content-Type': 'application/x-www-form-urlencoded'
});
}
getUser() {
return this.request.get('api/users.json');
Expand Down
2 changes: 1 addition & 1 deletion src/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class EventService {
* @param {integer} eventId single event id
*/
bookEvent(eventId) {
return this.request.post(this.bookEventUrl, { event_id: eventId});
return this.request.post(this.bookEventUrl, { event_id: eventId });
}

cancelEventBooking(eventId){
Expand Down
8 changes: 2 additions & 6 deletions src/services/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export class GameService {
* @param {object} data
*/
postCharacter(data) {
return this.request.post('api/characters', data, {
headers: new HttpHeaders().set('Content-Type', 'application/json')
});
return this.request.post('api/characters', data);
}
/**
* Get ranking
Expand Down Expand Up @@ -79,8 +77,6 @@ export class GameService {
"id": null
}
}) {
return this.request.post('api/items.json', options, {
headers: new HttpHeaders().set('Content-Type', 'application/json')
});
return this.request.post('api/items.json', options);
}
}
6 changes: 6 additions & 0 deletions src/shared/cache/cache.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class CacheService {
}

/**
* DEPRECATED
* get memory cached values by key
* @param {object||string}
*/
Expand All @@ -42,6 +43,7 @@ export class CacheService {
}

/**
* DEPRECATED
* Write data into local storage
* @param {string} path - path to store data
* @param {any} content - data to store
Expand All @@ -57,6 +59,7 @@ export class CacheService {
}

/**
* DEPRECATED
* Read data into local storage
* @param {string} path - path to read data
* @return {promise} <data store>
Expand Down Expand Up @@ -92,6 +95,9 @@ export class CacheService {
}
}

/**
* DEPRECATED
*/
public clear(): any {
return this.storage.clear();
}
Expand Down
42 changes: 22 additions & 20 deletions src/shared/request/request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,35 @@ export class RequestService {
return Observable.throw(currentError);
}
// Inject required fields to header of API request
appendHeader(customHeader: any = {
'contentType': 'application/json',
'apikey': null
}): HttpHeaders {
let result:any;
let headers = new HttpHeaders();
result = headers.set('Content-Type', customHeader.contentType);
appendHeader(custom: object = {}): HttpHeaders {
// Define default header
custom = _.merge({
'content-type': 'application/json'
}, custom);

let header: HttpHeaders = new HttpHeaders();

_.forEach(custom, (value, key) => {
header = header.set(key, _.toString(value));
});

// Inject apiKey from cached
let apiKey = this.cacheService.getCached('apikey') ||
this.cacheService.getLocal('apikey');
let apiKey = this.cacheService.getLocal('apikey');
if (!_.isEmpty(apiKey)) {
result = result.set('apikey', apiKey.toString());
header = header.set('apikey', _.toString(apiKey));
}
// Inject timelineID from cached
let timelineId = this.cacheService.getCached('timelineID') ||
this.cacheService.getLocal('timelineID');
let timelineId = this.cacheService.getLocal('timelineID');
if (timelineId) {
result = result.set('timelineID', timelineId.toString());
header = header.set('timelineID', _.toString(timelineId));
}
return result;

return header;
}
// Set API request options
setOptions(options?): {
headers?: HttpHeaders;
observe?: "body";
observe?: 'body';
params?: HttpParams;
reportProgress?: boolean;
withCredentials?: boolean;
Expand All @@ -100,7 +104,7 @@ export class RequestService {
let params = (options && options.params) ? options.params : new HttpParams();
if (options && options.search) {
_.each(options.search, (value, key) => {
params = params.set(key, value.toString());
params = params.set(key, _.toString(value));
});
}
let timelineId = this.cacheService.getLocal('timelineID');
Expand Down Expand Up @@ -132,10 +136,8 @@ export class RequestService {
* @param {Object} header
*/
post(endPoint: string, data: any, header?: any) {
let headers = this.appendHeader();
// @TODO: make sure if Content-Type is optional
headers = headers.delete('Content-Type');
headers = headers.set('Content-Type', 'application/x-www-form-urlencoded');
let headers = this.appendHeader(header);

return this.http.post(this.prefixUrl + endPoint, data, { headers })
.map(this.extractData)
.catch(this.handleError);
Expand Down