From 125330c8a236833c09ebea66d4b31782b0fc8531 Mon Sep 17 00:00:00 2001 From: Mark Polak Date: Sat, 2 Sep 2017 00:30:22 +0200 Subject: [PATCH] Adjust for api changes between 2.24 and 2.27 The categoryOptionGroupSet is now represented a list of groupSets. For DATIM purposes we'll just always pick the first one. References pepfar-datim/Global#2525 --- src/main/manifest.webapp | 4 +- src/main/mechanism/mechanisms-service.js | 16 ++-- src/test/fixtures/fixtures.js | 76 +++++++++---------- .../mechanisms/mechanisms-service_spec.js | 4 +- 4 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/main/manifest.webapp b/src/main/manifest.webapp index 9443e7f..5171823 100644 --- a/src/main/manifest.webapp +++ b/src/main/manifest.webapp @@ -1,5 +1,5 @@ { - "version": "1.4.2", + "version": "1.5.0", "name": "Data Approval", "description": "Approvals app for PEPFAR", "icons": { @@ -11,7 +11,7 @@ "company": "DHIS2 Core Team", "email": "markpo@ifi.uio.no" }, - "launch_path": "index.html?v=1.4.2", + "launch_path": "index.html?v=1.5.0", "default_locale": "en", "activities": { "dhis": { diff --git a/src/main/mechanism/mechanisms-service.js b/src/main/mechanism/mechanisms-service.js index 2f2fca9..dc1e40a 100644 --- a/src/main/mechanism/mechanisms-service.js +++ b/src/main/mechanism/mechanisms-service.js @@ -142,9 +142,10 @@ function mechanismsService(Restangular, $log, $q, approvalLevelsService, workflo function getPartnerFromCategoryOption(categoryOptionGroups, parterCOGSId) { var partner = _.find(categoryOptionGroups, function (categoryOptionGroup) { - if (categoryOptionGroup.categoryOptionGroupSet && - categoryOptionGroup.categoryOptionGroupSet.id && - categoryOptionGroup.categoryOptionGroupSet.id === parterCOGSId) { + if (categoryOptionGroup.groupSets && + categoryOptionGroup.groupSets[0] && + categoryOptionGroup.groupSets[0].id && + categoryOptionGroup.groupSets[0].id === parterCOGSId) { return true; } return false; @@ -158,9 +159,10 @@ function mechanismsService(Restangular, $log, $q, approvalLevelsService, workflo function getAgencyFromCategoryOption(categoryOptionGroups, agencyCOGSId) { var agency = _.find(categoryOptionGroups, function (categoryOptionGroup) { - if (categoryOptionGroup.categoryOptionGroupSet && - categoryOptionGroup.categoryOptionGroupSet.id && - categoryOptionGroup.categoryOptionGroupSet.id === agencyCOGSId) { + if (categoryOptionGroup.groupSets && + categoryOptionGroup.groupSets[0] && + categoryOptionGroup.groupSets[0].id && + categoryOptionGroup.groupSets[0].id === agencyCOGSId) { return true; } return false; @@ -386,7 +388,7 @@ function categoriesService(request, $q, $log) { 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]]') + 'fields=' + encodeURI('id,name,organisationUnits[id,name],categoryOptionCombos[id,name],categoryOptionGroups[id,name,groupSets[id]]') ]); } diff --git a/src/test/fixtures/fixtures.js b/src/test/fixtures/fixtures.js index a9338bd..21c4468 100644 --- a/src/test/fixtures/fixtures.js +++ b/src/test/fixtures/fixtures.js @@ -183,7 +183,7 @@ name: "(1234 - How....)" } ], - groups: [ + categoryOptionGroups: [ { id: "BnjwQmbgK1b", name: "Partner 1", @@ -217,7 +217,7 @@ name: "(9876 - Nat...)" } ], - groups: [ + categoryOptionGroups: [ { id: "wxAh2TvsTUj", name: "Partner 5", @@ -251,7 +251,7 @@ name: "(2342 - Wat...)" } ], - groups: [ + categoryOptionGroups: [ { id: "CSPJnuxBAnz", name: "Partner 4", @@ -277,7 +277,7 @@ name: "(5433 - JH...)" } ], - groups: [ + categoryOptionGroups: [ { id: "NLV6dy7BE2O", name: "Agency 2", @@ -311,7 +311,7 @@ name: "(7654 - Pre...)" } ], - groups: [ + categoryOptionGroups: [ { id: "vNQlvpUamTo", name: "Partner 2", @@ -339,7 +339,7 @@ "lastUpdated": "2014-09-18T11:03:00.174+0000" } ], - groups: [ + categoryOptionGroups: [ { id: "iadd8tHFS9C", name: "Partner 1", @@ -372,7 +372,7 @@ name: "(default)" } ], - groups: [] + categoryOptionGroups: [] } ] } @@ -499,20 +499,20 @@ name: "(1234 - How....)" } ], - groups: [ + categoryOptionGroups: [ { id: "BnjwQmbgK1b", name: "Partner 1", - categoryOptionGroupSet: { + groupSets: [{ id: "BOyWrF33hiR" - } + }] }, { id: "FPUgmtt8HRi", name: "Agency 1", - categoryOptionGroupSet: { + groupSets: [{ id: "bw8KHXzxd9i" - } + }] } ] }, @@ -533,20 +533,20 @@ name: "(9876 - Nat...)" } ], - groups: [ + categoryOptionGroups: [ { id: "wxAh2TvsTUj", name: "Partner 5", - categoryOptionGroupSet: { + groupSets: [{ id: "BOyWrF33hiR" - } + }] }, { id: "FPUgmtt8HRi", name: "Agency 1", - categoryOptionGroupSet: { + groupSets: [{ id: "bw8KHXzxd9i" - } + }] } ] }, @@ -567,20 +567,20 @@ name: "(2342 - Wat...)" } ], - groups: [ + categoryOptionGroups: [ { id: "CSPJnuxBAnz", name: "Partner 4", - categoryOptionGroupSet: { + groupSets: [{ id: "BOyWrF33hiR" - } + }] }, { id: "RGC9tURSc3W", name: "Agency 3", - categoryOptionGroupSet: { + groupSets: [{ id: "bw8KHXzxd9i" - } + }] } ] }, @@ -593,20 +593,20 @@ name: "(5433 - JH...)" } ], - groups: [ + categoryOptionGroups: [ { id: "NLV6dy7BE2O", name: "Agency 2", - categoryOptionGroupSet: { + groupSets: [{ id: "bw8KHXzxd9i" - } + }] }, { id: "yrIYjIn0aom", name: "Partner 3", - categoryOptionGroupSet: { + groupSets: [{ id: "BOyWrF33hiR" - } + }] } ] }, @@ -627,20 +627,20 @@ name: "(7654 - Pre...)" } ], - groups: [ + categoryOptionGroups: [ { id: "vNQlvpUamTo", name: "Partner 2", - categoryOptionGroupSet: { + groupSets: [{ id: "BOyWrF33hiR" - } + }] }, { id: "NLV6dy7BE2O", name: "Agency 2", - categoryOptionGroupSet: { + groupSets: [{ id: "bw8KHXzxd9i" - } + }] } ] }, @@ -655,20 +655,20 @@ "lastUpdated": "2014-09-18T11:03:00.174+0000" } ], - groups: [ + categoryOptionGroups: [ { id: "iadd8tHFS9C", name: "Partner 1", - categoryOptionGroupSet: { + groupSets: [{ id: "BOyWrF33hiR" - } + }] }, { id: "FPUgmtt8HRi", name: "Agency 1", - categoryOptionGroupSet: { + groupSets: [{ id: "bw8KHXzxd9i" - } + }] } ] } @@ -687,7 +687,7 @@ name: "(default)" } ], - groups: [] + categoryOptionGroups: [] } ] }; diff --git a/src/test/specs/mechanisms/mechanisms-service_spec.js b/src/test/specs/mechanisms/mechanisms-service_spec.js index 6373dbc..07eb8ff 100644 --- a/src/test/specs/mechanisms/mechanisms-service_spec.js +++ b/src/test/specs/mechanisms/mechanisms-service_spec.js @@ -12,8 +12,8 @@ describe('Mechanisms service', function () { ].join('&') ].join(''); - var defaultCategoryUrl = '/dhis/api/categoryOptions?paging=false&filter=categories.id:eq:GLevLNI9wkl&fields=id,name,organisationUnits%5Bid,name%5D,categoryOptionCombos%5Bid,name%5D,categoryOptionGroups%5Bid,name,categoryOptionGroupSet%5Bid%5D%5D'; - var fundingMechanismCategoryUrl = '/dhis/api/categoryOptions?paging=false&filter=categories.id:eq:SH885jaRe0o&fields=id,name,organisationUnits%5Bid,name%5D,categoryOptionCombos%5Bid,name%5D,categoryOptionGroups%5Bid,name,categoryOptionGroupSet%5Bid%5D%5D'; + var defaultCategoryUrl = '/dhis/api/categoryOptions?paging=false&filter=categories.id:eq:GLevLNI9wkl&fields=id,name,organisationUnits%5Bid,name%5D,categoryOptionCombos%5Bid,name%5D,categoryOptionGroups%5Bid,name,groupSets%5Bid%5D%5D'; + var fundingMechanismCategoryUrl = '/dhis/api/categoryOptions?paging=false&filter=categories.id:eq:SH885jaRe0o&fields=id,name,organisationUnits%5Bid,name%5D,categoryOptionCombos%5Bid,name%5D,categoryOptionGroups%5Bid,name,groupSets%5Bid%5D%5D'; var categoriesFromApi = fixtures.get('categories');