Esempio n. 1
0
        private static String GetLink <T>(T model, LinkAction action, String iconClass)
        {
            UrlHelper  url       = new UrlHelper(HttpContext.Current.Request.RequestContext);
            TagBuilder actionTag = new TagBuilder("a");
            TagBuilder icon      = new TagBuilder("i");

            actionTag.MergeAttribute("href", url.Action(action.ToString(), GetRouteValuesFor(model)));
            actionTag.AddCssClass(String.Format("{0}-action", action.ToString().ToLower()));
            icon.AddCssClass(iconClass);

            actionTag.InnerHtml = icon.ToString();

            return(actionTag.ToString());
        }
Esempio n. 2
0
        private void createLink(IEnumerable <Drawable> drawables, string text, string url = null, LinkAction linkType = LinkAction.External, string linkArgument = null, string tooltipText = null, Action action = null)
        {
            AddInternal(new DrawableLinkCompiler(drawables.OfType <SpriteText>().ToList())
            {
                TooltipText = tooltipText ?? (url != text ? url : string.Empty),
                Action      = action ?? (() =>
                {
                    switch (linkType)
                    {
                    case LinkAction.OpenBeatmap:
                        // TODO: proper query params handling
                        if (linkArgument != null && int.TryParse(linkArgument.Contains('?') ? linkArgument.Split('?')[0] : linkArgument, out int beatmapId))
                        {
                            game?.ShowBeatmap(beatmapId);
                        }
                        break;

                    case LinkAction.OpenBeatmapSet:
                        if (int.TryParse(linkArgument, out int setId))
                        {
                            game?.ShowBeatmapSet(setId);
                        }
                        break;

                    case LinkAction.OpenChannel:
                        try
                        {
                            channelManager?.OpenChannel(linkArgument);
                        }
                        catch (ChannelNotFoundException e)
                        {
                            Logger.Log($"The requested channel \"{linkArgument}\" does not exist");
                        }

                        break;

                    case LinkAction.OpenEditorTimestamp:
                    case LinkAction.JoinMultiplayerMatch:
                    case LinkAction.Spectate:
                        showNotImplementedError?.Invoke();
                        break;

                    case LinkAction.External:
                        game?.OpenUrlExternally(url);
                        break;

                    case LinkAction.OpenUserProfile:
                        if (long.TryParse(linkArgument, out long userId))
                        {
                            game?.ShowUser(userId);
                        }
                        break;

                    default:
                        throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
                    }
                }),
            });
Esempio n. 3
0
        public void AddLink(string text, string url, LinkAction linkType = LinkAction.External, string linkArgument = null, string tooltipText = null, Action <SpriteText> creationParameters = null)
        {
            AddInternal(new DrawableLinkCompiler(AddText(text, creationParameters).ToList())
            {
                TooltipText = tooltipText ?? (url != text ? url : string.Empty),
                Action      = () =>
                {
                    switch (linkType)
                    {
                    case LinkAction.OpenBeatmap:
                        // TODO: proper query params handling
                        if (linkArgument != null && int.TryParse(linkArgument.Contains('?') ? linkArgument.Split('?')[0] : linkArgument, out int beatmapId))
                        {
                            game?.ShowBeatmap(beatmapId);
                        }
                        break;

                    case LinkAction.OpenBeatmapSet:
                        if (int.TryParse(linkArgument, out int setId))
                        {
                            game?.ShowBeatmapSet(setId);
                        }
                        break;

                    case LinkAction.OpenChannel:
                        game?.OpenChannel(linkArgument);
                        break;

                    case LinkAction.OpenEditorTimestamp:
                    case LinkAction.JoinMultiplayerMatch:
                    case LinkAction.Spectate:
                        showNotImplementedError?.Invoke();
                        break;

                    case LinkAction.External:
                        host.OpenUrlExternally(url);
                        break;

                    case LinkAction.OpenUserProfile:
                        if (long.TryParse(linkArgument, out long userId))
                        {
                            game?.ShowUser(userId);
                        }
                        break;

                    default:
                        throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
                    }
                },
            });
Esempio n. 4
0
        public void AddLink(string text, string url, LinkAction linkType = LinkAction.External, string linkArgument = null, string tooltipText = null)
        {
            AddInternal(new DrawableLinkCompiler(AddText(text).ToList())
            {
                TooltipText = tooltipText ?? (url != text ? url : string.Empty),
                Action      = () =>
                {
                    switch (linkType)
                    {
                    case LinkAction.OpenBeatmap:
                        // todo: replace this with overlay.ShowBeatmap(id) once an appropriate API call is implemented.
                        if (int.TryParse(linkArgument, out int beatmapId))
                        {
                            Process.Start($"https://osu.ppy.sh/b/{beatmapId}");
                        }
                        break;

                    case LinkAction.OpenBeatmapSet:
                        if (int.TryParse(linkArgument, out int setId))
                        {
                            game?.ShowBeatmapSet(setId);
                        }
                        break;

                    case LinkAction.OpenChannel:
                        game?.OpenChannel(linkArgument);
                        break;

                    case LinkAction.OpenEditorTimestamp:
                    case LinkAction.JoinMultiplayerMatch:
                    case LinkAction.Spectate:
                        showNotImplementedError?.Invoke();
                        break;

                    case LinkAction.External:
                        Process.Start(url);
                        break;

                    default:
                        throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
                    }
                },
            });
Esempio n. 5
0
        public static IGridColumn <T> AddActionLink <T>(this IGridColumnCollection <T> column, LinkAction action)
        {
            if (Authorization.Provider != null && !Authorization.Provider.IsAuthorizedFor(CurrentAccountId, CurrentArea, CurrentController, action.ToString()))
            {
                return(null);
            }

            IGridColumn <T> gridColumn = column
                                         .Add()
                                         .SetWidth(20)
                                         .Encoded(false)
                                         .Sanitized(false)
                                         .Css("action-cell");

            AddLinkAction(gridColumn, action);

            return(gridColumn);
        }