Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions ProcessMaker/Http/Controllers/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Session;
use ProcessMaker\Http\Controllers\Api\TemplateController as TemplateApiController;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessTemplates;
use ProcessMaker\Models\ScreenTemplates;
use ProcessMaker\Models\Template;
use ProcessMaker\Templates\ProcessTemplate;
Expand Down Expand Up @@ -76,6 +77,28 @@ public function configure(string $type, $request)

public function show(Request $request)
{
$id = $request->route('id');

$template = ProcessTemplates::find($id);

if (!$template) {
// id might be a process id
$editingProcess = Process::where('id', $id)->where('is_template', 1)->first();
if ($editingProcess && $editingProcess->uuid) {
$template = ProcessTemplates::where('editing_process_uuid', $editingProcess->uuid)->first();
if ($template) {
return redirect()->route('modeler.template.show', ['id' => $template->id]);
}
}
abort(404);
}

// If template has an editing process, show template modeler with that process id (resuming existing session)
$editingProcess = $template->editingProcess;
if ($editingProcess) {
return view('processes.modeler.showTemplate')->with('id', $editingProcess->id);
}

$templateApiController = new TemplateApiController(new Template);
$response = $templateApiController->show('process', $request);
Session::flash('_alert', json_encode(['success', __('The template was created.')]));
Expand Down
11 changes: 11 additions & 0 deletions ProcessMaker/Models/ProcessTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ class ProcessTemplates extends Template

public $process_category_id;

/**
* The process currently being used to edit this template (if any).
*
* @return BelongsTo
*/
public function editingProcess()
{
return $this->belongsTo(Process::class, 'editing_process_uuid', 'uuid')
->where('processes.is_template', 1);
}

/**
* Category of the process.
*
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Templates/ProcessTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function index(Request $request)
public function show($request) : array
{
$template = ProcessTemplates::find($request->id);
$process = Process::where('uuid', $template->editing_process_uuid)->where('is_template', 1)->first();
$process = $template->editingProcess;

// If a process exists with the template editing process uuid delete that process and create a new process
// this ensures any updates to the template manifest will be reflected
Expand Down
Loading