DataInventory
Changes
app/Controllers/Http/ContactController.js 16(+11 -5)
app/Models/Contact.js 5(+5 -0)
app/Models/Organization.js 5(+5 -0)
resources/views/contacts/create.edge 12(+12 -0)
resources/views/contacts/index.edge 2(+2 -0)
resources/views/organizations/create.edge 12(+12 -0)
Details
app/Controllers/Http/ContactController.js 16(+11 -5)
diff --git a/app/Controllers/Http/ContactController.js b/app/Controllers/Http/ContactController.js
index c073c3b..7e14448 100644
--- a/app/Controllers/Http/ContactController.js
+++ b/app/Controllers/Http/ContactController.js
@@ -4,6 +4,7 @@
/** @typedef {import('@adonisjs/framework/src/Response')} Response */
/** @typedef {import('@adonisjs/framework/src/View')} View */
const Contact = use('App/Models/Contact')
+const Organization = use('App/Models/Organization')
const { validate } = use('Validator')
/**
@@ -20,8 +21,8 @@ class ContactController {
* @param {View} ctx.view
*/
async index ({ request, response, view }) {
- const contacts = await Contact.query().orderBy('last_name', 'asc').fetch()
-
+ const contacts = await Contact.query().with('organization').orderBy('last_name', 'asc').fetch()
+
return view.render('contacts.index', {
contacts: contacts.toJSON()
})
@@ -37,7 +38,10 @@ class ContactController {
* @param {View} ctx.view
*/
async create ({ request, response, view }) {
- return view.render('contacts.create')
+ const organizations = await Organization.all()
+ return view.render('contacts.create', {
+ organizations: organizations.toJSON()
+ })
}
/**
@@ -48,19 +52,21 @@ class ContactController {
* @param {Request} ctx.request
* @param {Response} ctx.response
*/
- async store ({ request, response }) {
- const data = request.only(['email', 'first_name', 'last_name', 'phone'])
+ async store ({ request, response, session }) {
+ const data = request.only(['email', 'first_name', 'last_name', 'phone', 'organization_id'])
const validation = await validate(request.all(), {
email: 'required',
first_name: 'required',
last_name: 'required',
phone: 'required',
+ organization_id: 'required',
}, {
'email.required': `Email is required`,
'first_name.required': `First Name is required`,
'last_name.required': `Last Name is required`,
'phone.required': `Phone Number is required`,
+ 'organization_id': `Orgnaization name required`,
})
if(validation.fails()) {
diff --git a/app/Controllers/Http/OrganizationController.js b/app/Controllers/Http/OrganizationController.js
index 619ceb3..bf26895 100644
--- a/app/Controllers/Http/OrganizationController.js
+++ b/app/Controllers/Http/OrganizationController.js
@@ -4,6 +4,7 @@
/** @typedef {import('@adonisjs/framework/src/Response')} Response */
/** @typedef {import('@adonisjs/framework/src/View')} View */
const Organization = use('App/Models/Organization')
+const Type = use('App/Models/OrganizationType')
const { validate } = use('Validator')
/**
@@ -20,7 +21,7 @@ class OrganizationController {
* @param {View} ctx.view
*/
async index ({ request, response, view }) {
- const organizations = await Organization.query().with('organization_types').orderBy('name', 'asc').fetch()
+ const organizations = await Organization.query().with('type').orderBy('name', 'asc').fetch()
return view.render('organizations.index', {
organizations: organizations.toJSON()
@@ -37,7 +38,10 @@ class OrganizationController {
* @param {View} ctx.view
*/
async create ({ request, response, view }) {
- return view.render('organizations.create')
+ const types = await Type.all()
+ return view.render('organizations.create', {
+ types: types.toJSON()
+ })
}
/**
app/Models/Contact.js 5(+5 -0)
diff --git a/app/Models/Contact.js b/app/Models/Contact.js
index 8462701..2f921c4 100644
--- a/app/Models/Contact.js
+++ b/app/Models/Contact.js
@@ -4,6 +4,11 @@
const Model = use('Model')
class Contact extends Model {
+
+ organization() {
+ return this.belongsTo('App/Models/Organization')
+ }
+
}
module.exports = Contact
app/Models/Organization.js 5(+5 -0)
diff --git a/app/Models/Organization.js b/app/Models/Organization.js
index 8dc49a5..1e2434a 100644
--- a/app/Models/Organization.js
+++ b/app/Models/Organization.js
@@ -4,6 +4,11 @@
const Model = use('Model')
class Organization extends Model {
+
+ type() {
+ return this.belongsTo('App/Models/OrganizationType')
+ }
+
}
module.exports = Organization
resources/views/contacts/create.edge 12(+12 -0)
diff --git a/resources/views/contacts/create.edge b/resources/views/contacts/create.edge
index 823a41b..9b6adb3 100644
--- a/resources/views/contacts/create.edge
+++ b/resources/views/contacts/create.edge
@@ -17,6 +17,18 @@
</div>
<div class="field">
+ <label class="label">Organization</label>
+ <div class="select">
+ <select name="organization_id">
+ <option>Select dropdown</option>
+ @each(organization in organizations)
+ <option value="{{organization.id}}">{{organization.name}}</option>
+ @endeach
+ </select>
+ </div>
+ </div>
+
+ <div class="field">
<label class="label">Contact Email</label>
<input class="input" type="text" name="email" placeholder="arthur.fish@oregon.gov" value="{{ old('email', '') }}" />
{{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('email'), hasErrorFor('email')) }}
resources/views/contacts/index.edge 2(+2 -0)
diff --git a/resources/views/contacts/index.edge b/resources/views/contacts/index.edge
index 4e65fbe..9bcbd38 100644
--- a/resources/views/contacts/index.edge
+++ b/resources/views/contacts/index.edge
@@ -17,6 +17,7 @@
<tr>
<th>Last Name</th>
<th>First Name</th>
+ <th>Organization</th>
<th>Email</th>
<th>Phone</th>
<th>Action</th>
@@ -27,6 +28,7 @@
<tr>
<td>{{ contact.last_name }}</td>
<td>{{ contact.first_name }}</td>
+ <td>{{ contact.organization.name }}</td>
<td>{{ contact.email}}</td>
<td>{{ contact.phone }}</td>
<td>
resources/views/organizations/create.edge 12(+12 -0)
diff --git a/resources/views/organizations/create.edge b/resources/views/organizations/create.edge
index 98a7f1f..da99eab 100644
--- a/resources/views/organizations/create.edge
+++ b/resources/views/organizations/create.edge
@@ -11,6 +11,18 @@
</div>
<div class="field">
+ <label class="label">Organization Type</label>
+ <div class="select">
+ <select name="organization_type_id">
+ <option>Select dropdown</option>
+ @each(type in types)
+ <option value="{{type.id}}">{{type.type}}</option>
+ @endeach
+ </select>
+ </div>
+ </div>
+
+ <div class="field">
<label class="label">Organization Email</label>
<input class="input" type="text" name="email" placeholder="State of Oregon" value="{{ old('email', '') }}" />
{{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('email'), hasErrorFor('email')) }}