diff --git a/.gitignore b/.gitignore index 6aee117..1fda97a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ fake-api *.zip src/main/_manifest.webapp +src/main/np \ No newline at end of file diff --git a/src/main/datasets/datasetgroup-service.js b/src/main/datasets/datasetgroup-service.js index 51c135f..35d2c12 100644 --- a/src/main/datasets/datasetgroup-service.js +++ b/src/main/datasets/datasetgroup-service.js @@ -20,9 +20,11 @@ function dataSetGroupService(d2Api, $q, periodService, Restangular, errorHandler filteredGroup.name = dataSetGroup.name; filteredGroup.dataSets = []; - filters = _.map(dataSetGroup.dataSets, function (dataSetId) { - return 'id:eq:' + dataSetId; - }); + filters = [ + 'id:in:[', + dataSetGroup.dataSets.join(','), + ']' + ].join(''); dataSetGroupsPromises.push(d2Api.dataSets.getList({ fields: 'name,shortName,id,periodType,categoryCombo[id,name,categories[id]]', diff --git a/src/main/manifest.webapp b/src/main/manifest.webapp index 4a32bf3..1d56a81 100644 --- a/src/main/manifest.webapp +++ b/src/main/manifest.webapp @@ -1 +1 @@ -{"version":"0.4.1","name":"Data Approval","description":"Approvals app for PEPFAR","icons":{"48":"img/icons/dataapproval.png"},"developer":{"url":"http://www.dhis2.org","name":"Mark Polak","company":"DHIS2 Core Team","email":"markpo@ifi.uio.no"},"launch_path":"index.html?v=0.4.1","default_locale":"en","activities":{"dhis":{"href":"*"}}} \ No newline at end of file +{"version":"0.4.2","name":"Data Approval","description":"Approvals app for PEPFAR","icons":{"48":"img/icons/dataapproval.png"},"developer":{"url":"http://www.dhis2.org","name":"Mark Polak","company":"DHIS2 Core Team","email":"markpo@ifi.uio.no"},"launch_path":"index.html?v=0.4.2","default_locale":"en","activities":{"dhis":{"href":"*"}}} \ No newline at end of file diff --git a/src/main/mechanism/mechanisms-service.js b/src/main/mechanism/mechanisms-service.js index ae0d96c..e9422bc 100644 --- a/src/main/mechanism/mechanisms-service.js +++ b/src/main/mechanism/mechanisms-service.js @@ -330,29 +330,28 @@ function categoriesService(request, $q, $log) { function getCategories(categoryIds) { var categoriesUrl = ['api', 'categories.json'].join('/'); var fields = 'fields=id,name'; - var filters = _.map(categoryIds, function (category) { - return 'id:eq:' + category; - }); + var filters; var queryParams; + var categoryOptionsPromises; + var categoriesPromise; - if (!areParamsCorrect(filters)) { + if (!areParamsCorrect(categoryIds)) { return $q.reject('Not all required params are set'); } - queryParams = filters = ['paging=false', createFilterQueryParamFrom(filters), fields]; + filters = [encodeURI(['id:in:[', categoryIds.join(','), ']'].join(''))]; + queryParams = ['paging=false', createFilterQueryParamFrom(filters), fields]; - var categoryOptionsPromises = categoryIds.map(function (categoryId) { - return request('api/categoryOptions', [ - 'paging=false', - 'filter=categories.id:eq:' + categoryId, - 'fields=' + encodeURI('id,name,organisationUnits[id,name],categoryOptionCombos[id,name],categoryOptionGroups[id,name,categoryOptionGroupSet[id]]') - ]).then(function (response) { - response.categoryId = categoryId; - return response; + categoryOptionsPromises = categoryIds + .map(function (categoryId) { + return requestCategoryOptionsByCategoryId(categoryId) + .then(function (response) { + response.categoryId = categoryId; + return response; + }); }); - }); - var categoriesPromise = request(categoriesUrl, queryParams) + categoriesPromise = request(categoriesUrl, queryParams) .then(extractCategories) .catch(function () { return $q.reject('Request for categories failed'); @@ -375,6 +374,14 @@ function categoriesService(request, $q, $log) { }); } + function requestCategoryOptionsByCategoryId(categoryId) { + return request('api/categoryOptions', [ + 'paging=false', + 'filter=categories.id:eq:' + categoryId, + 'fields=' + encodeURI('id,name,organisationUnits[id,name],categoryOptionCombos[id,name],categoryOptionGroups[id,name,categoryOptionGroupSet[id]]') + ]); + } + function extractCategories(data) { if (data && data.categories && data.categories.length) { $log.log('Loaded categories using $http'); @@ -405,7 +412,7 @@ function requestProvider($http, $q, AppManifest) { return request; /** - * Does an ajax GET request using jquery + * Does an ajax GET request using $http * * @param {String} url Url to request from * @param {Object} queryParams Query params that should be added to the url. diff --git a/src/test/specs/dataset/datasetgroup-service_spec.js b/src/test/specs/dataset/datasetgroup-service_spec.js index 298ba1c..d7209be 100644 --- a/src/test/specs/dataset/datasetgroup-service_spec.js +++ b/src/test/specs/dataset/datasetgroup-service_spec.js @@ -1,7 +1,7 @@ describe('Datasetgroup service', function () { - var merUrl = '/dhis/api/dataSets?fields=name,shortName,id,periodType,categoryCombo%5Bid,name,categories%5Bid%5D%5D&filter=id:eq:fx2HjpODE5y&filter=id:eq:xXmmo2so2V8&filter=id:eq:gpJ2TLXI3mY&filter=id:eq:w9BiI08vABw&paging=false'; - var eaUrl = '/dhis/api/dataSets?fields=name,shortName,id,periodType,categoryCombo%5Bid,name,categories%5Bid%5D%5D&filter=id:eq:eLRAaV32xH5&filter=id:eq:kLPghhtGPvZ&filter=id:eq:A4ivU53utt2&filter=id:eq:wEKkfO7aAI3&filter=id:eq:JmnzNK18klO&paging=false'; - var simsUrl = '/dhis/api/dataSets?fields=name,shortName,id,periodType,categoryCombo%5Bid,name,categories%5Bid%5D%5D&filter=id:eq:nideTeYxXLu&filter=id:eq:J9Yq8jDd3nF&filter=id:eq:iqaWSeKDhS3&filter=id:eq:M059pmNzZYE&paging=false'; + var merUrl = '/dhis/api/dataSets?fields=name,shortName,id,periodType,categoryCombo%5Bid,name,categories%5Bid%5D%5D&filter=id:in:%5Bfx2HjpODE5y,xXmmo2so2V8,gpJ2TLXI3mY,w9BiI08vABw%5D&paging=false'; + var eaUrl = '/dhis/api/dataSets?fields=name,shortName,id,periodType,categoryCombo%5Bid,name,categories%5Bid%5D%5D&filter=id:in:%5BeLRAaV32xH5,kLPghhtGPvZ,A4ivU53utt2,wEKkfO7aAI3,JmnzNK18klO%5D&paging=false'; + var simsUrl = '/dhis/api/dataSets?fields=name,shortName,id,periodType,categoryCombo%5Bid,name,categories%5Bid%5D%5D&filter=id:in:%5BnideTeYxXLu,J9Yq8jDd3nF,iqaWSeKDhS3,M059pmNzZYE%5D&paging=false'; var service; var $httpBackend; @@ -9,7 +9,7 @@ describe('Datasetgroup service', function () { filterPeriodTypes: jasmine.createSpy() }; var errorHandlerMock; - + var systemSettingRequest; beforeEach(module('d2-rest')); diff --git a/src/test/specs/mechanisms/mechanisms-service_spec.js b/src/test/specs/mechanisms/mechanisms-service_spec.js index 59c9ab7..3cdbc48 100644 --- a/src/test/specs/mechanisms/mechanisms-service_spec.js +++ b/src/test/specs/mechanisms/mechanisms-service_spec.js @@ -7,8 +7,7 @@ describe('Mechanisms service', function () { var apiUrlWithCorrectParameters = ['/dhis/api/categories.json?', [ 'paging=false', - 'filter=id:eq:SH885jaRe0o', - 'filter=id:eq:GLevLNI9wkl', + 'filter=id:in:%5BSH885jaRe0o,GLevLNI9wkl%5D', 'fields=id,name' //'fields=id,name,categoryOptions[id,name,organisationUnits[id,name],categoryOptionCombos[id,name],categoryOptionGroups[id,name,categoryOptionGroupSet[id]]' ].join('&')