JavaScript AngularJS+UI-Router common CRUD configuration

I'm struggling with ui-router configuration which will define basic CRUD in the application.

I need to be able to add, remove, edit and search for, say, clients. Quite basic task.

Main page with url "/clients/" shows [Add Client] button and Keyword input field for search with [Search] button.

Once I enter something into search field and press the button I should navigate to "/clients/search/:keyword", but essentially I'll stay on the same page and search results will be loaded below the input field.

That's quite easy to implement, but interesting starts when I need to edit a client.

When I click on one of the rows from search results I expect a popup to be show with client information/form. At the same time, application should navigate to certain URL, so I can use that URL to share with someone, or basically use back button in my browser. So application should navigate to "/clients/edit/:clientId". Make total sense, right?

Similar should happen when I try to add a new client. Application navigates to "/clients/add" or "/clients/edit/0".

How would your organise routes for that? Obovioulsy, Sticky routes and Deep State Redirect are required here. So I managed to organise it this way so far:

function clientStateConfig ($stateProvider, $rootScope) {

  console.log('Client State :: init');

  $stateProvider.state('main.clients', {
    url: '/clients',
    skipAuthorisation: true,
    controller: 'ClientStateController as clientState',
    template: clientStateTemplate
  }).state('main.clients.create', {
    url: '/create',
    skipAuthorisation: true,
    views: {
      'modal': {
        template: '<div ui-view></div>'
      }
    },
    onEnter: showClientModal
  }).state('main.clients.edit', {
    url: '/edit/:clientId',
    skipAuthorisation: true,
    views: {
      'modal': {
        template: '<div ui-view></div>'
      }
    },
    onEnter: showClientModal
  }).state('main.clients.search', {
    url: '/search/:keyword',
    skipAuthorisation: true,
    deepStateRedirect: true,
    sticky: true,
    views: {
      'search': {
        template: clientSearchStateTemplate,
        controller: 'ClientSearchStateController as clientSearch'
      }
    }
  });

};

function showClientModal ($uibModal, $previousState, $rootScope) {

  $previousState.memo('modalInvoker'); // remember the previous state with memoName 'modalInvoker'

  let modal = $uibModal.open({
    template: clientModalTemplate,
    backdrop: 'static',
    controller: 'ClientModalController as clientModal'
  });

 }

ClientState template:

<h1>Clients</h1>
<div ui-view="search"></div>
<div ui-view="modal"></div>

Search template: {{client}}

Modal and controllers code are not that relevant I think. So the first and main problem is - when I navigate to "/clients/" I don't, obviously, see the search field, because I need to go to "/clients/search/" instead. So clients route should always redirect to search. But if it always redirects to search - here comes the problem with popups when user enters "/clients/edit/123". It shouldn't navigate in that case.

Other way: I can put search field into root ClientState template, and trigger $state.go('main.clients.search') on search button from there. Which would be ideal. But the problem will appear when user enters url "/clients/search/superkeyword" directly form the browser, and ClientState won't have access to that keyword state param as it is child state param. So keyword input field will be blank.

I completely lost and confused with. How would you solve that?

Answer:1

I am a student and very new to JS, like this is my first project dealing with it. With that being said, please excuse how juvenile my coding may seem to you experts. I followed the instructions of my ...

I am a student and very new to JS, like this is my first project dealing with it. With that being said, please excuse how juvenile my coding may seem to you experts. I followed the instructions of my ...

I'm trying to iterate over a simple array using recursion. For this specific case, I'm trying to recreate .map() using recursion (without using .map()!. I currently am only pushing the last element ...

I'm trying to iterate over a simple array using recursion. For this specific case, I'm trying to recreate .map() using recursion (without using .map()!. I currently am only pushing the last element ...

  1. two dimensional array iteration in java
  2. 2 dimensional array iteration
  3. two dimensional array iteration
  4. javascript two dimensional array iteration
  5. c# two dimensional array iteration
  6. php multidimensional array iteration

Consider a matrix B= [[6,4,1,2], [5,3,9,7],[1,3,2,1]];. B is a matrix with three rows and four columns. I want to treat it as an array or a vector, namely B1=[6,4,1,2,5,3,9,7,1,3,2,1]. Moreover, I ...

Consider a matrix B= [[6,4,1,2], [5,3,9,7],[1,3,2,1]];. B is a matrix with three rows and four columns. I want to treat it as an array or a vector, namely B1=[6,4,1,2,5,3,9,7,1,3,2,1]. Moreover, I ...

  1. transform matrix into vector matlab
  2. transform matrix into dataframe r
  3. transform matrix into diagonal form
  4. transform matrix into upper triangular form
  5. transform matrix into vector
  6. transform matrix into jordan canonical form
  7. transform matrix into vector r
  8. transform matrix into column excel
  9. transform matrix into reduced echelon form
  10. transform matrix into row echelon form
  11. transform matrix into vector python
  12. transform matrix into positive definite
  13. transform matrix into dataframe
  14. transform matrix into vector excel
  15. transform matrix into dataframe python
  16. transform matrix into table matlab
  17. transform matrix into list python
  18. transform matrix into list
  19. transform matrix into upper triangular
  20. transform matrix in css

I have some code running in an html page that is calling a function that exists on window.external. The code works: SomeCode.js (lives in somePage.html): window.external['someFunction'](); However, ...

I have some code running in an html page that is calling a function that exists on window.external. The code works: SomeCode.js (lives in somePage.html): window.external['someFunction'](); However, ...

  1. setting iframe height to match content height
  2. setting iframe size
  3. setting iframe width and height
  4. setting iframe src in jquery
  5. setting iframe height dynamically
  6. setting iframe src in javascript
  7. setting iframe height
  8. setting iframe source with javascript
  9. setting iframe content dynamically
  10. setting iframe height to auto
  11. setting iframe content
  12. setting iframe width
  13. setting iframe height dynamically using jquery
  14. setting iframe border
  15. setting iframe dimensions
  16. setting iframe innerhtml
  17. setting iframe height in css
  18. iframe setting
  19. iframe setting cookie
  20. iframe setting in chrome