Skip to content

Commit

Permalink
Merge pull request #3089 from akvo/issue/3088-looping-through-objects
Browse files Browse the repository at this point in the history
Looping through objects (connect #3088)
  • Loading branch information
stellanl authored May 6, 2019
2 parents f07ec66 + 79306d5 commit 72ce99e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
35 changes: 19 additions & 16 deletions Dashboard/app/js/lib/controllers/survey-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ FLOW.projectControl = Ember.ArrayController.create({
dataCleaningEnabled(surveyGroup) {
const permissions = FLOW.currentUser.get('pathPermissions');

Object.keys(permissions).forEach((key) => {
if (permissions[key].indexOf('DATA_CLEANING') > -1) {
const keys = Object.keys(permissions);
for (let i = 0; i < keys.length; i++) {
if (permissions[keys[i]].indexOf('DATA_CLEANING') > -1) {
// check key against survey group
if (surveyGroup.get('keyId') === +key) {
if (surveyGroup.get('keyId') === +keys[i]) {
return true;
}

Expand All @@ -247,16 +248,16 @@ FLOW.projectControl = Ember.ArrayController.create({
if (ancestorIds === null) {
return false;
}
for (let i = 0; i < ancestorIds.length; i++) {
if (ancestorIds[i] === +key) {
for (let j = 0; j < ancestorIds.length; j++) {
if (ancestorIds[j] === +keys[i]) {
return true;
}
}


// finally check for all descendents that may have surveyGroup.keyId in their
// ancestor list otherwise will not be able to browse to them.
const keyedSurvey = FLOW.store.find(FLOW.SurveyGroup, key);
const keyedSurvey = FLOW.store.find(FLOW.SurveyGroup, keys[i]);
if (keyedSurvey) {
const keyedAncestorIds = keyedSurvey.get('ancestorIds');
if (keyedAncestorIds === null) {
Expand All @@ -269,7 +270,7 @@ FLOW.projectControl = Ember.ArrayController.create({
}
}
}
});
}

return false;
},
Expand Down Expand Up @@ -1355,13 +1356,14 @@ FLOW.translationControl = Ember.ArrayController.create(observe({

createIsoLangs() {
const tempArray = [];
Object.keys(FLOW.isoLanguagesDict).forEach((key) => {
const keys = Object.keys(FLOW.isoLanguagesDict);
for (let i = 0; i < keys.length; i++) {
tempArray.push(Ember.Object.create({
value: key,
labelShort: FLOW.isoLanguagesDict[key].nativeName,
labelLong: `${FLOW.isoLanguagesDict[key].nativeName} - ${FLOW.isoLanguagesDict[key].name}`,
value: keys[i],
labelShort: FLOW.isoLanguagesDict[keys[i]].nativeName,
labelLong: `${FLOW.isoLanguagesDict[keys[i]].nativeName} - ${FLOW.isoLanguagesDict[keys[i]].name}`,
}));
});
}
this.set('isoLangs', tempArray);
},

Expand Down Expand Up @@ -1479,12 +1481,13 @@ FLOW.translationControl = Ember.ArrayController.create(observe({
tempDict[item.get('langCode')] = item.get('langCode');
}
});
Object.keys(tempDict).forEach((key) => {
const keys = Object.keys(tempDict);
for (let i = 0; i < keys.length; i++) {
this.translations.pushObject(Ember.Object.create({
value: key,
label: FLOW.isoLanguagesDict[key].name,
value: keys[i],
label: FLOW.isoLanguagesDict[keys[i]].name,
}));
});
}
},

cancelAddTranslation() {
Expand Down
7 changes: 4 additions & 3 deletions Dashboard/app/js/lib/views/devices/assignment-edit-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ FLOW.ArrNoDupe = function (a) {
for (let i = 0; i < a.length; i++) {
templ[a.objectAt(i).clientId] = true;
}
Object.keys(templ).forEach((item) => {
const keys = Object.keys(templ);
for (let j = 0; j < keys.length; j++) {
gotIt = false;
for (let i = 0; i < a.length; i++) {
if (a.objectAt(i).clientId == item && !gotIt) {
if (a.objectAt(i).clientId == keys[j] && !gotIt) {
tempa.pushObject(a.objectAt(i));
gotIt = true;
}
}
});
}
return tempa;
};

Expand Down

0 comments on commit 72ce99e

Please sign in to comment.