2017-11-15 17:13:17 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import { task } from 'ember-concurrency';
|
2017-11-15 20:45:11 +00:00
|
|
|
import { logger } from 'nomad-ui/utils/classes/log';
|
|
|
|
import WindowResizable from 'nomad-ui/mixins/window-resizable';
|
2017-11-15 17:13:17 +00:00
|
|
|
|
|
|
|
const { Component, computed, inject, run } = Ember;
|
|
|
|
|
2017-11-15 20:45:11 +00:00
|
|
|
export default Component.extend(WindowResizable, {
|
2017-11-15 17:13:17 +00:00
|
|
|
token: inject.service(),
|
|
|
|
|
|
|
|
classNames: ['boxed-section'],
|
|
|
|
|
|
|
|
allocation: null,
|
|
|
|
task: null,
|
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
if (this.get('allocation') && this.get('task')) {
|
|
|
|
this.send('toggleStream');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-15 20:45:11 +00:00
|
|
|
didInsertElement() {
|
|
|
|
this.fillAvailableHeight();
|
|
|
|
},
|
|
|
|
|
|
|
|
windowResizeHandler() {
|
|
|
|
run.once(this, this.fillAvailableHeight);
|
|
|
|
},
|
|
|
|
|
|
|
|
fillAvailableHeight() {
|
|
|
|
// This math is arbitrary and far from bulletproof, but the UX
|
|
|
|
// of having the log window fill available height is worth the hack.
|
|
|
|
const cliWindow = this.$('.cli-window');
|
|
|
|
cliWindow.height(window.innerHeight - cliWindow.offset().top - 25);
|
|
|
|
},
|
|
|
|
|
2017-11-15 17:13:17 +00:00
|
|
|
mode: 'stdout',
|
|
|
|
|
|
|
|
logUrl: computed('allocation.id', 'allocation.node.httpAddr', function() {
|
|
|
|
const address = this.get('allocation.node.httpAddr');
|
|
|
|
const allocation = this.get('allocation.id');
|
|
|
|
|
|
|
|
return `//${address}/v1/client/fs/logs/${allocation}`;
|
|
|
|
}),
|
|
|
|
|
|
|
|
logParams: computed('task', 'mode', function() {
|
|
|
|
return {
|
|
|
|
task: this.get('task'),
|
|
|
|
type: this.get('mode'),
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
|
|
|
|
logger: logger('logUrl', 'logParams', function() {
|
|
|
|
const token = this.get('token');
|
|
|
|
return token.authorizedRequest.bind(token);
|
|
|
|
}),
|
|
|
|
|
|
|
|
head: task(function*() {
|
|
|
|
yield this.get('logger.gotoHead').perform();
|
|
|
|
run.scheduleOnce('afterRender', () => {
|
|
|
|
this.$('.cli-window').scrollTop(0);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
tail: task(function*() {
|
|
|
|
yield this.get('logger.gotoTail').perform();
|
|
|
|
run.scheduleOnce('afterRender', () => {
|
2017-11-15 20:45:11 +00:00
|
|
|
const cliWindow = this.$('.cli-window');
|
|
|
|
cliWindow.scrollTop(cliWindow[0].scrollHeight);
|
2017-11-15 17:13:17 +00:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
stream: task(function*() {
|
|
|
|
this.get('logger').on('tick', () => {
|
|
|
|
run.scheduleOnce('afterRender', () => {
|
2017-11-15 20:45:11 +00:00
|
|
|
const cliWindow = this.$('.cli-window');
|
2017-11-15 17:13:17 +00:00
|
|
|
cliWindow.scrollTop(cliWindow[0].scrollHeight);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
yield this.get('logger').startStreaming();
|
|
|
|
this.get('logger').off('tick');
|
|
|
|
}),
|
|
|
|
|
2017-11-15 20:45:11 +00:00
|
|
|
willDestroy() {
|
|
|
|
this.get('logger').stop();
|
|
|
|
},
|
|
|
|
|
2017-11-15 17:13:17 +00:00
|
|
|
actions: {
|
|
|
|
setMode(mode) {
|
|
|
|
this.get('logger').stop();
|
2017-11-15 20:45:11 +00:00
|
|
|
this.set('mode', mode);
|
|
|
|
this.get('stream').perform();
|
2017-11-15 17:13:17 +00:00
|
|
|
},
|
|
|
|
toggleStream() {
|
|
|
|
if (this.get('logger.isStreaming')) {
|
2017-11-15 20:45:11 +00:00
|
|
|
this.get('logger').stop();
|
2017-11-15 17:13:17 +00:00
|
|
|
} else {
|
|
|
|
this.get('stream').perform();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|