Exemplo n.º 1
0
        public IActionResult DataPicker([FromQuery] int docId, [FromQuery] int?pageIndex,
                                        [FromQuery] string?oldPath, [FromQuery] string target, [FromQuery] bool multiplesCanBePicked)
        {
            var sampleData = _fileDatabase.GetSampleData();
            var project    = _fileDatabase.GetDocumentById(docId);

            string[]? repeat = null;
            if (pageIndex is not null)
            {
                var page = project.Pages[pageIndex.Value];
                if (page.RepeatMode.Repeats)
                {
                    repeat = page.RepeatMode.DataPath;
                }
            }

            var prev = Array.Empty <string>();

            if (!string.IsNullOrWhiteSpace(oldPath))
            {
                prev = oldPath.Split('.');
            }

            var tree = JsonDataReader.BuildDataSourcePicker(project, sampleData, prev, repeat, pageIndex, multiplesCanBePicked);
            var list = JsonDataReader.FlattenTree(tree);

            var model = new DataSourceViewModel
            {
                Nodes = list, Target = target
            };

            return(PartialView("DataPathPicker", model) !);
        }
Exemplo n.º 2
0
        public void array_data_should_be_selectable_when_multi_mode_is_on()
        {
            var lastPath = new string[] { };
            var p        = Strings.Separator;

            var nodes = JsonDataReader.BuildDataSourcePicker(SampleProjectFiles.BasicFile, SampleData.Standard, lastPath, null, 0, true);

            Assert.That(nodes, Is.Not.Null, "Failed to extract picker data");

            // Check pickable paths are present
            var claimantMailCode = nodes.X("").X("Claimant").X("MailingAddress").X("Country").N("Code");

            Assert.That(claimantMailCode?.CanBePicked, Is.True, "pickable data is not valid");
            Assert.That(claimantMailCode?.DataPath, Is.EqualTo($"{p}Claimant{p}MailingAddress{p}Country{p}Code"), "data path doesn't match node path");
            Assert.That(claimantMailCode?.Depth, Is.EqualTo(4), "incorrect depth in data path");

            // Check object paths are not pickable
            var claimantMailCountry = nodes.X("").X("Claimant").X("MailingAddress").N("Country");

            Assert.That(claimantMailCountry?.CanBePicked, Is.False, "non-pickable data is not valid");

            // With multiple-mode set to true, the reclaims should be pickable
            var reclaims = nodes.X("").N("Reclaims");

            Assert.That(reclaims?.CanBePicked, Is.True, "multiple data was not pickable, but should have been");


            // Should be able to flatten nodes
            var flattened = JsonDataReader.FlattenTree(nodes).ToList();

            // Nothing should be pre-selected as we gave a null path
            var selected = flattened.Where(n => n.Selected).ToList();

            Assert.That(selected, Is.Empty, "There were selected items with no selection path given");

            // Only level-1 nodes should be expanded
            var wrongExpansions = flattened.Where(n => n.Expanded != (n.Depth == 0)).ToList();

            Assert.That(wrongExpansions, Is.Empty, "Some expansions were wrong");
        }