public async Task <CrudType> ButtonClickBeforeRepositoryActionAsync(ButtonSetup button, FormEditContext editContext, ButtonContext context)
        {
            await Task.Delay(1000);

            // this dictates how the repository must interpret the button action as after the button has been clicked
            return(CrudType.Refresh);
        }
 public async Task EnsureAuthorizedUserAsync(FormEditContext editContext, ButtonSetup button)
 {
     if (!await IsUserAuthorizedAsync(editContext, button))
     {
         throw new UnauthorizedAccessException();
     }
 }
 public OperationAuthorizationRequirement GetOperation(ButtonSetup button, FormEditContext editContext)
 {
     // use the RapidCMS.Core.Authorization.Operations to define what action this button represents
     // and how the authorization handler must challenge the current logged in user with to see whether they
     // can actually perform this action
     return(Operations.Delete);
 }
        public override async Task <CrudType> ButtonClickBeforeRepositoryActionAsync(ButtonSetup button, FormEditContext editContext, ButtonContext context)
        {
            var request = await _navigationHandler.CreateNavigationRequestAsync(button, editContext);

            if (request != null)
            {
                var collection = request.IsPage ? null : await _collectionResolver.ResolveSetupAsync(request.CollectionAlias);

                var usageType = request.IsNew ? UsageType.New
                    : request.IsEdit ? UsageType.Edit
                    : UsageType.View;

                NavigationState navigationState;

                if (request.IsPage)
                {
                    navigationState = new NavigationState(request.CollectionAlias, usageType);
                }
                else if (request.IsList)
                {
                    navigationState = new NavigationState(request.CollectionAlias, request.ParentPath, usageType);
                }
                else
                {
                    navigationState = new NavigationState(request.CollectionAlias, request.ParentPath, request.VariantAlias ?? collection !.EntityVariant.Alias, request.Id, usageType);
                }

                _navigationStateProvider.AppendNavigationState(navigationState);
            }

            return(CrudType.None);
        }
Esempio n. 5
0
        internal ButtonUI(IButtonActionHandler handler, ButtonSetup button, FormEditContext editContext)
        {
            ButtonId = button.ButtonId ?? throw new ArgumentNullException(nameof(button.ButtonId));

            Icon              = button.Icon;
            Label             = button.Label;
            ShouldConfirm     = handler.ShouldAskForConfirmation(button, editContext);
            IsPrimary         = button.IsPrimary;
            RequiresValidForm = handler.RequiresValidForm(button, editContext);
            IsVisible         = button.IsVisible;
            CustomType        = button.CustomType;
        }
Esempio n. 6
0
 public virtual Task <CrudType> ButtonClickBeforeRepositoryActionAsync(ButtonSetup button, FormEditContext editContext, ButtonContext context)
 {
     return(button.DefaultButtonType switch
     {
         DefaultButtonType.New => Task.FromResult(CrudType.Create),
         DefaultButtonType.SaveNew => Task.FromResult(CrudType.Insert),
         DefaultButtonType.SaveExisting => Task.FromResult(CrudType.Update),
         DefaultButtonType.Delete => Task.FromResult(CrudType.Delete),
         DefaultButtonType.Edit => Task.FromResult(CrudType.Edit),
         DefaultButtonType.Remove => Task.FromResult(CrudType.Remove),
         DefaultButtonType.Add => Task.FromResult(CrudType.Add),
         DefaultButtonType.Pick => Task.FromResult(CrudType.Pick),
         DefaultButtonType.Return => Task.FromResult(CrudType.Return),
         DefaultButtonType.Up => Task.FromResult(CrudType.Up),
         _ => Task.FromResult(CrudType.View),
     });
Esempio n. 7
0
    // go thru list - figure how many items in item list - add buttons as needed for each item
    private void AddButtons()
    {
        for (int i = 0; i < itemList.Count; i++)
        {
            Item item = itemList[i];

            //get a new obj from obj pool and store a ref to it in a new button
            GameObject newButton = buttonObjectPool.GetObject();

            //parent it to the panel w the vertical layout group on it = new button laid out correctly
            newButton.transform.SetParent(shopContentPanel, false);

            //tell the button to set itself up
            ButtonSetup sampleButton = newButton.GetComponent <ButtonSetup>();
            sampleButton.Setup(item, this);
        }
    }
        public void LoadActiveQuests()
        {
            displayObj = FindObjectOfType <QuestDisplay> ();
            // Find old buttons
            rt = GetComponent <RectTransform> ();
            ButtonSetup[] oldBtn = GetComponentsInChildren <ButtonSetup> ();

            foreach (ButtonSetup btn in oldBtn)
            {
                Destroy(btn.gameObject);
            }

            // Go through active events
            bool display = false;
            int  i       = 0;

            foreach (QuestEvent quest in QuestController.activeEvents)
            {
                if (quest.active == true)
                {
                    // Spawn button and pass the quest data
                    ButtonSetup newBtn = Instantiate(questButton, transform) as ButtonSetup;
                    newBtn.SetupQuestButton(quest);
                    i++;
                    // Make first item spawned display on the panel
                    if (!display)
                    {
                        newBtn.ActivateButton();
                        display = true;
                    }
                }
            }

            if (i == 0)
            {
                displayObj.DefaultDisplay();
            }

            rt.sizeDelta = new Vector2(0, 150 * i);
        }
Esempio n. 9
0
        public void Setup()
        {
            _button = new ButtonSetup
            {
                ButtonId = "123",
                Buttons  = new List <ButtonSetup>()
            };

            _collection = new CollectionSetup("icon", "color", "name", "alias", "repo")
            {
                ListEditor = new ListSetup(
                    null,
                    null,
                    null,
                    ListType.Table,
                    EmptyVariantColumnVisibility.Visible,
                    new List <PaneSetup>(),
                    new List <ButtonSetup>
                {
                    _button
                })
            };

            _collectionResolver = new Mock <ISetupResolver <CollectionSetup> >();
            _collectionResolver
            .Setup(x => x.ResolveSetupAsync(It.IsAny <string>()))
            .ReturnsAsync(_collection);

            _buttonActionHandler         = new Mock <IButtonActionHandler>();
            _buttonActionHandlerResolver = new Mock <IButtonActionHandlerResolver>();
            _buttonActionHandlerResolver
            .Setup(x => x.GetButtonActionHandler(It.IsAny <ButtonSetup>()))
            .Returns(_buttonActionHandler.Object);

            _authService     = new Mock <IAuthService>();
            _serviceProvider = new ServiceCollection().AddTransient <DataAnnotationEntityValidator>().BuildServiceProvider();

            _subject = new ButtonInteraction(_collectionResolver.Object, _buttonActionHandlerResolver.Object, _authService.Object);
        }
Esempio n. 10
0
 // this method is called just before the IRepository action is performed, based upon the CrudType this button returns
 public Task <CrudType> ButtonClickBeforeRepositoryActionAsync(ButtonSetup button, FormEditContext editContext, ButtonContext context)
 {
     if (editContext.Entity is Tag tag)
     {
         tag.Name = Guid.NewGuid().ToString()[0..6];
Esempio n. 11
0
        // ********************************************************************
        private IEnumerator DisplaySection()
        {
            Debug.Log("Dispaying section " + m_sectionIndex + " out of " + m_currentFrame.sections.Count);

            // Initialize stuff for new section
            m_currentSection = m_currentFrame.sections[m_sectionIndex];
            m_displayIndex   = 0;

            LogManager.Log("DialoguePanel: DisplaySection " + m_currentSection.text,
                           LogCategory.UI,
                           LogSeverity.LOG,
                           "Dialogue",
                           gameObject);

            m_currentTextSettings = new DialogueTextSettings();
            m_currentTextSettings.Merge(m_currentFrame.character.textSettings);
            m_currentTextSettings.Merge(m_currentSection.textSettings);


            Dictionary <char, float> textSymbolTime = new Dictionary <char, float>();

            // Get settings from character
            for (int i = 0; i < m_currentTextSettings.textSymbolTime.Count; ++i)
            {
                textSymbolTime[m_currentTextSettings.textSymbolTime[i].symbol] = m_currentTextSettings.textSymbolTime[i].time;
            }

            // Print text until we're done
            if (m_currentSection.text != null)
            {
                float textSpeed     = m_defaultTextSpeed * m_currentTextSettings.textSpeed;
                float secondsToWait = 1.0f / textSpeed;

                int    side           = -1;
                string currentSpecial = "";

                if (m_currentFrame.character.portrait != null)
                {
                    side = (int)m_currentFrame.portraitSide;
                    // Set portrait emotion
                    m_characterAnimator[side].SetInteger("Emotion", (int)m_currentSection.emotion);
                    // Set special animation triggers
                    if (m_currentSection.triggerAnimation > 0)
                    {
                        currentSpecial = "Special-" + m_currentSection.triggerAnimation;
                        m_characterAnimator[side].SetTrigger("Special-" + m_currentSection.triggerAnimation);
                    }
                    else
                    {
                        // Set portrait to talking animation ONLY if no special animation is playing.
                        m_characterAnimator[side].SetBool("Talk", true);
                    }
                }

                while (m_displayIndex < m_currentSection.text.Length)
                {
                    char  currentChar          = m_currentSection.text[m_displayIndex];
                    float currentSecondsToWait = secondsToWait;
                    if (textSymbolTime.ContainsKey(currentChar))
                    {
                        currentSecondsToWait = textSymbolTime[currentChar];
                    }

                    // if we were playing a special animation, see if it is time to start the talk animation
                    if (!currentSpecial.NullOrEmpty())
                    {
                        if (!m_characterAnimator[side].GetCurrentAnimatorStateInfo(1).IsName(currentSpecial))
                        {
                            currentSpecial = "";
                            m_characterAnimator[side].SetBool("Talk", true);
                        }
                    }

                    PrintText();
                    if (!m_shouldSkip)
                    {
                        yield return(new WaitForSeconds(currentSecondsToWait));
                    }
                }

                // Set portrait to idle animation
                if (m_currentFrame.character.portrait != null)
                {
                    side = (int)m_currentFrame.portraitSide;
                    m_characterAnimator[side].SetBool("Talk", false);
                }
            }

            // TODO: Wait for animation to finish if we triggered a special animation.

            // TODO: Some kind of manual "wait" system? (for cutscenes)

            // Load next section
            m_previousSections += m_currentSection.text;
            ++m_sectionIndex;
            if (m_sectionIndex < m_currentFrame.sections.Count)
            {
                StartCoroutine(DisplaySection());
            }
            else
            {
                m_shouldSkip = false;

                if (m_currentFrame.displayChoices)
                {
                    m_waitingForChoiceInput = true;

                    List <int> validLinks = new List <int>();
                    for (int i = 0; i < m_currentFrame.links.Count; ++i)
                    {
                        if (m_currentFrame.links[i].MeetsConditions())
                        {
                            validLinks.Add(i);
                        }
                    }
                    //Debug.Log("Choices found for frame " + m_currentFrame.id + ": " + validLinks.Count);
                    for (int i = 0; i < validLinks.Count; ++i)
                    {
                        int          index = validLinks[i];
                        DialogueLink link  = m_currentFrame.links[index];
                        //Debug.Log("Creating button for " + index + " link frame: " + link.linkedFrame.name);
                        GameObject choiceButton = GameObject.Instantiate(m_choiceButtonPrototype) as GameObject;
                        choiceButton.transform.SetParent(m_choiceRoot.transform);
                        if (i == 0 && InputManager.controlScheme == ControlScheme.GAMEPAD)
                        {
                            firstSelected = choiceButton.GetComponentInChildren <Button>();
                            SelectButton(firstSelected);
                        }

                        // Setup button
                        ButtonSetup setup = choiceButton.GetComponent <ButtonSetup>();
                        setup.SetText(link.text);
                        setup.SetIcon(link.icon);
                        if (link.animation)
                        {
                            setup.SetAnimation(link.animation);
                        }
                        AddListenerForChoice(choiceButton.transform.GetComponentInChildren <Button>(), link);
                        m_choices.Add(choiceButton.GetComponent <Animator>());
                    }

                    StartCoroutine(ShowChoices(true));
                }
                else
                {
                    LogManager.Log("DialoguePanel: Setting m_waitingForNextFrame = true for " + m_currentFrame,
                                   LogCategory.UI,
                                   LogSeverity.LOG,
                                   "Dialogue",
                                   gameObject);
                    m_waitingForNextFrame = true;
                    m_waitingIcon.SetActive(true);
                }
            }

            yield return(null);
        }
Esempio n. 12
0
        public Task <bool> IsUserAuthorizedAsync(FormEditContext editContext, ButtonSetup button)
        {
            var handler = _buttonActionHandlerResolver.GetButtonActionHandler(button);

            return(IsUserAuthorizedAsync(handler.GetOperation(button, editContext), editContext.Entity));
        }
Esempio n. 13
0
 public override Task <CrudType> ButtonClickBeforeRepositoryActionAsync(ButtonSetup button, FormEditContext editContext, ButtonContext context)
 => _mediator.NotifyEventAsync(this, new PaneRequestEventArgs(typeof(TSidePane), editContext, context));
 public IButtonActionHandler GetButtonActionHandler(ButtonSetup button)
 {
     return(_serviceProvider.GetService <IButtonActionHandler>(button.ButtonHandlerType));
 }
Esempio n. 15
0
 public Task <bool> IsUserAuthorizedAsync(FormEditContext editContext, ButtonSetup button)
 {
     return(Task.FromResult(true));
 }
Esempio n. 16
0
 public Task EnsureAuthorizedUserAsync(FormEditContext editContext, ButtonSetup button)
 {
     return(Task.CompletedTask);
 }
Esempio n. 17
0
 public Task <bool> IsUserAuthorizedAsync(FormEditContext editContext, ButtonSetup button)
 {
     throw new NotImplementedException("This method is not implemented in ApiAuthService as it makes no sense here.");
 }
 public bool ShouldAskForConfirmation(ButtonSetup button, FormEditContext editContext)
 {
     // triggers a confirm
     return(false);
 }
 public bool RequiresValidForm(ButtonSetup button, FormEditContext editContext)
 {
     // enables this button to block the action when the form associated with the button is not valid
     return(false);
 }
 public bool IsCompatible(ButtonSetup button, FormEditContext editContext)
 {
     // check if the button is compatible with the current view and hide it when it is not compatible
     return(true);
 }
Esempio n. 21
0
 public Task <NavigationRequest?> CreateNavigationRequestAsync(ButtonSetup button, FormEditContext editContext)
 {
     // this method can return a NavigationRequest to instruct the CMS to go to that page
     // if null is returned, the action is canceled.
     return(Task.FromResult(NavigationRequest.NavigateToCreateNewEntity("person", default)) !);
 }
Esempio n. 22
0
 public Task ButtonClickAfterRepositoryActionAsync(ButtonSetup button, FormEditContext editContext, ButtonContext context)
 {
     return(Task.CompletedTask);
 }
 public Task ButtonClickAfterRepositoryActionAsync(ButtonSetup button, FormEditContext editContext, ButtonContext context)
 {
     // this method is invoked after the repository has performed their action
     return(Task.CompletedTask);
 }