Skip to content

Commit 3c90d06

Browse files
committed
Updating crud multiview
1 parent 17e78f4 commit 3c90d06

File tree

5 files changed

+113
-171
lines changed

5 files changed

+113
-171
lines changed

src/controllers/Core_AdminController.php

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -500,21 +500,14 @@ public function getRoleUsers()
500500
$usersArray = $this->arrayToSelect($users, 'id', 'username', 'Select a user');
501501
$rolesArray = $this->arrayToSelect($roles, 'id', 'name', 'None');
502502

503-
// Set up the one page crud
504503
Crud::setTitle('Role Users')
505-
->setSortProperty('username')
506-
->setPaginationFlag(true)
507-
->setMulti($users, 'roles')
508-
->setMultiColumns(array('Users', 'Roles'))
509-
->setMultiDetails(array('name' => 'username', 'field' => 'user_id'))
510-
->setMultiPropertyDetails(array('name' => 'name', 'field' => 'role_id'));
511-
512-
// Add the form fields
513-
Crud::addFormField('user_id', 'select', $usersArray)
514-
->addFormField('role_id', 'multiselect', $rolesArray);
515-
516-
// Handle the view data
517-
Crud::make();
504+
->setSortProperty('username')
505+
->setPaginationFlag(true)
506+
->setUpMultiColumn()
507+
->addRootColumn('Users', $users, 'username', 'user_id', $usersArray)
508+
->addMultiColumn('Roles', 'roles', 'name', 'role_id', $rolesArray)
509+
->finish()
510+
->make();
518511
}
519512

520513
public function postRoleUsers()
@@ -568,23 +561,20 @@ public function postRoleUsers()
568561

569562
public function getActionRoles()
570563
{
571-
$actions = User_Permission_Action::orderByNameAsc()->get();
572564
$roles = User_Permission_Role::orderByNameAsc()->get();
565+
$actions = User_Permission_Action::orderByNameAsc()->get();
566+
567+
$rolesArray = $roles->toSelectArray('Select a role');
568+
$actionsArray = $actions->toSelectArray('None');
573569

574570
// Set up the one page crud
575571
Crud::setTitle('Action Roles')
576-
->setSortProperty('name')
577-
->setMulti($roles, 'actions')
578-
->setMultiColumns(array('Roles', 'Actions'))
579-
->setMultiDetails(array('name' => 'name', 'field' => 'role_id'))
580-
->setMultiPropertyDetails(array('name' => 'name', 'field' => 'action_id'));
581-
582-
// Add the form fields
583-
Crud::addFormField('role_id', 'select', $this->arrayToSelect($roles, 'id', 'name', 'Select a role'))
584-
->addFormField('action_id', 'multiselect', $this->arrayToSelect($actions, 'id', 'name', 'None'));
585-
586-
// Handle the view data
587-
Crud::make();
572+
->setSortProperty('name')
573+
->setUpMultiColumn()
574+
->addRootColumn('Roles', $roles, 'name', 'role_id', $rolesArray)
575+
->addMultiColumn('Actions', 'actions', 'name', 'action_id', $actionsArray)
576+
->finish()
577+
->make();
588578
}
589579

590580
public function postActionRoles()
@@ -712,19 +702,21 @@ public function getPreferencedelete($preferenceId)
712702

713703
public function getTheme()
714704
{
715-
$masterLess = base_path() .'/vendor/syntax/core/public/less/master.less';
705+
$masterLess = public_path() .'/css/colors.less';
716706

717707
$lines = file($masterLess);
718708

709+
// ppd($lines);
710+
719711
$colors = array();
720712

721-
$colors['grey'] = array('title' => 'Background Color', 'hex' => substr(explode('@grey: ', $lines[4])[1], 0, -2));
722-
$colors['primary'] = array('title' => 'Primary Color', 'hex' => substr(explode('@primaryColor: ', $lines[6])[1], 0, -2));
723-
$colors['info'] = array('title' => 'Information Color', 'hex' => substr(explode('@infoColor: ', $lines[10])[1], 0, -2));
724-
$colors['success'] = array('title' => 'Success Color', 'hex' => substr(explode('@successColor: ', $lines[13])[1], 0, -2));
725-
$colors['warning'] = array('title' => 'Warning Color', 'hex' => substr(explode('@warningColor: ', $lines[16])[1], 0, -2));
726-
$colors['error'] = array('title' => 'Error Color', 'hex' => substr(explode('@errorColor: ', $lines[19])[1], 0, -2));
727-
$colors['menu'] = array('title' => 'Active Menu Link Color', 'hex' => substr(explode('@menuColor: ', $lines[22])[1], 0, -2));
713+
$colors['grey'] = array('title' => 'Background Color', 'hex' => substr(explode('@grey: ', $lines[0])[1], 0, -2));
714+
$colors['primary'] = array('title' => 'Primary Color', 'hex' => substr(explode('@primaryColor: ', $lines[2])[1], 0, -2));
715+
$colors['info'] = array('title' => 'Information Color', 'hex' => substr(explode('@infoColor: ', $lines[6])[1], 0, -2));
716+
$colors['success'] = array('title' => 'Success Color', 'hex' => substr(explode('@successColor: ', $lines[9])[1], 0, -2));
717+
$colors['warning'] = array('title' => 'Warning Color', 'hex' => substr(explode('@warningColor: ', $lines[12])[1], 0, -2));
718+
$colors['error'] = array('title' => 'Error Color', 'hex' => substr(explode('@errorColor: ', $lines[15])[1], 0, -2));
719+
$colors['menu'] = array('title' => 'Active Menu Link Color', 'hex' => substr(explode('@menuColor: ', $lines[18])[1], 0, -2));
728720

729721
$this->setViewData('colors', $colors);
730722
}
@@ -734,28 +726,26 @@ public function postTheme()
734726
$input = e_array(Input::all());
735727

736728
if ($input != null) {
737-
$masterLess = base_path() .'/vendor/syntax/core/public/less/master.less';
738-
$masterCss = public_path() .'/css/master.css';#5097b5
729+
$masterLess = public_path() .'/css/colors.less';
739730

740731
$lines = file($masterLess);
741732

742733
// Set the new colors
743-
$lines[4] = '@grey: '. $input['grey'] .";\n";
744-
$lines[6] = '@primaryColor: '. $input['primary'] .";\n";
745-
$lines[10] = '@infoColor: '. $input['info'] .";\n";
746-
$lines[13] = '@successColor: '. $input['success'] .";\n";
747-
$lines[16] = '@warningColor: '. $input['warning'] .";\n";
748-
$lines[19] = '@errorColor: '. $input['error'] .";\n";
749-
$lines[22] = '@menuColor: '. $input['menu'] .";\n";
734+
$lines[0] = '@grey: '. $input['grey'] .";\n";
735+
$lines[2] = '@primaryColor: '. $input['primary'] .";\n";
736+
$lines[6] = '@infoColor: '. $input['info'] .";\n";
737+
$lines[9] = '@successColor: '. $input['success'] .";\n";
738+
$lines[12] = '@warningColor: '. $input['warning'] .";\n";
739+
$lines[15] = '@errorColor: '. $input['error'] .";\n";
740+
$lines[18] = '@menuColor: '. $input['menu'] .";\n";
750741

751742
File::delete($masterLess);
752-
File::delete($masterCss);
753743

754744
File::put($masterLess, implode($lines));
755745

756746
SSH::run(array(
757747
'cd '. base_path(),
758-
'lessc '. $masterLess .' '. $masterCss
748+
'gulp css'
759749
));
760750

761751
Ajax::setStatus('success');

src/services/Utility/View/Crud.php

Lines changed: 10 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,6 @@ class Crud {
1717
*/
1818
public $sortProperty;
1919

20-
/**
21-
* A flag to switch between multiview and standard
22-
*/
23-
public $multiViewFlag = false;
24-
25-
/**
26-
* The column names for the multiView
27-
*/
28-
public $multiViewColumns = array();
29-
30-
/**
31-
* The name to display for each object
32-
*/
33-
public $multiViewDetails = array();
34-
35-
/**
36-
* The name to display for each property of the object
37-
*/
38-
public $multiViewPropertyDetails = array();
39-
40-
/**
41-
* The collection to use for the multiView
42-
*/
43-
public $multiViewCollection;
44-
45-
/**
46-
* The property to tap on the collection
47-
*/
48-
public $multiViewProperty;
49-
5020
/**
5121
* A flag to show the delete button
5222
*/
@@ -73,9 +43,14 @@ class Crud {
7343
public $paginationFlag = false;
7444

7545
/**
76-
* An array of extra buttons to display
46+
* A flag to switch between multiview and standard
7747
*/
78-
public $buttons;
48+
public $multiViewFlag = false;
49+
50+
/**
51+
* Multiview object
52+
*/
53+
public $multiView;
7954

8055
/**
8156
* The fields to display on the page
@@ -89,7 +64,6 @@ class Crud {
8964

9065
public function __construct()
9166
{
92-
$this->buttons = new \stdClass();
9367
$this->displayFields = new \stdClass();
9468
$this->formFields = new \stdClass();
9569
}
@@ -104,77 +78,10 @@ public function make()
10478
CoreView::setRoute('helpers.crud')->addData('settings', $this);
10579
}
10680

107-
/**
108-
* Display multiple results as a parameter (replaces display fields)
109-
*
110-
* @param Utility_Collection $collection
111-
* @param string $column
112-
* @param string $property
113-
* @return Utility_Crud
114-
*/
115-
public function setMulti($collection, $property)
116-
{
117-
$this->multiViewFlag = true;
118-
$this->deleteFlag = false;
119-
$this->multiViewCollection = $collection;
120-
$this->multiViewProperty = $property;
121-
122-
return $this;
123-
}
124-
125-
/**
126-
* Set the column names for the display
127-
*
128-
* @param array $columns
129-
* @return Utility_Crud
130-
*/
131-
public function setMultiColumns($columns)
132-
{
133-
$this->multiViewColumns = $columns;
134-
135-
return $this;
136-
}
137-
138-
/**
139-
* Set the property to tap on the collection for it's name and the field this pertains to
140-
*
141-
* @param array $details
142-
* @return Utility_Crud
143-
*/
144-
public function setMultiDetails($details)
145-
{
146-
$this->multiViewDetails = $details;
147-
148-
return $this;
149-
}
150-
151-
/**
152-
* Set the property to tap on the collection's property for it's name and the field this pertains to
153-
*
154-
* @param array $details
155-
* @return Utility_Crud
156-
*/
157-
public function setMultiPropertyDetails($details)
81+
public function setUpMultiColumn()
15882
{
159-
$this->multiViewPropertyDetails = $details;
160-
161-
return $this;
162-
}
163-
164-
/**
165-
* Ad an extra button per row
166-
*
167-
* @param string $name
168-
* @param string $linkLocation
169-
* @param string $linkName
170-
* @param array $options
171-
* @return Utility_Crud
172-
*/
173-
public function addButton($name, $linkLocation, $linkName, $options = array())
174-
{
175-
$this->buttons->{$name} = HTML::link($linkLocation, $linkName, $options);
176-
177-
return $this;
83+
$this->multiViewFlag = true;
84+
return new Crud\Crud_MultiView($this);
17885
}
17986

18087
/**
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Syntax\Core\Utility\View\Crud;
4+
5+
use HTML;
6+
use CoreView;
7+
8+
class Crud_MultiView {
9+
10+
public $crud;
11+
12+
public $rootColumn;
13+
14+
public $multiColumn;
15+
16+
public function __construct($crud)
17+
{
18+
$this->crud = $crud;
19+
$this->rootColumn = new \stdClass();
20+
$this->multiColumn = new \stdClass();
21+
}
22+
23+
public function addRootColumn($title, $collection, $name, $field, $selectArray)
24+
{
25+
$this->rootColumn->title = $title;
26+
$this->rootColumn->collection = $collection;
27+
$this->rootColumn->name = $name;
28+
$this->rootColumn->field = $field;
29+
30+
$this->crud->addFormField($field, 'select', $selectArray);
31+
32+
return $this;
33+
}
34+
35+
public function addMultiColumn($title, $property, $name, $field, $selectArray)
36+
{
37+
$this->multiColumn->title = $title;
38+
$this->multiColumn->property = $property;
39+
$this->multiColumn->name = $name;
40+
$this->multiColumn->field = $field;
41+
42+
$this->crud->addFormField($field, 'multiselect', $selectArray);
43+
44+
return $this;
45+
}
46+
47+
public function finish()
48+
{
49+
$crud = $this->crud;
50+
unset($this->crud);
51+
52+
$crud->multiView = $this;
53+
54+
return $crud;
55+
}
56+
}

src/views/helpers/crud/type/multiview.blade.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,21 @@
88
<thead>
99
<tr>
1010
<th style="display: none;"></th>
11-
<?php
12-
$width = (90 / count($settings->multiViewColumns)) .'%';
13-
?>
14-
@foreach ($settings->multiViewColumns as $column)
15-
<th class="text-left" style="width: {{ $width }}">{{ ucwords(str_replace('_', ' ', $column)) }}</th>
16-
@endforeach
11+
<th class="text-left" style="width: 45%">{{ $settings->multiView->rootColumn->title }}</th>
12+
<th class="text-left" style="width: 45%">{{ $settings->multiView->multiColumn->title }}</th>
1713
<th class="text-center" style="width: 10%;">Actions</th>
1814
</tr>
1915
</thead>
2016
<tbody>
21-
@foreach ($settings->multiViewCollection as $collection)
17+
@foreach ($settings->multiView->rootColumn->collection as $collection)
2218
<tr>
2319
<td style="display: none;">
24-
<input type="hidden" id="{{ $collection->id }}" data-multi="{{{ json_encode($collection->{$settings->multiViewProperty}->id->toArray()) }}}" />
20+
<input type="hidden" id="{{ $collection->id }}" data-multi="{{{ json_encode($collection->{$settings->multiView->multiColumn->property}->id->toArray()) }}}" />
2521
</td>
26-
<td>{{ $collection->{$settings->multiViewDetails['name']} }}</td>
22+
<td>{{ $collection->{$settings->multiView->rootColumn->name} }}</td>
2723
<td>
28-
@foreach ($collection->{$settings->multiViewProperty} as $property)
29-
{{ $property->{$settings->multiViewPropertyDetails['name']} }}<br />
24+
@foreach ($collection->{$settings->multiView->multiColumn->property} as $property)
25+
{{ $property->{$settings->multiView->multiColumn->name} }}<br />
3026
@endforeach
3127
</td>
3228
<td class="text-center">
@@ -47,7 +43,7 @@
4743
</table>
4844
@if($settings->paginationFlag == true)
4945
<div class="text-center">
50-
{{ $settings->multiViewCollection->links() }}
46+
{{ $settings->multiView->rootColumn->collection->links() }}
5147
</div>
5248
@endif
5349
</div>
@@ -123,9 +119,9 @@ function editDetails(objectId) {
123119
var object = $('#'+ objectId);
124120
$('#id').val(objectId);
125121
126-
$('#input_'+ settings.multiViewDetails.field).val(objectId);
122+
$('#input_'+ settings.multiView.rootColumn.field).val(objectId);
127123
var multi = $.parseJSON(object.attr('data-multi'));
128-
$('#input_'+ settings.multiViewPropertyDetails.field).val(multi);
124+
$('#input_'+ settings.multiView.multiColumn.field).val(multi);
129125
130126
$('#listPanel').removeClass('col-md-12').addClass('col-md-8');
131127
$('.col-md-4').show();

0 commit comments

Comments
 (0)