improve interactivity in Review page

pull/35/head
Ondřej Hruška 6 years ago
parent 70cff26719
commit 69dabab6cc
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 37
      resources/assets/js/components/ColumnEditor.vue
  2. 25
      resources/assets/js/components/DraftNotePage.js
  3. 17
      resources/views/table/propose/review.blade.php

@ -19,6 +19,7 @@ Complex animated column editor for the table edit page
<th :style="tdWidthStyle('name')">Name</th> <th :style="tdWidthStyle('name')">Name</th>
<th :style="tdWidthStyle('type')">Type</th> <th :style="tdWidthStyle('type')">Type</th>
<th :style="tdWidthStyle('title')">Title</th> <th :style="tdWidthStyle('title')">Title</th>
<th style="width:2rem" v-if="!newTable"><!-- revert icon --></th>
<th> <th>
<a href="" type="button" v-if="!newTable && orderChanged" <a href="" type="button" v-if="!newTable && orderChanged"
@click.prevent="resetOrder()" @click.prevent="resetOrder()"
@ -90,9 +91,20 @@ Complex animated column editor for the table edit page
</td> </td>
</template> </template>
<td style="text-align: center;" v-if="!newTable">
<v-icon @click="discardEdit(col)"
v-if="col._editing && colNeedsSave(col)"
class="fa-undo text-danger pointer"
alt="Revert Change" />
</td>
<td class="text-nowrap"><!-- <td class="text-nowrap"><!--
Save button Save button
--><a href="" :class="['mr-1', 'btn', 'btn-outline-secondary', {'disabled': col._remove}]" --><a href="" :class="[
'mr-1', 'btn',
col._editing && colNeedsSave(col) ? 'btn-info' : 'btn-outline-secondary',
{'disabled': col._remove}
]"
v-if="!newTable" v-if="!newTable"
@click.prevent="toggleColEditing(col)"> @click.prevent="toggleColEditing(col)">
<v-icon v-if="col._editing" class="fa-save" alt="Save" /> <v-icon v-if="col._editing" class="fa-save" alt="Save" />
@ -210,7 +222,7 @@ export default {
data () { data () {
return { return {
newColNum: 0, newColNum: 0,
orderChanged: this.orderChanged, //orderChanged: this.orderChanged,
columns: this.xColumns, columns: this.xColumns,
colTypes: ['string', 'int', 'float', 'bool'], colTypes: ['string', 'int', 'float', 'bool'],
debouncedSortUpdate: _.debounce(() => this.submitColOrder(), 350) debouncedSortUpdate: _.debounce(() => this.submitColOrder(), 350)
@ -393,6 +405,11 @@ export default {
if (!editing) { if (!editing) {
this.submitColChange(col) this.submitColChange(col)
} else { } else {
let origvals = {};
_.each(col, (v, k) => {
if (k[0] != '_') origvals[k] = v
})
this.$set(this.columns[n], '_loadvals', origvals)
this.$set(this.columns[n], '_editing', true) this.$set(this.columns[n], '_editing', true)
} }
}, },
@ -424,6 +441,22 @@ export default {
this.columns = resp.data this.columns = resp.data
this.orderChanged = false this.orderChanged = false
}) })
},
colNeedsSave(col) {
if (!col._loadvals) return false;
for (const [key, value] of Object.entries(col._loadvals)) {
// changed if differs from orig value and also from previous value from revision
if (col[key] != value) return true
}
return false
},
discardEdit(col) {
col._editing = false;
for (const [key, value] of Object.entries(col._loadvals)) {
col[key] = value
}
} }
} }
} }

@ -1,21 +1,38 @@
import { query } from './table-editor-utils' import { query } from './table-editor-utils'
export default function (dataRoute) { export default function (opts) {
let $note = $('#field-note') let $note = $('#field-note')
let lastText = $note.val() let $submit = $('#submit-button')
let $emptyPrompt = $('#empty-note-prompt')
let lastText = $note.val().trim()
let handler = _.debounce(function () { let handler = _.debounce(function () {
query(dataRoute, { query(opts.route, {
action: 'note.set', action: 'note.set',
text: lastText text: lastText
}) })
}, 350) }, 350)
$note.on('input', () => { $note.on('input', () => {
let text = $note.val() let text = $note.val().trim()
if (text !== lastText) { if (text !== lastText) {
lastText = text lastText = text
handler() handler()
let empty = text.length === 0
if (opts.anyChanges) {
$submit.toggleClass('disabled', empty)
}
// Hide prompt text if anything is written
$emptyPrompt.toggleClass('hidden', !empty)
}
})
// prevent submit with empty note
$submit.on('click', (e) => {
if ($note.val().trim().length === 0) {
e.preventDefault()
} }
}) })
} }

@ -16,7 +16,7 @@
$anyColChanges = $numChangedColumns || $numNewColumns || $numRemovedColumns || $colsReordered; $anyColChanges = $numChangedColumns || $numNewColumns || $numRemovedColumns || $colsReordered;
$anyChanges = $anyRowChanges || $anyColChanges; $anyChanges = ($anyRowChanges || $anyColChanges) && strlen(trim($changeset->note)) > 0;
@endphp @endphp
@extends('table.propose.layout') @extends('table.propose.layout')
@ -123,14 +123,20 @@
<div class="row"> <div class="row">
<div class="col-md-7 offset-md-3"> <div class="col-md-7 offset-md-3">
@if(user()->ownsTable($table)) @if(user()->ownsTable($table))
<a href="" class="btn btn-outline-success {{$anyChanges?'':'disabled'}}"> <a href="" id="submit-button" class="btn btn-outline-success {{$anyChanges?'':'disabled'}}">
@icon(fa-save fa-pr)Save & Apply @icon(fa-save fa-pr)Save & Apply
</a> </a>
@else @else
<a href="" class="btn btn-outline-success {{$anyChanges?'':'disabled'}}"> <a href="" id="submit-button" class="btn btn-outline-success {{$anyChanges?'':'disabled'}}">
@icon(fa-paper-plane-o fa-pr)Submit for review @icon(fa-paper-plane-o fa-pr)Submit for review
</a> </a>
@endif @endif
@if($anyRowChanges || $anyColChanges)
<span class="text-muted ml-3" id="empty-note-prompt">Write a summary to submit your changes.</span>
@else
<span class="text-danger ml-3">No changes to submit.</span>
@endif
</div> </div>
</div> </div>
@ -141,7 +147,10 @@
@push('scripts') @push('scripts')
<script> <script>
ready(function () { ready(function () {
app.DraftNotePage(@json($table->draftUpdateRoute)) app.DraftNotePage({
route: @json($table->draftUpdateRoute),
anyChanges: @json($anyRowChanges || $anyColChanges)
})
}) })
</script> </script>
@endpush @endpush

Loading…
Cancel
Save