Skip to content

Commit

Permalink
Updated manager app to Ember CLI 0.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
heycarsten committed Mar 19, 2015
1 parent 542bc7a commit a0a7a3c
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 145 deletions.
21 changes: 9 additions & 12 deletions manager/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import Em from 'ember';

export default Em.Controller.extend({
year: function() {
year: Em.computed(function() {
return new Date().getFullYear();
}.property(),
}),

actions: {
toggleAccountMenu: function() {
var controller = this;

toggleAccountMenu() {
if (this.get('showAccountMenu')) {
return;
}

this.set('showAccountMenu', true);

Em.run.next(function() {
Em.$(document).one('click', function() {
controller.set('showAccountMenu', false);
Em.run.next(() => {
Em.$(document).one('click', () => {
this.set('showAccountMenu', false);
return true;
});
});
}
},

currentRouteClass: function() {
var path = this.get('currentPath');
return path.dasherize().replace(/\./g, '-');
}.property('currentPath'),
currentRouteClass: Em.computed(function() {
return this.get('currentPath').dasherize().replace(/\./g, '-');
}).property('currentPath')
});
4 changes: 2 additions & 2 deletions manager/app/controllers/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Em from 'ember';

export default Em.Controller.extend({
needs: 'application',
application: Em.inject.controller(),

currentPath: Em.computed.oneWay('controllers.application.currentPath'),
currentPath: Em.computed.reads('application.currentPath'),

inKeys: Em.computed.match('currentPath', /^dashboard\.keys/),
inAccount: Em.computed.match('currentPath', /^dashboard\.account/)
Expand Down
3 changes: 1 addition & 2 deletions manager/app/controllers/dashboard/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ import Em from 'ember';
// return ret;
// }.property('cycleRequests')

export default Em.ObjectController.extend({
});
export default Em.Controller.extend();
14 changes: 6 additions & 8 deletions manager/app/controllers/dashboard/keys/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ var KINDS = [
{ id: 'native_client', label: 'Desktop / Mobile \u2014 Apple iOS / Cocoa, Android, Blackberry, etc.' }
];

export default Em.ObjectController.extend({
export default Em.Controller.extend({
kindOptions: KINDS,
isWebClient: Em.computed.equal('kind', 'web_client'),
isClient: Em.computed.match('kind', /_client$/),
isWebClient: Em.computed.equal('model.kind', 'web_client'),
isClient: Em.computed.match('model.kind', /_client$/),

actions: {
createKey: function(model) {
var controller = this;

model.save().then(function() {
controller.transitionTo('dashboard.keys');
createKey(model) {
model.save().then(() => {
this.transitionTo('dashboard.keys');
}, Em.K);
}
}
Expand Down
16 changes: 8 additions & 8 deletions manager/app/controllers/dashboard/keys/show.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Em from 'ember';

export default Em.ObjectController.extend({
isWeb: Em.computed.equal('kind', 'web_client'),
isServer: Em.computed.equal('kind', 'private_server'),
isClient: Em.computed.equal('kind', 'native_client'),
export default Em.Controller.extend({
isWeb: Em.computed.equal('model.kind', 'web_client'),
isServer: Em.computed.equal('model.kind', 'private_server'),
isClient: Em.computed.equal('model.kind', 'native_client'),

currentMonth: function() {
currentMonth: Em.computed(function() {
return moment().format('MMMM');
}.property(),
}),

actions: {
deleteKey: function() {
if (this.get('totalCycleRequests') > 0) {
deleteKey() {
if (this.get('model.totalCycleRequests') > 0) {
if (!confirm('Are you sure you want to delete this Access Key? Any integrations that are using it will stop working.')) {
return;
}
Expand Down
14 changes: 6 additions & 8 deletions manager/app/controllers/login.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import Ember from 'ember';
import Em from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';

export default Ember.Controller.extend(LoginControllerMixin, {
export default Em.Controller.extend(LoginControllerMixin, {
authenticator: 'authenticator:un-auth',

actions: {
// display an error when authentication fails
authenticate: function() {
var controller = this;

this.send('loading');

this._super().then(null, function(xhr) {
this._super().catch(xhr => {
var msg;

if (xhr.status === 422) {
msg = xhr.responseJSON.error.detail;
} else {
msg = 'an HTTP ' + xhr.status + ' error occurred on the server, try again';
msg = `an HTTP ${xhr.status} error occurred on the server, try again`;
}

controller.send('loaded');
controller.set('errorMessage', msg.capitalize() + '.');
this.send('loaded');
this.set('errorMessage', msg.capitalize() + '.');
});
}
}
Expand Down
53 changes: 23 additions & 30 deletions manager/app/controllers/password/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,40 @@ import Em from 'ember';

export default Em.Controller.extend({
actions: {
submit: function() {
var controller = this;

submit() {
this.send('loading');

Em.$.ajax({
url: '/manager/passwords/' + this.get('token'),
type: 'PUT',
data: { password: this.get('password') }
}).then(
function(data) {
Em.run(function() {
controller.session.authenticate('authenticator:un-auth', data).then(function() {
controller.transitionToRoute('dashboard.keys');
});
}).then(data => {
Em.run(function() {
this.session.authenticate('authenticator:un-auth', data).then(() => {
this.transitionToRoute('dashboard.keys');
});
},

function(xhr) {
Em.run(function() {
// MEGAHAX :-/
var err = Em.Object.create({
remove: function(prop) {
var val = this.get(prop);

if (val) {
val.clear();
}
});
}).catch(xhr => {
Em.run(() => {
// MEGAHAX :-/
var err = Em.Object.create({
remove: function(prop) {
var val = this.get(prop);

if (val) {
val.clear();
}
});

xhr.responseJSON.errors.forEach(function(e) {
err[e.path.camelize()] = [{ message: e.detail }];
});
}
});

controller.set('errors', err);
controller.send('loaded');
xhr.responseJSON.errors.forEach(e => {
err[e.path.camelize()] = [{ message: e.detail }];
});
}
);

this.set('errors', err);
this.send('loaded');
});
});
}
}
});
14 changes: 6 additions & 8 deletions manager/app/controllers/password/recover.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@ export default Em.Controller.extend({

subTemplate: 'password/recover/form',

reset: function() {
reset() {
this.set('email', null);
this.set('subTemplate', 'password/recover/form');
},

actions: {
submit: function() {
var controller = this;

submit() {
this.send('loading');

Em.$.ajax({
url: '/manager/passwords',
type: 'POST',
data: { email: this.get('email') }
}).always(function() {
Em.run(function() {
controller.set('subTemplate', 'password/recover/done');
controller.send('loaded');
}).always(() => {
Em.run(() => {
this.set('subTemplate', 'password/recover/done');
this.send('loaded');
});
});
}
Expand Down
28 changes: 11 additions & 17 deletions manager/app/controllers/signup.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
import Em from 'ember';

export default Em.ObjectController.extend({
export default Em.Controller.extend({
disabled: false,
currentTemplate: 'signup/form',

reset: function() {
reset() {
this.setProperties({
name: null,
email: null,
name: null,
email: null,
password: null
});
},

actions: {
createAccount: function(model) {
var controller = this;

createAccount(model) {
this.send('loading');

model.save().then(
function() {
controller.send('loaded');
controller.set('currentTemplate', 'signup/done');
},

function() {
controller.send('loaded');
}
);
model.save().then(() => {
this.send('loaded');
this.set('currentTemplate', 'signup/done');
}).catch(() => {
this.send('loaded');
});
}
}
});
4 changes: 2 additions & 2 deletions manager/app/templates/dashboard/account.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Activity</h1>

<h2>Total requests this month: {{totalCycleRequests}}</h2>
<h2>Total requests this month: {{model.totalCycleRequests}}</h2>

{{line-area-chart
height=240
data=cycleRequests}}
data=model.cycleRequests}}
2 changes: 1 addition & 1 deletion manager/app/templates/dashboard/keys.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</tr>
</thead>
<tbody>
{{#each key in this}}
{{#each key in model}}
{{#link-to "dashboard.keys.show" key tagName="tr"}}
<td>{{key.label}}</td>
<td>{{key.humanKind}}</td>
Expand Down
18 changes: 7 additions & 11 deletions manager/app/templates/dashboard/keys/show.hbs
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
<h1>{{label}}</h1>

{{#if totalCycleRequests}}
{{#if model.totalCycleRequests}}
<section class="activity-detail">
<header>
<h1>{{currentMonth}}</h1>
<h2>Daily Activity</h2>
</header>
{{line-area-chart height=150 data=cycleRequests}}
{{line-area-chart height=150 data=model.cycleRequests}}
</section>
{{/if}}

<div class='key-and-usage-wrapper'>
<section class="key-detail">
<h1>API Key</h1>

<code class='key-payload'>{{unbound token}}</code>
<code class='key-payload'>{{unbound model.token}}</code>

<ul class='meta'>
{{#if isServer}}
{{#if model.isServer}}
<li>
<h2>Type</h2>
<p>Private / Server</p>
</li>
{{/if}}

{{#if isClient}}
{{else if model.isClient}}
<li>
<h2>Type</h2>
<p>Mobile / Desktop</p>
</li>
{{/if}}

{{#if isWeb}}
{{else if model.isWeb}}
<li>
<h2>Type</h2>
<p>Web Browser</p>
</li>
<li title="You can make requests from this domain with CORS or JSONP.">
<h2>Domain</h2>
<p>{{domain}}</p>
<p>{{model.domain}}</p>
</li>
<li title="Individual clients are limited to 1200 requests per hour.">
<h2>Rate Limit</h2>
Expand Down
2 changes: 1 addition & 1 deletion manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"devDependencies": {
"broccoli-asset-rev": "^2.0.0",
"broccoli-sass": "^0.4.0",
"ember-cli": "0.2.0-beta.1",
"ember-cli": "0.2.0",
"ember-cli-app-version": "0.3.1",
"ember-cli-babel": "^4.0.0",
"ember-cli-bourbon": "0.0.5",
Expand Down
5 changes: 5 additions & 0 deletions public/assets/manager-870aa2ae56d0e923000bb8591e292f60.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions public/assets/vendor-9c0369f3f4db079b809e8e53d5b7d2b5.js

Large diffs are not rendered by default.

This file was deleted.

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions public/manager/assets/vendor-982512408faa3112b39469ff46126f87.js

This file was deleted.

27 changes: 27 additions & 0 deletions public/manager/assets/vendor-9c0369f3f4db079b809e8e53d5b7d2b5.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public/manager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<base href="/manager/" />
<meta name="manager/config/environment" content="%7B%22modulePrefix%22%3A%22manager%22%2C%22environment%22%3A%22production%22%2C%22baseURL%22%3A%22/manager/%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%7D%2C%22APP%22%3A%7B%22name%22%3A%22manager%22%2C%22version%22%3A%220.0.0.c32657b6%22%7D%2C%22simple-auth%22%3A%7B%22session%22%3A%22session%3Aun-auth%22%2C%22authorizer%22%3A%22authorizer%3Aun-auth%22%2C%22authenticator%22%3A%22authenticator%3Aun-auth%22%2C%22routeAfterAuthentication%22%3A%22dashboard.keys%22%2C%22routeIfAlreadyAuthenticated%22%3A%22dashboard.keys%22%7D%2C%22exportApplicationGlobal%22%3Afalse%7D" />
<meta name="manager/config/environment" content="%7B%22modulePrefix%22%3A%22manager%22%2C%22environment%22%3A%22production%22%2C%22baseURL%22%3A%22/manager/%22%2C%22locationType%22%3A%22auto%22%2C%22EmberENV%22%3A%7B%22FEATURES%22%3A%7B%7D%7D%2C%22APP%22%3A%7B%22name%22%3A%22manager%22%2C%22version%22%3A%220.0.0.dc45090e%22%7D%2C%22simple-auth%22%3A%7B%22session%22%3A%22session%3Aun-auth%22%2C%22authorizer%22%3A%22authorizer%3Aun-auth%22%2C%22authenticator%22%3A%22authenticator%3Aun-auth%22%2C%22routeAfterAuthentication%22%3A%22dashboard.keys%22%2C%22routeIfAlreadyAuthenticated%22%3A%22dashboard.keys%22%7D%2C%22exportApplicationGlobal%22%3Afalse%7D" />

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Roboto:500,900,400italic,400,300,300italic,700,700italic' rel='stylesheet' type='text/css'>
Expand All @@ -21,8 +21,8 @@
<body>


<script src="assets/vendor-982512408faa3112b39469ff46126f87.js"></script>
<script src="assets/manager-7de8e4fa3f997a503d4cc4c8ac786c37.js"></script>
<script src="assets/vendor-9c0369f3f4db079b809e8e53d5b7d2b5.js"></script>
<script src="assets/manager-870aa2ae56d0e923000bb8591e292f60.js"></script>


</body>
Expand Down

0 comments on commit a0a7a3c

Please sign in to comment.