DataInventory
Changes
app/Controllers/Http/SubmissionController.js 23(+18 -5)
resources/views/submissions/create.edge 41(+41 -0)
Details
app/Controllers/Http/SubmissionController.js 23(+18 -5)
diff --git a/app/Controllers/Http/SubmissionController.js b/app/Controllers/Http/SubmissionController.js
index f2d6cc3..77a0d9a 100644
--- a/app/Controllers/Http/SubmissionController.js
+++ b/app/Controllers/Http/SubmissionController.js
@@ -8,7 +8,7 @@ const Submission = use('App/Models/Submission')
const Element = use('App/Models/Element')
const Steward = use('App/Models/Steward')
const Status = use('App/Models/Status')
-const { validate } = use('Validator')
+const { validate, validateAll } = use('Validator')
const Env = use('Env')
/**
@@ -66,11 +66,24 @@ class SubmissionController {
* @param {Response} ctx.response
*/
async store ({ request, response, session }) {
- const data = request.only(['name', 'element_id', 'steward_id', 'public', 'status_id'])
+ const data = request.only(['name', 'upload_date',
+ 'creation_date', 'published_date', 'element_id',
+ 'steward_id', 'public', 'status_id'])
- data['upload_date'] = new Date()
- data['creation_date'] = new Date()
- data['published_date'] = new Date()
+ 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')
+ }
await Submission.create(data)
resources/views/submissions/create.edge 41(+41 -0)
diff --git a/resources/views/submissions/create.edge b/resources/views/submissions/create.edge
index a4461c7..74f4797 100644
--- a/resources/views/submissions/create.edge
+++ b/resources/views/submissions/create.edge
@@ -35,6 +35,24 @@
</div>
<div class="field">
+ <label class="label">Received Date</label>
+ <input class="input received-datepicker" type="text" name="upload_date" value="{{ old('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="{{ old('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="{{ old('published_date', '') }}" />
+ {{ elIf('<span class="has-text-danger">$self</span>', getErrorFor('published_date'), hasErrorFor('published_date')) }}
+ </div>
+
+ <div class="field">
<label class="label">Status</label>
<div class="select">
<select name="status_id">
@@ -96,4 +114,27 @@
-->
</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 769e872..fe68927 100644
--- a/resources/views/submissions/index.edge
+++ b/resources/views/submissions/index.edge
@@ -26,7 +26,7 @@
<td>{{ submission.element.name }}</td>
<td>{{ submission.element.theme.name }}</td>
<td>{{ submission.steward.contact.first_name}} {{ submission.steward.contact.last_name}}</td>
- <td>{{ submission.created_at}}</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')