From 5715be11a6602301c1aadf47cb9e41f778bbf54a Mon Sep 17 00:00:00 2001 From: zhoss Date: Sun, 4 Jun 2017 22:23:06 +0100 Subject: [PATCH 1/2] add datepicker layout --- .../io/asfjava/ui/core/form/DatePicker.java | 23 ++++++++++ .../core/generators/DatePickerGenerator.java | 46 +++++++++++++++++++ .../ui/core/schema/CustomStringSchema.java | 43 +++++++++-------- 3 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 src/main/java/io/asfjava/ui/core/form/DatePicker.java create mode 100644 src/main/java/io/asfjava/ui/core/generators/DatePickerGenerator.java diff --git a/src/main/java/io/asfjava/ui/core/form/DatePicker.java b/src/main/java/io/asfjava/ui/core/form/DatePicker.java new file mode 100644 index 0000000..457bf60 --- /dev/null +++ b/src/main/java/io/asfjava/ui/core/form/DatePicker.java @@ -0,0 +1,23 @@ +package io.asfjava.ui.core.form; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(RUNTIME) +@Target(FIELD) +public @interface DatePicker { + String title(); + + String minDate() default "1995-09-01"; + + String maxDate() default ""; + + String format(); + + boolean noTitle() default false; + + boolean readOnly() default false; +} \ No newline at end of file diff --git a/src/main/java/io/asfjava/ui/core/generators/DatePickerGenerator.java b/src/main/java/io/asfjava/ui/core/generators/DatePickerGenerator.java new file mode 100644 index 0000000..a7de91a --- /dev/null +++ b/src/main/java/io/asfjava/ui/core/generators/DatePickerGenerator.java @@ -0,0 +1,46 @@ +package io.asfjava.ui.core.generators; + +import java.lang.reflect.Field; +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +import io.asfjava.ui.core.form.DatePicker; + +public class DatePickerGenerator implements FormDefinitionGenerator { + + @Override + public void generate(ObjectNode fieldFormDefinition, Field field) { + DatePicker annotation = field.getAnnotation(DatePicker.class); + + fieldFormDefinition.put("key", field.getName()); + fieldFormDefinition.put("title", annotation.title()); + fieldFormDefinition.put("minDate", annotation.minDate()); + + String maxDate = annotation.maxDate(); + if ("new Date()".equals(maxDate)) { + Date currentDate = new Date(); + fieldFormDefinition.put("maxDate", new SimpleDateFormat(annotation.format()).format(currentDate)); + } else { + fieldFormDefinition.put("maxDate", annotation.maxDate()); + } + + fieldFormDefinition.put("format", annotation.format()); + + boolean noTitle = annotation.noTitle(); + if (noTitle) { + fieldFormDefinition.put("notitle", noTitle); + } + + boolean readOnly = annotation.readOnly(); + if (readOnly) { + fieldFormDefinition.put("readonly", readOnly); + } + } + + @Override + public String getAnnoation() { + return DatePicker.class.getName(); + } +} \ No newline at end of file diff --git a/src/main/java/io/asfjava/ui/core/schema/CustomStringSchema.java b/src/main/java/io/asfjava/ui/core/schema/CustomStringSchema.java index 3009bf9..7adb665 100644 --- a/src/main/java/io/asfjava/ui/core/schema/CustomStringSchema.java +++ b/src/main/java/io/asfjava/ui/core/schema/CustomStringSchema.java @@ -1,19 +1,24 @@ -package io.asfjava.ui.core.schema; - -import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.module.jsonSchema.types.StringSchema; - -import io.asfjava.ui.core.form.TextField; - -class CustomStringSchema extends StringSchema { - - @Override - public void enrichWithBeanProperty(BeanProperty beanProperty) { - super.enrichWithBeanProperty(beanProperty); - TextField annotation = beanProperty.getAnnotation(TextField.class); - if (annotation != null && !annotation.pattern().isEmpty()) { - this.setPattern(annotation.pattern()); - } - } - -} +package io.asfjava.ui.core.schema; + +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormat; +import com.fasterxml.jackson.module.jsonSchema.types.StringSchema; + +import io.asfjava.ui.core.form.DatePicker; +import io.asfjava.ui.core.form.TextField; + +class CustomStringSchema extends StringSchema { + + @Override + public void enrichWithBeanProperty(BeanProperty beanProperty) { + super.enrichWithBeanProperty(beanProperty); + TextField annotation = beanProperty.getAnnotation(TextField.class); + if (annotation != null && !annotation.pattern().isEmpty()) { + this.setPattern(annotation.pattern()); + } + DatePicker datePicker = beanProperty.getAnnotation(DatePicker.class); + if (datePicker != null) { + this.setFormat(JsonValueFormat.DATE); + } + } +} From e7ee975c3a602b9cd02ae3b2016bbb82ccb12c4f Mon Sep 17 00:00:00 2001 From: zhoss Date: Sun, 4 Jun 2017 22:27:19 +0100 Subject: [PATCH 2/2] add datepicker addon --- demo/bower.json | 73 +++--- .../io/asfjava/ui/demo/screen/DemoForm.java | 224 +++++++++--------- demo/src/main/resources/static/index.html | 138 ++++++----- 3 files changed, 229 insertions(+), 206 deletions(-) diff --git a/demo/bower.json b/demo/bower.json index 6f3e519..707f3b0 100644 --- a/demo/bower.json +++ b/demo/bower.json @@ -1,35 +1,38 @@ -{ - "name": "demo", - "authors": [ - "Saif Jerbi " - ], - "directory": "src/main/resources/static", - "appPath": "src/main/resources/static", - "description": "this is a demo application using angular schema form and asf java ui library", - "main": "index.html", - "keywords": [ - "angular", - "schema", - "form", - "asf", - "java", - "ui", - "java", - "angular" - ], - "license": "MIT", - "homepage": "", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "dependencies": { - "angular-schema-form": "^0.8.13", - "angular-schema-form-bootstrap": "^0.2.0", - "bootstrap": "^3.3.7", - "lodash": "^4.17.4" - } - } +{ + "name": "demo", + "authors": [ + "Saif Jerbi " + ], + "directory": "src/main/resources/static", + "appPath": "src/main/resources/static", + "description": "this is a demo application using angular schema form and asf java ui library", + "main": "index.html", + "keywords": [ + "angular", + "schema", + "form", + "asf", + "java", + "ui", + "java", + "angular" + ], + "license": "MIT", + "homepage": "", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "jquery": "~3.2.1", + "angular-schema-form": "^0.8.13", + "angular-schema-form-bootstrap": "^0.2.0", + "angular-schema-form-datepicker": "~1.4.1", + "pickadate": "~3.5.6", + "bootstrap": "^3.3.7", + "lodash": "^4.17.4" + } + } diff --git a/demo/src/main/java/io/asfjava/ui/demo/screen/DemoForm.java b/demo/src/main/java/io/asfjava/ui/demo/screen/DemoForm.java index 9452cc4..084a69c 100644 --- a/demo/src/main/java/io/asfjava/ui/demo/screen/DemoForm.java +++ b/demo/src/main/java/io/asfjava/ui/demo/screen/DemoForm.java @@ -1,106 +1,118 @@ -package io.asfjava.ui.demo.screen; - -import java.io.Serializable; - -import io.asfjava.ui.core.form.CheckBox; -import io.asfjava.ui.core.form.ComboBox; -import io.asfjava.ui.core.form.Number; -import io.asfjava.ui.core.form.Password; -import io.asfjava.ui.core.form.RadioBox; -import io.asfjava.ui.core.form.TextArea; -import io.asfjava.ui.core.form.TextField; - -public class DemoForm implements Serializable { - - @TextField(title = "First Name", placeHolder = "Your first name", description = "This is a description for your first name field") - private String firstName; - - @TextField(title = "Last Name", placeHolder = "Your last name") - private String lastName; - - @TextField(title = "eMail", placeHolder = "Your email", pattern = "^\\S+@\\S+$", validationMessage = "Your mail must be in this format jhondoe@example.com", description = "This is Text Field with pattern and validation message") - private String email; - - @Number(title = "Number of children", placeHolder = "Number of children", description = "This is a number") - private Integer number; - - @Password(title = "Password", placeHolder = "Please set you password", description = "This is password") - private String password; - - @ComboBox(title = "Gender", titleMap = GenderTitleMap.class) - private String gender; - - @ComboBox(title = "Currency", values = { "euro", "dollar" }) - private String currency; - - @RadioBox(title = "Civil State", titleMap = CivilStateTitelsMap.class) - private String civilState; - - @TextArea(title = "Address", placeHolder = "Fill your address please", description = "This is textarea") - private String address; - - @CheckBox(title = "Color", values = { "red", "bleu", "green" }, defaultvalue = "red") - private String color; - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setEmail(String eMail) { - this.email = eMail; - } - - public String getEmail() { - return email; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public Integer getNumber() { - return number; - } - - public void setNumber(Integer number) { - this.number = number; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getGender() { - return gender; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getCivilState() { - return civilState; - } - - public void setCivilState(String civilState) { - this.civilState = civilState; - } - - private static final long serialVersionUID = -5073515619469444978L; -} +package io.asfjava.ui.demo.screen; + +import java.io.Serializable; + +import io.asfjava.ui.core.form.CheckBox; +import io.asfjava.ui.core.form.ComboBox; +import io.asfjava.ui.core.form.DatePicker; +import io.asfjava.ui.core.form.Number; +import io.asfjava.ui.core.form.Password; +import io.asfjava.ui.core.form.RadioBox; +import io.asfjava.ui.core.form.TextArea; +import io.asfjava.ui.core.form.TextField; + +public class DemoForm implements Serializable { + + @TextField(title = "First Name", placeHolder = "Your first name", description = "This is a description for your first name field") + private String firstName; + + @TextField(title = "Last Name", placeHolder = "Your last name") + private String lastName; + + @TextField(title = "eMail", placeHolder = "Your email", pattern = "^\\S+@\\S+$", validationMessage = "Your mail must be in this format jhondoe@example.com", description = "This is Text Field with pattern and validation message") + private String email; + + @Number(title = "Number of children", placeHolder = "Number of children", description = "This is a number") + private Integer number; + + @Password(title = "Password", placeHolder = "Please set you password", description = "This is password") + private String password; + + @ComboBox(title = "Gender", titleMap = GenderTitleMap.class) + private String gender; + + @DatePicker(title = "Birth Date", format = "yyyy-MM-dd") + private String birthDate; + + @ComboBox(title = "Currency", values = { "euro", "dollar" }) + private String currency; + + @RadioBox(title = "Civil State", titleMap = CivilStateTitelsMap.class) + private String civilState; + + @TextArea(title = "Address", placeHolder = "Fill your address please", description = "This is textarea") + private String address; + + @CheckBox(title = "Color", values = { "red", "bleu", "green" }, defaultvalue = "red") + private String color; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setEmail(String eMail) { + this.email = eMail; + } + + public String getEmail() { + return email; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getBirthDate() { + return birthDate; + } + + public void setBirthDate(String birthDate) { + this.birthDate = birthDate; + } + + public String getGender() { + return gender; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getCivilState() { + return civilState; + } + + public void setCivilState(String civilState) { + this.civilState = civilState; + } + + private static final long serialVersionUID = -5073515619469444978L; +} diff --git a/demo/src/main/resources/static/index.html b/demo/src/main/resources/static/index.html index 4bdb512..1f00ffd 100644 --- a/demo/src/main/resources/static/index.html +++ b/demo/src/main/resources/static/index.html @@ -1,65 +1,73 @@ - - - - - - - - - - - - - - Testing ASF Java UI - - - -
- -
-
-
- -
-
-
-
-

Model

-
{{model | json}}
-
-
-
-
-

Form

-
{{debug.form | json}}
-
-
-
-
-

Schema

-
{{debug.schema | json}}
-
-
-
-
-
- - - + + + + + + + + + + + + + + + + + + + + + + Testing ASF Java UI + + + +
+ +
+
+
+ +
+
+
+
+

Model

+
{{model | json}}
+
+
+
+
+

Form

+
{{debug.form | json}}
+
+
+
+
+

Schema

+
{{debug.schema | json}}
+
+
+
+
+
+ + +