예제 #1
0
    // time picker

    private IEnumerator SetupTimePicker()
    {
        // current targset time picker tagsets
        List <string> timeTagsets = new List <string> {
            "Day of week (string)", "Month (string)", "Year", "Hour", "Day within month"
        };

        // get all time tagsets corresponding to list above
        List <Tag> timeTagsetsData = new List <Tag>();

        yield return(StartCoroutine(ViRMA_APIController.GetTagset("", (tagsetsData) => {
            for (int i = tagsetsData.Count - 1; i > -1; i--)
            {
                if (!timeTagsets.Contains(tagsetsData[i].Label))
                {
                    tagsetsData.RemoveAt(i);
                }
            }
            timeTagsetsData = tagsetsData;
        })));

        // populate tagsets with their children
        foreach (Tag tagsetData in timeTagsetsData)
        {
            yield return(StartCoroutine(ViRMA_APIController.GetTagset(tagsetData.Id.ToString(), (tagData) => {
                tagsetData.Children = tagData;
            })));
        }

        foreach (Tag timeTagset in timeTagsetsData)
        {
            // generate day of the week options
            if (timeTagset.Label == "Day of week (string)")
            {
                foreach (Transform weekdayObj in ui_weekdays.transform)
                {
                    ViRMA_UiElement uiElement = weekdayObj.GetComponent <ViRMA_UiElement>();
                    allTimeOptions.Add(uiElement);

                    string weekdayLabel = weekdayObj.GetComponentInChildren <Text>().text;
                    foreach (Tag weekdayTag in timeTagset.Children)
                    {
                        if (weekdayTag.Label.Substring(0, 3) == weekdayLabel)
                        {
                            uiElement.buttonData = weekdayTag;
                            weekdayObj.GetComponent <Button>().onClick.AddListener(() => ToggleTimeOption(uiElement));
                        }
                    }
                }
            }

            // generate hour options
            if (timeTagset.Label == "Hour")
            {
                foreach (Transform hourObj in ui_hours.transform)
                {
                    ViRMA_UiElement uiElement = hourObj.GetComponent <ViRMA_UiElement>();
                    allTimeOptions.Add(uiElement);
                    string hourLabel = hourObj.GetComponentInChildren <Text>().text;
                    int    hour      = int.Parse(hourLabel.Substring(0, hourLabel.IndexOf(":")));
                    foreach (Tag hourTag in timeTagset.Children)
                    {
                        if (hourTag.Label == hour.ToString())
                        {
                            uiElement.buttonData = hourTag;
                            hourObj.GetComponent <Button>().onClick.AddListener(() => ToggleTimeOption(uiElement));
                        }
                    }
                }
            }

            // generate date options
            if (timeTagset.Label == "Day within month")
            {
                foreach (Transform dateObj in ui_dates.transform)
                {
                    ViRMA_UiElement uiElement = dateObj.GetComponent <ViRMA_UiElement>();
                    allTimeOptions.Add(uiElement);
                    string dateLabel = dateObj.GetComponentInChildren <Text>().text;
                    int    date      = int.Parse(dateLabel);
                    foreach (Tag dateTag in timeTagset.Children)
                    {
                        if (dateTag.Label == date.ToString())
                        {
                            uiElement.buttonData = dateTag;
                            dateObj.GetComponent <Button>().onClick.AddListener(() => ToggleTimeOption(uiElement));
                        }
                    }
                }
            }

            // generate month options
            if (timeTagset.Label == "Month (string)")
            {
                foreach (Transform monthObj in ui_months.transform)
                {
                    ViRMA_UiElement uiElement = monthObj.GetComponent <ViRMA_UiElement>();
                    allTimeOptions.Add(uiElement);
                    string monthLabel = monthObj.GetComponentInChildren <Text>().text;
                    foreach (Tag monthTag in timeTagset.Children)
                    {
                        string shortMonthLabel = monthTag.Label.Substring(0, 3);
                        if (shortMonthLabel == monthLabel)
                        {
                            uiElement.buttonData = monthTag;
                            monthObj.GetComponent <Button>().onClick.AddListener(() => ToggleTimeOption(uiElement));
                        }
                    }
                }
            }

            // generate year options
            if (timeTagset.Label == "Year")
            {
                foreach (Transform yearObj in ui_years.transform)
                {
                    ViRMA_UiElement uiElement = yearObj.GetComponent <ViRMA_UiElement>();
                    allTimeOptions.Add(uiElement);
                    string yearLabel = yearObj.GetComponentInChildren <Text>().text;
                    foreach (Tag yearTag in timeTagset.Children)
                    {
                        if (yearLabel == yearTag.Label)
                        {
                            uiElement.buttonData = yearTag;
                            yearObj.GetComponent <Button>().onClick.AddListener(() => ToggleTimeOption(uiElement));
                        }
                    }
                }
            }

            // if any time options do not exist in the DB, then reflect that in the button style
            foreach (ViRMA_UiElement timeOption in allTimeOptions)
            {
                if (timeOption.buttonData == null)
                {
                    timeOption.GenerateBtnDefaults(ViRMA_Colors.lightGrey, Color.white, true);
                }
            }
        }
    }
예제 #2
0
    // direct filters
    public void FetchDirectFilterMetadata()
    {
        GameObject directFilterPrefab = Resources.Load("Prefabs/DirectFilterOptn") as GameObject;

        Transform directFilterParent = ui_directFilers.GetComponentInChildren <ViRMA_UIScrollable>().transform.GetChild(0);

        foreach (Transform child in directFilterParent)
        {
            Destroy(child.gameObject);
        }
        directFilterParent.DetachChildren();

        foreach (Query.Filter activeFilter in globals.queryController.activeFilters)
        {
            if (activeFilter.Type == "node")
            {
                int targetId = activeFilter.Ids[0];
                StartCoroutine(ViRMA_APIController.GetHierarchyTag(targetId, (tagData) => {
                    GameObject directFilterObj = Instantiate(directFilterPrefab, directFilterParent);
                    directFilterObj.GetComponent <ViRMA_DirectFilterOption>().directFilterData = tagData;
                    directFilterObj.GetComponent <ViRMA_DirectFilterOption>().labelText.text   = tagData.Label;
                    directFilterObj.GetComponent <ViRMA_DirectFilterOption>().filterType       = "node";
                }));
            }
            else if (activeFilter.Type == "tag")
            {
                int    parentIdIndex = activeFilter.FilterId.IndexOf("_");
                string parentId      = activeFilter.FilterId.Substring(parentIdIndex + 1);
                StartCoroutine(ViRMA_APIController.GetTagset(parentId, (tagsetData) => {
                    foreach (Tag tagData in tagsetData)
                    {
                        foreach (int id in activeFilter.Ids)
                        {
                            if (tagData.Id == id)
                            {
                                GameObject directFilterObj = Instantiate(directFilterPrefab, directFilterParent);
                                directFilterObj.GetComponent <ViRMA_DirectFilterOption>().filterType       = "tag";
                                directFilterObj.GetComponent <ViRMA_DirectFilterOption>().directFilterData = tagData;

                                string adjustLabel = tagData.Label;

                                // adjust appearance of hour tags as direct filters
                                if (tagData.Parent.Label == "Hour")
                                {
                                    if (tagData.Label.Length == 1)
                                    {
                                        adjustLabel = "0" + tagData.Label + ":00";
                                    }
                                    else
                                    {
                                        adjustLabel = tagData.Label + ":00";
                                    }
                                }

                                // adjust the appearance of date tags as direct filters
                                if (tagData.Parent.Label == "Day within month")
                                {
                                    if (tagData.Label == "1")
                                    {
                                        adjustLabel = "1st";
                                    }
                                    else if (tagData.Label == "2")
                                    {
                                        adjustLabel = "2nd";
                                    }
                                    else if (tagData.Label == "3")
                                    {
                                        adjustLabel = "3rd";
                                    }
                                    else
                                    {
                                        adjustLabel = tagData.Label + "th";
                                    }
                                }

                                directFilterObj.GetComponent <ViRMA_DirectFilterOption>().labelText.text = adjustLabel;
                            }
                        }
                    }
                }));
            }
        }
    }