Giter Club home page Giter Club logo

extclassgenerator's Introduction

Ext Class Generator

Build Status

Code generator that creates Javascript classes for Ext JS and Sencha Touch either dynamically at runtime or during build time with the help of an Annotation Processing Tool (APT) processor.

See the Wiki for more information.

extclassgenerator's People

Contributors

carldea avatar ralscha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

extclassgenerator's Issues

ClassNotFound

Hi,
I use the ModelAnnotationProcessor within Intellij IDEA using the "gradle-apt-plugin", the console print some error message:

Warning: No SupportedSourceVersion annotation found on ch.rasc.extclassgenerator.ModelAnnotationProcessor, returning RELEASE_6.
Warning: 来自注释处理程序 'ch.rasc.extclassgenerator.ModelAnnotationProcessor' 的受支持 source 版本 'RELEASE_6' 低于 -source '1.8'
注: Running ModelAnnotationProcessor
Error com.jdsoft.studio.Author
Error: com.jdsoft.studio.Book
Error: com.jdsoft.studio.model.Project
Error: com.jdsoft.studio.model.SampleProject
注: Running ModelAnnotationProcessor
Warning: 以下选项未被任何处理程序识别: '[createBaseAndSubclass, surroundApiWithQuotes]'.

Then i debug the gradle,i found the inner exception is ClassNotFoundException,see pickure below:
classnotfoundexception
It seems like the classloader can't find the my Model class ,how shoud i handle this problem?
Thanks!

Add autodetectTypes switch to Model annotation

By default the model generator tries to figure out the type of a field when no ModelField annotation is present.

The performance can be improved when the server sends the data in the correct format and the type is set to 'auto'. For 'auto'-fields Ext Js skips the per-field processing.

To use this pattern every field has to be annotated with @ModelField(type = ModelType.AUTO). This is cumbersome if the bean contains a lot of fields.

We could improve this situation by adding a autodetectTypes boolean to the Model annotation. By default this attribute is true which corresponds to the current behaviour.

When this attribute is set to false, the type of every field that is not annotated with ModelField is set to auto.

Add requires for validators (Ext JS 5)

Ext Js 5 warns when using validator and not specify the validators in the requires config option

[W] [Ext.Loader] Synchronously loading 'Ext.data.validator.Presence'; consider adding Ext.require('Ext.data.validator.Presence') above Ext.onReady Util.js?_dc=1403671653161:692
[W] [Ext.Loader] Synchronously loading 'Ext.data.validator.Email'; consider adding Ext.require('Ext.data.validator.Email') above Ext.onReady Util.js?_dc=1403671653161:692

Example of a model with requires

Ext.define("SimpleApp.model.User", {
  extend : "Ext.data.Model",
  requires : ["Ext.data.validator.Presence", "Ext.data.validator.Email"],
  fields : [ {
    name : "id",
    type : "string"
  }, {
    name : "firstName",
    type : "string",
    convert : null
  }, {
    name : "lastName",
    type : "string",
    convert : null,
    validators : [ {
      type : "presence"
    } ]
  }, {
    name : "email",
    type : "string",
    convert : null,
    validators : [ {
      type : "email"
    } ]
  }, {
    name : "department",
    type : "string",
    convert : null
  } ]
});

Support a way to set the model field type to 'auto' even it's a known type

Here is a quote from this blog post: Deep Dive Into Ext JS 5 Data

"While eliminating field declarations is convenient at times and an easy way to eliminate per-field processing, this is not always possible. For example, the defaultValue and convert configs require processing for the field on which they are declared. When adding validators and references on fields, you can still avoid this processing by using the default field type “auto” (and avoiding the configs just mentioned)."

In the current release the generator tries to figure out the type of the field when the type AUTO is used

    @ModelField(type = ModelType.AUTO)
    public String name;

For this example the generator writes this field config

{name:"name",type:"string"}

We should change this so the type from the annotation is always used and only if the attribute is omitted autodetect the type.

'auto' is the default type, therefore the generator does not need to write the type config in this case.

pattern matcher error / should be escaped in js produced

Hi,

I just discovered what I think could be a bug.

I have a

@Pattern(regexp="^/\\w.*\\.\\w.*") 

on a java Json object

The generator produces

matcher : /^/\w.*\.\w.*/

instead it should be

 matcher : /^\/\w.*\.\w.*/

when I test the pattern with http://regexpal.com/ with following ones

^\/\w.*\.\w.* or ^/\w.*\.\w.*

both works, it matches what I want
/index.html

With the second pattern it fails with yuicompressor 2.4.7, I don' pretend familiarity with regular expression, but I guess the slash "/" should be escaped

useNull was renamed allowNull in Ext Js 5

The field config option useNull does not exist in Ext Js 5.
It was renamed allowNull.

Touch 2 allows both but useNull is deprecated.

Ext Js 4 only supports useNull.

model generator for validation type GENERIC produces twice type property

Hi,

I just discovered a bug related to your introduced feature ModelValidation with ExtJs 4.2.2

ch.rasc.extclassgenerator.validation.GenericValidation

I have a config such as

@ModelValidation(propertyName = "prop", value = ModelValidationType.GENERIC, parameters={@ModelValidationParameter(name="type", value= "notUnique"), @ModelValidationParameter(name="update", value= "true")})

JavaScript code generated is

validations : [ {
    type : "notUnique",
    field : "prop",
    type : "notUnique",
    update : "true"
  }]

type is duplicated
the bug is coming from following code in AbstractValidation.createValidation

            case GENERIC:
                String type = getParameterValue(modelValidationAnnotation.parameters(), "type");
                Map<String, Object> options = new LinkedHashMap<String, Object>();
                for (ModelValidationParameter parameter : modelValidationAnnotation.parameters()) {
                    options.put(parameter.name(), parameter.value());
                }
                return new GenericValidation(type, propertyName, options);

it should be instead

case GENERIC:
                String type = getParameterValue(modelValidationAnnotation.parameters(), "type");
                Map<String, Object> options = new LinkedHashMap<String, Object>();
                for (ModelValidationParameter parameter : modelValidationAnnotation.parameters()) {
                    if(!parameter.name().equals("type"))
                        options.put(parameter.name(), parameter.value());
                }
                return new GenericValidation(type, propertyName, options);

or whatever other way you want, to not include this parameter name ' type'

Thanks for this implementation, and give opportunity to developers to add their own validations rules.

ExtJS 6.2 association define support?

Hi,
It seems that the @ModelAssociation has not support ExtJ6.2.
This is my generated model define.
The Entity has many EntityAttribute
image

image

In client the Entity instance has a "attributes" method already,but the Entity can't load nesting EntityAttribute data.
Studio.model.entity.Entity.load("com.jdsoft.entity.TestEntity",{callback:function(ent){window.ent=ent}})
'ent.attributes().getCount()'
the ent.attributes().getCount() return 0;
I changed the association define using Ext6 format, it will load the nesting data.
image
image

I want know that the @ModelAssociation can used in ExtJS6 ? If not, is there a plan to support Extjs6?

Annotations on property getters

Is there a reason why annotations on property getters are not supported? It would allow generating model classes off an interface with JSR-303 annotations on it rather than the implementation. Hence, allowing sharing of the interface and validation constraints, but, not the implementation of the interface.

For example:

@Model
public interface User {    

    UUID getId();

    @NotEmpty
    @Email
    @Size(max=128)
    String getEmail();
...
}

Support for changing the extend of a Model (default 'Ext.data.Model')

Add new attribute extend to the Model annotation. This allows an application to overwrite the default 'Ext.data.Model'.

This could be useful because in ext js 5 there is this new schema concept. A "super class" can specify the schema config and all the model "classes" inherit this.

Ext.define('MyApp.model.Base', {
     extend: 'Ext.data.Model',

     schema: {
         namespace: 'MyApp.models'
     }
 });
  Ext.define("MyApp.model.Author", {  
     extend : "MyApp.models.Base",
   .....

Add field annotations for idProperty, versionProperty and clientIdProperty

Introduce three new field annotations

@ModelId
@ModelClientId
@ModelVersion

These are alternatives to @Model.idProperty, @Model.clientIdProperty and @Model.versionProperty

If a class has both the new annotations takes precedence.

Example:

@Model(value = "MyApp.Employee", identifier = "negative", idProperty="eId",
               versionProperty="version", clientIdProperty="clientId")
public class Employee {
    public int eId;
    public String version;
    public String clientId;
}

OR

@Model(value = "MyApp.Employee", identifier = "negative")
public class Employee {

    @ModelId
    public int eId;

    @ModelVersion
    public String version;

    @ModelClientId
    public String clientId;
}

Validator syntax changed in Ext JS 5

Ext JS 5 changed the way validators are configured. The config option is now called validators and the field name is the key.

Ext JS 5
http://docs.sencha.com/ext/5.0.0/apidocs/#!/api/Ext.data.Model-cfg-validators

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'name',     type: 'string' },
        { name: 'age',      type: 'int' },
        { name: 'phone',    type: 'string' },
        { name: 'gender',   type: 'string' },
        { name: 'username', type: 'string' },
        { name: 'alive',    type: 'boolean', defaultValue: true }
    ],

    validators: {
        age: 'presence',
        name: { type: 'length', min: 2 },
        gender: { type: 'inclusion', list: ['Male', 'Female'] },
        username: [
            { type: 'exclusion', list: ['Admin', 'Operator'] },
            { type: 'format', matcher: /([a-z]+)[0-9]{2,3}/i }
        ]
    }
});

Ext JS 4

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name',     type: 'string'},
        {name: 'age',      type: 'int'},
        {name: 'phone',    type: 'string'},
        {name: 'gender',   type: 'string'},
        {name: 'username', type: 'string'},
        {name: 'alive',    type: 'boolean', defaultValue: true}
    ],

    validations: [
        {type: 'presence',  field: 'age'},
        {type: 'length',    field: 'name',     min: 2},
        {type: 'inclusion', field: 'gender',   list: ['Male', 'Female']},
        {type: 'exclusion', field: 'username', list: ['Admin', 'Operator']},
        {type: 'format',    field: 'username', matcher: /([a-z]+)[0-9]{2,3}/}
    ]
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.