Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve condition in launcher #400

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/core/scenario/scenario.export.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function normalize(data) {
} else {
dictionnary[elem.id] = {
code: elem.code,
trueIf: elem.trueIf,
params: {
[elem.variablename]: elem.value
}
Expand All @@ -37,4 +38,4 @@ function normalize(data) {
}
});
return newArray;
}
}
3 changes: 2 additions & 1 deletion api/core/scenario/scenario.import.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = function(params) {
return gladys.stateType.getByServiceFunction({service: splitted[0], function: splitted[1]})
.then(stateType => gladys.state.create({
state: stateType.id,
trueIf: condition.trueIf,
condition_template: condition.condition_template,
active: condition.active,
launcher: launcher.id,
Expand Down Expand Up @@ -72,4 +73,4 @@ module.exports = function(params) {
};
});

};
};
4 changes: 2 additions & 2 deletions api/core/scenario/scenario.queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
JOIN actiontypeparam ON (actionparam.actiontypeparam = actiontypeparam.id)
WHERE action = ?;`,
getStatesLauncher: `
SELECT statetype.*, state.id AS stateId, state.condition_template AS condition_template
SELECT statetype.*, state.id AS stateId, state.condition_template AS condition_template, trueIf
FROM state
INNER JOIN statetype ON state.state = statetype.id
WHERE launcher = ?;
Expand All @@ -27,7 +27,7 @@ module.exports = {
WHERE launcher.id = ?;
`,
getStates: `
SELECT state.id, CONCAT(statetype.service, '.', statetype.function) as code, state.condition_template, state.active,
SELECT state.id, CONCAT(statetype.service, '.', statetype.function) as code, state.condition_template, state.active, state.trueIf,
stateparam.value, statetypeparam.variablename
FROM state
JOIN statetype ON state.state = statetype.id
Expand Down
9 changes: 6 additions & 3 deletions api/core/scenario/scenario.verifyconditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ function verify(statetype, params) {
return verifyFunction(paramsToSend);
})
.then(function(scope) {


var trueIf = true
if(statetype.trueIf === 0) trueIf = false

// module can send raw response if he don't need the template
if(scope === true) return Promise.resolve(scope);
if(scope === false) return Promise.reject(new Error('conditions_not_verified'));
if(scope === trueIf) return Promise.resolve(scope);
if(scope === !trueIf) return Promise.reject(new Error('conditions_not_verified'));

// if the scope is not a boolean, we inject it in the condition template
try {
Expand Down
2 changes: 1 addition & 1 deletion api/core/state/state.create.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ module.exports = function(state){
return gladys.stateParam.create(paramsArray);
})
.then(() => createdState);
};
};
5 changes: 5 additions & 0 deletions api/models/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module.exports = {
defaultsTo: true
},

trueIf: {
type: 'boolean',
defaultsTo: true
},

launcher: {
model: 'Launcher',
required: true
Expand Down
1 change: 1 addition & 0 deletions assets/js/app/scenario/scenario.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
var newState = {
launcher: vm.newLauncher.id,
state: stateType.id,
trueIf: true,
name: stateType.name
};

Expand Down
5 changes: 3 additions & 2 deletions assets/js/app/state/state.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@

var newState = {
state: state.state,
launcher: state.launcher
launcher: state.launcher,
trueIf: state.trueIf
};

// we create the condition template
Expand Down Expand Up @@ -82,4 +83,4 @@
}

}
})();
})();
6 changes: 5 additions & 1 deletion config/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"parameters-box-table-delete": "Delete",
"parameters-box-left": "Left",
"parameters-box-right": "Right",
"scenario-if-condition": "Condition is validated if",
"scenario-list": "My scenario",
"scenario-help": "Help",
"scenario-table-event": "Trigger",
Expand Down Expand Up @@ -398,5 +399,8 @@
"reset-password-new-password": "New Password",
"reset-password-button": "Change my password",
"reset-password-minimum-size-warning": "(Minimum 8 characters)",
"forgot-password-reset-failed": "Your password was not changed. Maybe the link was not valid anymore (It is valid only 2 hours), or maybe your password length was too low. Please try again."
"forgot-password-reset-failed": "Your password was not changed. Maybe the link was not valid anymore (It is valid only 2 hours), or maybe your password length was too low. Please try again.",
"True": "True",
"False": "False",
"is": "is"
}
8 changes: 6 additions & 2 deletions config/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"parameters-box-table-delete": "Supprimer",
"parameters-box-left": "Gauche",
"parameters-box-right": "Droite",
"scenario-if-condition": "La condition est validée si",
"scenario-list": "Mes scénarios",
"scenario-help": "Aide",
"scenario-table-event": "Déclencheur",
Expand Down Expand Up @@ -562,5 +563,8 @@
"reset-password-new-password": "Nouveau mot de passe",
"reset-password-button": "Changer mon mot de passe",
"reset-password-minimum-size-warning": "(Minimum 8 caractères)",
"forgot-password-reset-failed": "Le changement de votre mot de passe a échoué. Le lien n'était peut être plus valide (il n'est valide que 2 heures) ou le mot de passe était trop court. Merci de ré-essayer."
}
"forgot-password-reset-failed": "Le changement de votre mot de passe a échoué. Le lien n'était peut être plus valide (il n'est valide que 2 heures) ou le mot de passe était trop court. Merci de ré-essayer.",
"True": "Vraie",
"False": "Fausse",
"is": "est"
}
8 changes: 5 additions & 3 deletions test/fixtures/state.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"id": 1,
"launcher": 1,
"state": 1,
"condition_template": "true"
"condition_template": "true",
"trueIf": 0
},
{
"id": 2,
"launcher": 3,
"state": 2,
"condition_template": "true"
"condition_template": "true",
"trueIf": 0
}
]
]
9 changes: 7 additions & 2 deletions views/scenario/modal.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@

<form class="form-horizontal">

<h4>{{state.name}}</h4>
<center>
<h4>
<%= __('scenario-if-condition') %>&nbsp;&nbsp;<label class="btn btn-primary" style="cursor: default">{{state.name}}</label>&nbsp;<%= __('is') %>&nbsp;<button class="btn" ng-class="state.trueIf ? 'btn-primary' : 'btn-default'" ng-click="state.trueIf = true"><%= __('True') %></button>&nbsp;&nbsp;<button class="btn" ng-class="!state.trueIf ? 'btn-primary' : 'btn-default'" ng-click="state.trueIf = false"><%= __('False') %></button>
</h4>
</center>
<hr/>

<!-- State Params -->
<div class="form-group" ng-repeat="stateParam in state.params">
Expand Down Expand Up @@ -317,4 +322,4 @@
</div>
</div>
</div>
<!-- END OF MODAL -->
<!-- END OF MODAL -->