Support for object literal routing parameters in Angular UI Router - angular-ui-router

I've been using Angular UI Router with a current project and have introduced some compound form inputs that I'd like to use as parameters in URL building for my routes. Essentially, the models I would like to parameterize are object literals, and I'm curious to know if ui-router has any ability to represent these as URL parameters.
In other parts of our application we have represented compound parameters with dot notation, e.g. ?field1.a=&field1.b=&field1.c, and I know some PHP frameworks make use of an array notation, e.g. ?field1[a]=field1[b]=field1[c] for representing multiple form fields associated with a single model.
From what I can tell, angular ui-router doesn't support similar. We are using v0.2.8, and at ~L131 there is a normalization function that will coerce object literals to their [object Object] string representation. It is this value that appears in URLs built with this kind of parameter, e.g. ?field1=[object Object].
I have considered lumping all the relevant fields together as a single parameter with a JSON string value as a workaround, e.g. ?filter={"field1":{}, "field2":{}, ...}, but wanted to check in to see if anyone has a better solution.
Thanks!

You have good timing. Typed parameter support was just merged into ui-router master. It isn't part of the 0.2.10 release, but should be part of 0.3.0 release, which is a few weeks away. If you build your own copy of bleeding-edge master and use this functionality now, please submit feedback to the ui-router project!
Here's the pull request that got merged with typed parameter support: https://github.com/angular-ui/ui-router/pull/1032
Read the docs regarding Type in https://github.com/angular-ui/ui-router/blob/master/src/urlMatcherFactory.js#L583

Related

How can I use isValidJSValue to validate a query variable in my client code?

I'm writing client-side code for an app that will query a GraphQL server. In a couple of places in my code, I'm passing around data that will eventually get turned into a query variable, so it needs to validate against a specific GraphQLInputType in my schema. On looking into some of the utilities that graphql-js provides, it looks like the isValidJSValue checker is exactly what I'm looking for, and its comments even mention that it's intended to be used to do just that.
The issue is that I don't have access to the GraphQL type I want to validate against as a JS object, which is what I'm pretty sure that function is looking for. I'm importing my schema (as an npm depdendency) as JSON, or I also have it in the schema notation. Is there some other utility I can use to get the JS type I need from one of those sources, and then use that to check my data with isValidJSValue? Or is there some other way I could go about this that I just haven't thought of?
You can use the JSON schema you have imported to construct an actual GraphQL schema instance using buildClientSchema here: https://github.com/graphql/graphql-js/blob/master/src/utilities/buildClientSchema.js
Then, it should be a simple matter of looking in the types field of the resulting schema to find your input type, and then calling isValidJSValue on it.
I'm curious, though - why validate the value on the client before sending it, rather than just relying on the validation the server will do?

Is it possible to specify parameters which go into the post body with blueprint?

I'd like to be able to document the parameters as if they were URL parameters, since I like how that bit of documentation renders a handy table. However, in my API, I would like those paremeters to plug into the JSON body rather than the URL. Is there a way to achieve this?
The dedicated syntax for describing, discussing (and thus also validating) message-body is in the making.
It will be based on the Markdown Syntax for Object Notation, similar to the actual URI Parameters description syntax (eventually these two should converge).
Also see related How to specify an optional element for a json request object and Is it possible to document what JSON response fields are? questions.

Symfony2 validation filters

In my Symfony 2 application I need to filter input before passing it on to validation [1], however, I can't seem to find any system within Symfony to do this.
The type of filtering I looking for is e.g. to be able to filter a dash out of a specific field before validating it. E.g. users can enter 123-123 but the only accepted value is 123123. Just as I can set up validation rules with constraints, I'm looking for something similar for filters.
[1] http://symfony.com/doc/current/book/validation.html
Nifr's answer is good but is missing of an important alternative that, if I understand correctly your question, seems to fit perfectly your needs.
You can use a hook that is pretty much an event listener: if something happens or is going to happen, it intercepts the event and redirect it to your function.
In this case, you need a PRE_BIND hook (is deprecated since 2.3 version, now it's called PRE_SUBMIT)
Read this if you need help about
Either write your own Validation Assert to filter and then proxy the other validators for this purpose ...
... or one or multiple Regex Asserts.
... or use a DataTransformer to transform/filter the input.
With the DataTransformer involved you could aswell consider creating a new FieldType which renders two inputs with a seperator like the date form-field does. ( if not not used with widget => single_text )

OData $filter substringof applied to a list of strings

I have an ASP.NET Web API Controller that exposes an IQueryable(Of String) - which is a list of descriptions. These fields can be in the order of tens of thousands, thus I use $top and $skip to only get a chunk of it - that works fine.
Now I am trying to filter these results, through the OData substringof('mydesc',Property) filter. As you can see, it requires for me to pass in a Property name on which to filter. However, since I'm returning a list of strings, I don't actually have any properties to filter on.
This causes the server to return errors like
No property or field 'tostring' exists in type 'String' - when called with $filter=substringof('asd',tostring).
If I change the call to $filter=substringof('asd',''), no errors are thrown, but no results either.
My question is, can I somehow format the $filter operator to find substrings within my list of strings, without looking for a property/field, or am I going to have to declare a class with a single property, just to enable filtering?
Things have changed since the last time I answered this. OData V3 has support for querying collection of primitives using '$it'. Asp.net Web API supports this syntax as well. For example, in your controller you can return IQueryable<string> and send a request like
$filter=substring('mydesc', $it) or
$filter=length($it) ge 5
etc. You can also expose collections of other primitives like IQueryable etc.
unfortunately declaring a class with a single property seems to be the only solution that I can think of. OData $filter doesn't have any support for something like the this parameter in C#
another less obvious approach is to expose a computed concatenated value representing the list, substringof could then be used to query the list as a single property value

extJS4 difference between Ext.Ajax and Ext.data.proxy.Ajax

I am new to the extJS framework and after looking at these two classes I am curious when it is better to use one or the other. Is one better for submitting and one for getting? In my current situation I am using a grid and the api says to use the proxy.Ajax which I trust. But lets say I want to send the JSON back to a database, would I be better off using Ext.Ajax?
Also I am rather new to JSON I understand that its just a string with regular expressions essentially. What is the best way to send the json straight to a database if I don’t want to store the json locally?
Ext.Ajax is used to make one-off requests to a server. You can use this for GET and POST requests.
Ext.data.proxy.Ajax is used by the data package, in particular, Ext.data.Store's. You cannot use this 'manually'. You must use it via the data package.

Resources