Skip to content

Commit 23901ea

Browse files
Add documentation view button for package-process-documenter (#3072)
1 parent dcd29fe commit 23901ea

3 files changed

Lines changed: 101 additions & 1 deletion

File tree

‎ProcessMaker/PackageHelper.php‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace ProcessMaker;
4+
5+
use Illuminate\Support\Str;
6+
7+
/**
8+
* A way to check if a package is installed by seeing if its service provider
9+
* class exists. This should be computationally cheaper than the method used in the
10+
* about page (but doesn't provide the extra data that the about page has).
11+
*
12+
* The constants below are added as a convenience, and are not a complete list of package
13+
* service providers. They do drive the "magic" method way of using this helper, though.
14+
*
15+
* You can use this helper by:
16+
* - using the magic methods:
17+
* e.g. PackageHelper::isPmPackageProcessDocumenterInstalled()
18+
* - passing the constants directly:
19+
* e.g. PackageHelper::isPackageInstalled(PackageHelper::PM_DOCKER_EXECUTOR_LUA)
20+
* - passing your own service provider class string:
21+
* e.g. PackageHelper::isPackageInstalled('ProcessMaker\Package\WebEntry\WebEntryServiceProvider')
22+
*
23+
* We don't use the ::class way to get the service provider's classname string, since
24+
* that would fail if the class is not installed.
25+
*
26+
* @package ProcessMaker
27+
*
28+
* @method static bool isPmDockerExecutorLuaInstalled()
29+
* @method static bool isPmDockerExecutorNodeInstalled()
30+
* @method static bool isPmDockerExecutorPhpInstalled()
31+
* @method static bool isPmPackageProcessDocumenterInstalled()
32+
* @method static bool isPmPackageWebentryInstalled()
33+
*/
34+
class PackageHelper
35+
{
36+
const PM_DOCKER_EXECUTOR_LUA = 'ProcessMaker\Package\DockerExecutorLua\DockerExecutorLuaServiceProvider';
37+
const PM_DOCKER_EXECUTOR_NODE = 'ProcessMaker\Package\DockerExecutorNode\DockerExecutorNodeServiceProvider';
38+
const PM_DOCKER_EXECUTOR_PHP = 'ProcessMaker\Package\DockerExecutorPhp\DockerExecutorPhpServiceProvider';
39+
const PM_PACKAGE_PROCESS_DOCUMENTER = 'ProcessMaker\Package\PackageProcessDocumenter\PackageServiceProvider';
40+
const PM_PACKAGE_WEBENTRY = 'ProcessMaker\Package\WebEntry\WebEntryServiceProvider';
41+
42+
public static function isPackageInstalled(string $serviceProviderClass): bool
43+
{
44+
if (! $serviceProviderClass) {
45+
return false;
46+
}
47+
48+
return class_exists($serviceProviderClass);
49+
}
50+
51+
/**
52+
* Handle "magic" invocation.
53+
*
54+
* @param $methodName
55+
* @param $parameters
56+
* @return bool
57+
* @throws \Exception
58+
*/
59+
public static function __callStatic(string $methodName, array $parameters): bool
60+
{
61+
$matches = [];
62+
$matchesMagicMethodSignature = preg_match('/^is(.+)Installed$/', $methodName, $matches);
63+
if ($matchesMagicMethodSignature) {
64+
$constantName = self::magicNameToConstantName($matches[1]);
65+
if (! defined('self::' . $constantName)) {
66+
throw new \Exception(
67+
sprintf('%s: No constant named \'%s\' defined.', self::class, $constantName)
68+
);
69+
}
70+
return self::isPackageInstalled(constant('self::' . $constantName));
71+
}
72+
73+
throw new \Exception(sprintf('%s: No function named \'%s\' defined.', self::class, $methodName));
74+
}
75+
76+
/**
77+
* Turns the inside of a magic method invocation into its
78+
* symbolic constant form (i.e. ALL_UPPER_SNAKE).
79+
*/
80+
private static function magicNameToConstantName(string $magicName): string
81+
{
82+
return strtoupper(Str::snake($magicName));
83+
}
84+
}

‎resources/js/processes/components/ProcessesListing.vue‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@
7070
>
7171
<i class="fas fa-cog fa-lg fa-fw"></i>
7272
</b-btn>
73+
<b-btn
74+
variant="link"
75+
@click="onAction('view-documentation', props.rowData, props.rowIndex)"
76+
v-b-tooltip.hover
77+
:title="$t('View Documentation')"
78+
v-if="permission.includes('view-processes') && isDocumenterInstalled"
79+
>
80+
<i class="fas fa-map-signs fa-lg fa-fw"></i>
81+
</b-btn>
7382
<b-btn
7483
variant="link"
7584
@click="onAction('export-item', props.rowData, props.rowIndex)"
@@ -120,7 +129,7 @@
120129
121130
export default {
122131
mixins: [datatableMixin, dataLoadingMixin],
123-
props: ["filter", "id", "status", "permission"],
132+
props: ["filter", "id", "status", "permission", "isDocumenterInstalled"],
124133
data() {
125134
return {
126135
orderBy: "name",
@@ -180,6 +189,9 @@
180189
goToEdit(data) {
181190
window.location = "/processes/" + data + "/edit";
182191
},
192+
goToDocumentation(processId) {
193+
window.location = `/modeler/${processId}/print`;
194+
},
183195
goToDesigner(data) {
184196
window.location = "/modeler/" + data;
185197
},
@@ -225,6 +237,9 @@
225237
case "edit-item":
226238
this.goToEdit(data.id);
227239
break;
240+
case "view-documentation":
241+
this.goToDocumentation(data.id);
242+
break;
228243
case "export-item":
229244
this.goToExport(data.id);
230245
break;

‎resources/views/processes/list.blade.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
v-on:edit="edit"
4242
v-on:reload="reload"
4343
:permission="{{ \Auth::user()->hasPermissionsFor('processes') }}"
44+
is-documenter-installed="{{\ProcessMaker\PackageHelper::isPmPackageProcessDocumenterInstalled()}}"
4445
></processes-listing>
4546
</div>
4647
</div>

0 commit comments

Comments
 (0)