Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add process categories #597

Merged
merged 28 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5807f7c
Dry up process category test
nolanpro Aug 20, 2018
e508eb0
Add ability to sort process categories to API call
nolanpro Aug 20, 2018
5e5368b
Add process categories menu, route, and basic templates
nolanpro Aug 21, 2018
3b8a48b
Add process category modal for adding/editing
nolanpro Aug 21, 2018
6f0a1c7
Refactor process category modal box add/edit
nolanpro Aug 22, 2018
7bb3865
Add status column to process category
nolanpro Aug 22, 2018
247931d
Add ability to update the category status
nolanpro Aug 22, 2018
92d2f7e
Fix api request types and reload data after adding
nolanpro Aug 22, 2018
6814a32
Handle validation in the model instead of the manager
nolanpro Aug 22, 2018
560ffea
Use the datatable pattern from users for the process category api
nolanpro Aug 23, 2018
9f21c96
Add filter input to process category listing
nolanpro Aug 23, 2018
c792569
Merge branch 'develop' into feature/537
nolanpro Aug 23, 2018
4280519
Update process create endpoint to use new category api and fix menus
nolanpro Aug 23, 2018
1d43f37
Add confirm to delete process category
nolanpro Aug 23, 2018
e06effe
Remove process category manager and move logic to controller
nolanpro Aug 23, 2018
1b697fe
Move process category validations to the model
nolanpro Aug 23, 2018
e3dfd7b
Remove category status migration
nolanpro Aug 23, 2018
e00c6ca
Only show active categories when creating a process
nolanpro Aug 23, 2018
18d877e
Merge branch 'develop' into feature/537
velkymx Aug 23, 2018
46198ac
Add status color circles to process categories
nolanpro Aug 23, 2018
64a55ef
Fix raw sql because groups is a reserved word in later mysql versions
nolanpro Aug 24, 2018
22a682c
Fix hasMany association on process category
nolanpro Aug 24, 2018
77e5f34
Merge branch 'develop' into feature/537
nolanpro Aug 27, 2018
98fde18
Merge branch 'develop' into feature/537
nolanpro Aug 27, 2018
85bc9ef
Merge branch 'develop' into feature/537
nolanpro Aug 27, 2018
e38ba4f
Update process categories to reflect changes in roles and permissions
nolanpro Aug 27, 2018
e46f841
Merge branch 'develop' into feature/537
velkymx Aug 28, 2018
3112118
Update success message for process categories
nolanpro Aug 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public function index(Request $request)
// Need to include number of users associations with this group
$groups = $groups->leftJoin('group_users', 'group_users.group_id', 'groups.id')
->groupBy('groups.id')
->select(DB::raw('groups.*, count(group_users.id) as total_users'));
->select(DB::raw('`groups`.*, count(group_users.id) as total_users'));
}
$groups = $groups->paginate($perPage);
} else {
if($orderBy == 'total_users') {
// Need to include users count with roles
$groups = Group::leftJoin('group_users', 'group_users.group_id', 'groups.id')
->groupBy('groups.id')
->select(DB::raw('groups.*, count(group_users.id) as total_users'))
->select(DB::raw('`groups`.*, count(group_users.id) as total_users'))
->orderBy($orderBy, $orderDirection)->paginate($perPage);
} else {
$groups = Group::orderBy($orderBy, $orderDirection)->paginate($perPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use ProcessMaker\Facades\ProcessCategoryManager;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Model\Permission;
use ProcessMaker\Model\ProcessCategory;
use ProcessMaker\Transformers\ProcessCategoryTransformer;
use Ramsey\Uuid\Uuid;

/**
* Implements endpoints to manage the process categories.
Expand All @@ -25,12 +26,24 @@ class ProcessCategoryController extends Controller
*/
public function index(Request $request)
{
$this->authorize('has-permission', Permission::PM_SETUP_PROCESS_CATEGORIES);
$query = ProcessCategory::where('uid', '!=', '')
->withCount('processes');

$filter = $request->input("filter");
$start = $request->input("start");
$limit = $request->input("limit");
$response = ProcessCategoryManager::index($filter, $start, $limit);
return response($this->formatList($response), 200);
$filter === null ? : $query->where(
'name', 'like', '%' . $filter . '%'
);

$orderBy = $request->input('order_by', 'name');
$orderDirection = $request->input('order_direction', 'ASC');
$orderBy === null ? : $query->orderBy($orderBy, $orderDirection);

$status = $request->input('status');
$status === null ? : $query->where('status', $status);

$perPage = $request->input('per_page', 10);
$result = $query->paginate($perPage);
return fractal($result, new ProcessCategoryTransformer())->respond();
}

/**
Expand All @@ -42,10 +55,15 @@ public function index(Request $request)
*/
public function store(Request $request)
{
$this->authorize('has-permission', Permission::PM_SETUP_PROCESS_CATEGORIES);
$data = $request->json()->all();
$response = ProcessCategoryManager::store($data);
return response($this->format($response), 201);

$processCategory = new ProcessCategory();
$processCategory->uid = str_replace('-', '', Uuid::uuid4());
$processCategory->fill($data);
$processCategory->saveOrFail();


return fractal($processCategory, new ProcessCategoryTransformer())->respond(201);
}

/**
Expand All @@ -59,8 +77,10 @@ public function store(Request $request)
public function update(Request $request, ProcessCategory $processCategory)
{
$data = $request->json()->all();
$response = ProcessCategoryManager::update($processCategory, $data);
return response($this->format($response), 200);
$processCategory->fill($data);
$processCategory->saveOrFail();

return fractal($processCategory, new ProcessCategoryTransformer())->respond(200);
}

/**
Expand All @@ -72,7 +92,7 @@ public function update(Request $request, ProcessCategory $processCategory)
*/
public function destroy(ProcessCategory $processCategory)
{
ProcessCategoryManager::remove($processCategory);
$processCategory->delete();
return response('', 204);
}

Expand All @@ -85,39 +105,7 @@ public function destroy(ProcessCategory $processCategory)
*/
public function show(ProcessCategory $processCategory)
{
return response($this->format($processCategory), 200);
}

/**
* Format the process category as a JSON response.
*
* @param ProcessCategory $processCategory
*
* @return array
*/
public function format(ProcessCategory $processCategory)
{
return [
"cat_uid" => $processCategory->uid,
"cat_name" => $processCategory->name,
"cat_total_processes" => isset($processCategory->processes_count)
? $processCategory->processes_count : 0,
];
}

/**
* Format the process category index as a JSON response.
*
* @param Collection $processCategories
*
* @return array
*/
public function formatList(Collection $processCategories)
{
$response = [];
foreach ($processCategories as $processCategory) {
$response[] = $this->format($processCategory);
}
return $response;
return fractal($processCategory, new ProcessCategoryTransformer())
->respond();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace ProcessMaker\Http\Controllers\Designer;

use ProcessMaker\Http\Controllers\Controller;

class ProcessCategoryController extends Controller
{

/**
* Get the list task
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
return view('processes.categories.index');
}

}
15 changes: 14 additions & 1 deletion ProcessMaker/Http/Middleware/GenerateMenus.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,20 @@ public function handle(Request $request, Closure $next)
'id' => 'homeid'
]);
});
Menu::make('sidebar_process', function ($menu) {});

Menu::make('sidebar_processes', function ($menu) {
$submenu = $menu->add(__('menus.sidebar_processes.processes'));
$submenu->add(__('menus.sidebar_processes.processes'), [
'route' => 'processes',
'icon' => 'fa-play-circle',
'id' => 'processes'
]);
$submenu->add(__('menus.sidebar_processes.categories'), [
'route' => 'process-categories-index',
'icon' => 'fa-list',
'id' => 'process-categories'
]);
});

Menu::make('sidebar_designer', function ($menu) {});

Expand Down
142 changes: 0 additions & 142 deletions ProcessMaker/Managers/ProcessCategoryManager.php

This file was deleted.

Loading