diff --git a/ProcessMaker/Http/Controllers/Api/Administration/GroupsController.php b/ProcessMaker/Http/Controllers/Api/Administration/GroupsController.php
index 482d52b338..e6c9d21f35 100644
--- a/ProcessMaker/Http/Controllers/Api/Administration/GroupsController.php
+++ b/ProcessMaker/Http/Controllers/Api/Administration/GroupsController.php
@@ -39,7 +39,7 @@ 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 {
@@ -47,7 +47,7 @@ public function index(Request $request)
// 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);
diff --git a/ProcessMaker/Http/Controllers/Api/Administration/ProcessCategoryController.php b/ProcessMaker/Http/Controllers/Api/Administration/ProcessCategoryController.php
index 77c256a1dd..3f0ac167dc 100644
--- a/ProcessMaker/Http/Controllers/Api/Administration/ProcessCategoryController.php
+++ b/ProcessMaker/Http/Controllers/Api/Administration/ProcessCategoryController.php
@@ -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.
@@ -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();
}
/**
@@ -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);
}
/**
@@ -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);
}
/**
@@ -72,7 +92,7 @@ public function update(Request $request, ProcessCategory $processCategory)
*/
public function destroy(ProcessCategory $processCategory)
{
- ProcessCategoryManager::remove($processCategory);
+ $processCategory->delete();
return response('', 204);
}
@@ -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();
}
}
diff --git a/ProcessMaker/Http/Controllers/Designer/ProcessCategoryController.php b/ProcessMaker/Http/Controllers/Designer/ProcessCategoryController.php
new file mode 100644
index 0000000000..76f0c0ac49
--- /dev/null
+++ b/ProcessMaker/Http/Controllers/Designer/ProcessCategoryController.php
@@ -0,0 +1,20 @@
+ '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) {});
diff --git a/ProcessMaker/Managers/ProcessCategoryManager.php b/ProcessMaker/Managers/ProcessCategoryManager.php
deleted file mode 100644
index 1dd3bf74f7..0000000000
--- a/ProcessMaker/Managers/ProcessCategoryManager.php
+++ /dev/null
@@ -1,142 +0,0 @@
-validate(
- [
- 'start' => $start,
- 'limit' => $limit,
- ],
- [
- 'start' => 'nullable|numeric|min:0',
- 'limit' => 'nullable|numeric|min:0',
- ]
- );
- $query = ProcessCategory::select([
- 'uid',
- 'name',
- ])->where('uid', '!=', '')
- ->withCount('processes');
- $filter === null ?: $query->where('name', 'like', "%$filter%");
- $start === null ? : $query->offset($start);
- $limit === null ? : $query->limit($limit);
- return $query->get();
- }
-
- /**
- * Stores a new process category.
- *
- * @param array $data
- *
- * @return \ProcessMaker\Model\ProcessCategory
- */
- public function store(array $data)
- {
- $this->validate(
- $data,
- [
- 'cat_name' => 'required|string|max:100|unique:process_categories,name',
- ]
- );
- return ProcessCategory::create([
- 'uid' => str_replace('-', '', Uuid::uuid4()),
- 'name' => $data['cat_name'],
- ]);
- }
-
- /**
- * Update a process category.
- *
- * @param ProcessCategory $processCategory
- * @param array $data
- *
- * @return \ProcessMaker\Model\ProcessCategory
- */
- public function update(ProcessCategory $processCategory, array $data)
- {
- $this->validate(
- $data,
- [
- 'cat_name' => 'required|string|max:100|unique:process_categories,name',
- ]
- );
- $processCategory->update([
- 'name' => $data['cat_name'],
- ]);
- $processCategory->save();
- return $processCategory;
- }
-
- /**
- * Remove a process category.
- *
- * @param ProcessCategory $processCategory
- *
- * @return bool
- */
- public function remove(ProcessCategory $processCategory)
- {
- $this->validate(
- [
- 'processCategory' => $processCategory,
- ],
- [
- 'processCategory' => 'process_category_manager.category_does_not_have_processes',
- ]
- );
- return $processCategory->delete();
- }
-
- /**
- * Validate the given data with the given rules.
- *
- * @param array $data
- * @param array $rules
- * @param array $messages
- * @param array $customAttributes
- *
- * @throws ValidationException
- */
- private function validate(
- array $data,
- array $rules,
- array $messages = [],
- array $customAttributes = []
- ) {
- $validator = Validator::make($data, $rules, $messages, $customAttributes);
-
- /**
- * Validate that the category does not have processes.
- */
- $validator->addExtension(
- 'process_category_manager.category_does_not_have_processes',
- function ($attribute, $processCategory, $parameters, ValidatorImplementation $validator) {
- return $processCategory->processes()->count() === 0;
- }
- );
-
- if ($validator->fails()) {
- throw new ValidationException($validator);
- }
- }
-}
diff --git a/ProcessMaker/Model/ProcessCategory.php b/ProcessMaker/Model/ProcessCategory.php
index 59786d517b..fab465576d 100644
--- a/ProcessMaker/Model/ProcessCategory.php
+++ b/ProcessMaker/Model/ProcessCategory.php
@@ -4,6 +4,8 @@
use Illuminate\Database\Eloquent\Model;
use Watson\Validating\ValidatingTrait;
+use Illuminate\Support\Facades\Validator;
+use ProcessMaker\Exception\ValidationException;
use ProcessMaker\Model\Traits\Uuid;
/**
@@ -22,13 +24,17 @@ class ProcessCategory extends Model
use ValidatingTrait;
use Uuid;
+ const STATUS_ACTIVE = 'ACTIVE';
+ const STATUS_INACTIVE = 'INACTIVE';
+
/**
* Validation rules.
*
* @var array $rules
*/
- protected $rules = [
+ public $rules = [
'name' => 'required|string|max:100|unique:process_categories,name',
+ 'status' => 'required|string|in:ACTIVE,INACTIVE',
];
@@ -39,6 +45,7 @@ class ProcessCategory extends Model
*/
protected $fillable = [
'name',
+ 'status',
];
/**
@@ -58,6 +65,34 @@ public function getRouteKeyName()
*/
public function processes()
{
- return $this->hasMany(Process::class, 'id', 'id');
+ return $this->hasMany(Process::class);
+ }
+
+ /**
+ * Check that the category has no processes before deleting
+ *
+ * @return bool|null
+ *
+ * @throws \Exception
+ */
+ public function delete()
+ {
+ $validator = Validator::make([
+ 'processCategory' => $this,
+ ], [
+ 'processCategory' => 'process_category_manager.category_does_not_have_processes',
+ ]);
+
+ $validator->addExtension(
+ 'process_category_manager.category_does_not_have_processes',
+ function ($attribute, $processCategory, $parameters, $validator) {
+ return $processCategory->processes()->count() === 0;
+ }
+ );
+
+ if ($validator->fails()) {
+ throw new ValidationException($validator);
+ }
+ parent::delete();
}
}
diff --git a/ProcessMaker/Transformers/ProcessCategoryTransformer.php b/ProcessMaker/Transformers/ProcessCategoryTransformer.php
new file mode 100644
index 0000000000..1599d81358
--- /dev/null
+++ b/ProcessMaker/Transformers/ProcessCategoryTransformer.php
@@ -0,0 +1,23 @@
+toArray();
+ if (!array_key_exists('processes_count', $data)) {
+ $data['processes_count'] = $processCategory->processes->count();
+ }
+ return $data;
+ }
+}
+
\ No newline at end of file
diff --git a/database/factories/ProcessCategory.php b/database/factories/ProcessCategory.php
deleted file mode 100644
index 0d7868e257..0000000000
--- a/database/factories/ProcessCategory.php
+++ /dev/null
@@ -1,14 +0,0 @@
-define(\ProcessMaker\Model\ProcessCategory::class, function (Faker $faker) {
- return [
- 'uid' => Uuid::uuid4(),
- 'name' => $faker->name(),
- ];
-});
diff --git a/database/factories/ProcessCategoryFactory.php b/database/factories/ProcessCategoryFactory.php
new file mode 100644
index 0000000000..cc2f847c9d
--- /dev/null
+++ b/database/factories/ProcessCategoryFactory.php
@@ -0,0 +1,18 @@
+define(ProcessCategory::class, function (Faker $faker) {
+ return [
+ 'uid' => Uuid::uuid4(),
+ 'name' => $faker->name(),
+ 'status' => $faker->randomElement(
+ [ProcessCategory::STATUS_ACTIVE, ProcessCategory::STATUS_INACTIVE]
+ )
+ ];
+});
diff --git a/database/migrations/2018_06_04_124650_create_process_categories_table.php b/database/migrations/2018_06_04_124650_create_process_categories_table.php
index 7fe754ca29..e16703aaef 100644
--- a/database/migrations/2018_06_04_124650_create_process_categories_table.php
+++ b/database/migrations/2018_06_04_124650_create_process_categories_table.php
@@ -18,6 +18,8 @@ public function up()
$table->increments('id');
$table->uuid('uid')->unique();
$table->string('name')->default('');
+ $table->enum('status', ['ACTIVE', 'INACTIVE'])
+ ->default('ACTIVE');
$table->timestamps();
});
}
diff --git a/resources/assets/js/processes/categories/components/CategoriesListing.vue b/resources/assets/js/processes/categories/components/CategoriesListing.vue
new file mode 100644
index 0000000000..c6b0a91b33
--- /dev/null
+++ b/resources/assets/js/processes/categories/components/CategoriesListing.vue
@@ -0,0 +1,119 @@
+
+