mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-15 01:16:22 +02:00
API and gui for archiving #43
This commit is contained in:
parent
10e6ee1091
commit
48d2e0c304
@ -1,6 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
featureCreated : 'feature-created',
|
featureCreated : 'feature-created',
|
||||||
featureUpdated : 'feature-updated',
|
featureUpdated : 'feature-updated',
|
||||||
|
featureArchive : 'feature-archive',
|
||||||
strategyCreated: 'strategy-created',
|
strategyCreated: 'strategy-created',
|
||||||
strategyDeleted: 'strategy-deleted'
|
strategyDeleted: 'strategy-deleted'
|
||||||
};
|
};
|
@ -79,6 +79,32 @@ module.exports = function (app) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.delete('/features/:featureName', function (req, res) {
|
||||||
|
var featureName = req.params.featureName;
|
||||||
|
var userName = req.connection.remoteAddress;
|
||||||
|
|
||||||
|
featureDb.getFeature(featureName)
|
||||||
|
.then(function () {
|
||||||
|
return eventStore.create({
|
||||||
|
type: eventType.featureArchive,
|
||||||
|
createdBy: userName,
|
||||||
|
data: {
|
||||||
|
name: featureName
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
res.status(200).end();
|
||||||
|
})
|
||||||
|
.catch(NotFoundError, function () {
|
||||||
|
res.status(404).end();
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
logger.error("Could not archive feature="+featureName, err);
|
||||||
|
res.status(500).end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function validateUniqueName(req) {
|
function validateUniqueName(req) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
featureDb.getFeature(req.body.name)
|
featureDb.getFeature(req.body.name)
|
||||||
|
@ -13,10 +13,15 @@ eventStore.on(eventType.featureUpdated, function (event) {
|
|||||||
return updateFeature(event.data);
|
return updateFeature(event.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eventStore.on(eventType.featureArchive, function (event) {
|
||||||
|
return archiveFeature(event.data);
|
||||||
|
});
|
||||||
|
|
||||||
function getFeatures() {
|
function getFeatures() {
|
||||||
return knex
|
return knex
|
||||||
.select(FEATURE_COLUMNS)
|
.select(FEATURE_COLUMNS)
|
||||||
.from('features')
|
.from('features')
|
||||||
|
.where({archived: 0})
|
||||||
.orderBy('name', 'asc')
|
.orderBy('name', 'asc')
|
||||||
.map(rowToFeature);
|
.map(rowToFeature);
|
||||||
}
|
}
|
||||||
@ -70,6 +75,16 @@ function updateFeature(data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function archiveFeature(data) {
|
||||||
|
return knex('features')
|
||||||
|
.where({name: data.name})
|
||||||
|
.update({archived: 1})
|
||||||
|
.catch(function (err) {
|
||||||
|
logger.error('Could not archive feature, error was: ', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getFeatures: getFeatures,
|
getFeatures: getFeatures,
|
||||||
getFeature: getFeature,
|
getFeature: getFeature,
|
||||||
|
@ -33,6 +33,12 @@ var Feature = React.createClass({
|
|||||||
this.toggleEditMode();
|
this.toggleEditMode();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
archiveFeature: function() {
|
||||||
|
if (confirm("Are you sure you want to delete " + this.props.feature.name + "?")) {
|
||||||
|
this.props.onArchive(this.props.feature);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
renderEditMode: function() {
|
renderEditMode: function() {
|
||||||
return (
|
return (
|
||||||
@ -64,14 +70,19 @@ var Feature = React.createClass({
|
|||||||
{this.props.feature.strategy}
|
{this.props.feature.strategy}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td width="110">
|
<td width="150">
|
||||||
<div className="line">
|
<div className="line">
|
||||||
<div className="unit size1of2">
|
<div className="unit size1of3">
|
||||||
|
<button title='Archive' onClick={this.archiveFeature} title="Remove">
|
||||||
|
<span className="icon-kryss1" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="unit size1of3">
|
||||||
<button className={this.state.editMode ? "primary" : ""} title='Edit' onClick={this.toggleEditMode}>
|
<button className={this.state.editMode ? "primary" : ""} title='Edit' onClick={this.toggleEditMode}>
|
||||||
<span className="icon-redigere" />
|
<span className="icon-redigere" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="unit size1of2">
|
<div className="unit size1of3">
|
||||||
<button className={this.state.showHistory ? "primary" : ""} title='History' onClick={this.toggleHistory}>
|
<button className={this.state.showHistory ? "primary" : ""} title='History' onClick={this.toggleHistory}>
|
||||||
<span className="icon-visning_liste" />
|
<span className="icon-visning_liste" />
|
||||||
</button>
|
</button>
|
||||||
|
@ -8,7 +8,8 @@ var FeatureList = React.createClass({
|
|||||||
<Feature
|
<Feature
|
||||||
key={feature.name}
|
key={feature.name}
|
||||||
feature={feature}
|
feature={feature}
|
||||||
onChange={this.props.onFeatureChanged} />
|
onChange={this.props.onFeatureChanged}
|
||||||
|
onArchive={this.props.onFeatureArchive}/>
|
||||||
);
|
);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
@ -55,6 +55,15 @@ var FeatureTogglesComponent = React.createClass({
|
|||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
archiveFeature: function (feature) {
|
||||||
|
this.stopFeaturePoller();
|
||||||
|
|
||||||
|
this.state.featureStore
|
||||||
|
.archiveFeature(feature)
|
||||||
|
.then(this.startFeaturePoller)
|
||||||
|
.catch(this.handleError);
|
||||||
|
},
|
||||||
|
|
||||||
startFeaturePoller: function () {
|
startFeaturePoller: function () {
|
||||||
this.state.featurePoller.start();
|
this.state.featurePoller.start();
|
||||||
},
|
},
|
||||||
@ -121,6 +130,7 @@ var FeatureTogglesComponent = React.createClass({
|
|||||||
<FeatureList
|
<FeatureList
|
||||||
features={this.state.features}
|
features={this.state.features}
|
||||||
onFeatureChanged={this.updateFeature}
|
onFeatureChanged={this.updateFeature}
|
||||||
|
onFeatureArchive={this.archiveFeature}
|
||||||
onFeatureSubmit={this.createFeature}
|
onFeatureSubmit={this.createFeature}
|
||||||
onFeatureCancel={this.cancelNewFeature}
|
onFeatureCancel={this.cancelNewFeature}
|
||||||
onNewFeature={this.newFeature} />
|
onNewFeature={this.newFeature} />
|
||||||
|
@ -27,6 +27,14 @@ FeatureStore.prototype = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
archiveFeature: function (feature) {
|
||||||
|
return reqwest({
|
||||||
|
url: 'features/' + feature.name,
|
||||||
|
method: 'delete',
|
||||||
|
type: TYPE
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
getFeatures: function () {
|
getFeatures: function () {
|
||||||
return reqwest({
|
return reqwest({
|
||||||
url: 'features',
|
url: 'features',
|
||||||
|
Loading…
Reference in New Issue
Block a user