From f244a7bd10a82fcbdaf1738f297a338142022755 Mon Sep 17 00:00:00 2001
From: bertrand <bpinel@ippon.fr>
Date: Sun, 9 Dec 2018 09:51:01 +0100
Subject: [PATCH] Big cleanup removing fake entities...

---
 addon/controllers/entity-factory.js           | 13 ++++++++
 addon/templates/entity-factory.hbs            |  9 ++++++
 app/controllers/entity-factory.js             |  1 +
 app/router.js                                 |  3 ++
 app/templates/entity-factory.js               |  1 +
 .../templates/entity-factory/__name__.hbs     |  2 +-
 blueprints/entity-factory/index.js            | 12 +++++++-
 blueprints/jdl-importer/index.js              |  6 +++-
 jdl/jhipster_user.jh                          | 26 ++++++++++++++++
 mirage/config.js                              | 23 ++++++++++++++
 mirage/scenarios/default.js                   |  7 +++++
 mirage/scenarios/tobedeleted.txt              |  1 +
 mirage/serializers/application.js             |  4 +++
 mirage/serializers/tobedeleted.txt            |  1 +
 package.json                                  |  5 +++-
 .../app/controllers/entity-factory/toto.js    | 30 -------------------
 tests/dummy/app/models/.gitkeep               |  0
 tests/dummy/app/models/toto.js                |  8 -----
 tests/dummy/app/router.js                     |  3 +-
 tests/dummy/app/routes/entity-factory/toto.js |  8 -----
 tests/dummy/app/templates/application.hbs     |  2 +-
 .../app/templates/entity-factory/toto.hbs     |  5 ----
 tests/dummy/mirage/config.js                  |  1 -
 tests/dummy/mirage/factories/toto.js          | 23 --------------
 tests/dummy/mirage/models/toto.js             |  7 -----
 tests/dummy/mirage/scenarios/default.js       |  1 -
 tests/unit/controllers/entity-factory-test.js | 12 ++++++++
 27 files changed, 124 insertions(+), 90 deletions(-)
 create mode 100644 addon/controllers/entity-factory.js
 create mode 100644 addon/templates/entity-factory.hbs
 create mode 100644 app/controllers/entity-factory.js
 create mode 100644 app/templates/entity-factory.js
 create mode 100644 jdl/jhipster_user.jh
 create mode 100644 mirage/config.js
 create mode 100644 mirage/scenarios/default.js
 create mode 100644 mirage/scenarios/tobedeleted.txt
 create mode 100644 mirage/serializers/application.js
 create mode 100644 mirage/serializers/tobedeleted.txt
 delete mode 100644 tests/dummy/app/controllers/entity-factory/toto.js
 delete mode 100644 tests/dummy/app/models/.gitkeep
 delete mode 100644 tests/dummy/app/models/toto.js
 delete mode 100644 tests/dummy/app/routes/entity-factory/toto.js
 delete mode 100644 tests/dummy/app/templates/entity-factory/toto.hbs
 delete mode 100644 tests/dummy/mirage/factories/toto.js
 delete mode 100644 tests/dummy/mirage/models/toto.js
 create mode 100644 tests/unit/controllers/entity-factory-test.js

diff --git a/addon/controllers/entity-factory.js b/addon/controllers/entity-factory.js
new file mode 100644
index 0000000..c1270ad
--- /dev/null
+++ b/addon/controllers/entity-factory.js
@@ -0,0 +1,13 @@
+import Controller from '@ember/controller';
+
+export default Controller.extend({
+    entities: [
+    ],
+    entity: '',
+    actions: {
+        selectEntity(entity) {
+            this.set('entity', entity);
+            this.transitionToRoute('entity-factory.'+entity);
+        }
+    }
+});
\ No newline at end of file
diff --git a/addon/templates/entity-factory.hbs b/addon/templates/entity-factory.hbs
new file mode 100644
index 0000000..3976c07
--- /dev/null
+++ b/addon/templates/entity-factory.hbs
@@ -0,0 +1,9 @@
+<div class="container"> 
+    Available entities : 
+    <select class="ember-select" onchange={{action "selectEntity" value="target.value"}}>
+        {{#each entities as |entityChoice|}}
+            <option value={{entityChoice}} selected={{eq entity entityChoice}}>{{entityChoice}}</option>
+        {{/each}}
+    </select>
+</div>
+{{outlet}}
\ No newline at end of file
diff --git a/app/controllers/entity-factory.js b/app/controllers/entity-factory.js
new file mode 100644
index 0000000..de27314
--- /dev/null
+++ b/app/controllers/entity-factory.js
@@ -0,0 +1 @@
+export { default } from 'ember-aws-ehipster/controllers/entity-factory';
diff --git a/app/router.js b/app/router.js
index d0bb009..f033602 100644
--- a/app/router.js
+++ b/app/router.js
@@ -7,6 +7,9 @@ const Router = EmberRouter.extend({
 });
 
 Router.map(function() {
+	this.route('entity-factory/tag');
+	this.route('entity-factory/entry');
+	this.route('entity-factory/blog');
 });
 
 export default Router;
diff --git a/app/templates/entity-factory.js b/app/templates/entity-factory.js
new file mode 100644
index 0000000..8502d09
--- /dev/null
+++ b/app/templates/entity-factory.js
@@ -0,0 +1 @@
+export { default } from 'ember-aws-ehipster/templates/entity-factory';
diff --git a/blueprints/entity-factory/files/__root__/templates/entity-factory/__name__.hbs b/blueprints/entity-factory/files/__root__/templates/entity-factory/__name__.hbs
index 9db66f6..7f48650 100644
--- a/blueprints/entity-factory/files/__root__/templates/entity-factory/__name__.hbs
+++ b/blueprints/entity-factory/files/__root__/templates/entity-factory/__name__.hbs
@@ -1,7 +1,7 @@
 {{outlet}}
 <div class="container-fluid">
 
-<h2>List of <%=singularEntityName%> Entities</h2>
+<h3>List of <%=singularEntityName%> entities</h3>
 
 {{#models-table data=<%=singularEntityName%>TableContent columns=<%=singularEntityName%>TableColumns delete="deleteRecord" as |mt|}}
   {{mt.global-filter}}
diff --git a/blueprints/entity-factory/index.js b/blueprints/entity-factory/index.js
index 359db11..9de8742 100644
--- a/blueprints/entity-factory/index.js
+++ b/blueprints/entity-factory/index.js
@@ -108,7 +108,12 @@ module.exports = {
         if (type === 'boolean') {
           buttonType = "checkbox";
         } 
-        form.push('{{form.element controlType="'+buttonType+'" label="'+camelizedName+'" value='+camelizedName+' onChange=(action (mut '+camelizedName+')) placeholder="'+camelizedName+'"}}');
+        if (type === 'date') {
+          form.push('<div class="row form-group"><label class="col-form-label col-md-4">'+camelizedName+
+          '</label>{{pikaday-input useUTC=true format="DD/MM/YYYY" onSelection=(action (mut '+camelizedName+'))}}</div>');
+        } else {
+          form.push('{{form.element controlType="'+buttonType+'" label="'+camelizedName+'" value='+camelizedName+' onChange=(action (mut '+camelizedName+')) placeholder="'+camelizedName+'"}}');
+        }
         ctrlVars.push(camelizedName+': null,');
         toCreateEntity.push(camelizedName+": this."+camelizedName);
       }
@@ -182,6 +187,11 @@ module.exports = {
     let routerPath = (options.dummy) ? "tests/dummy/app/router.js" : "app/router.js";
     let routeName = '\tthis.route\(\''+blueprintName+'/'+entityName+'\'\);';
     addLineToFile(this, routerPath, /Router\.map\(function\(\) {/, routeName);
+
+    // Add Entity select entry in the entity controller file
+    let entityIndexPath = (options.dummy) ? "tests/dummy/app/controllers/entity-factory.js" : "app/controllers/entity-factory.js";
+    let entityIndexEntry= "'"+entityName+"'";
+    addLineToFile(this, entityIndexPath, /entities: \[/, entityIndexEntry);
   }
 };
 
diff --git a/blueprints/jdl-importer/index.js b/blueprints/jdl-importer/index.js
index 1b2e824..2b33c6d 100644
--- a/blueprints/jdl-importer/index.js
+++ b/blueprints/jdl-importer/index.js
@@ -53,6 +53,10 @@ module.exports = {
             entity.options.push(property.name+':number');
             break;
 
+          case 'Boolean':
+            entity.options.push(property.name+':number');
+            break;
+
           default:
             this.ui.writeLine("Huston, we have a problem with unknow type "+property.name);
             break;
@@ -101,7 +105,7 @@ module.exports = {
         if (options.dummy) {
           cmd += ' --dummy';
         }
-        //console.log(cmd);
+        console.log(cmd);
         shelljs.exec(cmd);
     }
 
diff --git a/jdl/jhipster_user.jh b/jdl/jhipster_user.jh
new file mode 100644
index 0000000..9dbced5
--- /dev/null
+++ b/jdl/jhipster_user.jh
@@ -0,0 +1,26 @@
+entity User {
+ login String required,
+ passwordHash String,
+ firstName String,
+ lastName String,
+ email String,
+ imageUrl String,
+ activated Boolean,
+ langKey String,
+ activationKey String,
+ resetKey String,
+ createdBy String,
+ createdDate Date,
+ lastModifiedBy String
+ lastModifiedDate String
+}
+
+entity Authority {
+ name String required
+}
+
+relationship ManyToMany {
+	User{user(id)} to Authority{authorityName}
+}
+
+
diff --git a/mirage/config.js b/mirage/config.js
new file mode 100644
index 0000000..e916128
--- /dev/null
+++ b/mirage/config.js
@@ -0,0 +1,23 @@
+import ENV from './../config/environment';
+export default function() {
+	this.namespace = '';
+	if (!ENV.APP.proxy) {
+		this.get('/tags');
+		this.get('/tags/:id');
+		this.delete('/tags/:id');
+		this.patch('/tags/:id');
+		this.post('/tags');
+		this.get('/entries');
+		this.get('/entries/:id');
+		this.delete('/entries/:id');
+		this.patch('/entries/:id');
+		this.post('/entries');
+		this.get('/blogs');
+		this.get('/blogs/:id');
+		this.delete('/blogs/:id');
+		this.patch('/blogs/:id');
+		this.post('/blogs');
+	} else {
+		this.passthrough();
+	}
+}
diff --git a/mirage/scenarios/default.js b/mirage/scenarios/default.js
new file mode 100644
index 0000000..a55e391
--- /dev/null
+++ b/mirage/scenarios/default.js
@@ -0,0 +1,7 @@
+export default function(server) {
+	server.createList('tag', 8);
+
+	server.createList('entry', 8);
+
+	server.createList('blog', 8);
+}
diff --git a/mirage/scenarios/tobedeleted.txt b/mirage/scenarios/tobedeleted.txt
new file mode 100644
index 0000000..f203f96
--- /dev/null
+++ b/mirage/scenarios/tobedeleted.txt
@@ -0,0 +1 @@
+To be sure that the directory exists...
\ No newline at end of file
diff --git a/mirage/serializers/application.js b/mirage/serializers/application.js
new file mode 100644
index 0000000..eb1733c
--- /dev/null
+++ b/mirage/serializers/application.js
@@ -0,0 +1,4 @@
+import { JSONAPISerializer } from 'ember-cli-mirage';
+
+	export default JSONAPISerializer.extend({
+});
diff --git a/mirage/serializers/tobedeleted.txt b/mirage/serializers/tobedeleted.txt
new file mode 100644
index 0000000..f203f96
--- /dev/null
+++ b/mirage/serializers/tobedeleted.txt
@@ -0,0 +1 @@
+To be sure that the directory exists...
\ No newline at end of file
diff --git a/package.json b/package.json
index f85ad27..a896d29 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "ember-aws-ehipster",
-  "version": "0.2.1",
+  "version": "0.2.7",
   "description": "The default blueprint for ember-cli addons.",
   "keywords": [
     "ember-addon"
@@ -28,6 +28,8 @@
     "ember-cli-mirage": "^0.4.9",
     "ember-data": "^3.5.0",
     "ember-models-table": "^2.7.0",
+    "ember-truth-helpers": "^2.1.0",
+    "ember-pikaday": "^2.3.0",
     "jhipster-core": "^3.4.0",
     "shelljs": "^0.8.2"
   },
@@ -40,6 +42,7 @@
     "ember-cli-eslint": "^4.2.1",
     "ember-cli-htmlbars-inline-precompile": "^1.0.0",
     "ember-cli-inject-live-reload": "^1.4.1",
+    "ember-cli-moment-shim": "^3.7.1",
     "ember-cli-qunit": "^4.1.1",
     "ember-cli-shims": "^1.2.0",
     "ember-cli-sri": "^2.1.0",
diff --git a/tests/dummy/app/controllers/entity-factory/toto.js b/tests/dummy/app/controllers/entity-factory/toto.js
deleted file mode 100644
index 9d46bc4..0000000
--- a/tests/dummy/app/controllers/entity-factory/toto.js
+++ /dev/null
@@ -1,30 +0,0 @@
-import Controller from '@ember/controller';
-
-export default Controller.extend({
-
-totoTableColumns: Ember.computed(function() {
-var col = Ember.A([
-    Ember.Object.create({
-	propertyName: "title",
-	title: "title"
-}),
-Ember.Object.create({
-	propertyName: "description",
-	title: "description"
-}),
-Ember.Object.create({
-	propertyName: "number",
-	title: "number"
-}),
-Ember.Object.create({
-	propertyName: "isVisible",
-	title: "isVisible"
-}),
-]);
-return col;
-}),
-
-totoTableContent: Ember.computed(function() {
- return this.get("model");
-})
-});
\ No newline at end of file
diff --git a/tests/dummy/app/models/.gitkeep b/tests/dummy/app/models/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/tests/dummy/app/models/toto.js b/tests/dummy/app/models/toto.js
deleted file mode 100644
index 3e6fad0..0000000
--- a/tests/dummy/app/models/toto.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import DS from 'ember-data';
-
-export default DS.Model.extend({
-  title: DS.attr('string'),
-  description: DS.attr('string'),
-  number: DS.attr('number'),
-  isVisible: DS.attr('boolean')
-});
\ No newline at end of file
diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js
index f765969..1552e4a 100644
--- a/tests/dummy/app/router.js
+++ b/tests/dummy/app/router.js
@@ -7,8 +7,7 @@ const Router = EmberRouter.extend({
 });
 
 Router.map(function() {
-	this.route('entity-factory/toto');
-  this.route('entity-factory/toto');
+
 });
 
 export default Router;
diff --git a/tests/dummy/app/routes/entity-factory/toto.js b/tests/dummy/app/routes/entity-factory/toto.js
deleted file mode 100644
index 268a9b4..0000000
--- a/tests/dummy/app/routes/entity-factory/toto.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import Route from '@ember/routing/route';
-
-export default Route.extend({
-   model() {
-       return this.store.findAll('toto');
-   }
-
-});
\ No newline at end of file
diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs
index 5230580..2f57967 100644
--- a/tests/dummy/app/templates/application.hbs
+++ b/tests/dummy/app/templates/application.hbs
@@ -1,3 +1,3 @@
-<h2 id="title">Welcome to Ember</h2>
+<h2 id="title">A Guinea Pig in the Cloud</h2>
 
 {{outlet}}
\ No newline at end of file
diff --git a/tests/dummy/app/templates/entity-factory/toto.hbs b/tests/dummy/app/templates/entity-factory/toto.hbs
deleted file mode 100644
index 64a00b3..0000000
--- a/tests/dummy/app/templates/entity-factory/toto.hbs
+++ /dev/null
@@ -1,5 +0,0 @@
-<h2>List of toto</h2>
-{{models-table
-         data=totoTableContent
-         columns=totoTableColumns}}
-{{outlet}}
\ No newline at end of file
diff --git a/tests/dummy/mirage/config.js b/tests/dummy/mirage/config.js
index 66a08b4..16cf48b 100644
--- a/tests/dummy/mirage/config.js
+++ b/tests/dummy/mirage/config.js
@@ -1,4 +1,3 @@
 export default function() {
 	this.namespace = '';
-this.get('/totos', 'totos');
 }
diff --git a/tests/dummy/mirage/factories/toto.js b/tests/dummy/mirage/factories/toto.js
deleted file mode 100644
index 814694a..0000000
--- a/tests/dummy/mirage/factories/toto.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import {
-    Factory,
-    faker
-  } from 'ember-cli-mirage';
-  
-  export default Factory.extend({
-    //default generated factory
-	
-	title () {
-		return faker.name.findName()
-	},
-	description () {
-		return faker.name.findName()
-	},
-	number () {
-		return faker.random.number({min: 0,max: 10000})
-	},
-	isVisible () {
-		return faker.random.boolean()
-	}
-
-  })
-  
\ No newline at end of file
diff --git a/tests/dummy/mirage/models/toto.js b/tests/dummy/mirage/models/toto.js
deleted file mode 100644
index 7acee99..0000000
--- a/tests/dummy/mirage/models/toto.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import {
-    Model
-  } from 'ember-cli-mirage';
-  
-  export default Model.extend({
-  });
-  
\ No newline at end of file
diff --git a/tests/dummy/mirage/scenarios/default.js b/tests/dummy/mirage/scenarios/default.js
index 4c68877..1b5dd13 100644
--- a/tests/dummy/mirage/scenarios/default.js
+++ b/tests/dummy/mirage/scenarios/default.js
@@ -1,3 +1,2 @@
 export default function(server) {
-	server.createList('toto', 10);
 }
diff --git a/tests/unit/controllers/entity-factory-test.js b/tests/unit/controllers/entity-factory-test.js
new file mode 100644
index 0000000..57a99ff
--- /dev/null
+++ b/tests/unit/controllers/entity-factory-test.js
@@ -0,0 +1,12 @@
+import { module, test } from 'qunit';
+import { setupTest } from 'ember-qunit';
+
+module('Unit | Controller | entity-factory', function(hooks) {
+  setupTest(hooks);
+
+  // Replace this with your real tests.
+  test('it exists', function(assert) {
+    let controller = this.owner.lookup('controller:entity-factory');
+    assert.ok(controller);
+  });
+});
-- 
GitLab