Ejemplo n.º 1
0
 public override async Task FollowUp()
 {
     //If different existing spreadsheet is selected then we have to load worksheet list for it
     if (ActivityUI.UseExistingSpreadsheetOption.Selected && !string.IsNullOrEmpty(ActivityUI.ExistingSpreadsheetsList.Value))
     {
         var previousSpreadsheet = SelectedSpreadsheet;
         if (string.IsNullOrEmpty(previousSpreadsheet) || !string.Equals(previousSpreadsheet, ActivityUI.ExistingSpreadsheetsList.Value))
         {
             ActivityUI.ExistingWorksheetsList.ListItems = (await _googleSheet.GetWorksheets(ActivityUI.ExistingSpreadsheetsList.Value, GetGoogleAuthToken()))
                                                           .Select(x => new ListItem {
                 Key = x.Value, Value = x.Key
             })
                                                           .ToList();
             var firstWorksheet = ActivityUI.ExistingWorksheetsList.ListItems.First();
             ActivityUI.ExistingWorksheetsList.SelectByValue(firstWorksheet.Value);
         }
         SelectedSpreadsheet = ActivityUI.ExistingSpreadsheetsList.Value;
         ActivityUI.ExistingSpreadsheetsList.ListItems = (await _googleSheet.GetSpreadsheets(GetGoogleAuthToken())).Select(x => new ListItem {
             Key = x.Value, Value = x.Key
         }).ToList();
     }
     else
     {
         ActivityUI.ExistingWorksheetsList.ListItems.Clear();
         ActivityUI.ExistingWorksheetsList.selectedKey = string.Empty;
         ActivityUI.ExistingWorksheetsList.Value       = string.Empty;
         SelectedSpreadsheet = string.Empty;
     }
 }
Ejemplo n.º 2
0
        public override async Task FollowUp()
        {
            CrateSignaller.ClearAvailableCrates();

            List <Crate> crates       = new List <Crate>();
            var          googleAuth   = GetGoogleAuthToken();
            var          spreadsheets = await _googleApi.GetSpreadsheets(googleAuth);

            ActivityUI.SpreadsheetList.ListItems = spreadsheets
                                                   .Select(x => new ListItem {
                Key = x.Value, Value = x.Key
            })
                                                   .ToList();

            var selectedSpreadsheet = ActivityUI.SpreadsheetList.selectedKey;

            if (!string.IsNullOrEmpty(selectedSpreadsheet))
            {
                //This chunk here is about removing a selection if a spreadsheet was deleted but at the same time it was chosen in UI
                if (ActivityUI.SpreadsheetList.ListItems.All(x => x.Key != selectedSpreadsheet))
                {
                    ActivityUI.SpreadsheetList.selectedKey = null;
                    ActivityUI.SpreadsheetList.Value       = null;
                }
            }

            //If spreadsheet selection is cleared we hide worksheet DDLB
            if (string.IsNullOrEmpty(ActivityUI.SpreadsheetList.selectedKey))
            {
                ActivityUI.HideWorksheetList();
                StoredSelectedSheet = null;
            }
            else
            {
                var previousValues = StoredSelectedSheet;
                //Spreadsheet was changed - populate the list of worksheets and select first one
                if (previousValues == null || previousValues.Key != ActivityUI.SpreadsheetList.Value)
                {
                    var worksheets = await _googleApi.GetWorksheets(ActivityUI.SpreadsheetList.Value, googleAuth);

                    //We show worksheet list only if there is more than one worksheet
                    if (worksheets.Count > 1)
                    {
                        ActivityUI.ShowWorksheetList();
                        ActivityUI.WorksheetList.ListItems = worksheets.Select(x => new ListItem {
                            Key = x.Value, Value = x.Key
                        }).ToList();
                        var firstWorksheet = ActivityUI.WorksheetList.ListItems.First();
                        ActivityUI.WorksheetList.SelectByKey(firstWorksheet.Key);
                    }
                    else
                    {
                        ActivityUI.HideWorksheetList();
                    }
                }
                //Retrieving worksheet headers to make them avaialble for downstream activities
                var selectedSpreasheetWorksheet = new KeyValueDTO(ActivityUI.SpreadsheetList.Value,
                                                                  ActivityUI.WorksheetList.IsHidden
                                                                   ? string.Empty
                                                                   : ActivityUI.WorksheetList.Value);
                var columnHeaders = await _googleApi.GetWorksheetHeaders(selectedSpreasheetWorksheet.Key, selectedSpreasheetWorksheet.Value, googleAuth);

                StoredSelectedSheet = selectedSpreasheetWorksheet;
                var table = await GetSelectedSpreadSheet();

                var hasHeaderRow = TryAddHeaderRow(table);
                Storage.ReplaceByLabel(Crate.FromContent(GetRuntimeCrateLabel(), new StandardTableDataCM {
                    Table = table, FirstRowHeaders = hasHeaderRow
                }));

                CrateSignaller.MarkAvailableAtRuntime <StandardTableDataCM>(GetRuntimeCrateLabel(), true)
                .AddFields(columnHeaders.Select(x => new FieldDTO(x.Key)));

                //here was logic responsible for handling one-row tables but it was faulty. It's main purpose was to spawn fields like "value immediatly below of" in a StandardPayload.
                //You might view TabularUtilities.PrepareFieldsForOneRowTable for reference
            }
        }