From 206fae749b2eb243314b1a9546759630c7e9e8fc Mon Sep 17 00:00:00 2001 From: "Lam, Doris T (393A)" Date: Wed, 22 Aug 2018 14:00:09 -0700 Subject: [PATCH 1/2] support getting bulk elements for tables based on spec --- src/services/ViewService.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/services/ViewService.js b/src/services/ViewService.js index f1320d4b4..5ca200091 100644 --- a/src/services/ViewService.js +++ b/src/services/ViewService.js @@ -163,23 +163,32 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer toGet = displayed; } } + toGetSet = new Set(toGet); if (view._contents && view._contents.operand) { var contents = view._contents.operand; for (var i = 0; i < contents.length; i++) { if (contents[i] && contents[i].instanceId) { - toGet.push(contents[i].instanceId); + toGetSet.add(contents[i].instanceId); } } } - if (view.specification) { + if (view.specification && view.specification.operand) { var specContents = view.specification.operand; for (var j = 0; j < specContents.length; j++) { if (specContents[j] && specContents[j].instanceId) { - toGet.push(specContents[j].instanceId); + toGetSet.add(specContents[j].instanceId); } } } - toGetSet = new Set(toGet); + if (isTable(view) && view.specification && view.specification.value) { + try { + var tableJson = JSON.parse(view.specification.value); + if (tableJson.body) { + collectTableSources(toGetSet, tableJson.body); + } + } catch (e) { + } + } $http.get(URLService.getViewElementIdsURL(reqOb)) .then(function(response) { var data = response.data.elementIds; @@ -204,6 +213,24 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer return deferred.promise; }; + var collectTableSources = function(sourceSet, body) { + var i, j, k; + for (i = 0; i < body.length; i++) { + var row = body[i]; + for (j = 0; j < row.length; j++) { + var cell = row[j]; + for (k = 0; k < cell.content.length; k++) { + var thing = cell.content[k]; + if (thing.type === 'Table' && thing.body) { + collectTableSources(thing.body); + } else if (thing.type === 'Paragraph' && thing.source) { + sourceSet.add(thing.source); + } + } + } + } + }; + /** * @ngdoc method * @name mms.ViewService#getDocumentViews From fbc7e1ad4ca5ada82d746b82734736bb86127856 Mon Sep 17 00:00:00 2001 From: "Lam, Doris T (393A)" Date: Tue, 28 Aug 2018 14:38:56 -0700 Subject: [PATCH 2/2] revert to using array until the end --- src/services/ViewService.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/services/ViewService.js b/src/services/ViewService.js index 5ca200091..b0f2c83ef 100644 --- a/src/services/ViewService.js +++ b/src/services/ViewService.js @@ -153,7 +153,6 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer .then(function(view) { var toGet = []; var results = []; - var toGetSet; if (view._displayedElementIds) { var displayed = view._displayedElementIds; if (!angular.isArray(displayed)) { @@ -163,12 +162,11 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer toGet = displayed; } } - toGetSet = new Set(toGet); if (view._contents && view._contents.operand) { var contents = view._contents.operand; for (var i = 0; i < contents.length; i++) { if (contents[i] && contents[i].instanceId) { - toGetSet.add(contents[i].instanceId); + toGet.push(contents[i].instanceId); } } } @@ -176,7 +174,7 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer var specContents = view.specification.operand; for (var j = 0; j < specContents.length; j++) { if (specContents[j] && specContents[j].instanceId) { - toGetSet.add(specContents[j].instanceId); + toGet.push(specContents[j].instanceId); } } } @@ -184,7 +182,7 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer try { var tableJson = JSON.parse(view.specification.value); if (tableJson.body) { - collectTableSources(toGetSet, tableJson.body); + collectTableSources(toGet, tableJson.body); } } catch (e) { } @@ -192,10 +190,9 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer $http.get(URLService.getViewElementIdsURL(reqOb)) .then(function(response) { var data = response.data.elementIds; - for (var i = 0; i < data.length; i++) { - toGetSet.add(data[i]); - } + toGet = toGet.concat(data); }).finally(function() { + var toGetSet = new Set(toGet); reqOb.elementIds = Array.from(toGetSet); ElementService.getElements(reqOb, weight, update) .then(function(data) { @@ -213,7 +210,7 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer return deferred.promise; }; - var collectTableSources = function(sourceSet, body) { + var collectTableSources = function(sources, body) { var i, j, k; for (i = 0; i < body.length; i++) { var row = body[i]; @@ -222,9 +219,9 @@ function ViewService($q, $http, $rootScope, URLService, ElementService, UtilsSer for (k = 0; k < cell.content.length; k++) { var thing = cell.content[k]; if (thing.type === 'Table' && thing.body) { - collectTableSources(thing.body); + collectTableSources(sources, thing.body); } else if (thing.type === 'Paragraph' && thing.source) { - sourceSet.add(thing.source); + sources.push(thing.source); } } }