/** * Create our message's model using the current user's email address as 'message.from' * Then extend it with all the properties from (non-url) state parameter 'message'. * Keep two copies: the editable one and the original one. * These copies are used to check if the message is dirty. */ ngOnInit() { const messageParam = this.transition.params().message; this.pristineMessage = Object.assign({from: this.appConfig.emailAddress}, messageParam); this.message = copy(this.pristineMessage); }
/** * Navigates back to the previous state. * * - Checks the $transition$ which activated this controller for a 'from state' that isn't the implicit root state. * - If there is no previous state (because the user deep-linked in, etc), then go to 'mymessages.messagelist' */ gotoPreviousState() { const transition = this.transition; const hasPrevious = !!transition.from().name; const state = hasPrevious ? transition.from() : 'mymessages.messagelist'; const params = hasPrevious ? transition.params('from') : {}; this.stateService.go(state, params); }
export function getFolder(foldersService: FoldersDataService, transition: Transition) { return foldersService.get(transition.params().folderId); }
/** * A resolve function for 'login' state which figures out what state to return to, after a successful login. * * If the user was initially redirected to login state (due to the requiresAuth redirect), then return the toState/params * they were redirected from. Otherwise, if they transitioned directly, return the fromState/params. Otherwise * return the main "home" state. */ export function returnTo ($transition$: Transition): any { if ($transition$.redirectedFrom() != null) { // The user was redirected to the login state (e.g., via the requiresAuth hook when trying to activate contacts) // Return to the original attempted target state (e.g., contacts) return $transition$.redirectedFrom().targetState(); } const $state = $transition$.router.stateService; // The user was not redirected to the login state; they directly activated the login state somehow. // Return them to the state they came from. if ($transition$.from().name !== '') { return $state.target($transition$.from(), $transition$.params('from')); } // If the fromState's name is empty, then this was the initial transition. Just return them to the home state return $state.target('home'); }
export function getMessage(messagesService: MessagesDataService, transition: Transition) { return messagesService.get(transition.params().messageId); }