rafactor & comments

This commit is contained in:
Synox 2016-07-03 20:19:24 +02:00
parent 4673331801
commit ffdeecdf0d
5 changed files with 15 additions and 16 deletions

View File

@ -13,16 +13,16 @@ class MailboxService {
this.chance = new Chance();
}
openMailbox(username) {
gotoMailbox(username) {
username = MailboxService.cleanUsername(username);
this.setCurrentAddress(username);
this.address = username; // use username until real address has been loaded
this.$state.go('inbox', {username: username});
}
loadEmails(username) {
return this.$http.get(this.config.backend_url, {params: {username: username, action: "get"}})
.then(response=> {
this.setCurrentAddress(response.data.address);
this.address = response.data.address;
return response.data;
}
);
@ -32,9 +32,9 @@ class MailboxService {
return username.replace(/[@].*$/, '');
}
createMailbox() {
gotoRandomAddress() {
let username = this.generateRandomUsername();
this.openMailbox(username);
this.gotoMailbox(username);
}
generateRandomUsername() {
@ -42,7 +42,7 @@ class MailboxService {
if (this.chance.bool()) {
username = this.chance.word({syllables: 3});
} else {
username = this.chance.first();
username = this.chance.first(); // first name
}
if (this.chance.bool()) {
username += this.chance.integer({min: 50, max: 99});
@ -58,9 +58,6 @@ class MailboxService {
return this.$stateParams.username;
}
setCurrentAddress(address) {
this.address = address;
}
getCurrentAddress() {
return this.address

View File

@ -8,21 +8,23 @@ class NavbarController {
}
$onInit() {
// the address is updated after loading the page. the value must be watched and upated later.
this.$rootScope.$watch(
()=> this.mailboxService.getCurrentAddress(),
(newValue, oldValue)=> {
this.address = newValue;
}
);
// load the temporary address (which is the username)
this.address = this.mailboxService.getCurrentAddress();
}
openMailbox(username) {
this.mailboxService.openMailbox(username);
gotoMailbox(username) {
this.mailboxService.gotoMailbox(username);
}
createMailbox() {
this.mailboxService.createMailbox();
gotoRandomAddress() {
this.mailboxService.gotoRandomAddress();
}
}

View File

@ -5,14 +5,14 @@
</div>
<form class="navbar-form navbar-left">
<a class="btn btn-default" ng-click="$ctrl.createMailbox()" role="button">
<a class="btn btn-default" ng-click="$ctrl.gotoRandomAddress()" role="button">
<span class="glyphicon glyphicon-random" aria-hidden="true"></span>
create random
</a>
</form>
<form class="navbar-form navbar-left" role="search" ng-submit="$ctrl.openMailbox($ctrl.address)">
<form class="navbar-form navbar-left" role="search" ng-submit="$ctrl.gotoMailbox($ctrl.address)">
<input ng-model="$ctrl.address" type='text' class="form-control"/>
<button type="submit" class="btn btn-default">open</button>
</form>

View File

@ -3,7 +3,7 @@ import uiRouter from 'angular-ui-router';
import template from './navbar.html';
import controller from './navbar.controller';
import './navbar.css'
import './navbar.scss'
let navbarModule = angular.module('navbar', [uiRouter])
.component('navbar', {