<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Linq.Expressions;
using Signum.Utilities;
using System.Web.Mvc.Html;
using Signum.Entities;
using Signum.Entities.Reflection;

namespace Signum.Web
{
    public class Item
    {
        public FindOptions FindOptions { get; set; }
        public string ManualA {get; set;} //Specify all the tag string <a href='http://www.signumframework.com'>Signum</a>
        public string ManualHref {get; set;} //Specify the href element to be inserted in an A tag with the specified Title and Text
        public string Class { get; set; }
        /// <summary>
        /// Shortcut for "FindOptions = new FindOptions {QueryName = value}"
        /// </summary>
        public object QueryName 
        { 
            set 
            { 
                FindOptions = new FindOptions { QueryName = value }; 
            } 
        }
        
        string text;
        public string Text
        {
            get
            { 
                return text ??
                       ((FindOptions != null && FindOptions.QueryName != null) ?
                            (Navigator.Manager.QuerySettings[FindOptions.QueryName].TryCC(qs => qs.UrlName) ?? "") :
                            ""); 
            }
            set { text = value; }
        }

        string title;
        public string Title
        {
            get { return title ?? Text; }
            set { title = value; }
        }

        public List<Item> SubItems;

        public bool IsVisible()
        {
            if (SubItems != null && SubItems.Count > 0)
                return SubItems.Exists(mi => mi.IsVisible());

            if (FindOptions != null)
                return Navigator.IsFindable(FindOptions.QueryName);

            return ManualHref.HasText() || ManualA.HasText();
        }

        public bool CurrentPage(string link, string currentUrl)
        {
            if (!link.HasText() || !currentUrl.HasText())
                return false;
            return currentUrl.EndsWith(link);
        }

        public string ToString(string currentUrl)
        {
            StringBuilder sb = new StringBuilder();
            if (IsVisible())
            {
                sb.AppendLine("<li>");
                if (ManualHref.HasText())
                {
                    sb.AppendLine("<a href=\"{0}\" title=\"{1}\" class=\"{2}\">{3}</a>".Formato(
                        ManualHref,
                        Title,
                        CurrentPage(ManualHref, currentUrl) ? Class + " active": Class,
                        Text));
                }
                else if (ManualA.HasText())
                {
                    sb.AppendLine(ManualA);
                }
                else
                {
                    sb.AppendLine("<a href=\"{0}\" title=\"{1}\" class=\"{2}\">{3}</a>".Formato(
                        Navigator.FindRoute(FindOptions.QueryName) + FindOptions.ToString(false, true, "?"),
                        Title,
                        CurrentPage(Navigator.FindRoute(FindOptions.QueryName) + FindOptions.ToString(false, true, "?"), currentUrl) ? Class + " active" : Class,
                        Text));
                }
            }
            else
            {
                if (FindOptions == null && ManualA == null && ManualHref == null)
                    sb.AppendLine("<li>{1}".Formato(Text));
            }

            return sb.ToString();
        }
    }


    public class OrderedMenu {
        string currentUrl;
        public OrderedMenu() {
        }
        public string ToString(string currentUrl) {
            StringBuilder sb = new StringBuilder();
            this.currentUrl = currentUrl;
            sb.Append(this.ToString(0));
            return sb.ToString();
        }

        private string ToString(int i) {
            StringBuilder sb = new StringBuilder();
            if (node != null)
                sb.Append(NodeToString(i, children == null ? 0 : children.Count)); // + NodeToString(i, children.Count)
           /* else {
                sb.Append("<li>Unknown</li>");
            }*/
            if (children != null && children.Count > 0)
            {
                if (i == 0)
                    sb.AppendLine("<ul class='nav'>");
                else
                    sb.AppendLine("<ul{0}>".Formato((i > 0) ? " class='submenu'" : ""));
                foreach (OrderedMenu menu in children)
                {
                    sb.Append(menu.ToString(i+1));
                }
                sb.Append("</ul>");<commit_msg>(TFS CS 4837)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Linq.Expressions;
using Signum.Utilities;
using System.Web.Mvc.Html;
using Signum.Entities;
using Signum.Entities.Reflection;

namespace Signum.Web
{
    public class Item
    {
        public FindOptions FindOptions { get; set; }
        public string ManualA {get; set;} //Specify all the tag string <a href='http://www.signumframework.com'>Signum</a>
        public string ManualHref {get; set;} //Specify the href element to be inserted in an A tag with the specified Title and Text
        public string Class { get; set; }
        /// <summary>
        /// Shortcut for "FindOptions = new FindOptions {QueryName = value}"
        /// </summary>
        public object QueryName 
        { 
            set 
            { 
                FindOptions = new FindOptions { QueryName = value }; 
            } 
        }
        
        string text;
        public string Text
        {
            get
            { 
                return text ??
                       ((FindOptions != null && FindOptions.QueryName != null) ?
                            (Navigator.Manager.QuerySettings[FindOptions.QueryName].TryCC(qs => qs.UrlName) ?? "") :
                            ""); 
            }
            set { text = value; }
        }

        string title;
        public string Title
        {
            get { return title ?? Text; }
            set { title = value; }
        }

        public List<Item> SubItems;

        public bool IsVisible()
        {
            if (SubItems != null && SubItems.Count > 0)
                return SubItems.Exists(mi => mi.IsVisible());

            if (FindOptions != null)
                return Navigator.IsFindable(FindOptions.QueryName);

            return ManualHref.HasText() || ManualA.HasText();
        }

        public bool CurrentPage(string link, string currentUrl)
        {
            if (!link.HasText() || !currentUrl.HasText())
                return false;
            return currentUrl.EndsWith(link);
        }

        public string ToString(string currentUrl)
        {
            StringBuilder sb = new StringBuilder();
            if (IsVisible())
            {
                sb.AppendLine("<li>");
                if (ManualHref.HasText())
                {
                    sb.AppendLine("<a href=\"{0}\" title=\"{1}\" class=\"{2}\">{3}</a>".Formato(
                        ManualHref,
                        Title,
                        CurrentPage(ManualHref, currentUrl) ? Class + " active": Class,
                        Text));
                }
                else if (ManualA.HasText())
                {
                    sb.AppendLine(ManualA);
                }
                else
                {
                    sb.AppendLine("<a href=\"{0}\" title=\"{1}\" class=\"{2}\">{3}</a>".Formato(
                        Navigator.FindRoute(FindOptions.QueryName) + FindOptions.ToString(false, true, "?"),
                        Title,
                        CurrentPage(Navigator.FindRoute(FindOptions.QueryName) + FindOptions.ToString(false, true, "?"), currentUrl) ? Class + " active" : Class,
                        Text));
                }
            }
            else
            {
                if (FindOptions == null && ManualA == null && ManualHref == null)
                    sb.AppendLine("<li>{1}".Formato(Text));
            }

            return sb.ToString();
        }
    }


    public class OrderedMenu {
        string currentUrl;
        string @class;
        public OrderedMenu() {
        }
        public string ToString(string currentUrl)
        {
            return this.ToString(currentUrl, "");
        }

        public string ToString(string currentUrl, string @class) {
            StringBuilder sb = new StringBuilder();
            this.currentUrl = currentUrl;
            this.@class = @class;
            sb.Append(this.ToString(0));
            return sb.ToString();
        }

        private string ToString(int i) {
            StringBuilder sb = new StringBuilder();
            if (node != null)
                sb.Append(NodeToString(i, children == null ? 0 : children.Count)); // + NodeToString(i, children.Count)
           /* else {
                sb.Append("<li>Unknown</li>");
            }*/
            if (children != null && children.Count > 0)
            {
                if (i == 0)
                    sb.AppendLine("<ul class='{0}'>".Formato(this.@class));
                else
                    sb.AppendLine("<ul{0}>".Formato((i > 0) ? " class='submenu'" : ""));
                foreach (OrderedMenu menu in children)
                {
                    sb.Append(menu.ToString(i+1));
                }
                sb.Append("</ul>");
{'fraction_non_alphanumeric': 0.11959260814783704, 'fraction_numerical': 0.0040949181016379675, 'mean_word_length': 1.3565066798614547, 'pattern_counts': {'":': 2, '<': 35, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1425976', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2381, 'n_words': 551}