Commit efef8779 authored by Bertrand PINEL's avatar Bertrand PINEL
Browse files

First complete version using validated forms

parent cdd8f967
<button <button
class="btn btn-default" class="btn btn-primary"
onclick={{action "sendAction" "delete" record}}> onclick={{action "sendAction" "delete" record}}>
Delete Delete
</button> </button>
...@@ -46,6 +46,14 @@ module.exports = { ...@@ -46,6 +46,14 @@ module.exports = {
addLineToFile(this, configPath, /'use strict';/, proxy); addLineToFile(this, configPath, /'use strict';/, proxy);
addLineToFile(this, configPath, /when it is created/, "\t\tproxy: usingProxy(),"); addLineToFile(this, configPath, /when it is created/, "\t\tproxy: usingProxy(),");
let validatedFormConfig = '\t"ember-validated-form": {\n\t\tlabel: {\n\t\t\tsubmit: "label.save"\n\t\t},\n'+
'\t\tcss: {\n\t\t\tgroup: "form-group",\n\t\t\tradio: "radio",\n\t\t\tcontrol: "form-control",\n'+
'\t\t\tlabel: "col-form-label",\n\t\t\thelp: "small form-text text-danger",'+
'\n\t\t\thint: "small form-text text-muted",\n\t\t\tcheckbox: "checkbox",\n\t\t\tbutton: "btn btn-default",'+
'\n\t\t\tsubmit: "btn btn-primary",\n\t\t\tloading: "loading",\n\t\t\tvalid: "is-valid",'+
'\n\t\t\terror: "is-invalid"\n\t\t}\n\t},\n';
addLineToFile(this, configPath, /let ENV = {/, validatedFormConfig);
// Add import of ember_aws_ehipster.css to apps.css // Add import of ember_aws_ehipster.css to apps.css
let stylePath = (options.dummy) ? "tests/dummy/app/styles/app.css" : "app/styles/app.css"; let stylePath = (options.dummy) ? "tests/dummy/app/styles/app.css" : "app/styles/app.css";
let importcss = "@import 'ember-aws-ehipster.css';\n"; let importcss = "@import 'ember-aws-ehipster.css';\n";
......
...@@ -2,10 +2,13 @@ import Controller from '@ember/controller'; ...@@ -2,10 +2,13 @@ import Controller from '@ember/controller';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
import { A } from '@ember/array'; import { A } from '@ember/array';
import EmberObject from '@ember/object'; import EmberObject from '@ember/object';
import <%=capitalizeEntityName%>Validations from "../../validations/<%=singularEntityName%>";
import { task } from "ember-concurrency";
export default Controller.extend({ export default Controller.extend({
isAddingEntry: false, isAddingEntry: false,
newEntry: EmberObject.create({<%=controllerInitEntity%>}), newEntry: EmberObject.create({<%=controllerInitEntity%>}),
<%=capitalizeEntityName%>Validations,
<%=controllerModelTable%> <%=controllerModelTable%>
...@@ -22,5 +25,12 @@ export default Controller.extend({ ...@@ -22,5 +25,12 @@ export default Controller.extend({
console.log('record is '+ record); console.log('record is '+ record);
record.destroyRecord(); record.destroyRecord();
} }
} },
submitEntry: task(function*(model) {
yield model.save();
let newEntity = this.store.createRecord('<%=singularEntityName%>',yield model.get('data'));
yield newEntity.save();
console.log("new entry of id "+newEntity.get('id')+" created");
this.set('addEntryModal', false);
})
}); });
\ No newline at end of file
...@@ -22,9 +22,5 @@ ...@@ -22,9 +22,5 @@
{{#modal.body}} {{#modal.body}}
<%=templateEntityForm%> <%=templateEntityForm%>
{{/modal.body}} {{/modal.body}}
{{#modal.footer}}
{{#bs-button onClick=(action modal.close)}}Cancel{{/bs-button}}
{{#bs-button type="success" onClick=(action modal.submit)}}Save{{/bs-button}}
{{/modal.footer}}
{{/bs-modal}} {{/bs-modal}}
</div> </div>
\ No newline at end of file
...@@ -57,6 +57,7 @@ module.exports = { ...@@ -57,6 +57,7 @@ module.exports = {
locals(options) { locals(options) {
let camelizedName = stringUtils.camelize(options.entity.name); let camelizedName = stringUtils.camelize(options.entity.name);
let capitizeName = stringUtils.capitalize(camelizedName);
/* /*
for (let name in entityOptions) { for (let name in entityOptions) {
...@@ -76,6 +77,7 @@ module.exports = { ...@@ -76,6 +77,7 @@ module.exports = {
*/ */
return { return {
singularEntityName: camelizedName, singularEntityName: camelizedName,
capitalizeEntityName: capitizeName,
entityValidation: entityValidation(camelizedName, options.entity.options), entityValidation: entityValidation(camelizedName, options.entity.options),
entityModel: entityModel(camelizedName, options.entity.options), entityModel: entityModel(camelizedName, options.entity.options),
mirageFactory: mirageFactory(camelizedName, options.entity.options), mirageFactory: mirageFactory(camelizedName, options.entity.options),
...@@ -160,7 +162,8 @@ function addLineToFile(ctx, filePath, markerString, addedLine) { ...@@ -160,7 +162,8 @@ function addLineToFile(ctx, filePath, markerString, addedLine) {
}; };
function templateEntityForm(name, options) { function templateEntityForm(name, options) {
let form = ['{{#bs-form formLayout="vertical" model=newEntry onSubmit=(action "submit") as |form|}}']; let capitalizeName = stringUtils.capitalize(name);
let form = ['{{#validated-form model = (changeset newEntry '+capitalizeName+'Validations) on-submit = (perform submitEntry) as |f|}}'];
let attributes = []; let attributes = [];
for (var prop in options) { for (var prop in options) {
let type = options[prop].split(':')[0]; let type = options[prop].split(':')[0];
...@@ -168,18 +171,17 @@ function templateEntityForm(name, options) { ...@@ -168,18 +171,17 @@ function templateEntityForm(name, options) {
switch (type) { switch (type) {
case "string": case "string":
case "number": case "number":
form.push('{{form.element controlType="text" label=\"' + prop + '\" property=\"'+ prop + '\" value=' + form.push('{{f.input label="'+prop+'" name="'+prop+'" }}');
prop + ' onChange=(action (mut ' + prop + ')) placeholder=\"' + prop + '\"}}');
break; break;
case "boolean": case "boolean":
form.push('{{form.element controlType="checkbox" label=\"' + prop + '\" property=\"'+ prop + '\" value=' + form.push('\t\t{{f.input type="checkbox" label="'+prop+'" name="'+prop+'" }}');
prop + ' onChange=(action (mut ' + prop + ')) placeholder=\"' + prop + '\"}}');
break; break;
case "date": case "date":
form.push('<div class="row form-group"><label class="col-form-label col-md-4">' + prop + form.push('\t\t{{#f.input label="'+prop+'" name="'+prop+'" as |fi|}}\n' +
'</label>{{pikaday-input useUTC=true format="DD/MM/YYYY" onSelection=(action (mut ' + prop + '))}}</div>'); '\t\t\t{{pikaday-input useUTC=true format="DD/MM/YYYY" onSelection=fi.update}}\n' +
'\t\t{{/f.input}}');
break; break;
case 'belongs-to': case 'belongs-to':
...@@ -195,7 +197,7 @@ function templateEntityForm(name, options) { ...@@ -195,7 +197,7 @@ function templateEntityForm(name, options) {
break; break;
} }
} }
form.push("{{/bs-form}}"); form.push('\t\t{{f.submit class="btn btn-primary" label="Save"}}\n\t{{/validated-form}}');
return form.join('\n'); return form.join('\n');
}; };
......
{ {
"name": "ember-aws-ehipster", "name": "ember-aws-ehipster",
"version": "0.3.9", "version": "0.3.17",
"description": "Attempt to build a complete web application using serverless architecture on AWS", "description": "Attempt to build a complete web application using serverless architecture on AWS",
"keywords": [ "keywords": [
"ember-addon", "ember-addon",
...@@ -36,17 +36,17 @@ ...@@ -36,17 +36,17 @@
"ember-pikaday": "^2.3.0", "ember-pikaday": "^2.3.0",
"jhipster-core": "^3.4.0", "jhipster-core": "^3.4.0",
"shelljs": "^0.8.2", "shelljs": "^0.8.2",
"ember-validated-form": "^2.0.0-alpha.3", "ember-validated-form": "^1.4.2",
"ember-concurrency": "^0.8.26", "ember-concurrency": "^0.8.26",
"ember-changeset": "^1.6.0", "ember-changeset": "^1.6.0",
"ember-changeset-validations": "^1.3.3" "ember-changeset-validations": "^1.3.3",
"ember-cli-string-helpers": "^2.0.0",
"ember-composable-helpers": "^2.1.0"
}, },
"devDependencies": { "devDependencies": {
"broccoli-asset-rev": "^2.4.5", "broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^3.0.0", "ember-ajax": "^3.0.0",
"ember-auto-import": "^1.2.15", "ember-auto-import": "^1.2.15",
"ember-changeset": "^1.6.0",
"ember-changeset-validations": "^1.3.3",
"ember-cli": "~3.1.4", "ember-cli": "~3.1.4",
"ember-cli-dependency-checker": "^2.0.0", "ember-cli-dependency-checker": "^2.0.0",
"ember-cli-eslint": "^4.2.1", "ember-cli-eslint": "^4.2.1",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment