Merge pull request #83 from vincent99/master

Back on container page goes back to the screen you were previous on
This commit is contained in:
Vincent Fiduccia 2015-03-03 11:25:23 -08:00
commit 1ea568354c
21 changed files with 120 additions and 36 deletions

View File

@ -16,6 +16,7 @@ export function initialize(container, application) {
headers: headers headers: headers
}) })
.then(function(obj) { .then(function(obj) {
// If we get a good response back, the API supports authentication
var body = JSON.parse(obj.xhr.responseText); var body = JSON.parse(obj.xhr.responseText);
var token = body.data[0]; var token = body.data[0];
@ -26,6 +27,7 @@ export function initialize(container, application) {
return Ember.RSVP.resolve(undefined,'API supports authentication'); return Ember.RSVP.resolve(undefined,'API supports authentication');
}) })
.catch(function(obj) { .catch(function(obj) {
// Otherwise this API is too old to do auth.
application.set('hasAuthentication', false); application.set('hasAuthentication', false);
application.set('authenticationEnabled', false); application.set('authenticationEnabled', false);
application.set('initError', obj); application.set('initError', obj);

View File

@ -1,4 +1,5 @@
export function initialize(container, application) { export function initialize(container, application) {
// Inject the contents of ENV.APP in config/environment.js into all the things as an 'app' property
application.inject('controller', 'app', 'application:main'); application.inject('controller', 'app', 'application:main');
application.inject('route', 'app', 'application:main'); application.inject('route', 'app', 'application:main');
application.inject('view', 'app', 'application:main'); application.inject('view', 'app', 'application:main');

View File

@ -0,0 +1,39 @@
import Ember from "ember";
export function initialize(/* container, application */) {
Ember.Route.reopen({
// Remember the current route (into the application route's previousRoute/Params properties)
beforeModel: function() {
this._super.apply(this,arguments);
var appRoute = this.container.lookup('route:application');
var infos = this.router.router.currentHandlerInfos;
if ( infos && infos.length )
{
var params = [];
var info;
for ( var i = 0 ; i < infos.length ; i++ )
{
info = infos[i];
if ( info._names && info._names.length )
{
for ( var j = 0 ; j < info._names.length ; j++ )
{
params.push(info.params[ info._names[j] ]);
}
}
}
appRoute.set('previousRoute', info.name);
appRoute.set('previousParams', params);
//console.log('Set previous route to', info.name, params);
}
},
});
}
export default {
name: 'extend-ember-route',
initialize: initialize
};

View File

@ -1,6 +1,7 @@
import Ember from "ember"; import Ember from "ember";
export function initialize(/* container, application */) { export function initialize(/* container, application */) {
// Allot tooltip and style to be bound on all views
Ember.View.reopen({ Ember.View.reopen({
attributeBindings: ['tooltip','style'], attributeBindings: ['tooltip','style'],
}); });

View File

@ -1,4 +1,5 @@
export function initialize(/* container, application */) { export function initialize(/* container, application */) {
// Define some more easings and inject into jQuery
jQuery.extend(jQuery.easing, { jQuery.extend(jQuery.easing, {
easeOutBack: function (x, t, b, c, d, s) { easeOutBack: function (x, t, b, c, d, s) {
if (s === undefined) { if (s === undefined) {

View File

@ -1,4 +1,5 @@
export function initialize(container/*, application*/) { export function initialize(container/*, application*/) {
// Shortcuts for debugging. These should never be used in code.
window.l = function(name) { window.l = function(name) {
return container.lookup(name); return container.lookup(name);
}; };

View File

@ -1,6 +1,7 @@
import SessionStorage from 'ui/utils/session-storage'; import SessionStorage from 'ui/utils/session-storage';
export function initialize(container, application) { export function initialize(container, application) {
// Inject HTML5 session storage into all the things as 'session' property
container.register('session:main', SessionStorage); container.register('session:main', SessionStorage);
application.inject('controller', 'session', 'session:main'); application.inject('controller', 'session', 'session:main');
application.inject('route', 'session', 'session:main'); application.inject('route', 'session', 'session:main');

View File

@ -12,17 +12,21 @@ export function initialize(container, application) {
headers: function() { headers: function() {
var out = {}; var out = {};
// Please don't send us www-authenticate headers
out[C.NO_CHALLENGE_HEADER] = C.NO_CHALLENGE_VALUE; out[C.NO_CHALLENGE_HEADER] = C.NO_CHALLENGE_VALUE;
// Never send token or project ID if auth isn't on // Never send token or project ID if auth isn't on
if ( application.get('authenticationEnabled') ) if ( application.get('authenticationEnabled') )
{ {
// Send the token as the Authorization header
var authValue = session.get(C.AUTH_SESSION_KEY); var authValue = session.get(C.AUTH_SESSION_KEY);
if ( authValue ) if ( authValue )
{ {
out[C.AUTH_HEADER] = C.AUTH_TYPE + ' ' + authValue; out[C.AUTH_HEADER] = C.AUTH_TYPE + ' ' + authValue;
} }
// Send the current project id as a header if in a project
var projectId = session.get(C.PROJECT_SESSION_KEY); var projectId = session.get(C.PROJECT_SESSION_KEY);
if ( projectId ) if ( projectId )
{ {
@ -33,6 +37,7 @@ export function initialize(container, application) {
return out; return out;
}.property().volatile(), }.property().volatile(),
// Override store.all() so that it only returns un-purged resources.
reallyAll: store.all, reallyAll: store.all,
all: function(type) { all: function(type) {
type = normalizeType(type); type = normalizeType(type);

View File

@ -1,11 +1,15 @@
export function initialize(/*container, application*/) { export function initialize(/*container, application*/) {
// Add 'touch' or 'no-touch' to the <body> so CSS can depend on the devicve type.
var body = $('BODY'); var body = $('BODY');
if ('ontouchstart' in document.documentElement) if ('ontouchstart' in document.documentElement)
{ {
// Has touch, like an iPad
body.addClass('touch'); body.addClass('touch');
} }
else else
{ {
// Does not have touch, like a desktop
body.addClass('no-touch'); body.addClass('no-touch');
} }
} }

View File

@ -2,16 +2,10 @@ import Ember from 'ember';
import C from 'ui/utils/constants'; import C from 'ui/utils/constants';
export default Ember.Route.extend({ export default Ember.Route.extend({
actions: { previousParams: null,
beforeModel: function() { previousRoute: null,
this._super.apply(this,arguments);
var err = this.get('app.initError');
if ( err )
{
this.send('error',err);
}
},
actions: {
loading: function(transition/*, originRoute*/) { loading: function(transition/*, originRoute*/) {
//console.log('Loading action...'); //console.log('Loading action...');
$('#loading-underlay').show().fadeIn({duration: 100, queue: false, easing: 'linear', complete: function() { $('#loading-underlay').show().fadeIn({duration: 100, queue: false, easing: 'linear', complete: function() {
@ -29,11 +23,26 @@ export default Ember.Route.extend({
}, },
error: function(err) { error: function(err) {
this.controller.set('error',err); this.controllerFor('application').set('error',err);
this.transitionTo('failWhale'); this.transitionTo('failWhale');
console.log('Application ' + err.stack); console.log('Application ' + err.stack);
}, },
goToPrevious: function() {
var route = this.get('previousRoute');
if ( route === 'loading' )
{
route = 'index';
}
var args = (this.get('previousParams')||[]).slice();
args.unshift(route);
this.transitionTo.apply(this,args).catch(() => {
this.transitionTo('index');
});
},
logout: function(transition,timedOut) { logout: function(transition,timedOut) {
var session = this.get('session'); var session = this.get('session');
session.clear(); session.clear();

View File

@ -6,6 +6,7 @@ export default Ember.Controller.extend({
activeTab: '', activeTab: '',
pageName: '', pageName: '',
backRoute: null, backRoute: null,
backPrevious: null,
hasAside: false, hasAside: false,
projects: null, projects: null,

View File

@ -100,6 +100,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
setPageLayout: function(opt) { setPageLayout: function(opt) {
this.controller.set('pageName', opt.label || ''); this.controller.set('pageName', opt.label || '');
this.controller.set('backRoute', opt.backRoute || null); this.controller.set('backRoute', opt.backRoute || null);
this.controller.set('backPrevious', opt.backPrevious || null);
if ( typeof opt.hasAside === 'undefined' ) if ( typeof opt.hasAside === 'undefined' )
{ {

View File

@ -4,8 +4,10 @@
projects=projects projects=projects
project=project project=project
backRoute=backRoute backRoute=backRoute
backPrevious=backPrevious
hasAside=hasAside hasAside=hasAside
switchProject="switchProject" switchProject="switchProject"
goToPrevious="goToPrevious"
}} }}
<main {{bind-attr class="hasAside"}}> <main {{bind-attr class="hasAside"}}>
{{outlet}} {{outlet}}

View File

@ -35,6 +35,10 @@ export default Ember.Component.extend({
actions: { actions: {
switchProject: function(id) { switchProject: function(id) {
this.sendAction('switchProject', id); this.sendAction('switchProject', id);
},
goToPrevious: function() {
this.sendAction('goToPrevious');
} }
}, },
}); });

View File

@ -71,6 +71,8 @@
<h3> <h3>
{{#if backRoute}} {{#if backRoute}}
{{#link-to backRoute}}<i class="ss-navigateleft"></i>{{pageName}}{{/link-to}} {{#link-to backRoute}}<i class="ss-navigateleft"></i>{{pageName}}{{/link-to}}
{{else if backPrevious}}
<a {{action "goToPrevious"}}><i class="ss-navigateleft"></i>{{pageName}}</a>
{{else}} {{else}}
{{pageName}} {{pageName}}
{{/if}} {{/if}}

View File

@ -72,6 +72,6 @@ export default Ember.Route.extend({
}, },
activate: function() { activate: function() {
this.send('setPageLayout', {label: 'Container', backRoute: 'hosts'}); this.send('setPageLayout', {label: 'Container', backPrevious: true});
}, },
}); });

View File

@ -0,0 +1,11 @@
import Ember from 'ember';
export default Ember.View.extend({
didInsertElement: function() {
$('BODY').addClass('white');
},
willDestroyElement: function() {
$('BODY').removeClass('white');
},
});

View File

@ -0,0 +1,7 @@
import Ember from 'ember';
export default Ember.Route.extend({
model: function(/*params*/) {
return this.modelFor('host');
}
});

View File

@ -1,6 +1,7 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Route.extend({ export default Ember.Route.extend({
/*
previousRoute: null, previousRoute: null,
previousParams: null, previousParams: null,
@ -43,4 +44,5 @@ export default Ember.Route.extend({
}); });
}, },
} }
*/
}); });

View File

@ -121,6 +121,7 @@ HEADER {
A:visited, A:visited,
A:hover, A:hover,
A:focus { A:focus {
cursor: pointer;
text-decoration: none; text-decoration: none;
color: $header_link_text; color: $header_link_text;
} }

View File

@ -1,44 +1,33 @@
export var platform = (navigator.platform||'').toLowerCase(); export var platform = (navigator.platform||'').toLowerCase();
export var isLinuxy = platform.indexOf('linux') >= 0; //export var isLinuxy = platform.indexOf('linux') >= 0;
export var isMac = platform.indexOf('mac') >= 0; export var isMac = platform.indexOf('mac') >= 0;
//var isWin = platform.indexOf('win') >= 0; //var isWin = platform.indexOf('win') >= 0;
export var alternateKey = 'altKey'; export var alternateKey = 'ctrlKey';
export var alternateLabel = 'Alt'; export var alternateLabel = 'Control';
if ( isMac || isLinuxy)
export var moreKey = 'ctrlKey';
export var moreLabel = 'Control';
export var rangeKey = 'shiftKey';
export var rangeLabel = 'Shift';
if ( isMac )
{ {
alternateKey = 'metaKey'; alternateKey = 'metaKey';
if ( isMac ) alternateLabel = 'Command';
{ moreKey = 'metaKey';
alternateLabel = 'Command'; moreLabel = 'Command';
}
else
{
alternateLabel = 'Meta';
}
} }
export function isAlternate(event) { export function isAlternate(event) {
return !!event[alternateKey]; return !!event[alternateKey];
} }
// ------------
export var moreKey = 'ctrlKey';
export var moreLabel = 'Control';
if ( isMac )
{
moreKey = 'metaKey';
moreLabel = 'Command';
}
export function isMore(event) { export function isMore(event) {
return !!event[moreKey]; return !!event[moreKey];
} }
// ------------
export var rangeKey = 'shiftKey';
export var rangeLabel = 'Shift';
export function isRange(event) { export function isRange(event) {
return !!event[rangeKey]; return !!event[rangeKey];
} }