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"
]
},
"docker-version": "1.4.1",
"boot2docker-version": "1.4.1",
"docker-version": "1.5.0",
"boot2docker-version": "1.5.0",
"atom-shell-version": "0.21.1",
"virtualbox-version": "4.3.20",
"virtualbox-filename": "VirtualBox-4.3.20.pkg",

View File

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

View File

@ -54,7 +54,7 @@ var ContainerListItem = React.createClass({
}
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}>
{state}
<div className="info">

View File

@ -5,7 +5,6 @@ var path = require('path');
var assign = require('object-assign');
var docker = require('./Docker');
var registry = require('./Registry');
var ContainerUtil = require('./ContainerUtil');
var _placeholders = {};
var _containers = {};
@ -45,6 +44,7 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
stream.on('data', function (str) {
var data = JSON.parse(str);
console.log(data);
if (data.status === 'Already exists') {
layerProgress[data.id] = 1;
@ -136,18 +136,22 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
}
},
_resumePulling: function () {
var downloading = _.filter(_.values(_containers), function (container) {
var downloading = _.filter(_.values(this.containers()), function (container) {
return container.State.Downloading;
});
// Recover any pulls that were happening
var self = this;
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.on('data', 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 {
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._resumePulling();
this._startListeningToEvents();
@ -213,12 +225,6 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
}
// Fix leading slash in container names
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;
callback(null, container);
}
@ -256,12 +262,16 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
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');
_muted[containerName] = true;
_progress[containerName] = 0;
self._pullImage(repository, tag, function () {
delete _placeholders[containerName];
localStorage.setItem('store.placeholders', JSON.stringify(_placeholders));
self._createContainer(containerName, {Image: imageName}, function () {
delete _progress[containerName];
_muted[containerName] = false;
@ -292,6 +302,10 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
});
},
remove: function (name, callback) {
if (_placeholders[name]) {
delete _placeholders[name];
return;
}
var container = docker.client().getContainer(name);
if (_containers[name].State.Paused) {
container.unpause(function (err) {
@ -331,7 +345,7 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
}
},
containers: function() {
return _.extend(_placeholders, _containers);
return _.extend(_containers, _placeholders);
},
container: function (name) {
return this.containers()[name];

View File

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

View File

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

View File

@ -27,7 +27,7 @@ var App = React.createClass({
var routes = (
<Route name="app" path="/" handler={App}>
<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="containerLogs" path="/containers/:name/logs" handler={ContainerLogs}/>
<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* () {
yield this.updateBinaries();
var steps = yield this.requiredSteps();
console.log(steps);
for (let step of steps) {
console.log(step.name);
_currentStep = step;
step.percent = 0;
while (true) {
@ -181,6 +183,7 @@ var SetupStore = assign(Object.create(EventEmitter.prototype), {
break;
} catch (err) {
if (err) {
console.log(err);
_error = err;
this.emit(this.ERROR_EVENT);
} else {