Exemplo n.º 1
0
        public override async Task FollowUp()
        {
            if (!string.IsNullOrEmpty(ActivityUI.StatTypesList.Value))
            {
                var previousGroup = SelectedStatType;
                if (string.IsNullOrEmpty(previousGroup) || !string.Equals(previousGroup, ActivityUI.StatTypesList.Value))
                {
                    var propertyInfos = StatXUtilities.GetStatTypeProperties(ActivityUI.StatTypesList.Value);
                    ActivityUI.ClearDynamicFields();
                    foreach (var property in propertyInfos)
                    {
                        var t = property.PropertyType;
                        if (t.IsGenericType && typeof(IList <>).IsAssignableFrom(t.GetGenericTypeDefinition()) ||
                            t.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList <>)))
                        {
                            //render corresponding FieldList control for properties that are collections
                            ActivityUI.AvailableStatItemsList.Add(CreateFieldListBasedOnStatType());
                        }
                        else
                        {
                            ActivityUI.AvailableStatProperties.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(property.Name, property.Name, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                        }
                    }
                }
                SelectedStatType = ActivityUI.StatTypesList.Value;
            }
            else
            {
                ActivityUI.ClearDynamicFields();
                SelectedStatType = string.Empty;
            }

            SelectedStatGroup = ActivityUI.ExistingStatGroupList.Value;
            ActivityUI.ExistingStatGroupList.ListItems = (await _statXIntegration.GetGroups(StatXUtilities.GetStatXAuthToken(AuthorizationToken)))
                                                         .Select(x => new ListItem {
                Key = x.Name, Value = x.Id
            }).ToList();
            ActivityUI.ExistingStatGroupList.Value = SelectedStatGroup;
        }
Exemplo n.º 2
0
        public override async Task FollowUp()
        {
            if (!string.IsNullOrEmpty(ActivityUI.ExistingGroupsList.Value))
            {
                var previousGroup = SelectedGroup;
                if (string.IsNullOrEmpty(previousGroup) || !string.Equals(previousGroup, ActivityUI.ExistingGroupsList.Value))
                {
                    var stats = await _statXIntegration.GetStatsForGroup(StatXUtilities.GetStatXAuthToken(AuthorizationToken), ActivityUI.ExistingGroupsList.Value);

                    if (stats.Any(x => string.IsNullOrEmpty(x.Title)))
                    {
                        StatXUtilities.AddAdvisoryMessage(Storage);
                    }
                    else
                    {
                        if (Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault() != null)
                        {
                            ActivityUI.ExistingGroupStats.ListItems = stats.Select(x => new ListItem {
                                Key = string.IsNullOrEmpty(x.Title) ? x.Id : x.Title, Value = x.Id
                            }).ToList();
                        }
                        Storage.RemoveByLabel("Advisories");
                    }

                    ActivityUI.ExistingGroupStats.ListItems = stats
                                                              .Select(x => new ListItem {
                        Key = string.IsNullOrEmpty(x.Title) ? x.Id : x.Title, Value = x.Id
                    }).ToList();

                    var firstStat = stats.FirstOrDefault();
                    if (firstStat != null)
                    {
                        ActivityUI.ExistingGroupStats.SelectByValue(firstStat.Id);
                        ActivityUI.StatTitle.TextValue = firstStat.Title;
                        ActivityUI.StatNotes.TextValue = firstStat.Notes;
                        var statDTO = firstStat as GeneralStatWithItemsDTO;
                        if (statDTO != null)
                        {
                            if (statDTO.VisualType == StatTypes.PickList)
                            {
                                ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser("Current Index", "CurrentIndex", requestUpstream: true, groupLabelText: "Available Stat Properties"));
                            }
                            else
                            {
                                foreach (var item in statDTO.Items)
                                {
                                    ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(item.Name, item.Name, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                                }
                            }
                        }
                        else
                        {
                            ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(string.IsNullOrEmpty(firstStat.Title) ? firstStat.Id : firstStat.Title, string.IsNullOrEmpty(firstStat.Title) ? firstStat.Id : firstStat.Title, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                        }
                    }
                }
                SelectedGroup = ActivityUI.ExistingGroupsList.Value;
                //refresh statx groups
                ActivityUI.ExistingGroupsList.ListItems = (await _statXIntegration.GetGroups(StatXUtilities.GetStatXAuthToken(AuthorizationToken)))
                                                          .Select(x => new ListItem {
                    Key = x.Name, Value = x.Id
                }).ToList();
                ActivityUI.ExistingGroupsList.Value = SelectedGroup;
            }
            else
            {
                ActivityUI.StatTitle.Value = string.Empty;
                ActivityUI.StatNotes.Value = string.Empty;
                ActivityUI.ExistingGroupStats.ListItems.Clear();
                ActivityUI.ExistingGroupStats.selectedKey = string.Empty;
                ActivityUI.ExistingGroupStats.Value       = string.Empty;
                SelectedGroup = string.Empty;
            }

            if (!string.IsNullOrEmpty(ActivityUI.ExistingGroupStats.Value))
            {
                var previousStat = SelectedStat;
                var stats        = await _statXIntegration.GetStatsForGroup(StatXUtilities.GetStatXAuthToken(AuthorizationToken), ActivityUI.ExistingGroupsList.Value);

                if (stats.Any(x => string.IsNullOrEmpty(x.Title)))
                {
                    StatXUtilities.AddAdvisoryMessage(Storage);
                }
                else
                {
                    if (Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault() != null)
                    {
                        ActivityUI.ExistingGroupStats.ListItems = stats.Select(x => new ListItem {
                            Key = string.IsNullOrEmpty(x.Title) ? x.Id : x.Title, Value = x.Id
                        }).ToList();
                    }
                    Storage.RemoveByLabel("Advisories");
                }

                if (string.IsNullOrEmpty(previousStat) || !string.Equals(previousStat, ActivityUI.ExistingGroupStats.Value))
                {
                    var currentStat = stats.FirstOrDefault(x => x.Id == ActivityUI.ExistingGroupStats.Value);
                    if (currentStat != null)
                    {
                        ActivityUI.ClearDynamicFields();
                        var statDTO = currentStat as GeneralStatWithItemsDTO;
                        if (statDTO != null && statDTO.Items.Any())
                        {
                            if (statDTO.VisualType == StatTypes.PickList)
                            {
                                ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser("Current Index", "CurrentIndex", requestUpstream: true, groupLabelText: "Available Stat Properties"));
                            }
                            else
                            {
                                foreach (var item in statDTO.Items)
                                {
                                    ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(item.Name, item.Name, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                                }
                            }
                        }
                        else
                        {
                            ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(string.IsNullOrEmpty(currentStat.Title) ? currentStat.Id : currentStat.Title, string.IsNullOrEmpty(currentStat.Title) ? currentStat.Id : currentStat.Title, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                        }
                    }
                }

                #region Refresh Stat Items to Track for Changes in app
                SelectedStat = ActivityUI.ExistingGroupStats.Value;
                ActivityUI.ExistingGroupStats.ListItems = stats.Select(x => new ListItem {
                    Key = string.IsNullOrEmpty(x.Title) ? x.Id : x.Title, Value = x.Id
                }).ToList();
                ActivityUI.ExistingGroupStats.Value = SelectedStat;
                var statToCheck = stats.FirstOrDefault(x => x.Id == SelectedStat);


                //check for changes in statValue Array
                if (statToCheck != null)
                {
                    ActivityUI.ExistingGroupStats.selectedKey = string.IsNullOrEmpty(statToCheck.Title) ? statToCheck.Id : statToCheck.Title;
                    var statDTO = statToCheck as GeneralStatWithItemsDTO;
                    if (statDTO != null && statDTO.Items.Any())
                    {
                        var oldStatNames = ActivityUI.StatValues.Select(x => x.Name).ToList();
                        var newStatNames = new List <string>();

                        if (statDTO.VisualType != StatTypes.PickList)
                        {
                            newStatNames = statDTO.Items.Select(x => x.Name).ToList();

                            //recreate new items
                            var newItems         = newStatNames.Where(x => !oldStatNames.Contains(x)).ToList();
                            var oldItemsToDelete = oldStatNames.Where(x => !newStatNames.Contains(x)).ToList();

                            foreach (var item in oldItemsToDelete.ToList())
                            {
                                var itemToDelete = ActivityUI.StatValues.FirstOrDefault(x => x.Name == item);
                                if (itemToDelete != null)
                                {
                                    ActivityUI.StatValues.Remove(itemToDelete);
                                }
                            }

                            foreach (var item in newItems)
                            {
                                ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(item, item, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                            }
                        }
                    }
                    else
                    {
                        var currentTextSource = ActivityUI.StatValues.FirstOrDefault()?.Name;
                        if (currentTextSource != (string.IsNullOrEmpty(statToCheck.Title) ? statToCheck.Id : statToCheck.Title))
                        {
                            ActivityUI.StatValues?.Clear();
                            ActivityUI.StatValues.Add(UiBuilder.CreateSpecificOrUpstreamValueChooser(string.IsNullOrEmpty(statToCheck.Title) ? statToCheck.Id : statToCheck.Title, string.IsNullOrEmpty(statToCheck.Title) ? statToCheck.Id : statToCheck.Title, requestUpstream: true, groupLabelText: "Available Stat Properties"));
                        }
                    }
                }

                #endregion
            }
            else
            {
                ActivityUI.StatTitle.Value = string.Empty;
                ActivityUI.StatNotes.Value = string.Empty;
                ActivityUI.ClearDynamicFields();
                ActivityUI.ExistingGroupStats.ListItems.Clear();
                ActivityUI.ExistingGroupStats.selectedKey = string.Empty;
                ActivityUI.ExistingGroupStats.Value       = string.Empty;
                SelectedStat = string.Empty;
            }
        }
        public override async Task FollowUp()
        {
            //Load DocuSign template again in case there are new templates available
            LoadDocuSignTemplates();
            var selectedTemplateId = SelectedTemplateId;

            //If template selection is cleared we should remove existing template fields
            if (string.IsNullOrEmpty(selectedTemplateId))
            {
                PreviousSelectedTemplateId = null;
                ActivityUI.ClearDynamicFields();
                Storage.RemoveByLabel(UserFieldsAndRolesCrateLabel);
                return;
            }
            if (selectedTemplateId == PreviousSelectedTemplateId)
            {
                return;
            }
            ActivityUI.ClearDynamicFields();
            PreviousSelectedTemplateId = selectedTemplateId;
            var docuSignConfiguration = DocuSignManager.SetUp(AuthorizationToken);
            var tabsAndFields         = DocuSignManager.GetTemplateRecipientsTabsAndDocuSignTabs(docuSignConfiguration, selectedTemplateId);
            var roles             = tabsAndFields.Item1.Where(x => x.Tags.Contains(DocuSignConstants.DocuSignSignerTag, StringComparison.InvariantCultureIgnoreCase)).ToArray();
            var userDefinedFields = tabsAndFields.Item1.Where(x => x.Tags.Contains(DocuSignConstants.DocuSignTabTag));
            var envelopeData      = tabsAndFields.Item2.ToLookup(x => x.Fr8DisplayType);

            //check for DocuSign default template names and add advisory json
            var hasDefaultNames = DocuSignManager.DocuSignTemplateDefaultNames(tabsAndFields.Item2);

            if (hasDefaultNames)
            {
                var advisoryCrate          = Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault();
                var currentAdvisoryResults = advisoryCrate == null ? new AdvisoryMessagesCM() : advisoryCrate.Content;

                var advisory = currentAdvisoryResults.Advisories.FirstOrDefault(x => x.Name == AdvisoryName);

                if (advisory == null)
                {
                    currentAdvisoryResults.Advisories.Add(new AdvisoryMessageDTO {
                        Name = AdvisoryName, Content = AdvisoryContent
                    });
                }
                else
                {
                    advisory.Content = AdvisoryContent;
                }

                Storage.Add(Crate.FromContent("Advisories", currentAdvisoryResults));
            }
            //Add TextSource control for every DocuSign role to activity UI
            ActivityUI.RolesFields.AddRange(roles.Select(x => UiBuilder.CreateSpecificOrUpstreamValueChooser(x.Key, x.Key, requestUpstream: true, specificValue: x.Value)));
            //Add TextSrouce control for every DocuSign template text field to activity UI
            ActivityUI.TextFields.AddRange(envelopeData[ControlTypes.TextBox].Select(x => UiBuilder.CreateSpecificOrUpstreamValueChooser(x.Name, x.Name, requestUpstream: true, specificValue: x.Value)));
            //Add RadioButtonGroup with respective options for every DocuSign template radio selection field to activity UI
            ActivityUI.RadioButtonGroupFields.AddRange(
                envelopeData[ControlTypes.RadioButtonGroup]
                .OfType <DocuSignMultipleOptionsTabDTO>()
                .Select(x => new RadioButtonGroup
            {
                GroupName = x.Name,
                Name      = x.Name,
                Label     = $"For the <strong>{x.Name}</strong>, use:",
                Radios    = x.Items.Select(y => new RadioButtonOption
                {
                    Name     = y.Value,
                    Value    = y.Value,
                    Selected = y.Selected
                })
                            .ToList()
            }));
            //Add CheckBox for every DocuSign template yes/no field to activity UI
            ActivityUI.CheckBoxFields.AddRange(envelopeData[ControlTypes.CheckBox].Select(x => new CheckBox {
                Name = x.Name, Label = x.Name, Selected = Convert.ToBoolean(x.Value)
            }));
            //Add DropDownList for every DocuSign template list selection field to activity UI
            ActivityUI.DropDownListFields.AddRange(
                envelopeData[ControlTypes.DropDownList]
                .OfType <DocuSignMultipleOptionsTabDTO>()
                .Select(x => new DropDownList
            {
                Name      = x.Name,
                Label     = $"For the <strong>{x.Name}</strong>, use:",
                ListItems = x.Items.Select(y => new ListItem
                {
                    Key      = string.IsNullOrEmpty(y.Value) ? y.Text : y.Value,
                    Value    = string.IsNullOrEmpty(y.Text) ? y.Value : y.Text,
                    Selected = y.Selected
                })
                            .ToList()
            }));

            Storage.ReplaceByLabel(Crate.FromContent(UserFieldsAndRolesCrateLabel, new KeyValueListCM(userDefinedFields.Concat(roles))));
        }