rafactor & comments
This commit is contained in:
parent
4673331801
commit
ffdeecdf0d
|
@ -13,16 +13,16 @@ class MailboxService {
|
||||||
this.chance = new Chance();
|
this.chance = new Chance();
|
||||||
}
|
}
|
||||||
|
|
||||||
openMailbox(username) {
|
gotoMailbox(username) {
|
||||||
username = MailboxService.cleanUsername(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});
|
this.$state.go('inbox', {username: username});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadEmails(username) {
|
loadEmails(username) {
|
||||||
return this.$http.get(this.config.backend_url, {params: {username: username, action: "get"}})
|
return this.$http.get(this.config.backend_url, {params: {username: username, action: "get"}})
|
||||||
.then(response=> {
|
.then(response=> {
|
||||||
this.setCurrentAddress(response.data.address);
|
this.address = response.data.address;
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -32,9 +32,9 @@ class MailboxService {
|
||||||
return username.replace(/[@].*$/, '');
|
return username.replace(/[@].*$/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
createMailbox() {
|
gotoRandomAddress() {
|
||||||
let username = this.generateRandomUsername();
|
let username = this.generateRandomUsername();
|
||||||
this.openMailbox(username);
|
this.gotoMailbox(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
generateRandomUsername() {
|
generateRandomUsername() {
|
||||||
|
@ -42,7 +42,7 @@ class MailboxService {
|
||||||
if (this.chance.bool()) {
|
if (this.chance.bool()) {
|
||||||
username = this.chance.word({syllables: 3});
|
username = this.chance.word({syllables: 3});
|
||||||
} else {
|
} else {
|
||||||
username = this.chance.first();
|
username = this.chance.first(); // first name
|
||||||
}
|
}
|
||||||
if (this.chance.bool()) {
|
if (this.chance.bool()) {
|
||||||
username += this.chance.integer({min: 50, max: 99});
|
username += this.chance.integer({min: 50, max: 99});
|
||||||
|
@ -58,9 +58,6 @@ class MailboxService {
|
||||||
return this.$stateParams.username;
|
return this.$stateParams.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
setCurrentAddress(address) {
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
getCurrentAddress() {
|
getCurrentAddress() {
|
||||||
return this.address
|
return this.address
|
||||||
|
|
|
@ -8,21 +8,23 @@ class NavbarController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
|
// the address is updated after loading the page. the value must be watched and upated later.
|
||||||
this.$rootScope.$watch(
|
this.$rootScope.$watch(
|
||||||
()=> this.mailboxService.getCurrentAddress(),
|
()=> this.mailboxService.getCurrentAddress(),
|
||||||
(newValue, oldValue)=> {
|
(newValue, oldValue)=> {
|
||||||
this.address = newValue;
|
this.address = newValue;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
// load the temporary address (which is the username)
|
||||||
this.address = this.mailboxService.getCurrentAddress();
|
this.address = this.mailboxService.getCurrentAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
openMailbox(username) {
|
gotoMailbox(username) {
|
||||||
this.mailboxService.openMailbox(username);
|
this.mailboxService.gotoMailbox(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
createMailbox() {
|
gotoRandomAddress() {
|
||||||
this.mailboxService.createMailbox();
|
this.mailboxService.gotoRandomAddress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="navbar-form navbar-left">
|
<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>
|
<span class="glyphicon glyphicon-random" aria-hidden="true"></span>
|
||||||
create random
|
create random
|
||||||
</a>
|
</a>
|
||||||
</form>
|
</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"/>
|
<input ng-model="$ctrl.address" type='text' class="form-control"/>
|
||||||
<button type="submit" class="btn btn-default">open</button>
|
<button type="submit" class="btn btn-default">open</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import uiRouter from 'angular-ui-router';
|
||||||
|
|
||||||
import template from './navbar.html';
|
import template from './navbar.html';
|
||||||
import controller from './navbar.controller';
|
import controller from './navbar.controller';
|
||||||
import './navbar.css'
|
import './navbar.scss'
|
||||||
|
|
||||||
let navbarModule = angular.module('navbar', [uiRouter])
|
let navbarModule = angular.module('navbar', [uiRouter])
|
||||||
.component('navbar', {
|
.component('navbar', {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user