Couple things:
1) There's definitely weirdness when dealing with trailing-slash URLs.
dateplanner/week/ would be routed by ui-router to anything like
dateplanner/week/:id instead of dateplanner/week, and I've run into issues
with stuff like that. In routes that end in a :id that I mean to route to
backend stuff, I tend to do validations on $stateParams (is a number, etc),
mainly because users who type in the wrong stuff direct to the URL bar or
click on a badly-formed link should get a gentle "hey, watch out" page with
help and bug-report links rather than a page that's misformed because I'm
trying to load profiles/NaN off my back end REST server.
2) I'd consider making a week/current and day/today route. If you put them
in there (I think earlier than the wildcard'd routes, I don't actually know
how ui-router handles fall-throughs and route matching rules), you can just
use special-case controllers for current and today.
I do something similar to (2) with user-profile stuff. So /profiles/123
goes to profiles number 123, but the controller on /profiles/me just says
something _like_:
function profilesMeController($scope, $state) {
$state.go("profiles.detail({profileId:
"+$scope.currentUser.profileId+"})");
}
Which will redirect to the appropriate profiles/:id route. You could do
something similar - in the today controller, calculate the appropriate
params and issue a $state.go.
You could probably attach this behavior to dateplanner/week directly
instead of defining it as abstract.
Orrr, you could do a $rootScope.$on('$stateChangeStart'), and cancel a
state change to your today routes and re-emit the same thing on as I
suggested above. I'm not wild about this approach personally, mainly
because I like to have all the calls that would influence routing decisions
made in the appropriate config block, instead of attached to $rootScope
with listeners.
Hope this helps
e
On Sun, Aug 3, 2014 at 1:38 PM, bastienneJS <[email protected]>
wrote:
> I have searched this forum, google and Stackoverflow, built sites with
> angularjs, github etc...
>
> There are no samples or helpful material to fullfil my requirements.
>
> That is my plunker: http://plnkr.co/edit/GMfMcXgHguYjFYoxWEaM?p=preview
>
> I like angularJS so far but the 'ui router' module seems really a
> limitation for what I need or I do it totally wrong.
>
> If you look at the plunker there is a planner button with 3 views
> day/week/month.
>
> For all 3 states day/week/month I would like to have these 3 url`s in the
> browser url bar e.g.:
>
> /#/projects/1/dateplanner/day/"CurrentDate"
> /#/projects/2/dateplanner/week/"FirstDayOfWeek"
> /#/projects/3/dateplanner/month/7
>
> At the moment I have "hacked" the day url but there are still many "day
> state" scenarios where the passed current date gets lost from the url e.g.
>
> - switching between "date planner" and "document browser" button the url
> is then /#/projects/43/dateplanner/day/-- (current date is missing)
> even worse is that my day "hack" has introduced a bad behavior that is
> the day controller shows the alert('daily') TWO times ?!
> - Manipulating the day states date in the url bar , I am still unsure
> wether I should go in direction stateChangeStart on rootscope
> - When I switch from the week/month state away by pressing the day button
> there is again the current date missing in the
> url #/projects/43/dateplanner/day/--
>
> The same bugs are in the week/month state where I get only these urls:
>
> /#/projects/2/dateplanner/week/
> /#/projects/3/dateplanner/month
>
> That means there are at least 3 cases where the url can get wrong for all
> 3 states.
>
> All the ui router samples I have found are super simple... have as always
> nothing to do with real life requirements so I ask you guys here on the
> forum.
>
> 1.) What is the recommended approach to get the 3 cases done correctly
> with the ui-router?
> 2.) Is there any hook mechanism that allows my to write my FirstDayOfWeek,
> month number etc... into the $state/$stateparams before the state is
> activated/accepted because all parameters in the url match to a state?
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.