From a9455f99a007c4ea69affcdec03a679d1cfe529a Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Mon, 19 Dec 2016 22:31:04 -0500 Subject: [PATCH] Add export functionality to the dashboard edit-list feature, and clean up the edit-list blade a bit --- readme.md | 40 ++++++++++--------- resources/assets/sass/dashboard.scss | 25 +++++++----- resources/views/dashboard/core.blade.php | 5 ++- resources/views/dashboard/edit-list.blade.php | 20 ++++++---- 4 files changed, 52 insertions(+), 38 deletions(-) diff --git a/readme.md b/readme.md index 4ff0187..280d593 100644 --- a/readme.md +++ b/readme.md @@ -34,24 +34,6 @@ First add a function to generate the page: * `rows`: A function returning an array containing the data to be shown on this page * `cols`: An array containing a set of arrays where the first element of each is the visible column name and the second is the column name in the array -#### Export Functionality - -Viewable models must have an entry in the switch statement of the `getExport` function to make the export button work: - -```php - switch ($model) { - case 'contact': - $headings = [ 'Date', 'Name', 'Email', 'Message' ]; - $items = Contact::select('created_at', 'name', 'email', 'message')->get(); - break; - default: - abort(404); - } -``` - -* `$headings`: The visible column names in the same order as the array containing the items to be exported -* `$items`: A function returning an array containing the data to be exported - ### Adding an Editable Model to the Dashboard #### Editable List of Rows @@ -67,7 +49,8 @@ Viewable models must have an entry in the switch statement of the `getExport` fu 'rows' => Shows::getShowsList(), 'column' => 'title', 'sortcol' => false, - 'delete' => true + 'delete' => true, + 'export' => true ]); } ``` @@ -96,6 +79,7 @@ Viewable models must have an entry in the switch statement of the `getExport` fu * `column`: The column name in the array that contains the data to display in each row * `sortcol`: The name of the column containing the sort order or `false` to disable * `delete`: A delete button will appear in the list if this is set to `true` +* `export`: An export button will appear in the heading if this is set to `true` #### Delete Functionality @@ -255,3 +239,21 @@ Add an array to the menu array in `resources/views/dashboard/elements/menu.blade [ 'Contact', 'contact' ] ]) ``` + +#### Additional Requirement for Export Functionality + +Viewable models and editable models with `export` set to `true` must have an entry in the switch statement of the `getExport` function to make the export button work: + +```php + switch ($model) { + case 'contact': + $headings = [ 'Date', 'Name', 'Email', 'Message' ]; + $items = Contact::select('created_at', 'name', 'email', 'message')->get(); + break; + default: + abort(404); + } +``` + +* `$headings`: The visible column names in the same order as the array containing the items to be exported +* `$items`: A function returning an array containing the data to be exported diff --git a/resources/assets/sass/dashboard.scss b/resources/assets/sass/dashboard.scss index 919d2f2..e95db6e 100644 --- a/resources/assets/sass/dashboard.scss +++ b/resources/assets/sass/dashboard.scss @@ -106,19 +106,22 @@ body { color: $c-dashboard-light; font-weight: bold; - .btn { + .dashboard-heading { float: right; - position: relative; - bottom: 3px; - min-width: 70px; - height: 26px; - padding-top: 1px; - padding-bottom: 2px; - } - a { - color: $c-text; - text-decoration: none; + .btn { + position: relative; + bottom: 3px; + min-width: 70px; + height: 26px; + padding-top: 1px; + padding-bottom: 2px; + } + + a { + color: $c-text; + text-decoration: none; + } } } } diff --git a/resources/views/dashboard/core.blade.php b/resources/views/dashboard/core.blade.php index 37420b4..b3c6966 100644 --- a/resources/views/dashboard/core.blade.php +++ b/resources/views/dashboard/core.blade.php @@ -7,7 +7,10 @@
{{ $heading }} - @yield('dashboard-heading') + +
+ @yield('dashboard-heading') +
diff --git a/resources/views/dashboard/edit-list.blade.php b/resources/views/dashboard/edit-list.blade.php index 9b60233..24dad98 100644 --- a/resources/views/dashboard/edit-list.blade.php +++ b/resources/views/dashboard/edit-list.blade.php @@ -1,15 +1,15 @@ @extends('dashboard.core') @section('dashboard-heading') + @if($export == true) + + @endif + @endsection @section('dashboard-body') - @set('sort_data', $sortcol != false ? "data-sort=$sortcol" : '') - @set('sort_icon', $sortcol != false ? '' : '') - @set('delete_button', $delete == true ? '' : '') - -
    +
      @foreach($rows as $row) @@ -17,13 +17,19 @@
      - {!! $sort_icon !!} + @if($sortcol != false) + + @endif + {{ $row[$column] }}
      - {!! $delete_button !!} + + @if($delete == true) + + @endif