jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.47k stars 4.02k forks source link

Generated AngularJS Controller Doesn't Work on Save #6048

Closed vw98075 closed 7 years ago

vw98075 commented 7 years ago
Overview of the issue

With the generated code, one of my entities can not be saved. On the 8080 port, the form remains the same and nothing shows up on the console after I click the submit button. On the 9000 port, however, a log message shows fetching for related entities from the database after I click the button. There isn't an error message on any console, including the browser's console. The followings is the html file.

HTML template

And the followings is the controller. Note I insert the console.log and nothing is printed on a browser console.

Controller code (function() { 'use strict'; angular .module('pacificTraderApp') .controller('SkuSDialogController', SkuSDialogController); SkuSDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$uibModalInstance', 'DataUtils', 'entity', 'SkuS', 'ProductS']; function SkuSDialogController ($timeout, $scope, $stateParams, $uibModalInstance, DataUtils, entity, SkuS, ProductS) { var vm = this; vm.skuS = entity; vm.clear = clear; vm.datePickerOpenStatus = {}; vm.openCalendar = openCalendar; vm.byteSize = DataUtils.byteSize; vm.openFile = DataUtils.openFile; vm.save = save; vm.products = ProductS.query(); $timeout(function (){ angular.element('.form-group:eq(1)>input').focus(); }); function clear () { $uibModalInstance.dismiss('cancel'); } function save () { console.log("Saving ..."); vm.isSaving = true; if (vm.skuS.id !== null) { SkuS.update(vm.skuS, onSaveSuccess, onSaveError); } else { SkuS.save(vm.skuS, onSaveSuccess, onSaveError); } } function onSaveSuccess (result) { $scope.$emit('pacificTraderApp:skuSUpdate', result); $uibModalInstance.close(result); vm.isSaving = false; } function onSaveError () { vm.isSaving = false; } vm.datePickerOpenStatus.activeStartDate = false; vm.datePickerOpenStatus.activeEndDate = false; function openCalendar (date) { vm.datePickerOpenStatus[date] = true; } } })();
Motivation for or Use Case
Reproduce the error
Related issues
Suggest a Fix

In the controller,

      vm.save =  function() {
         vm.isSaving = true;
        if (vm.myEntity.id !== null) {
           MyEntity.update(vm.myEntity, onSaveSuccess, onSaveError);
        } else {
          MyEntity.save(vm.myEntity, onSaveSuccess, onSaveError);
        }
    }

Or in the html file,

    <div ng-controller="SkuSDialogController as vm">
JHipster Version(s)

4.5.6

JHipster configuration

An output of jhipster info is quite long. I only copy the related portion here

SkuS.json
    {
    "fluentMethods": true,
    "relationships": [
        {
            "relationshipName": "productSup",
            "otherEntityName": "productSup",
            "relationshipType": "many-to-one",
            "otherEntityField": "id"
        }
    ],
    "fields": [
        {
            "fieldName": "name",
            "fieldType": "String",
            "fieldValidateRules": [
                "maxlength"
            ],
            "fieldValidateRulesMaxlength": 80
        },
        {
            "fieldName": "description",
            "fieldType": "byte[]",
            "fieldTypeBlobContent": "text"
        },
        {
            "fieldName": "upc",
            "fieldType": "String",
            "fieldValidateRules": [
                "maxlength"
            ],
            "fieldValidateRulesMaxlength": 80
        },
        {
            "fieldName": "attributes",
            "fieldType": "String"
        },
        {
            "fieldName": "unitPrice",
            "fieldType": "BigDecimal",
            "fieldValidateRules": [
                "required",
                "min"
            ],
            "fieldValidateRulesMin": 0
        },
        {
            "fieldName": "expressShippingFee",
            "fieldType": "BigDecimal",
            "fieldValidateRules": [
                "min"
            ],
            "fieldValidateRulesMin": 0
        },
        {
            "fieldName": "activeStartDate",
            "fieldType": "ZonedDateTime",
            "fieldValidateRules": [
                "required"
            ]
        },
        {
            "fieldName": "activeEndDate",
            "fieldType": "ZonedDateTime"
        },
        {
            "fieldName": "idx1",
            "fieldType": "Integer",
            "fieldValidateRules": [
                "required",
                "min"
            ],
            "fieldValidateRulesMin": 0
        },
        {
            "fieldName": "idx2",
            "fieldType": "Integer",
            "fieldValidateRules": [
                "min"
            ],
            "fieldValidateRulesMin": 0
        },
        {
            "fieldName": "inventoryType",
            "fieldType": "String",
            "fieldValidateRules": [
                "required",
                "maxlength"
            ],
            "fieldValidateRulesMaxlength": 8
        },
        {
            "fieldName": "quantityAvailable",
            "fieldType": "Integer",
            "fieldValidateRules": [
                "min"
            ],
            "fieldValidateRulesMin": 0
        },
        {
            "fieldName": "inEnglish",
            "fieldType": "Boolean"
        }
    ],
    "changelogDate": "20170705160532",
    "entityTableName": "sku_s",
    "dto": "no",
    "pagination": "pagination",
    "service": "serviceClass"
    }
    ...
    relationship OneToMany {
       ProductSup{skus} to SkuSup{product},
       ...
    }
    relationship ManyToOne {
        VolumnPricingSup{skus} to SkuSup,
        FulfillmentItem{sku} to SkuSup,
        ...
    }

The .yo-rc.json file

    {
    "generator-jhipster": {
    "promptValues": {
      "packageName": "com.abc.myapp"
    },
    "jhipsterVersion": "4.5.6",
    "baseName": "myapp",
    "packageName": "com.abc.myapp",
    "packageFolder": "com/abc/myapp",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "no",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Memory",
    "prodDatabaseType": "postgresql",
    "searchEngine": "elasticsearch",
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "gradle",
    "enableSocialSignIn": false,
    "jwtSecretKey": "xxxxxxx",
    "clientFramework": "angular1",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "monolith",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "otherModules": [
      {
        "name": "generator-jhipster-nav-element",
        "version": "1.2.2"
      },
      {
        "name": "generator-jhipster-docker",
        "version": "2.2.0"
      },
      {
        "name": "generator-jhipster-bootstrap-material-design",
        "version": "3.5.1"
      },
      {
        "name": "generator-jhipster-entity-audit",
        "version": "2.4.1"
      },
      {
        "name": "generator-jhipster-vuejs",
        "version": "0.0.3"
      }
    ],
    "enableTranslation": false
    }
    }
Entity configuration(s) entityName.json files generated in the .jhipster directory

The related SkuS.json is shown above. And the ProductSup is the following:

{
"fluentMethods": true,
"relationships": [
    {
        "relationshipType": "one-to-many",
        "relationshipName": "skus",
        "otherEntityName": "skuSup",
        "otherEntityRelationshipName": "product"
    },
    {
        "relationshipType": "many-to-many",
        "otherEntityRelationshipName": "",
        "relationshipName": "category",
        "otherEntityName": "category",
        "otherEntityField": "id",
        "ownerSide": true
    }
],
"fields": [
    {
        "fieldName": "brand",
        "fieldType": "String",
        "fieldValidateRules": [
            "required",
            "maxlength"
        ],
        "fieldValidateRulesMaxlength": 80
    },
    {
        "fieldName": "name",
        "fieldType": "String",
        "fieldValidateRules": [
            "required",
            "maxlength"
        ],
        "fieldValidateRulesMaxlength": 80
    },
    {
        "fieldName": "model",
        "fieldType": "String",
        "fieldValidateRules": [
            "maxlength"
        ],
        "fieldValidateRulesMaxlength": 80
    },
    {
        "fieldName": "keywords",
        "fieldType": "String"
    },
    {
        "fieldName": "description",
        "fieldType": "byte[]",
        "fieldTypeBlobContent": "text",
        "fieldValidateRules": [
            "required"
        ]
    },
        {
        "fieldName": "specification",
        "fieldType": "String",
        "fieldValidateRules": [
            "maxlength"
        ],
        "fieldValidateRulesMaxlength": 255
    },
    {
        "fieldName": "hasVariants",
        "fieldType": "Boolean",
        "fieldValidateRules": [
            "required"
        ]
    },
    {
        "fieldName": "variantAvailibityMatrix",
        "fieldType": "String"
    },
    {
        "fieldName": "status",
        "fieldType": "String",
        "fieldValidateRules": [
            "required",
            "maxlength"
        ],
        "fieldValidateRulesMaxlength": 8
    },
    {
        "fieldName": "tMallProductURL",
        "fieldType": "String",
        "fieldValidateRules": [
            "maxlength"
        ],
        "fieldValidateRulesMaxlength": 255
    },
    {
        "fieldName": "jdProductURL",
        "fieldType": "String",
        "fieldValidateRules": [
            "maxlength"
        ],
        "fieldValidateRulesMaxlength": 255
    },
    {
        "fieldName": "inEnglish",
        "fieldType": "Boolean",
        "fieldValidateRules": [
            "required"
        ]
    },
    {
        "fieldName": "limitationPerCustomer",
        "fieldType": "Integer",
        "fieldValidateRules": [
            "min"
        ],
        "fieldValidateRulesMin": 1
    }
],
"changelogDate": "20170708185112",
"entityTableName": "product_sup",
"dto": "no",
"pagination": "pagination",
"service": "serviceClass"
}
Browsers and Operating System

Linux Mint 18.2

jdubois commented 7 years ago

Can you write a good title?

jdubois commented 7 years ago

Thanks !

gmarziou commented 7 years ago

An output of jhipster info is quite long. I only copy the related portion here

Well you copied only one entity SkuS and forgot its related entity ProductS. For long text fragments, you can always use HTML 5 details tag.

<details>
 <summary>Summary Goes Here</summary>
 ...this is hidden, collapsable content...
</details>
jdubois commented 7 years ago

@gmarziou we should use this in our issue template, have you tried it?

jdubois commented 7 years ago

@vw98075 if you use your browser in "dev mode", can you see the network rework? Does clicking on the button produce a request? If yes, you should be able to see it on the backend, with our logging aspect. This is to understand if the issue is on the backend or on the frontend.

gmarziou commented 7 years ago

@jdubois Yes I used it many times, it has some restrictions though, you cannot have complex markdown in included text but for code or command output it'll be fine using <pre> tag, maybe not for jhipster info as it returns some ## headers I think.

gmarziou commented 7 years ago

@vw98075 I wonder why this happens only to one entity, maybe this is related to your way of naming entities using plural?

gmarziou commented 7 years ago

I edited the issue using details tag.

deepu105 commented 7 years ago

@gmarziou we can incorporate the details tag into the output of jhipster info so that code is wrapped in it. What say?

jdubois commented 7 years ago

Sorry but you also posted this on StackOverflow at https://stackoverflow.com/questions/44960062/nothing-happens-after-clicking-the-submit-button

-> I'm closing this as "invalid" as you have answers on SO, and as there should only be one "ticket" or "question"

gmarziou commented 7 years ago

@deepu105 yes good idea. I can PR it if you want

gmarziou commented 7 years ago

Just tried in a stackoverflow answer, it does not collapse but it does not look bad either, so jhipster:info can use it safely or we could add a --raw option or a question. image

deepu105 commented 7 years ago

I think its ok if it doesnt collapse in SO, the primary purpose is for us to work on issues efficiently

gmarziou commented 7 years ago

OK, I will do it. BTW, maybe we should generate a file rather than printing on console, this would allow us to use a yeoman template

gmarziou commented 7 years ago

It works with firefox and mobile chrome

vw98075 commented 7 years ago

@jdubois Sorry for this late reply. It was a bed time here when your folks had a conversation on this problem. To answer your question, I retest it and don't see any traffic on the network panel of the browser. And I was not aware of such guideline which a question only can be posted either here or Stockoverflow. Sorry for that. I first noticed this problem two days ago. I thought the problem must be something I didn't do it right. I try not to bother your folks as possible. I believe that it is a front end problem. The Spring Rest controller method is not hit.

@gmarziou I will rename the entity and replace the "S" at the end with something else. And report back to you later.

A update: After I rename the related entity names from SkuS to SkuSup, the problem still persists. I believe that problem is likely caused by associated relationships. I add all related relationship definitions from an output of "jhipster info".