Skip to content

Commit 34ff4da

Browse files
authored
Merge pull request #8707 from ProcessMaker/task/FOUR-27903
FOUR-27903: Add Prev/Next navigation to Screen Template preview (Shared & My Templates)
2 parents f9c3aef + 320955b commit 34ff4da

5 files changed

Lines changed: 135 additions & 2 deletions

File tree

resources/js/components/templates/PreviewTemplate.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,16 @@
122122
watch: {
123123
selectedTemplateOptions() {
124124
this.$emit('template-options-selected', this.selectedTemplateOptions);
125-
}
125+
},
126+
template: {
127+
deep: true,
128+
handler() {
129+
this.templateData = this.template?.template ? this.template.template : this.template;
130+
this.type = this.templateData?.type;
131+
this.showCssPreview = false;
132+
this.code = "";
133+
},
134+
},
126135
},
127136
methods: {
128137
hidePreview() {
@@ -193,4 +202,4 @@
193202
.css-preview-card .css-preview .editor {
194203
height: inherit;
195204
}
196-
</style>
205+
</style>

resources/js/processes/screen-templates/components/MyTemplatesListing.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<template-preview-container
161161
ref="preview"
162162
:selected-template="selectedTemplate"
163+
@select-template="handleSelectTemplate"
163164
@mark-selected-row="markSelectedRow"
164165
/>
165166
</div>
@@ -251,7 +252,17 @@ export default {
251252
this.loading = false;
252253
});
253254
},
255+
mounted() {
256+
this.bindPreviewTabClose("#nav-myTemplates-tab");
257+
},
258+
beforeDestroy() {
259+
this.unbindPreviewTabClose();
260+
},
254261
methods: {
262+
handleSelectTemplate(template) {
263+
this.selectedTemplate = template;
264+
this.markSelectedRow(template.id);
265+
},
255266
fetch() {
256267
this.loading = true;
257268
this.apiDataLoading = true;

resources/js/processes/screen-templates/components/PublicTemplatesListing.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
<template-preview-container
163163
ref="preview"
164164
:selected-template="selectedTemplate"
165+
@select-template="handleSelectTemplate"
165166
@mark-selected-row="markSelectedRow"
166167
/>
167168
</div>
@@ -260,7 +261,17 @@ export default {
260261
this.apiNoResults = false;
261262
});
262263
},
264+
mounted() {
265+
this.bindPreviewTabClose("#nav-publicTemplates-tab");
266+
},
267+
beforeDestroy() {
268+
this.unbindPreviewTabClose();
269+
},
263270
methods: {
271+
handleSelectTemplate(template) {
272+
this.selectedTemplate = template;
273+
this.markSelectedRow(template.id);
274+
},
264275
fetch() {
265276
this.loading = true;
266277
this.apiDataLoading = true;

resources/js/processes/screen-templates/components/TemplatePreviewContainer.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@
1717
:close="onClose"
1818
:templateId="template.id"
1919
>
20+
<b-button-group>
21+
<b-button
22+
class="arrow-button"
23+
variant="outline-secondary"
24+
:disabled="!existPrev"
25+
@click="goPrevNext('Prev')"
26+
>
27+
<i class="fas fa-chevron-left" />
28+
</b-button>
29+
<b-button
30+
class="arrow-button"
31+
variant="outline-secondary"
32+
:disabled="!existNext"
33+
@click="goPrevNext('Next')"
34+
>
35+
<i class="fas fa-chevron-right" />
36+
</b-button>
37+
</b-button-group>
2038
<div class="ml-auto mr-0 text-right">
2139
<b-button
2240
class="btn-light text-secondary"

resources/js/processes/screen-templates/mixins/templatePreviewMixin.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const templatePreviewMixin = {
44
showPreview: false,
55
showRight: true,
66
template: {},
7+
prevTemplate: {},
8+
nextTemplate: {},
9+
existPrev: false,
10+
existNext: false,
711
data: [],
812
templateTitle: "",
913
loading: true,
@@ -28,6 +32,9 @@ const templatePreviewMixin = {
2832
this.template = info;
2933
this.showPreview = true;
3034
this.data = data;
35+
this.existPrev = false;
36+
this.existNext = false;
37+
this.defineNextPrevTemplate();
3138
},
3239
showButton() {
3340
this.isMouseOver = true;
@@ -85,6 +92,33 @@ const templatePreviewMixin = {
8592
this.showTemplatePreview = false;
8693
this.selectedTemplate = null;
8794
},
95+
closePreviewFrame() {
96+
if (this.$refs?.preview?.onClose) {
97+
this.$refs.preview.onClose();
98+
return;
99+
}
100+
if (typeof this.onClose === "function") {
101+
this.onClose();
102+
}
103+
},
104+
bindPreviewTabClose(tabSelector) {
105+
if (!tabSelector || typeof $ === "undefined") {
106+
return;
107+
}
108+
this._previewTabSelector = tabSelector;
109+
this._previewTabHandler = () => {
110+
this.closePreviewFrame();
111+
};
112+
$(tabSelector).on("hide.bs.tab.templatePreview", this._previewTabHandler);
113+
},
114+
unbindPreviewTabClose() {
115+
if (!this._previewTabSelector || typeof $ === "undefined") {
116+
return;
117+
}
118+
$(this._previewTabSelector).off("hide.bs.tab.templatePreview", this._previewTabHandler);
119+
this._previewTabSelector = null;
120+
this._previewTabHandler = null;
121+
},
88122
onClose() {
89123
this.$emit('mark-selected-row', 0);
90124
this.showPreview = false;
@@ -99,6 +133,56 @@ const templatePreviewMixin = {
99133
this.isLoading = "";
100134
this.stopFrame = false;
101135
this.size = 50;
136+
this.prevTemplate = {};
137+
this.nextTemplate = {};
138+
this.existPrev = false;
139+
this.existNext = false;
140+
},
141+
defineNextPrevTemplate() {
142+
if (!Array.isArray(this.data)) {
143+
this.prevTemplate = {};
144+
this.nextTemplate = {};
145+
this.existPrev = false;
146+
this.existNext = false;
147+
return;
148+
}
149+
150+
let prevTemplate = {};
151+
let nextTemplate = {};
152+
let seeNextTemplate = false;
153+
for (const templateIndex in this.data) {
154+
if (!seeNextTemplate) {
155+
if (this.data[templateIndex] === this.template) {
156+
seeNextTemplate = true;
157+
} else {
158+
prevTemplate = this.data[templateIndex];
159+
this.existPrev = true;
160+
}
161+
} else {
162+
nextTemplate = this.data[templateIndex];
163+
this.existNext = true;
164+
break;
165+
}
166+
}
167+
this.prevTemplate = prevTemplate;
168+
this.nextTemplate = nextTemplate;
169+
},
170+
goPrevNext(action) {
171+
let targetTemplate = null;
172+
if (action === "Next" && this.existNext) {
173+
targetTemplate = this.nextTemplate;
174+
}
175+
if (action === "Prev" && this.existPrev) {
176+
targetTemplate = this.prevTemplate;
177+
}
178+
179+
if (!targetTemplate) {
180+
return;
181+
}
182+
183+
this.$emit("select-template", targetTemplate);
184+
this.$emit("mark-selected-row", targetTemplate.id);
185+
this.showSideBar(targetTemplate, this.data);
102186
},
103187
},
104188
};

0 commit comments

Comments
 (0)