mlouah / myDocs

0 stars 0 forks source link

Max shown Authors = 20 items while updating doc #3

Closed mlouah closed 2 weeks ago

mlouah commented 2 weeks ago

involved files

// doc doc-update.vue

 <div class="form-group">
            <label class="form-control-label" for="doc-mainAuthor">Main Author</label>
            <select class="form-control" id="doc-mainAuthor" data-cy="mainAuthor" name="mainAuthor" v-model="doc.mainAuthor">
              <option v-bind:value="null"></option>
              <option
                v-bind:value="doc.mainAuthor && docAuthorOption.id === doc.mainAuthor.id ? doc.mainAuthor : docAuthorOption"
                v-for="docAuthorOption in docAuthors"
                :key="docAuthorOption.id"
              >
                {{ docAuthorOption.name }}
              </option>
            </select>
          </div>

doc-update.component.ts

doc-update.vue : combo

// doc author

doc-author.service.ts public retrieve(paginationQuery?: any): Promise<any> axios.get(baseApiUrl +?${buildPaginationQueryOpts(paginationQuery)})

sorts.ts: buildPaginationQueryOpts()

mlouah commented 2 weeks ago

Le composant doc-author.component.ts n'a rien avoir avec le nombre d'item dans le combo d'update !!! La variable suite fixe combien d'item seront afficher dans la page doc.vue comme son nom l'indique!

public itemsPerPage = 50;

mlouah commented 2 weeks ago

pour logguer depuis Java script: console.log('My texte:', variable.data);

mlouah commented 2 weeks ago

Link:"http://localhost:8080/api/doc-authors?sort=id%2Casc&page=0&size=50 au niveau de la console !

mlouah commented 2 weeks ago

Jhipster community has already reported this issue :

This has to be fixed from a backend side:spring.data.web.pageable.maxPageSize=2147483647

mlouah commented 2 weeks ago

Final solution: 1) DocAuthorResource.java contains the following code image

mlouah commented 2 weeks ago

Finalement la solution est simple :( https://chatgpt.com/c/671fbfea-d32c-800d-ad07-f8d726c9f420

Since you're using JHipster 7.9.3, all the methods I mentioned previously are still applicable, but let’s focus specifically on the version you’re using and its standard practices.

1. Default Configuration using application.yml

This method works well for JHipster 7.9.3. You can configure the default Pageable properties globally:

  1. Open your src/main/resources/config/application.yml or application-dev.yml.
  2. Add or update the following settings:

    spring:
     data:
       web:
         pageable:
           default-page-size: 50  # Set your desired default size
           max-page-size: 200     # (Optional) Set a maximum limit if needed

This will set the default page size globally for all pageable requests handled by Spring Data.

2. Using @PageableDefault in Controller

You can modify specific controller methods to set a default page size. In JHipster, the controllers are typically in src/main/java/com/yourproject/web/rest/.

Example for a specific REST method:

import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ExampleResource {

    @GetMapping("/api/examples")
    public ResponseEntity<List<ExampleDTO>> getAllExamples(
        @PageableDefault(size = 50) Pageable pageable) {
        Page<ExampleDTO> page = exampleService.findAll(pageable);
        HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/examples");
        return ResponseEntity.ok().headers(headers).body(page.getContent());
    }
}

This will change the default page size for this specific endpoint without impacting other parts of your application.

3. Changing the Frontend Default Request in Vue.js

If you want to set a default page size in your frontend code, specifically in the API calls made by Vue.js, you can modify the parameters passed to the backend. In your Vue component, typically located in src/main/webapp/app/entities, locate the retrieve method and update it to include a default page size:

this.docAuthorService()
  .retrieve({ page: 0, size: 50 }) // Set the size to 50 or your desired default
  .then(response => {
    this.docAuthors = response.data;
  })
  .catch(error => {
    console.error('Error fetching doc authors:', error);
  });

4. Global Default Fallback using a Custom Configuration Class

You can create a custom configuration class in your JHipster project under src/main/java/com/yourproject/config:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.web.config.PageableHandlerMethodArgumentResolverCustomizer;

@Configuration
public class PageableConfig {

    @Bean
    public PageableHandlerMethodArgumentResolverCustomizer pageableCustomizer() {
        return pageableResolver -> {
            pageableResolver.setFallbackPageable(PageRequest.of(0, 50)); // Default size of 50
            pageableResolver.setMaxPageSize(200); // Optional: limit maximum size
        };
    }
}

This solution applies globally and ensures a default page size if none is specified in a request.


Final Recommendation for JHipster 7.9.3


If you want a global solution that applies across all controllers and pageable requests, I suggest using Method 1 (updating application.yml) or Method 4 (custom configuration class). If you want more fine-grained control over page sizes, Method 2 (using @PageableDefault) would be more appropriate.

If you need further assistance specific to JHipster or the version you're using, feel free to ask!

mlouah commented 2 weeks ago

Even if the default size was 100, the dropdown list does not contains empty line 👍 Ne marche pas pour le profile Dev !!!