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
7 changes: 6 additions & 1 deletion ProcessMaker/Http/Controllers/Api/ScreenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ public function index(Request $request)
* ),
* )
*/
public function show(Screen $screen)
public function show(Request $request, Screen $screen)
{
$include = $request->input('include', '');
if ($include) {
$screen->load(explode(',', $include));
}

return new ScreenResource($screen);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
:show-labels="false"
label="title"
track-by="id"
:name="name"
@open="load()"
@search-change="load"
:name="name"
>
<template slot="noResult">
{{ $t("No elements found. Consider changing the search query.") }}
Expand Down Expand Up @@ -46,7 +46,7 @@
@asset="processAssetCreation"
/>
<a
v-if="content && content.id"
v-if="canOpenScreen"
:href="`/designer/screen-builder/${content.id}/edit`"
target="_blank"
>
Expand Down Expand Up @@ -85,6 +85,11 @@ export default {
uniqId: uniqueId("screen-select-"),
};
},
computed: {
canOpenScreen() {
return Boolean(this.content && this.content.id && this.isEditableScreen(this.content));
},
},
watch: {
content: {
handler() {
Expand Down Expand Up @@ -118,6 +123,21 @@ export default {
this.setDefault();
},
methods: {
includesWithCategory(include) {
const includes = new Set(
String(include || "")
.split(",")
.map((value) => value.trim())
.filter(Boolean),
);

includes.add("category");

return Array.from(includes).join(",");
},
isEditableScreen(screen) {
return !(screen?.is_system || screen?.category?.is_system);
},
type() {
if (this.params && this.params.type) {
return this.params.type;
Expand All @@ -137,7 +157,11 @@ export default {
loadScreen(value) {
this.loading = true;
ProcessMaker.apiClient
.get(`screens/${value}`)
.get(`screens/${value}`, {
params: {
include: "category",
},
})
.then(({ data }) => {
this.loading = false;
this.content = data;
Expand All @@ -160,6 +184,7 @@ export default {
type: this.type(),
interactive: this.interactive(),
include_system: 1,
include: this.includesWithCategory(this.params?.include),
order_direction: "asc",
status: "active",
selectList: true,
Expand All @@ -186,15 +211,19 @@ export default {
}

ProcessMaker.apiClient
.get("screens", { params: {
key: this.defaultKey,
include_system: 1,
order_by: "id",
order_direction: "ASC",
per_page: 1,
}})
.get("screens", {
params: {
key: this.defaultKey,
include_system: 1,
include: "category",
order_by: "id",
order_direction: "ASC",
per_page: 1,
},
})
.then(({ data }) => {
this.content = data.data[0];
const [screen] = data.data;
this.content = screen;
});
},
/**
Expand Down
28 changes: 28 additions & 0 deletions tests/Feature/Api/ScreenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,34 @@ public function testGetScreen()
$response->assertJsonStructure(self::STRUCTURE);
}

public function testListScreenCanIncludeCategoryForSystemScreens()
{
$screen = Screen::getScreenByKey('interstitial');

$response = $this->apiCall(
'GET',
self::API_TEST_SCREEN . '?include_system=1&include=category&key=interstitial&per_page=1'
);

$response->assertStatus(200);
$response->assertJsonPath('data.0.id', $screen->id);
$response->assertJsonPath('data.0.category.is_system', 1);
}

public function testGetScreenCanIncludeCategoryForSystemScreens()
{
$screen = Screen::getScreenByKey('interstitial');

$response = $this->apiCall(
'GET',
self::API_TEST_SCREEN . '/' . $screen->id . '?include=category'
);

$response->assertStatus(200);
$response->assertJsonPath('id', $screen->id);
$response->assertJsonPath('category.is_system', 1);
}

/**
* Update Screen parameter are required
*/
Expand Down
Loading