Note saving, revert buttons in review page

pull/35/head
Ondřej Hruška 6 years ago
parent b1d1fa4880
commit 58c28b776b
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 37
      app/Http/Controllers/TableEditController.php
  2. 50
      app/Tables/Changeset.php
  3. 28
      package-lock.json
  4. 6
      resources/assets/js/app.js
  5. 3
      resources/assets/js/components/ColumnEditor.vue
  6. 21
      resources/assets/js/components/DraftNotePage.js
  7. 21
      resources/assets/js/components/table-editor-utils.js
  8. 18
      resources/assets/js/vue-init.js
  9. 50
      resources/views/table/propose/review.blade.php
  10. 1
      routes/web.php

@ -264,9 +264,36 @@ class TableEditController extends Controller
$changeset->setColOrder($input->order); $changeset->setColOrder($input->order);
break; break;
case 'col.reset-sort': case 'note.set':
$changeset->columnOrder = []; $changeset->note = $input->text;
$resp = $changeset->fetchAndTransformColumns(); break;
case 'reset.col-order': // called via POST or GET
$changeset->resetColumnOrder();
break;
case 'reset.col-remove': // called via GET
$changeset->resetRemovedColumns();
break;
case 'reset.col-add': // called via GET
$changeset->resetAddedColumns();
break;
case 'reset.col-update': // called via GET
$changeset->resetUpdatedColumns();
break;
case 'reset.row-remove': // called via GET
$changeset->resetRemovedRows();
break;
case 'reset.row-add': // called via GET
$changeset->resetAddedRows();
break;
case 'reset.row-update': // called via GET
$changeset->resetUpdatedRows();
break; break;
default: default:
@ -280,6 +307,10 @@ class TableEditController extends Controller
$this->storeChangeset($changeset); $this->storeChangeset($changeset);
if ($request->method() == 'GET') {
return back();
}
// Redirect requested via form // Redirect requested via form
if ($code == 200 && $input->has('redirect')) { if ($code == 200 && $input->has('redirect')) {
return redirect($input->redirect); return redirect($input->redirect);

@ -480,7 +480,7 @@ class Changeset
if ($this->isNewColumn($id)) { if ($this->isNewColumn($id)) {
unset($this->newColumns[$id]); unset($this->newColumns[$id]);
// remove it from order // remove it from order
$this->columnOrder = array_diff($this->columnOrder, [$id]); $this->columnOrder = array_values(array_diff($this->columnOrder, [$id]));
} }
else { else {
$this->removedColumns[] = $id; $this->removedColumns[] = $id;
@ -611,7 +611,7 @@ class Changeset
$order = array_intersect($order, $ids); $order = array_intersect($order, $ids);
$missing = array_diff($ids, $order); $missing = array_diff($ids, $order);
$this->columnOrder = array_merge($order, $missing); $this->columnOrder = array_values(array_merge($order, $missing));
$this->clearColumnOrderIfUnchanged(); $this->clearColumnOrderIfUnchanged();
} }
@ -644,10 +644,54 @@ class Changeset
->pluck('id') ->pluck('id')
->diff($this->removedColumns) ->diff($this->removedColumns)
->merge(collect($this->newColumns)->pluck('id')) ->merge(collect($this->newColumns)->pluck('id'))
->all(); ->values()->all();
$this->columnOrder = array_values($this->columnOrder);
if ($expected == $this->columnOrder) { if ($expected == $this->columnOrder) {
$this->columnOrder = []; $this->columnOrder = [];
} }
} }
public function resetColumnOrder()
{
$this->columnOrder = [];
}
public function resetRemovedColumns()
{
$this->removedColumns = [];
}
public function resetAddedColumns()
{
$this->columnOrder = array_values(
array_diff($this->columnOrder,
collect($this->newColumns)->pluck('id')->all()
)
);
$this->newColumns = [];
$this->clearColumnOrderIfUnchanged();
}
public function resetUpdatedColumns()
{
$this->columnUpdates = [];
}
public function resetRemovedRows()
{
$this->removedRows = [];
}
public function resetAddedRows()
{
$this->newRows = [];
}
public function resetUpdatedRows()
{
$this->rowUpdates = [];
}
} }

28
package-lock.json generated

@ -4895,14 +4895,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -4917,20 +4915,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -5047,8 +5042,7 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -5060,7 +5054,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -5075,7 +5068,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -5083,14 +5075,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -5109,7 +5099,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -5190,8 +5179,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -5203,7 +5191,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -5325,7 +5312,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",

@ -12,4 +12,10 @@ $(function () {
$('[data-toggle="tooltip"]').tooltip({ $('[data-toggle="tooltip"]').tooltip({
container: 'body' container: 'body'
}) })
$(document).on('click', 'a[data-confirm]', function (e) {
if (!window.confirm(this.dataset.confirm)) {
e.preventDefault()
}
})
}) })

@ -265,6 +265,7 @@ export default {
this.query({ this.query({
action: 'col.add', action: 'col.add',
}, (resp) => { }, (resp) => {
resp.data._editing = true;
this.columns.push(resp.data) this.columns.push(resp.data)
}) })
} }
@ -414,7 +415,7 @@ export default {
resetOrder() { resetOrder() {
this.query({ this.query({
action: 'col.reset-sort' action: 'reset.col-order'
}, (resp) => { }, (resp) => {
this.columns = resp.data; this.columns = resp.data;
}) })

@ -0,0 +1,21 @@
import { query } from './table-editor-utils'
export default function (dataRoute) {
let $note = $('#field-note')
let lastText = $note.val()
let handler = _.debounce(function () {
query(dataRoute, {
action: 'note.set',
text: lastText
})
}, 350)
$note.on('input', () => {
let text = $note.val()
if (text !== lastText) {
lastText = text
handler()
}
})
}

@ -2,17 +2,22 @@ function busy (yes) {
$('#draft-busy').css('opacity', yes ? 1 : 0) $('#draft-busy').css('opacity', yes ? 1 : 0)
} }
let loaderHideTimeout;
function query (route, data, sucfn, erfn) { function query (route, data, sucfn, erfn) {
busy(true)
if (!sucfn) sucfn = () => {} if (!sucfn) sucfn = () => {}
if (!erfn) erfn = () => {} if (!erfn) erfn = () => {}
clearTimeout(loaderHideTimeout)
window.axios.post(route, data).then(sucfn).catch((error) => { busy(true)
console.error(error.message) window.axios.post(route, data)
erfn(error.response.data) .then(sucfn)
}).then(() => { .catch((error) => {
busy(false) console.error(error.message)
}) erfn(error.response.data)
})
.finally(() => {
loaderHideTimeout = setTimeout(() => busy(false), 50)
})
} }
export { export {

@ -1,21 +1,23 @@
import DraftNotePage from './components/DraftNotePage'
window.Vue = require('vue') window.Vue = require('vue')
const ColumnEditor = Vue.component('column-editor', require('./components/ColumnEditor.vue')) const ColumnEditor = Vue.component('column-editor', require('./components/ColumnEditor.vue'))
const RowsEditor = Vue.component('rows-editor', require('./components/RowsEditor.vue')) const RowsEditor = Vue.component('rows-editor', require('./components/RowsEditor.vue'))
const Icon = Vue.component('v-icon', require('./components/Icon.vue')) const Icon = Vue.component('v-icon', require('./components/Icon.vue'))
// const app = new Vue({
// el: '#app'
// });
window.app = { window.app = {
ColumnEditor: function (selector, data) { ColumnEditor (selector, data) {
return new ColumnEditor({ propsData: data }).$mount(selector) return new ColumnEditor({ propsData: data }).$mount(selector)
}, },
RowsEditor: function (selector, data) {
RowsEditor (selector, data) {
return new RowsEditor({ propsData: data }).$mount(selector) return new RowsEditor({ propsData: data }).$mount(selector)
}, },
Icon: function (selector, data) {
Icon (selector, data) {
return new Icon({ propsData: data }).$mount(selector) return new Icon({ propsData: data }).$mount(selector)
} },
DraftNotePage
} }

@ -37,15 +37,27 @@
@if($anyRowChanges) @if($anyRowChanges)
@if($numChangedRows) @if($numChangedRows)
<div class="text-info"><b>{{ $numChangedRows }}</b> changed</div> <div class="text-info">
<b>{{ $numChangedRows }}</b> changed
<a href="{{$table->draftUpdateRoute}}?action=reset.row-update" class="ml-2"
data-confirm="Revert all row changes?">Reset</a>
</div>
@endif @endif
@if($numNewRows) @if($numNewRows)
<div class="text-success"><b>{{ $numNewRows }}</b> new</div> <div class="text-success">
<b>{{ $numNewRows }}</b> new
<a href="{{$table->draftUpdateRoute}}?action=reset.row-add" class="ml-2"
data-confirm="Discard all added rows?">Reset</a>
</div>
@endif @endif
@if($numRemovedRows) @if($numRemovedRows)
<div class="text-danger"><b>{{ $numRemovedRows }}</b> removed</div> <div class="text-danger">
<b>{{ $numRemovedRows }}</b> removed
<a href="{{$table->draftUpdateRoute}}?action=reset.row-remove" class="ml-2"
data-confirm="Undo row removals?">Reset</a>
</div>
@endif @endif
@else @else
@ -62,19 +74,35 @@
@if($anyColChanges) @if($anyColChanges)
@if($numChangedColumns) @if($numChangedColumns)
<div class="text-info"><b>{{ $numChangedColumns }}</b> changed</div> <div class="text-info">
<b>{{ $numChangedColumns }}</b> changed
<a href="{{$table->draftUpdateRoute}}?action=reset.col-update" class="ml-2"
data-confirm="Revert all column changes?">Reset</a>
</div>
@endif @endif
@if($numNewColumns) @if($numNewColumns)
<div class="text-success"><b>{{ $numNewColumns }}</b> new</div> <div class="text-success">
<b>{{ $numNewColumns }}</b> new
<a href="{{$table->draftUpdateRoute}}?action=reset.col-add" class="ml-2"
data-confirm="Discard all added columns?">Reset</a>
</div>
@endif @endif
@if($numRemovedColumns) @if($numRemovedColumns)
<div class="text-danger"><b>{{ $numRemovedColumns }}</b> removed</div> <div class="text-danger">
<b>{{ $numRemovedColumns }}</b> removed
<a href="{{$table->draftUpdateRoute}}?action=reset.col-remove" class="ml-2"
data-confirm="Undo column removals?">Reset</a>
</div>
@endif @endif
@if($colsReordered) @if($colsReordered)
<div class="text-info">Order changed</div> <div class="text-info">
Order changed
<a href="{{$table->draftUpdateRoute}}?action=reset.col-order" class="ml-2"
data-confirm="Reset column order changes?">Reset</a>
</div>
@endif @endif
@else @else
@ -109,3 +137,11 @@
</div> </div>
</div> </div>
@stop @stop
@push('scripts')
<script>
ready(function () {
app.DraftNotePage(@json($table->draftUpdateRoute))
})
</script>
@endpush

@ -51,6 +51,7 @@ Route::group(['middleware' => ['auth', 'activated']], function () {
Route::post('@{user}/{table}/delete', 'TableController@delete')->name('table.delete'); Route::post('@{user}/{table}/delete', 'TableController@delete')->name('table.delete');
Route::post('@{user}/{table}/draft/update', 'TableEditController@draftUpdate')->name('table.draft-update'); Route::post('@{user}/{table}/draft/update', 'TableEditController@draftUpdate')->name('table.draft-update');
Route::get('@{user}/{table}/draft/update', 'TableEditController@draftUpdate');
Route::get('@{user}/{table}/draft/discard', 'TableEditController@discard')->name('table.draft-discard'); Route::get('@{user}/{table}/draft/discard', 'TableEditController@discard')->name('table.draft-discard');
Route::get('@{user}/{table}/draft/{tab?}', 'TableEditController@draft')->name('table.draft'); Route::get('@{user}/{table}/draft/{tab?}', 'TableEditController@draft')->name('table.draft');
}); });

Loading…
Cancel
Save