Skip to content

Commit

Permalink
Prepare for 2.19 filter change
Browse files Browse the repository at this point in the history
  • Loading branch information
Markionium committed Jun 10, 2015
1 parent 4ef4866 commit c032a5b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ fake-api

*.zip
src/main/_manifest.webapp
src/main/np
8 changes: 5 additions & 3 deletions src/main/datasets/datasetgroup-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]]',
Expand Down
2 changes: 1 addition & 1 deletion src/main/manifest.webapp
Original file line number Diff line number Diff line change
@@ -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":"*"}}}
{"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":"*"}}}
39 changes: 23 additions & 16 deletions src/main/mechanism/mechanisms-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/test/specs/dataset/datasetgroup-service_spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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;
var periodService = {
filterPeriodTypes: jasmine.createSpy()
};
var errorHandlerMock;

var systemSettingRequest;

beforeEach(module('d2-rest'));
Expand Down
3 changes: 1 addition & 2 deletions src/test/specs/mechanisms/mechanisms-service_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('&')
Expand Down

0 comments on commit c032a5b

Please sign in to comment.