DataInventory

feat: crud submissions

3/17/2020 9:59:15 AM

Changes

public/logo.svg 1(+0 -1)

public/pyramid.png 0(+0 -0)

public/splash.png 0(+0 -0)

public/style.css 92(+0 -92)

public/title.svg 1(+0 -1)

start/hooks.js 2(+1 -1)

Details

diff --git a/app/Controllers/Http/SubmissionController.js b/app/Controllers/Http/SubmissionController.js
index 77a0d9a..44d71cb 100644
--- a/app/Controllers/Http/SubmissionController.js
+++ b/app/Controllers/Http/SubmissionController.js
@@ -112,6 +112,22 @@ class SubmissionController {
    * @param {View} ctx.view
    */
   async edit ({ params, request, response, view }) {
+    const fof = await Submission.findOrFail(params.id)
+    const submission = await Submission.query()
+      .with('element.theme')
+      .with('steward.contact')
+      .with('status')
+      .first()
+    const elements = await Element.all()
+    const stewards = await Steward.query().with('contact').fetch()
+    const status = await Status.all()
+
+    return view.render('submissions.edit', {
+      submission: submission.toJSON(),
+      elements: elements.toJSON(),
+      stewards: stewards.toJSON(),
+      statuses: status.toJSON()
+    })
   }
 
   /**
@@ -122,7 +138,31 @@ class SubmissionController {
    * @param {Request} ctx.request
    * @param {Response} ctx.response
    */
-  async update ({ params, request, response }) {
+  async update ({ params, request, response, session }) {
+    const data = request.only(['name', 'upload_date',
+      'creation_date', 'published_date', 'element_id', 
+      'steward_id', 'public', 'status_id'])
+
+    const validation = await validateAll(data, {
+      'name': 'required',
+      'element_id': 'required',
+      'steward_id': 'required',
+      'public': 'required',
+      'status_id': 'required'
+    })
+
+    if (validation.fails()) {
+      session
+        .withErrors(validation.messages())
+        .flashAll()
+      return response.redirect('back')
+    }
+
+    const submission = await Submission.findOrFail(params.id)
+    submission.merge(data)
+    await submission.save()
+
+    return response.redirect(Env.get('APP_URL') + '/submissions')
   }
 
   /**
@@ -134,6 +174,10 @@ class SubmissionController {
    * @param {Response} ctx.response
    */
   async destroy ({ params, request, response }) {
+    const submission = await Submission.findOrFail(params.id)
+    await submission.delete()
+
+    return response.redirect(Env.get('APP_URL') + '/submissions')
   }
 }
 
diff --git a/resources/views/submissions/edit.edge b/resources/views/submissions/edit.edge
new file mode 100644
index 0000000..9d67263
--- /dev/null
+++ b/resources/views/submissions/edit.edge
@@ -0,0 +1,140 @@
+@layout('layouts.main')
+
+@section('content')
+
+<form method="POST" action="{{ APP_URL() + route('/submissions.update', {id: submission.id}) + '?_method=PUT' }}">
+  {{ csrfField() }}
+  <div class="field">
+    <label class="label">Name of Submission</label>
+    <input class="input" type="text" name="name" placeholder="Enterprise Zones, Jan 2019" value="{{ submission.name }}" />
+    {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('name'), hasErrorFor('name')) }}
+  </div>
+
+  <div class="field">
+    <label class="label">Status</label>
+    <div class="select">
+      <select name="status_id">
+        <option>Select dropdown</option>
+        @each(status in statuses)
+          <option value="{{status.id}}" {{status.id === submission.status_id ? 'selected' : ''}}>{{status.status}}</option>
+        @endeach
+      </select>
+    </div>
+  </div>
+
+  <div class="field">
+    <label class="label">Element</label>
+    <div class="select">
+      <select name="element_id">
+        <option>Select dropdown</option>
+        @each(element in elements)
+          <option value="{{element.id}}" {{element.id === submission.element_id ? 'selected' : ''}}>{{element.name}}</option>
+        @endeach
+      </select>
+    </div>
+  </div>
+
+  <div class="field">
+    <label class="label">Steward</label>
+    <div class="select">
+      <select name="steward_id">
+        <option>Select dropdown</option>
+        @each(steward in stewards)
+          <option value="{{steward.id}}" {{steward.id === submission.element_id ? 'selected' : ''}}>{{steward.contact.first_name}} {{steward.contact.last_name}}</option>
+        @endeach
+      </select>
+    </div>
+  </div>
+
+  <div class="field">
+    <label class="label">Received Date</label>
+    <input class="input received-datepicker" type="text" name="upload_date" value="{{ TO_LOCALE(submission.upload_date) }}" />
+    {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('upload_date'), hasErrorFor('upload_date')) }}
+  </div>
+
+  <div class="field">
+    <label class="label">Created Date</label>
+    <input class="input created-datepicker" type="text" name="creation_date" value="{{ TO_LOCALE(submission.creation_date) }}" />
+    {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('creation_date'), hasErrorFor('creation_date')) }}
+  </div>
+
+  <div class="field">
+    <label class="label">Published Date</label>
+    <input class="input published-datepicker" type="text" name="published_date" value="{{ TO_LOCALE(submission.published_date) }}" />
+    {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('published_date'), hasErrorFor('published_date')) }}
+  </div>
+
+  <div class="field">
+    <label class="label">Local File Location</label>
+    <input class="input" type="text" name="local_file_location" placeholder="S:/shared/gis/adminbnds/submission.zip" value="{{ submission.local_file_location }}" />
+    {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('local_file_location'), hasErrorFor('local_file_location')) }}
+  </div>
+
+  <div class="field">
+    <label class="label">Download File Location</label>
+    <input class="input" type="text" name="download_file_location" placeholder="ftp://ftp.gis.oregon.gov/adminbound/EnterpriseZones2019.zip" value="{{ submission.download_file_location }}" />
+    {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('download_file_location'), hasErrorFor('download_file_location')) }}
+  </div>
+
+  <div class="field">
+    <label class="label">ArcGIS Server Service Location</label>
+    <input class="input" type="text" name="service_location_ags" placeholder="https://navigator.state.or.us/arcgis/rest/services/Projects/Prep_TransCams/MapServer/0" value="{{ submission.service_location_ags }}" />
+    {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('service_location_ags'), hasErrorFor('service_location_ags')) }}
+  </div>
+
+  <div class="field">
+    <label class="label">ArcGIS Online Service ItemID</label>
+    <input class="input" type="text" name="service_location_agol" placeholder="41d7a22bc09942e9ba0cee1f5746e02c" value="{{ submission.service_location_agol }}" />
+    {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('service_location_agol'), hasErrorFor('service_location_agol')) }}
+  </div>
+
+  <div class="field">
+    <label class="label">Public</label>
+    <div class="select">
+      <select name="public">
+        <option value="true"  {{submission.public ? 'selected' : ''}}>Yes</option>
+        <option value="false" {{!submission.public ? 'selected' : ''}}>No</option>
+      </select>
+    </div>
+  </div>
+
+  <div class="field is-grouped">
+      <div class="control">
+        <button class="button is-link ss-submit" type="submit">Submit</button>
+      </div>
+      <div class="control">
+      <button class="button is-text"><a href="{{ APP_URL() + route('/submissions.index') }}">Cancel</a></button>
+      </div>
+    </div>
+    <!--
+    <div class="notification is-warning">
+      <button class="delete"></button>
+      Building Snapshots for some items may take a couple minutes.  Please be patient!
+    </div>
+    -->
+</form>
+
+@section('scripts')
+<script>
+  const received = datepicker('.received-datepicker', {
+    formatter: (input, date, instance) => {
+      const value = date.toLocaleDateString()
+      input.value = value // => '1/1/2099'
+    }
+  })
+  const created = datepicker('.created-datepicker', {
+    formatter: (input, date, instance) => {
+      const value = date.toLocaleDateString()
+      input.value = value // => '1/1/2099'
+    }
+  })
+  const published = datepicker('.published-datepicker', {
+    formatter: (input, date, instance) => {
+      const value = date.toLocaleDateString()
+      input.value = value // => '1/1/2099'
+    }
+  })
+</script>
+@endsection
+
+@endsection 
\ No newline at end of file
diff --git a/resources/views/submissions/index.edge b/resources/views/submissions/index.edge
index fe68927..dd88945 100644
--- a/resources/views/submissions/index.edge
+++ b/resources/views/submissions/index.edge
@@ -13,8 +13,8 @@
         <th>Name</th>
         <th>Element</th>
         <th>Theme</th>
-        <th>Steward</th>
-        <th>Date Submitted</th>
+        <th>Date Created</th>
+        <th>Date Published</th>
         <th>Status</th>
         <th>Action</th>
       </tr>
@@ -25,23 +25,15 @@
         <td>{{ submission.name }}</td>
         <td>{{ submission.element.name }}</td>
         <td>{{ submission.element.theme.name }}</td>
-        <td>{{ submission.steward.contact.first_name}} {{ submission.steward.contact.last_name}}</td>
-        <td>{{ TO_LOCALE(submission.created_at)}}</td>
-        @if(submission.status.status == 'Completed')
-          <td><span class="tag is-success" style="margin: 10px;">{{ submission.status.status }}</span></td>
-        @elseif(submission.status.status == 'In progress')
-          <td><span class="tag is-warning" style="margin: 10px;">{{ submission.status.status }}</span></td>
-        @elseif(submission.status.status == 'Not Started')
-          <td><span class="tag is-dark" style="margin: 10px;">{{ submission.status.status }}</span></td>
-        @elseif(submission.status.status == 'Awaiting Response')
-          <td><span class="tag is-light" style="margin: 10px;">{{ submission.status.status }}</span></td>
-        @else
-          <td>{{ submission.status.status }}</td>
-        @endif
+        <td>{{ TO_LOCALE(submission.creation_date)}}</td>
+        <td>{{ TO_LOCALE(submission.published_date)}}</td>
+        <td>{{ submission.status.status }}</td>
         <td>
-          <form action="{{ APP_URL() + route('/themes.destroy', { id: submission.id }) + '?_method=DELETE'}}" method="post">
+          <form action="{{ APP_URL() + route('/submissions.destroy', { id: submission.id }) + '?_method=DELETE'}}" method="post">
             {{ csrfField() }}
             <button type="submit" name="button" class="is-small button is-danger" onclick="return confirm('Are you sure you want to delete this theme?');">Delete</button>
+            &nbsp;
+            <a href="{{APP_URL() + route('/submissions.edit', { id: submission.id })}}" class="button is-small is-warning">Edit</a>
           </form>
         </td>
       </tr>

start/hooks.js 2(+1 -1)

diff --git a/start/hooks.js b/start/hooks.js
index 5fd426b..a9b49d1 100644
--- a/start/hooks.js
+++ b/start/hooks.js
@@ -9,7 +9,7 @@ hooks.after.providersBooted(() => {
     })
 
     View.global('TO_LOCALE', function (d) {
-        if(!d) return null 
+        if(!d) return ''
         var d = new Date(d)
         return d.toLocaleDateString()
     })