Coder Social home page Coder Social logo

fabrik.common's People

Contributors

benfoster avatar tugberkugurlu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fabrik.common's Issues

CheckBoxListFor posted values weirdness

There seems to be a bug in CheckBoxListFor concerning the values used after postback.
I cant get my posted values persist on the checkboxes, and I think it is because of the following inconsistency.
For the record, I have applied the fix from #30
The viewbag holds my data for the checkboxes (mind the selected = true!):

            ViewBag.Sectors = sectors.Select(sector =>
                new SelectListItem
                {
                    Text = sector.Name,
                    Value = sector.Id.ToString(),
                    Selected = true 
                })
            .ToList();

And the helper is using these values ...

@Html.CheckBoxListFor(model => model.SiteNewsSectors, ViewBag.Sectors as IEnumerable<SelectListItem>, new { @class = "form-control" })

... to render everything as expected.
However if I do a submit, and my model is not validated the page is redisplayed, but this time without checked boxes while the list is populated the same way, but for some reason the 'items' parameter has a list without the selected properties set to true.
Another submit reverses this and everything is checked again... If selected is set to false the check boxes are always unchecked as expected. But I cant populate the list with some values set to true that way either (my original problem).

Hijax Extensions

Add HijaxAttribute and JsonStatusCodeResult currently in Fabrik.

var contacts = response.Content.ReadAsAsync<IEnumerable<contact>>().Result;

i'm having the issue in the above line as
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON
object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable
`1[ConsoleApplication1.contact]' because the type requires a JSON array (e.g. [1
,2,3]) to deserialize correctly.

give me a solution for this issue..

Compressor throws exception

return input.CopyToAsync(output)
.ContinueWith(task => output.Position = 0); // reset stream position back to 0

This line throws an exception because Position is not writeable (it's of type BufferManagerOutputStream

Does this even work?

In/NotIn extensions

    public static bool In<T>(this T t, params T[] values)
    {
        return values.Contains(t);
    }

    public static bool NotIn<T>(this T t, params T[] values)
    {
        return !In(t, values);
    }

MIssing Method

Hi,

Thanks very much for this, very good library. However, I'm having troubles with the build. It errors on this line:

var urlHelper = response.RequestMessage.GetUrlHelper();

In the PostResponseEnricher class. Any ideas?

Sitemap generates xml with utf-16 encoding.

The Sitemap genereator may still generate a sitemap with utf-16 encoding specified in the xml declaration because it uses XmlTextWriter to generate the xml which retrieves the encoding from the environment settings and will overwrite the content encoding declared in the XDocument.

I had to create a custom ActionResult using StringWriter rather than XmlTextWriter:

    public class Utf8StringWriter : StringWriter
    {
        public override Encoding Encoding
        {
            get { return new UTF8Encoding(false); }
        }
    }

    public class Utf8SitemapResult : ActionResult
    {
        private readonly IEnumerable<ISitemapItem> items;
        private readonly ISitemapGenerator generator;

        public Utf8SitemapResult(IEnumerable<ISitemapItem> items) : this(items, new SitemapGenerator())
        {

        }

        public Utf8SitemapResult(IEnumerable<ISitemapItem> items, ISitemapGenerator generator)
        {
            Ensure.Argument.NotNull(items, "items");
            Ensure.Argument.NotNull(generator, "generator");

            this.items = items;
            this.generator = generator;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;

            response.ContentType = "text/xml";
            response.ContentEncoding = Encoding.UTF8;

            using (var writer = new Utf8StringWriter())
            {
                var doc = generator.GenerateSiteMap(items);
                doc.Save(writer, SaveOptions.None);

                response.Write(writer);
            }
        }
    }

Failed to embed BZip2 from DotNetZip as Compressor

I've tried to use BZip2OutputStream from Ionic.BZip2 (DotNetZip) to implement my own compressor and I failed. I've ended up with output stream contains only 4 bytes and then the error occurs on client when receiving the answer.

I've implemented compressor as direct implementation of ICompressor interface, here's the method for compression:

public async Task Compress(Stream source, Stream compressed)
{
    using (BZip2OutputStream bzip = new BZip2OutputStream(compressed, true))
    {
        await source.CopyToAsync(bzip);
    }
}

BTW Ionic.Zlib.GZipStream works well instead of .NET GZipStream.

Correctly handle Q values.

The current implementation is incorrect, when dealing with Q values for the Accept-Encoding header.

For example, with this request...

GET /foo HTTP/1.1
Accept-Encoding: gzip;q=0

...GZip should NEVER be chosen. And this one...

GET /foo HTTP/1.1
Accept-Encoding: gzip;q=0.5, deflate;q=1

... should choose deflate.

See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3

Fortunately, this should be an easy fix (since your code is very well built); just replace lines 28-30 of CompressionHandler.cs with something like this:

var compressor = (from a in request.Headers.AcceptEncoding
                  let q = a.Quality ?? 1.0
                  where q > 0
                  join c in Compressors on a.Value.ToUpperInvariant() equals c.EncodingType.ToUpperInvariant()
                  orderby q descending
                  select c).FirstOrDefault();

Now, this still doesn't get it to 100%, because identity is a value that is allowed, which means no compression. I'm not sure what the best way to special-case that is, but I leave that as an exercise for the real developers. ;)

HtmlHelperExtensions should use TemplateInfo to generate element names

Helpers such as Html.CheckBoxListFor currently use ExpressionHelper.GetExpressionText(expression) to generate element names. This generates an incorrect name when using the helper within nested editor templates. E.g.

Index.cshtml:

@Html.EditorFor(model => model.Other)

EditorTemplates/Other.cshtml

@Html.CheckBoxListFor(model => model.Tags, Model.AvailableTags)

Should generate the field name Other.Tags but is actually just Tags.

The solution is to use TemplateInfo to get the full name:

var name = ExpressionHelper.GetExpressionText(expression);
var fullName = helper.ViewData.TemplateInfo.GetFullHtmlFieldName(name);

Localization in (Enum)CheckBoxListFor?

I've started using CheckBoxListFor and it's a life saver!
Today, I was searching for a way to apply localization. In specific, I am looking to localize enum values.

Is there a built-in way to do this with EnumCheckBoxListFor?

For example, given that I have the following enum:

public enum SomethingEnum
{
    [Display(Name = "Een")] // Dutch, but I want to introduce English and Dutch as localization options.
    ONE,
    [Display(Name = "Twee")] 
    TWO,
    [Display(Name = "Drie")]
    THREE
}

I've tried in two ways:

@Html.EnumCheckBoxListFor(model => model.SelectableSomethingEnums)

and

@Html.CheckBoxListFor(model => model.SelectedSomething, new SelectList(Model.SelectableSomethings, "Id", "Type"))

My ViewModel is something like this:

public class ViewModel
{
    // For use with CheckBoxListFor
    public IEnumerable<Something> SelectableSomethings { get; set; } 
    public int SelectedSomething{ get; set; }

    // For use with EnumCheckBoxListFor
    public IEnumerable<SomethingEnum> SelectableSomethingEnums{ get; set; } 
}

public class Something
{
    internal Something() { }

    public int Id { get; internal set; }
    public SomethingEnum Type { get; internal set; }
}

Is localization of enums currently supported? If so, in what way? If not, will it be added? :)

Deploy issue, can't run it on my computer

When I download it and try to run it (Fabrik.Common.Web.Example) on vs2013,
it's fails to build. After I fix the (*.dll) with nuget, it continues to fail
error1

Nothing seems to be able to run the solution.

Enum CheckboxList helper

    public static MvcHtmlString EnumCheckBoxListFor<TModel, TEnum>(this HtmlHelper<TModel> html, Expression<Func<TModel, IEnumerable<TEnum>>> expression)
    {
        Ensure.Argument.Is(typeof(TEnum).IsEnum, "Must be a valid Enum type.");

        var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);

        var values = from v in Enum.GetValues(typeof(TEnum)).Cast<TEnum>()
                     select new
                     {
                         Text = v.ToString().SeparatePascalCase(),
                         Value = v.ToString()
                     };

        var selectList = new SelectList(values, "Value", "Text");
        return html.CheckBoxListFor(expression, selectList);
    }

MediaTypeViewResult formatter does not support header values with quality parameter

A MediatypeViewResultFormatter with supported media type text/html should handle text/html;q=0.7.

Ideally we would parse the quality value but as a minimum should change the matching logic to use string.contains:

var supportedMediaType = SupportedMediaTypes.Any(
      mt => acceptTypes.Any(at => at.Contains(mt, StringComparison.OrdinalIgnoreCase)));

We also need to provide a default formatter or at least return a 415 (unsupported media type) if none of the formatters are matched.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.