2015-03-03 19:27:17 +01:00
|
|
|
var Reflux = require("reflux");
|
2015-03-16 21:27:56 +01:00
|
|
|
var Server = require('./FeatureToggleServerFacade');
|
|
|
|
|
|
|
|
var FeatureToggleActions = Reflux.createActions({
|
2016-04-24 22:41:37 +02:00
|
|
|
'init': { asyncResult: true },
|
|
|
|
'initArchive': { asyncResult: true },
|
|
|
|
'create': { asyncResult: true },
|
|
|
|
'update': { asyncResult: true },
|
|
|
|
'archive': { asyncResult: true },
|
|
|
|
'revive': { asyncResult: true }
|
2015-03-16 21:27:56 +01:00
|
|
|
});
|
|
|
|
|
2016-04-24 22:41:37 +02:00
|
|
|
FeatureToggleActions.init.listen(function() {
|
2015-03-17 22:52:10 +01:00
|
|
|
Server.getFeatures(function(error, features) {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (error) {
|
|
|
|
this.failed(error);
|
|
|
|
} else {
|
|
|
|
this.completed(features);
|
|
|
|
}
|
2015-03-17 22:52:10 +01:00
|
|
|
}.bind(this));
|
|
|
|
});
|
|
|
|
|
2016-04-24 22:41:37 +02:00
|
|
|
FeatureToggleActions.initArchive.listen(function() {
|
2015-03-17 22:52:10 +01:00
|
|
|
Server.getArchivedFeatures(function(error, archivedToggles) {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (error) {
|
|
|
|
this.failed(error);
|
|
|
|
} else {
|
|
|
|
this.completed(archivedToggles);
|
|
|
|
}
|
2015-03-17 22:52:10 +01:00
|
|
|
}.bind(this));
|
|
|
|
});
|
|
|
|
|
2016-04-24 22:41:37 +02:00
|
|
|
FeatureToggleActions.create.listen(function(feature) {
|
2015-03-16 21:27:56 +01:00
|
|
|
Server.createFeature(feature, function(error) {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (error) {
|
|
|
|
this.failed(error);
|
|
|
|
} else {
|
|
|
|
this.completed(feature);
|
|
|
|
}
|
2015-03-16 21:27:56 +01:00
|
|
|
}.bind(this));
|
|
|
|
});
|
|
|
|
|
2016-04-24 22:41:37 +02:00
|
|
|
FeatureToggleActions.update.listen(function(feature) {
|
2015-03-16 21:27:56 +01:00
|
|
|
Server.updateFeature(feature, function(error) {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (error) {
|
|
|
|
this.failed(error);
|
|
|
|
} else {
|
|
|
|
this.completed(feature);
|
|
|
|
}
|
2015-03-16 21:27:56 +01:00
|
|
|
}.bind(this));
|
|
|
|
});
|
|
|
|
|
2016-04-24 22:41:37 +02:00
|
|
|
FeatureToggleActions.archive.listen(function(feature) {
|
2015-03-16 21:27:56 +01:00
|
|
|
Server.archiveFeature(feature, function(error) {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (error) {
|
|
|
|
this.failed(error);
|
|
|
|
} else {
|
|
|
|
this.completed(feature);
|
|
|
|
}
|
2015-03-16 21:27:56 +01:00
|
|
|
}.bind(this));
|
|
|
|
});
|
|
|
|
|
2016-04-24 22:41:37 +02:00
|
|
|
FeatureToggleActions.revive.listen(function(feature) {
|
2015-03-16 21:27:56 +01:00
|
|
|
Server.reviveFeature(feature, function(error) {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (error) {
|
|
|
|
this.failed(error);
|
|
|
|
} else {
|
|
|
|
this.completed(feature);
|
|
|
|
}
|
2015-03-16 21:27:56 +01:00
|
|
|
}.bind(this));
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = FeatureToggleActions;
|