Skip to content

Commit

Permalink
Merge branch 'release/1.9.30'
Browse files Browse the repository at this point in the history
  • Loading branch information
kymni committed Apr 3, 2018
2 parents 9a74860 + 3e54abd commit ce8deaa
Show file tree
Hide file tree
Showing 21 changed files with 714 additions and 164 deletions.
25 changes: 19 additions & 6 deletions Dashboard/app/js/lib/controllers/data-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,14 @@ FLOW.questionAnswerControl = Ember.ArrayController.create({
// over a set of responses to questions in a specific question group, ordered
// by question order. For repeat question groups two adjacent sub lists
// represent two iterations of responses for that group
contentByGroup: Ember.computed('content.isLoaded', function(key, value) {
var content = Ember.get(this, 'content'),
self = this;
if (content) {
contentByGroup: Ember.computed('content.isLoaded',
'FLOW.questionContol.content.isLoaded',
'FLOW.questionContol.content.isLoaded', function(key, value) {
var content = Ember.get(this, 'content'), self = this;
var questions = FLOW.questionControl.get('content');
var questionGroups = FLOW.questionGroupControl.get('content');

if (content && questions && questionGroups) {
var surveyQuestions = FLOW.questionControl.get('content');
var groups = FLOW.questionGroupControl.get('content');
var allResponses = [];
Expand Down Expand Up @@ -347,9 +351,18 @@ FLOW.questionAnswerControl = Ember.ArrayController.create({
return allIterations;
},

doQuestionAnswerQuery: function (surveyInstanceId) {
doQuestionAnswerQuery: function (surveyInstance) {
var formId = surveyInstance.get('surveyId');
var form = FLOW.surveyControl.filter(function (form) {
return form.get('keyId') === formId;
}).get(0);

if (formId !== FLOW.selectedControl.selectedSurvey.get('keyId')) {
FLOW.selectedControl.set('selectedSurvey', form);
}

this.set('content', FLOW.store.findQuery(FLOW.QuestionAnswer, {
'surveyInstanceId': surveyInstanceId
'surveyInstanceId': surveyInstance.get('keyId')
}));
},
});
Expand Down
8 changes: 8 additions & 0 deletions Dashboard/app/js/lib/controllers/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ FLOW.isoLanguagesDict = {
"name": "Persian",
"nativeName": "فارسی"
},
"pis": {
"name": "Pijin",
"nativeName": "Pijin"
},
"pl": {
"name": "Polish",
"nativeName": "polski"
Expand Down Expand Up @@ -635,6 +639,10 @@ FLOW.isoLanguagesDict = {
"name": "Tibetan Standard, Tibetan, Central",
"nativeName": "བོད་ཡིག"
},
"tpi": {
"name": "Tok Pisin",
"nativeName": "Tok Pisin"
},
"tk": {
"name": "Turkmen",
"nativeName": "Türkmen, Түркмен"
Expand Down
87 changes: 67 additions & 20 deletions Dashboard/app/js/lib/controllers/survey-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ FLOW.surveyControl = Ember.ArrayController.create({
}.observes('FLOW.selectedControl.selectedSurveyGroup'),

selectFirstForm: function() {
if(FLOW.selectedControl.selectedSurvey) return; // ignore if form is already selected
if (this.get('content') && this.content.get('isLoaded')) {
var form = this.content.get('firstObject');
if (form) {
Expand Down Expand Up @@ -814,29 +815,50 @@ FLOW.questionGroupControl = Ember.ArrayController.create({

// execute group delete
deleteQuestionGroup: function (questionGroupId) {
var questionGroup, questionsGroupsInSurvey, sId, qgOrder;
var questionGroup, sId, qgOrder;
sId = FLOW.selectedControl.selectedSurvey.get('keyId');
questionGroup = FLOW.store.find(FLOW.QuestionGroup, questionGroupId);
qgOrder = questionGroup.get('order');

questionGroup.deleteRecord();

// restore order of remaining groups
questionGroupsInSurvey = FLOW.store.filter(FLOW.QuestionGroup, function (item) {
return item.get('surveyId') == sId;
// reorder the rest of the question groups
this.reorderQuestionGroups(sId, qgOrder, "decrement");
this.submitBulkQuestionGroupsReorder(sId);

FLOW.selectedControl.selectedSurvey.set('status', 'NOT_PUBLISHED');
FLOW.store.commit();
},

reorderQuestionGroups: function (surveyId, reorderPoint, reorderOperation) {
var questionGroupsInSurvey = FLOW.store.filter(FLOW.QuestionGroup, function (item) {
return item.get('surveyId') == surveyId;
});

// restore order
// move items up to make space
questionGroupsInSurvey.forEach(function (item) {
if (item.get('order') > qgOrder) {
item.set('order', item.get('order') - 1);
if (reorderOperation == "increment") {
if (item.get('order') > reorderPoint) {
item.set('order', item.get('order') + 1);
}
} else if (reorderOperation == "decrement") {
if (item.get('order') > reorderPoint) {
item.set('order', item.get('order') - 1);
}
}
});
},

submitBulkQuestionGroupsReorder: function (surveyId) {
FLOW.questionControl.set('bulkCommit', true);
var questionGroupsInSurvey = FLOW.store.filter(FLOW.QuestionGroup, function (item) {
return item.get('surveyId') == surveyId;
});
// restore order in case the order has gone haywire
FLOW.questionControl.restoreOrder(questionGroupsInSurvey);
FLOW.selectedControl.selectedSurvey.set('status', 'NOT_PUBLISHED');
FLOW.store.commit();
FLOW.store.adapter.set('bulkCommit', false);
FLOW.questionControl.set('bulkCommit', false);
}
});

Expand All @@ -850,6 +872,7 @@ FLOW.questionControl = Ember.ArrayController.create({
sortProperties: ['order'],
sortAscending: true,
preflightQId: null,
bulkCommit: false,

populateAllQuestions: function () {
var sId;
Expand Down Expand Up @@ -889,24 +912,16 @@ FLOW.questionControl = Ember.ArrayController.create({
},

deleteQuestion: function (questionId) {
qgId = this.content.get('questionGroupId');
var question, qgId, qOrder;
question = FLOW.store.find(FLOW.Question, questionId);
qgId = question.get('questionGroupId');
qOrder = question.get('order');
question.deleteRecord();

// restore order
questionsInGroup = FLOW.store.filter(FLOW.Question, function (item) {
return item.get('questionGroupId') == qgId;
});
//reorder the rest of the questions
this.reorderQuestions(qgId, qOrder, "decrement");
this.submitBulkQuestionsReorder([qgId]);

questionsInGroup.forEach(function (item) {
if (item.get('order') > qOrder) {
item.set('order', item.get('order') - 1);
}
});
// restore order in case the order has gone haywire
this.restoreOrder(questionsInGroup);
FLOW.selectedControl.selectedSurvey.set('status', 'NOT_PUBLISHED');
FLOW.store.commit();
},
Expand Down Expand Up @@ -977,6 +992,38 @@ FLOW.questionControl = Ember.ArrayController.create({
}
}.observes('FLOW.selectedControl.selectedQuestion'),

reorderQuestions: function (qgId, reorderPoint, reorderOperation) {
var questionsInGroup = FLOW.store.filter(FLOW.Question, function (item) {
return item.get('questionGroupId') == qgId;
});

// move items up to make space
questionsInGroup.forEach(function (item) {
if (reorderOperation == "increment") {
if (item.get('order') > reorderPoint) {
item.set('order', item.get('order') + 1);
}
} else if (reorderOperation == "decrement") {
if (item.get('order') > reorderPoint) {
item.set('order', item.get('order') - 1);
}
}
});
},

submitBulkQuestionsReorder: function (qgIds) {
this.set('bulkCommit', true);
for (var i=0; i>qgIds.length; i++) {
var questionsInGroup = FLOW.store.filter(FLOW.Question, function (item) {
return item.get('questionGroupId') == qgIds[i];
});
// restore order in case the order has gone haywire
FLOW.questionControl.restoreOrder(questionsInGroup);
}
FLOW.store.commit();
FLOW.store.adapter.set('bulkCommit', false);
this.set('bulkCommit', false);
},


// true if all items have been saved
Expand Down
22 changes: 22 additions & 0 deletions Dashboard/app/js/lib/models/FLOWrest-adapter-v2-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ DS.FLOWRESTAdapter = DS.RESTAdapter.extend({
// includes 'bulk' in the POST call, to allign
// with updateRecords and deleteRecords behaviour.
createRecords: function (store, type, records) {
//do not bulk commit when creating questions and question groups
if (FLOW.questionControl.get('bulkCommit')) {
this.set('bulkCommit', false);
}

if (get(this, 'bulkCommit') === false) {
return this._super(store, type, records);
}
Expand All @@ -207,5 +212,22 @@ DS.FLOWRESTAdapter = DS.RESTAdapter.extend({
this.didCreateRecords(store, type, records, json);
}
});
},


updateRecords: function(store, type, records) {
//if updating questions and question groups ordering, enable bulkCommit
if (FLOW.questionControl.get('bulkCommit')) {
this.set('bulkCommit', true);
}
this._super(store, type, records);
},

deleteRecords: function(store, type, records) {
//do not bulk commit when deleting questions and question groups
if (FLOW.questionControl.get('bulkCommit')) {
this.set('bulkCommit', false);
}
this._super(store, type, records);
}
});
13 changes: 8 additions & 5 deletions Dashboard/app/js/lib/views/data/inspect-data-table-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FLOW.inspectDataTableView = FLOW.View.extend({
FLOW.dateControl.set('toDate', null);
FLOW.dateControl.set('fromDate', null);
FLOW.surveyInstanceControl.set('pageNumber', 0);
FLOW.surveyInstanceControl.set('currentContents', null);
FLOW.locationControl.set('selectedLevel1', null);
FLOW.locationControl.set('selectedLevel2', null);
},
Expand Down Expand Up @@ -149,7 +150,7 @@ FLOW.inspectDataTableView = FLOW.View.extend({
// Survey instance edit popup window
// TODO solve when popup is open, no new surveyIdQuery is done
showEditSurveyInstanceWindow: function (event) {
FLOW.questionAnswerControl.doQuestionAnswerQuery(event.context.get('keyId'));
FLOW.questionAnswerControl.doQuestionAnswerQuery(event.context);
this.get('alreadyLoaded').push(event.context.get('surveyId'));
this.set('selectedSurveyInstanceId', event.context.get('keyId'));
this.set('selectedSurveyInstanceNum', event.context.clientId);
Expand Down Expand Up @@ -181,12 +182,13 @@ FLOW.inspectDataTableView = FLOW.View.extend({
return false;
}
});
nextSIkeyId = filtered.objectAt(0).get('keyId');
var nextSI = filtered.objectAt(0);
nextSIkeyId = nextSI.get('keyId');
this.set('selectedSurveyInstanceId', nextSIkeyId);
this.set('selectedSurveyInstanceNum', nextItem);
this.createSurveyInstanceString();
this.downloadQuestionsIfNeeded();
FLOW.questionAnswerControl.doQuestionAnswerQuery(nextSIkeyId);
FLOW.questionAnswerControl.doQuestionAnswerQuery(nextSI);
}
},

Expand All @@ -208,12 +210,13 @@ FLOW.inspectDataTableView = FLOW.View.extend({
return false;
}
});
nextSIkeyId = filtered.objectAt(0).get('keyId');
var nextSI = filtered.objectAt(0);
nextSIkeyId = nextSI.get('keyId');
this.set('selectedSurveyInstanceId', nextSIkeyId);
this.set('selectedSurveyInstanceNum', nextItem);
this.createSurveyInstanceString();
this.downloadQuestionsIfNeeded();
FLOW.questionAnswerControl.doQuestionAnswerQuery(nextSIkeyId);
FLOW.questionAnswerControl.doQuestionAnswerQuery(nextSI);
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FLOW.MonitoringDataTableView = FLOW.View.extend({
},

showSurveyInstanceDetails: function (evt) {
FLOW.questionAnswerControl.doQuestionAnswerQuery(evt.context.get('keyId'));
FLOW.questionAnswerControl.doQuestionAnswerQuery(evt.context);
$('.si_details').hide();
$('tr[data-flow-id="si_details_' + evt.context.get('keyId') + '"]').show();
},
Expand Down Expand Up @@ -98,6 +98,12 @@ FLOW.MonitoringDataTableView = FLOW.View.extend({
hasPrevPage: function () {
return FLOW.router.surveyedLocaleController.get('pageNumber');
}.property('FLOW.router.surveyedLocaleController.pageNumber'),

willDestroyElement: function () {
FLOW.router.surveyedLocaleController.set('currentContents', null);
FLOW.metaControl.set('numSLLoaded',null)
FLOW.router.surveyedLocaleController.set('pageNumber',0)
}
});

/**
Expand Down
Loading

0 comments on commit ce8deaa

Please sign in to comment.