Skip to content

Commit

Permalink
ES6 => ES5 on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Oct 15, 2017
1 parent 5b30757 commit 23a7fb5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 66 deletions.
18 changes: 12 additions & 6 deletions assets/js/app/scenario/scenario.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
}

scenarioService.exportScenario(id)
.then((data) => {
.then(function (data) {
vm.currentScenario = {
yaml: jsyaml.safeDump(data.data),
index: index,
Expand All @@ -265,29 +265,35 @@
}
$('#modalUpdateScenario').modal('show');
})
.catch((err) => notificationService.errorNotificationTranslated('DEFAULT.ERROR'));
.catch(function (err) {
notificationService.errorNotificationTranslated('DEFAULT.ERROR')
});
}

function updateScenario(currentScenario) {

// if we are updating an existing scenario
if(currentScenario.id) {
scenarioService.updateScenario(currentScenario.id, jsyaml.safeLoad(editor.getValue()))
.then((data) => {
.then(function (data) {
vm.launchers[vm.currentScenario.index] = data.data.trigger;
$('#modalUpdateScenario').modal('hide');
})
.catch(() => notificationService.errorNotificationTranslated('SCENARIO.UPDATE_ERROR'));
.catch(function () {
notificationService.errorNotificationTranslated('SCENARIO.UPDATE_ERROR')
});
}

// creating a new scenario
else {
scenarioService.importScenario(jsyaml.safeLoad(editor.getValue()))
.then((data) => {
.then(function(data){
vm.launchers.push(data.data.trigger);
$('#modalUpdateScenario').modal('hide');
})
.catch(() => notificationService.errorNotificationTranslated('SCENARIO.CREATE_ERROR'));
.catch(function () {
notificationService.errorNotificationTranslated('SCENARIO.CREATE_ERROR')
});
}
}

Expand Down
34 changes: 20 additions & 14 deletions assets/js/app/sentence/sentence.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
vm.status = 'pending';
vm.trainNew = trainNew;
vm.training = false;
// helpers
vm.eq = (a, b) => a === b;
vm.neq = (a, b) => a != b;
vm.oneOf = (value, array) => ~array.indexOf(value);

activate();

Expand All @@ -50,11 +46,11 @@
function trainNew() {
vm.training = true;
brainService.trainNew()
.then(() => {
.then(function() {
vm.training = false
notificationService.successNotificationTranslated('BRAIN.TRAINNED_SUCCESS_NOTIFICATION');
})
.catch(() => {
.catch(function () {
vm.training = false
notificationService.errorNotificationTranslated('BRAIN.TRAINNED_FAIL_NOTIFICATION');
});
Expand All @@ -71,31 +67,41 @@

function change(sentence) {
sentence.status = "approved";
return sentenceService.update(sentence)
return sentenceService.update(sentence);
}
function reject(id) {

function reject(id, index) {
return sentenceService.reject(id)
.then( ({ data }) => vm.sentences[vm.sentences.findIndex(sentence => sentence.id === data.id)] = data)
.then(function(data){
vm.sentences[index] = data.data;
});
}
function approve(id) {
function approve(id, index) {
return sentenceService.approve(id)
.then( ({ data }) => vm.sentences[vm.sentences.findIndex(sentence => sentence.id === data.id)] = data)
.then(function(){
vm.sentences[index] = data.data;
});
}
function getLabels() {
return sentenceService.getLabels().then(data => vm.labels = data.data);
return sentenceService.getLabels()
.then(function(data){
vm.labels = data.data;
});
}
function loadMore(){
if(!vm.remoteIsBusy && !vm.noMoreSentences){
return get(vm.status, vm.startValue+vm.nbElementToGet, vm.startValue)
.then(() => vm.startValue += vm.nbElementToGet)
.then( function() {
vm.startValue += vm.nbElementToGet;
});
}
else {
Promise.resolve()
}
}
function get(status, take, skip) {
vm.remoteIsBusy = true;
return sentenceService.get({status}, take, skip)
return sentenceService.get({status: status}, take, skip)
.then(function(data){
if(data.data.length === 0){
vm.noMoreSentences = true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^2.2.1",
"grunt-contrib-less": "^1.4.1",
"grunt-contrib-uglify": "^3.0.1",
"grunt-contrib-uglify": "^3.1.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-mocha-test": "^0.13.2",
"grunt-sails-linker": "^1.0.4",
Expand Down
6 changes: 3 additions & 3 deletions views/sentence/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<td>{{sentence.text}}</td>
<td>
<select name="selectRoom" id="selectRoom" class="form-control" ng-model="sentence.label" ng-change="vm.change(sentence)">
<option ng-value="label.label" ng-repeat="label in vm.labels" ng-selected="vm.eq(label.label, sentence.label)">{{label.label}}</option>
<option ng-value="label.label" ng-repeat="label in vm.labels" ng-selected="(label.label == sentence.label)">{{label.label}}</option>
</select>
</td>
<td>{{sentence.status}}</td>
<td>
<button ng-hide="vm.oneOf(sentence.status, ['approved', 'official'])" class="btn btn-primary btn-sm" ng-click="vm.approve(sentence.id);" ><%= __('Approve') %></button>
<button ng-hide="vm.eq(sentence.status, 'rejected')" class="btn btn-danger btn-sm" ng-click="vm.reject(sentence.id);" ><%= __('Reject') %></button>
<button ng-hide="['approved', 'official'].indexOf(sentence.status) != -1" class="btn btn-primary btn-sm" ng-click="vm.approve(sentence.id);" ><%= __('Approve') %></button>
<button ng-hide="(sentence.status == 'rejected')" class="btn btn-danger btn-sm" ng-click="vm.reject(sentence.id);" ><%= __('Reject') %></button>
</td>
</tr>
</tbody>
Expand Down
63 changes: 21 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,7 @@ concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

concat-stream@^1.4.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7"
dependencies:
inherits "^2.0.3"
readable-stream "^2.2.2"
typedarray "^0.0.6"

concat-stream@~1.4.4:
concat-stream@^1.4.1, concat-stream@~1.4.4:
version "1.4.10"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.4.10.tgz#acc3bbf5602cb8cc980c6ac840fa7d8603e3ef36"
dependencies:
Expand Down Expand Up @@ -898,28 +890,28 @@ dateformat@~1.0.12:
get-stdin "^4.0.1"
meow "^3.3.0"

debug@*, debug@2.2.0, debug@^2.1.1, debug@^2.2.0, debug@~2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
debug@*, debug@2.6.8, debug@^2.1.1, debug@^2.2.0, debug@^2.6.0:
version "2.6.8"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
dependencies:
ms "0.7.1"
ms "2.0.0"

debug@0.7.4:
version "0.7.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-0.7.4.tgz#06e1ea8082c2cb14e39806e22e2f6f757f92af39"

debug@2.2.0, debug@~2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
dependencies:
ms "0.7.1"

debug@2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351"
dependencies:
ms "0.7.2"

debug@2.6.8, debug@^2.6.0:
version "2.6.8"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc"
dependencies:
ms "2.0.0"

decamelize@^1.0.0, decamelize@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
Expand Down Expand Up @@ -1704,9 +1696,9 @@ grunt-contrib-uglify@1.0.1:
uglify-js "~2.6.2"
uri-path "^1.0.0"

grunt-contrib-uglify@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/grunt-contrib-uglify/-/grunt-contrib-uglify-3.0.1.tgz#fdeb5f938a4c8042f8e86ae46f63554e8e9511cb"
grunt-contrib-uglify@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/grunt-contrib-uglify/-/grunt-contrib-uglify-3.1.0.tgz#10d1e4849210ec92bf0b08247e24186354d5e9ee"
dependencies:
chalk "^1.0.0"
maxmin "^1.1.0"
Expand Down Expand Up @@ -2023,7 +2015,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"

inherits@2, inherits@2.0.3, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.1:
inherits@2, inherits@2.0.3, inherits@~2.0.0, inherits@~2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

Expand Down Expand Up @@ -2753,14 +2745,10 @@ moment-timezone@^0.5.0:
dependencies:
moment ">= 2.9.0"

"moment@>= 2.9.0", moment@^2.18.1:
"moment@>= 2.9.0", moment@^2.10.3, moment@^2.18.1:
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"

moment@^2.10.3:
version "2.17.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.17.1.tgz#fed9506063f36b10f066c8b59a144d7faebe1d82"

morgan@~1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.6.1.tgz#5fd818398c6819cba28a7cd6664f292fe1c0bbf2"
Expand Down Expand Up @@ -3229,16 +3217,7 @@ rc@1.0.1:
minimist "~0.0.7"
strip-json-comments "0.1.x"

rc@^1.1.7:
version "1.1.7"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.1.7.tgz#c5ea564bb07aff9fd3a5b32e906c1d3a65940fea"
dependencies:
deep-extend "~0.4.0"
ini "~1.3.0"
minimist "^1.2.0"
strip-json-comments "~2.0.1"

rc@^1.2.1:
rc@^1.1.7, rc@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.1.tgz#2e03e8e42ee450b8cb3dce65be1bf8974e1dfd95"
dependencies:
Expand Down Expand Up @@ -3268,7 +3247,7 @@ read@1.0.x:
dependencies:
mute-stream "~0.0.4"

"readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.5, readable-stream@^2.1.4, readable-stream@^2.2.2:
"readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.5, readable-stream@^2.1.4:
version "2.2.3"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.3.tgz#9cf49463985df016c8ae8813097a9293a9b33729"
dependencies:
Expand Down Expand Up @@ -4243,7 +4222,7 @@ typechecker@~2.0.1:
version "2.0.8"
resolved "https://registry.yarnpkg.com/typechecker/-/typechecker-2.0.8.tgz#e83da84bb64c584ccb345838576c40b0337db82e"

typedarray@^0.0.6, typedarray@~0.0.5:
typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

Expand Down Expand Up @@ -4354,11 +4333,11 @@ utils-merge@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.0.tgz#0294fb922bb9375153541c4f7096231f287c8af8"

uuid@3.0.1, uuid@^3.0.0:
uuid@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"

uuid@^3.1.0:
uuid@^3.0.0, uuid@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

Expand Down

0 comments on commit 23a7fb5

Please sign in to comment.