From 09a62cf165e2f81ec2f599b1c6ad416e9b621af0 Mon Sep 17 00:00:00 2001
From: Matthew Dillon <matthewrdillon@gmail.com>
Date: Sat, 30 Sep 2017 21:20:00 -0700
Subject: [PATCH] ENH: Simple collection details (#27)

---
 app/components/collection-detail-container.js  | 18 ++++++++++++++++++
 .../{collections.js => collections/index.js}   |  3 +++
 app/router.js                                  |  4 +++-
 app/routes/collections/detail.js               | 11 +++++++++++
 .../{collections.js => collections/index.js}   |  0
 app/templates/collections.hbs                  |  1 -
 app/templates/collections/detail.hbs           |  1 +
 app/templates/collections/index.hbs            |  6 ++++++
 app/templates/components/ccdb-table.hbs        |  8 ++++----
 .../components/collection-detail-container.hbs |  6 ++++++
 .../components/collections-container.hbs       |  8 +++++++-
 package.json                                   |  1 +
 tests/unit/controllers/collections-test.js     | 12 ------------
 tests/unit/routes/collections-test.js          | 10 ----------
 14 files changed, 60 insertions(+), 29 deletions(-)
 create mode 100644 app/components/collection-detail-container.js
 rename app/controllers/{collections.js => collections/index.js} (69%)
 create mode 100644 app/routes/collections/detail.js
 rename app/routes/{collections.js => collections/index.js} (100%)
 delete mode 100644 app/templates/collections.hbs
 create mode 100644 app/templates/collections/detail.hbs
 create mode 100644 app/templates/collections/index.hbs
 create mode 100644 app/templates/components/collection-detail-container.hbs
 delete mode 100644 tests/unit/controllers/collections-test.js
 delete mode 100644 tests/unit/routes/collections-test.js

diff --git a/app/components/collection-detail-container.js b/app/components/collection-detail-container.js
new file mode 100644
index 0000000..e26790e
--- /dev/null
+++ b/app/components/collection-detail-container.js
@@ -0,0 +1,18 @@
+import Ember from 'ember';
+
+const { Component } = Ember;
+
+export default Component.extend({
+  // ARGS
+  model: null,
+
+  columns: [
+    { label: 'Project', valuePath: 'project.name', },
+    { label: 'Study Location', valuePath: 'studyLocation.code', },
+    { label: 'Method', valuePath: 'collectionMethod.code', },
+    { label: 'Type', valuePath: 'collectionType.name', },
+    { label: '# of Traps', valuePath: 'numberOfTraps', },
+    { label: 'Start', valuePath: 'startDateTime', },
+    { label: 'End', valuePath: 'endDateTime', },
+  ],
+});
diff --git a/app/controllers/collections.js b/app/controllers/collections/index.js
similarity index 69%
rename from app/controllers/collections.js
rename to app/controllers/collections/index.js
index 73da5ae..b6143e1 100644
--- a/app/controllers/collections.js
+++ b/app/controllers/collections/index.js
@@ -10,5 +10,8 @@ export default Controller.extend({
     changePage(page) {
       this.set('page', page);
     },
+    rowClick(row) {
+      this.transitionToRoute('collections.detail', row.get('id'));
+    },
   },
 });
diff --git a/app/router.js b/app/router.js
index 3234f26..32c57ae 100644
--- a/app/router.js
+++ b/app/router.js
@@ -9,7 +9,9 @@ const Router = Ember.Router.extend({
 Router.map(function() {
   this.route('login');
   this.route('logout');
-  this.route('collections');
+  this.route('collections', function() {
+    this.route('detail', { path: '/:collection_id' });
+  });
 });
 
 export default Router;
diff --git a/app/routes/collections/detail.js b/app/routes/collections/detail.js
new file mode 100644
index 0000000..cff1611
--- /dev/null
+++ b/app/routes/collections/detail.js
@@ -0,0 +1,11 @@
+import Ember from 'ember';
+
+const { Route, RSVP } = Ember;
+
+export default Route.extend({
+  model(params) {
+    return RSVP.all([
+      this.get('store').findRecord('collection', params.collection_id)
+    ]);
+  },
+});
diff --git a/app/routes/collections.js b/app/routes/collections/index.js
similarity index 100%
rename from app/routes/collections.js
rename to app/routes/collections/index.js
diff --git a/app/templates/collections.hbs b/app/templates/collections.hbs
deleted file mode 100644
index a2b1217..0000000
--- a/app/templates/collections.hbs
+++ /dev/null
@@ -1 +0,0 @@
-{{collections-container model=model changePage=(action 'changePage')}}
diff --git a/app/templates/collections/detail.hbs b/app/templates/collections/detail.hbs
new file mode 100644
index 0000000..9f5f596
--- /dev/null
+++ b/app/templates/collections/detail.hbs
@@ -0,0 +1 @@
+{{collection-detail-container model=model}}
diff --git a/app/templates/collections/index.hbs b/app/templates/collections/index.hbs
new file mode 100644
index 0000000..53b5edb
--- /dev/null
+++ b/app/templates/collections/index.hbs
@@ -0,0 +1,6 @@
+{{
+  collections-container
+  model=model
+  changePage=(action 'changePage')
+  onRowClick=(action 'rowClick')
+}}
diff --git a/app/templates/components/ccdb-table.hbs b/app/templates/components/ccdb-table.hbs
index 685c2ee..7f1cdfd 100644
--- a/app/templates/components/ccdb-table.hbs
+++ b/app/templates/components/ccdb-table.hbs
@@ -1,12 +1,12 @@
 {{#if hasBlock}}
   {{yield (hash
-    table=(component 'light-table' table=table)
-    pagination=(component 'ccdb-pagination' model=model changePage=(action changePage))
+    grid=(component 'light-table' table=table onRowClicked=(action (optional onRowClicked)))
+    pagination=(component 'ccdb-pagination' model=model changePage=(action (optional changePage)))
   )}}
 {{else}}
-  {{ccdb-pagination model=model changePage=(action changePage)}}
+  {{ccdb-pagination model=model changePage=(action (optional changePage))}}
   {{#light-table table tableClassNames="table table-striped" as |t|}}
     {{t.head}}
-    {{t.body}}
+    {{t.body onRowClick=(action (optional onRowClick))}}
   {{/light-table}}
 {{/if}}
diff --git a/app/templates/components/collection-detail-container.hbs b/app/templates/components/collection-detail-container.hbs
new file mode 100644
index 0000000..bcc031b
--- /dev/null
+++ b/app/templates/components/collection-detail-container.hbs
@@ -0,0 +1,6 @@
+{{#ccdb-table model=model columns=columns as |c|}}
+  {{#c.grid as |g|}}
+    {{g.head}}
+    {{g.body}}
+  {{/c.grid}}
+{{/ccdb-table}}
diff --git a/app/templates/components/collections-container.hbs b/app/templates/components/collections-container.hbs
index ab74bb0..17bcdfb 100644
--- a/app/templates/components/collections-container.hbs
+++ b/app/templates/components/collections-container.hbs
@@ -1 +1,7 @@
-{{ccdb-table model=model columns=columns changePage=(action changePage)}}
+{{
+  ccdb-table
+  model=model
+  columns=columns
+  changePage=(action changePage)
+  onRowClick=(action onRowClick)
+}}
diff --git a/package.json b/package.json
index 8a41093..0553304 100644
--- a/package.json
+++ b/package.json
@@ -31,6 +31,7 @@
     "ember-cli-shims": "^1.1.0",
     "ember-cli-sri": "^2.1.0",
     "ember-cli-uglify": "^1.2.0",
+    "ember-composable-helpers": "^2.0.3",
     "ember-data": "~2.14.3",
     "ember-export-application-global": "^2.0.0",
     "ember-inflector": "^2.0.1",
diff --git a/tests/unit/controllers/collections-test.js b/tests/unit/controllers/collections-test.js
deleted file mode 100644
index b92a9ac..0000000
--- a/tests/unit/controllers/collections-test.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import { moduleFor, test } from 'ember-qunit';
-
-moduleFor('controller:collections', 'Unit | Controller | collections', {
-  // Specify the other units that are required for this test.
-  // needs: ['controller:foo']
-});
-
-// Replace this with your real tests.
-test('it exists', function(assert) {
-  let controller = this.subject();
-  assert.ok(controller);
-});
diff --git a/tests/unit/routes/collections-test.js b/tests/unit/routes/collections-test.js
deleted file mode 100644
index 5bf1e5d..0000000
--- a/tests/unit/routes/collections-test.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import { moduleFor, test } from 'ember-qunit';
-
-moduleFor('route:collections', 'Unit | Route | collections', {
-  unit: true,
-});
-
-test('it exists', function(assert) {
-  const route = this.subject();
-  assert.ok(route);
-});