Using localstorage

This commit is contained in:
Jeffrey Morgan 2015-02-16 11:57:13 -08:00
parent 403d805b12
commit 3415ad7bb9
8 changed files with 41 additions and 21 deletions

View File

@ -38,8 +38,8 @@
"node_modules/6to5" "node_modules/6to5"
] ]
}, },
"docker-version": "1.4.1", "docker-version": "1.5.0",
"boot2docker-version": "1.4.1", "boot2docker-version": "1.5.0",
"atom-shell-version": "0.21.1", "atom-shell-version": "0.21.1",
"virtualbox-version": "4.3.20", "virtualbox-version": "4.3.20",
"virtualbox-filename": "VirtualBox-4.3.20.pkg", "virtualbox-filename": "VirtualBox-4.3.20.pkg",

View File

@ -19,7 +19,7 @@ var ContainerDetail = React.createClass({
}, },
init: function () { init: function () {
var currentRoute = _.last(this.getRoutes()).name; var currentRoute = _.last(this.getRoutes()).name;
if (currentRoute === 'containerDetail') { if (currentRoute === 'containerDetails') {
this.transitionTo('containerHome', {name: this.getParams().name}); this.transitionTo('containerHome', {name: this.getParams().name});
} }
}, },

View File

@ -54,7 +54,7 @@ var ContainerListItem = React.createClass({
} }
return ( return (
<Router.Link data-container={name} to="containerDetail" params={{name: container.Name}}> <Router.Link data-container={name} to="containerDetails" params={{name: container.Name}}>
<li onMouseEnter={self.handleItemMouseEnter} onMouseLeave={self.handleItemMouseLeave}> <li onMouseEnter={self.handleItemMouseEnter} onMouseLeave={self.handleItemMouseLeave}>
{state} {state}
<div className="info"> <div className="info">

View File

@ -5,7 +5,6 @@ var path = require('path');
var assign = require('object-assign'); var assign = require('object-assign');
var docker = require('./Docker'); var docker = require('./Docker');
var registry = require('./Registry'); var registry = require('./Registry');
var ContainerUtil = require('./ContainerUtil');
var _placeholders = {}; var _placeholders = {};
var _containers = {}; var _containers = {};
@ -45,6 +44,7 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
stream.on('data', function (str) { stream.on('data', function (str) {
var data = JSON.parse(str); var data = JSON.parse(str);
console.log(data);
if (data.status === 'Already exists') { if (data.status === 'Already exists') {
layerProgress[data.id] = 1; layerProgress[data.id] = 1;
@ -136,18 +136,22 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
} }
}, },
_resumePulling: function () { _resumePulling: function () {
var downloading = _.filter(_.values(_containers), function (container) { var downloading = _.filter(_.values(this.containers()), function (container) {
return container.State.Downloading; return container.State.Downloading;
}); });
// Recover any pulls that were happening // Recover any pulls that were happening
var self = this; var self = this;
downloading.forEach(function (container) { downloading.forEach(function (container) {
docker.client().pull(container.KitematicDownloadingImage, function (err, stream) { docker.client().pull(container.Config.Image, function (err, stream) {
delete _placeholders[container.Name];
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
stream.setEncoding('utf8'); stream.setEncoding('utf8');
stream.on('data', function () {}); stream.on('data', function () {});
stream.on('end', function () { stream.on('end', function () {
self._createContainer(container.Name, {Image: container.KitematicDownloadingImage}, function () {}); self._createContainer(container.Name, {Image: container.Config.Image}, function () {
self.emit(self.CLIENT_CONTAINER_EVENT, container.Name);
});
}); });
}); });
}); });
@ -197,6 +201,14 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
} else { } else {
callback(); callback();
} }
var placeholderData = JSON.parse(localStorage.getItem('store.placeholders'));
console.log(placeholderData);
console.log(_.keys(_containers));
if (placeholderData) {
_placeholders = _.omit(placeholderData, _.keys(_containers));
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
}
console.log(_placeholders);
this.emit(this.CLIENT_CONTAINER_EVENT); this.emit(this.CLIENT_CONTAINER_EVENT);
this._resumePulling(); this._resumePulling();
this._startListeningToEvents(); this._startListeningToEvents();
@ -213,12 +225,6 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
} }
// Fix leading slash in container names // Fix leading slash in container names
container.Name = container.Name.replace('/', ''); container.Name = container.Name.replace('/', '');
// Add Downloading State (stored in environment variables) to containers for Kitematic
var env = ContainerUtil.env(container);
container.State.Downloading = !!env.KITEMATIC_DOWNLOADING;
container.KitematicDownloadingImage = env.KITEMATIC_DOWNLOADING_IMAGE;
_containers[container.Name] = container; _containers[container.Name] = container;
callback(null, container); callback(null, container);
} }
@ -256,12 +262,16 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
Downloading: true Downloading: true
} }
}; };
console.log(_placeholders);
console.log(JSON.stringify(_placeholders));
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
self.emit(self.CLIENT_CONTAINER_EVENT, containerName, 'create'); self.emit(self.CLIENT_CONTAINER_EVENT, containerName, 'create');
_muted[containerName] = true; _muted[containerName] = true;
_progress[containerName] = 0; _progress[containerName] = 0;
self._pullImage(repository, tag, function () { self._pullImage(repository, tag, function () {
delete _placeholders[containerName]; delete _placeholders[containerName];
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
self._createContainer(containerName, {Image: imageName}, function () { self._createContainer(containerName, {Image: imageName}, function () {
delete _progress[containerName]; delete _progress[containerName];
_muted[containerName] = false; _muted[containerName] = false;
@ -292,6 +302,10 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
}); });
}, },
remove: function (name, callback) { remove: function (name, callback) {
if (_placeholders[name]) {
delete _placeholders[name];
return;
}
var container = docker.client().getContainer(name); var container = docker.client().getContainer(name);
if (_containers[name].State.Paused) { if (_containers[name].State.Paused) {
container.unpause(function (err) { container.unpause(function (err) {
@ -331,7 +345,7 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
} }
}, },
containers: function() { containers: function() {
return _.extend(_placeholders, _containers); return _.extend(_containers, _placeholders);
}, },
container: function (name) { container: function (name) {
return this.containers()[name]; return this.containers()[name];

View File

@ -15,7 +15,10 @@ var LogStore = assign(Object.create(EventEmitter.prototype), {
div.appendChild(text); div.appendChild(text);
return div.innerHTML; return div.innerHTML;
}, },
fetchLogs: function (name, callback) { fetchLogs: function (name) {
if (!name || !docker.client()) {
return;
}
var index = 0; var index = 0;
var self = this; var self = this;
docker.client().getContainer(name).logs({ docker.client().getContainer(name).logs({
@ -24,7 +27,6 @@ var LogStore = assign(Object.create(EventEmitter.prototype), {
stderr: true, stderr: true,
timestamps: true timestamps: true
}, function (err, stream) { }, function (err, stream) {
callback(err);
if (_streams[name]) { if (_streams[name]) {
return; return;
} }
@ -59,7 +61,7 @@ var LogStore = assign(Object.create(EventEmitter.prototype), {
}, },
logs: function (name) { logs: function (name) {
if (!_streams[name]) { if (!_streams[name]) {
this.fetchLogs(name, () => {}); this.fetchLogs(name);
} }
return _logs[name] || []; return _logs[name] || [];
} }

View File

@ -33,14 +33,15 @@ bugsnag.releaseStage = process.env.NODE_ENV === 'development' ? 'development' :
bugsnag.notifyReleaseStages = ['production']; bugsnag.notifyReleaseStages = ['production'];
bugsnag.appVersion = app.getVersion(); bugsnag.appVersion = app.getVersion();
router.run(Handler => React.render(<Handler/>, document.body));
SetupStore.run().then(boot2docker.ip).then(ip => { SetupStore.run().then(boot2docker.ip).then(ip => {
console.log(ip); console.log(ip);
docker.setHost(ip); docker.setHost(ip);
ContainerStore.init(function (err) { ContainerStore.init(function (err) {
if (err) { console.log(err); } if (err) { console.log(err); }
router.run(Handler => React.render(<Handler/>, document.body));
router.transitionTo('containers'); router.transitionTo('containers');
}); });
}).catch(err => { }).catch(err => {
console.log(err);
bugsnag.notify(err); bugsnag.notify(err);
}); });

View File

@ -27,7 +27,7 @@ var App = React.createClass({
var routes = ( var routes = (
<Route name="app" path="/" handler={App}> <Route name="app" path="/" handler={App}>
<Route name="containers" handler={Containers}> <Route name="containers" handler={Containers}>
<Route name="containerDetail" path="/containers/:name" handler={ContainerDetails}> <Route name="containerDetails" path="/containers/:name" handler={ContainerDetails}>
<Route name="containerHome" path="/containers/:name/home" handler={ContainerHome} /> <Route name="containerHome" path="/containers/:name/home" handler={ContainerHome} />
<Route name="containerLogs" path="/containers/:name/logs" handler={ContainerLogs}/> <Route name="containerLogs" path="/containers/:name/logs" handler={ContainerLogs}/>
<Route name="containerSettings" path="/containers/:name/settings" handler={ContainerSettings}> <Route name="containerSettings" path="/containers/:name/settings" handler={ContainerSettings}>

View File

@ -165,7 +165,9 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), {
run: Promise.coroutine(function* () { run: Promise.coroutine(function* () {
yield this.updateBinaries(); yield this.updateBinaries();
var steps = yield this.requiredSteps(); var steps = yield this.requiredSteps();
console.log(steps);
for (let step of steps) { for (let step of steps) {
console.log(step.name);
_currentStep = step; _currentStep = step;
step.percent = 0; step.percent = 0;
while (true) { while (true) {
@ -181,6 +183,7 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), {
break; break;
} catch (err) { } catch (err) {
if (err) { if (err) {
console.log(err);
_error = err; _error = err;
this.emit(this.ERROR_EVENT); this.emit(this.ERROR_EVENT);
} else { } else {