mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	API and gui for archiving #43
This commit is contained in:
		
							parent
							
								
									5e40d4dc7f
								
							
						
					
					
						commit
						658e3ac2bc
					
				@ -1,6 +1,7 @@
 | 
			
		||||
module.exports = {
 | 
			
		||||
    featureCreated : 'feature-created',
 | 
			
		||||
    featureUpdated : 'feature-updated',
 | 
			
		||||
    featureArchive : 'feature-archive',
 | 
			
		||||
    strategyCreated: 'strategy-created',
 | 
			
		||||
    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) {
 | 
			
		||||
        return new Promise(function(resolve, reject) {
 | 
			
		||||
            featureDb.getFeature(req.body.name)
 | 
			
		||||
 | 
			
		||||
@ -13,10 +13,15 @@ eventStore.on(eventType.featureUpdated, function (event) {
 | 
			
		||||
    return updateFeature(event.data);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
eventStore.on(eventType.featureArchive, function (event) {
 | 
			
		||||
    return archiveFeature(event.data);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function getFeatures() {
 | 
			
		||||
    return knex
 | 
			
		||||
        .select(FEATURE_COLUMNS)
 | 
			
		||||
        .from('features')
 | 
			
		||||
        .where({archived: 0})
 | 
			
		||||
        .orderBy('name', 'asc')
 | 
			
		||||
        .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 = {
 | 
			
		||||
    getFeatures: getFeatures,
 | 
			
		||||
    getFeature: getFeature,
 | 
			
		||||
 | 
			
		||||
@ -33,6 +33,12 @@ var Feature = React.createClass({
 | 
			
		||||
        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() {
 | 
			
		||||
        return (
 | 
			
		||||
@ -64,14 +70,19 @@ var Feature = React.createClass({
 | 
			
		||||
                        {this.props.feature.strategy}
 | 
			
		||||
                    </td>
 | 
			
		||||
 | 
			
		||||
                    <td width="110">
 | 
			
		||||
                    <td width="150">
 | 
			
		||||
                        <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}>
 | 
			
		||||
                                    <span className="icon-redigere" />
 | 
			
		||||
                                </button>
 | 
			
		||||
                            </div>
 | 
			
		||||
                            <div className="unit size1of2">
 | 
			
		||||
                            <div className="unit size1of3">
 | 
			
		||||
                                <button className={this.state.showHistory ? "primary" : ""} title='History' onClick={this.toggleHistory}>
 | 
			
		||||
                                    <span className="icon-visning_liste" />
 | 
			
		||||
                                </button>
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,8 @@ var FeatureList = React.createClass({
 | 
			
		||||
                <Feature
 | 
			
		||||
                  key={feature.name}
 | 
			
		||||
                  feature={feature}
 | 
			
		||||
                  onChange={this.props.onFeatureChanged} />
 | 
			
		||||
                  onChange={this.props.onFeatureChanged}
 | 
			
		||||
                  onArchive={this.props.onFeatureArchive}/>
 | 
			
		||||
            );
 | 
			
		||||
        }.bind(this));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -55,6 +55,15 @@ var FeatureTogglesComponent = React.createClass({
 | 
			
		||||
          .catch(this.handleError);
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    archiveFeature: function (feature) {
 | 
			
		||||
        this.stopFeaturePoller();
 | 
			
		||||
 | 
			
		||||
        this.state.featureStore
 | 
			
		||||
            .archiveFeature(feature)
 | 
			
		||||
            .then(this.startFeaturePoller)
 | 
			
		||||
            .catch(this.handleError);
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    startFeaturePoller: function () {
 | 
			
		||||
        this.state.featurePoller.start();
 | 
			
		||||
    },
 | 
			
		||||
@ -121,6 +130,7 @@ var FeatureTogglesComponent = React.createClass({
 | 
			
		||||
                <FeatureList
 | 
			
		||||
                  features={this.state.features}
 | 
			
		||||
                  onFeatureChanged={this.updateFeature}
 | 
			
		||||
                  onFeatureArchive={this.archiveFeature}
 | 
			
		||||
                  onFeatureSubmit={this.createFeature}
 | 
			
		||||
                  onFeatureCancel={this.cancelNewFeature}
 | 
			
		||||
                  onNewFeature={this.newFeature} />
 | 
			
		||||
 | 
			
		||||
@ -27,6 +27,14 @@ FeatureStore.prototype = {
 | 
			
		||||
        });
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    archiveFeature: function (feature) {
 | 
			
		||||
        return reqwest({
 | 
			
		||||
            url: 'features/' + feature.name,
 | 
			
		||||
            method: 'delete',
 | 
			
		||||
            type: TYPE
 | 
			
		||||
        });
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    getFeatures: function () {
 | 
			
		||||
        return reqwest({
 | 
			
		||||
            url: 'features',
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user