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

View File

@ -1,4 +1,5 @@
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('route', '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";
export function initialize(/* container, application */) {
// Allot tooltip and style to be bound on all views
Ember.View.reopen({
attributeBindings: ['tooltip','style'],
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -71,6 +71,8 @@
<h3>
{{#if backRoute}}
{{#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}}
{{pageName}}
{{/if}}

View File

@ -72,6 +72,6 @@ export default Ember.Route.extend({
},
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';
export default Ember.Route.extend({
/*
previousRoute: null,
previousParams: null,
@ -43,4 +44,5 @@ export default Ember.Route.extend({
});
},
}
*/
});

View File

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

View File

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