Fixing rename bugs

This commit is contained in:
Jeffrey Morgan 2015-02-16 23:18:42 -08:00
parent de6747627e
commit 613c944f0c
7 changed files with 58 additions and 31 deletions

View File

@ -29,16 +29,15 @@ var options = {
gulp.task('js', function () {
return gulp.src('src/**/*.js')
.pipe(plumber(function(error) {
gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.message));
}))
.pipe(gulpif(options.dev || options.test, sourcemaps.init()))
.pipe(react())
.pipe(babel({blacklist: ['regenerator']}))
.pipe(gulpif(options.dev || options.test, sourcemaps.write('.')))
.pipe(gulp.dest((options.dev || options.test) ? './build' : './dist/osx/' + options.filename + '/Contents/Resources/app/build'))
.pipe(gulpif(options.dev, livereload()))
.pipe(plumber(function(error) {
gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.message));
this.emit('end');
}));
.pipe(gulpif(options.dev, livereload()));
});
gulp.task('images', function() {

View File

@ -51,7 +51,7 @@
"babel": "^4.0.1",
"bluebird": "^2.9.6",
"bugsnag-js": "^2.4.7",
"dockerode": "2.0.4",
"dockerode": "^2.0.7",
"download": "^4.0.0",
"exec": "0.1.2",
"jquery": "^2.1.3",

View File

@ -31,6 +31,7 @@ var ContainerSettingsGeneral = React.createClass({
getInitialState: function () {
return {
slugName: null,
nameError: null,
env: {},
pendingEnv: {}
};
@ -48,6 +49,7 @@ var ContainerSettingsGeneral = React.createClass({
}
this.setState({
env: ContainerUtil.env(container),
nameError: null
});
},
handleNameChange: function (e) {
@ -61,7 +63,8 @@ var ContainerSettingsGeneral = React.createClass({
});
} else {
this.setState({
slugName: containerNameSlugify(newName)
slugName: containerNameSlugify(newName),
nameError: null
});
}
},
@ -75,20 +78,35 @@ var ContainerSettingsGeneral = React.createClass({
if (newName === this.props.container.Name) {
return;
}
if (fs.existsSync(path.join(process.env.HOME, 'Kitematic', this.props.container.Name))) {
fs.renameSync(path.join(process.env.HOME, 'Kitematic', this.props.container.Name), path.join(process.env.HOME, 'Kitematic', newName));
}
this.setState({
slugName: null
});
ContainerStore.updateContainer(this.props.container.Name, {
name: newName
}, function (err) {
this.transitionTo('containerSettingsGeneral', {name: newName});
if (err) {
console.error(err);
var oldName = this.props.container.Name;
if (ContainerStore.container(newName)) {
this.setState({
nameError: 'A container already exists with this name.'
});
return;
}
var oldPath = path.join(process.env.HOME, 'Kitematic', oldName);
var newPath = path.join(process.env.HOME, 'Kitematic', newName);
rimraf(newPath, () => {
if (fs.existsSync(oldPath)) {
fs.renameSync(oldPath, newPath);
}
}.bind(this));
var binds = _.pairs(this.props.container.Volumes).map(function (pair) {
return pair[1] + ':' + pair[0];
});
var newBinds = binds.map(b => {
return b.replace(path.join(process.env.HOME, 'Kitematic', oldName), path.join(process.env.HOME, 'Kitematic', newName));
});
ContainerStore.updateContainer(oldName, {Binds: newBinds, name: newName}, err => {
this.transitionTo('containerSettingsGeneral', {name: newName});
rimraf(oldPath, () => {});
console.log(err);
});
});
},
handleSaveEnvVar: function () {
var $rows = $('.env-vars .keyval-row');
@ -172,6 +190,10 @@ var ContainerSettingsGeneral = React.createClass({
btnSaveName = (
<a className="btn btn-action" onClick={this.handleSaveContainerName}>Save</a>
);
} else if (this.state.nameError) {
willBeRenamedAs = (
<p><strong>{this.state.nameError}</strong></p>
);
}
var rename = (
<div className="settings-section">

View File

@ -5,6 +5,7 @@ var path = require('path');
var assign = require('object-assign');
var docker = require('./Docker');
var registry = require('./Registry');
var LogStore = require('./LogStore');
var _placeholders = {};
var _containers = {};
@ -207,13 +208,10 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
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();
@ -242,7 +240,13 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
callback(err);
return;
}
async.map(containers, function (container, callback) {
var names = new Set(_.map(containers, container => container.Names[0].replace('/', '')));
_.each(_.keys(_containers), name => {
if (!names.has(name)) {
delete _containers[name];
}
});
async.each(containers, function (container, callback) {
self.fetchContainer(container.Id, function (err) {
callback(err);
});
@ -267,8 +271,6 @@ 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');
@ -289,13 +291,18 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), {
callback(null, containerName);
},
updateContainer: function (name, data, callback) {
_muted[name] = true;
if (!data.name) {
data.name = data.Name;
}
_muted[name] = true;
_muted[data.name] = true;
if (name !== data.name) {
LogStore.rename(name, data.name);
}
var fullData = assign(_containers[name], data);
this._createContainer(name, fullData, function (err) {
_muted[name] = false;
_muted[data.name] = false;
this.emit(this.CLIENT_CONTAINER_EVENT, name);
callback(err);
}.bind(this));

View File

@ -34,7 +34,7 @@ var LogStore = assign(Object.create(EventEmitter.prototype), {
if (err) {
return;
}
_logs[name] = [];
_logs[name] = _logs[name] || [];
stream.setEncoding('utf8');
var timeout;
stream.on('data', function (buf) {
@ -64,6 +64,11 @@ var LogStore = assign(Object.create(EventEmitter.prototype), {
this.fetchLogs(name);
}
return _logs[name] || [];
},
rename: function (name, newName) {
if (_logs[name]) {
_logs[newName] = _logs[name];
}
}
});

View File

@ -64,11 +64,6 @@ var MenuTemplate = [
{
label: 'File',
submenu: [
{
label: 'New Container',
accelerator: 'Command+N',
selector: 'undo:'
},
{
type: 'separator'
},

View File

@ -165,7 +165,6 @@ 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;