Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOUR-10447: Add Preview for screens #1671

Merged
merged 14 commits into from
Oct 6, 2023
13 changes: 13 additions & 0 deletions src/assets/spiner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 49 additions & 8 deletions src/components/inspectors/PreviewPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@
</b-row>

<b-row>
<div class="item-title"> {{ screenTitle }} </div>
<div class="task-title"> {{ taskTitle }} </div>
</b-row>

<no-preview-available/>
<div id="spinner" class="row justify-content-center" v-if="showSpinner">
<img alt="spinner" :src="spinner">
</div>

<no-preview-available v-show="!previewUrl"/>
<iframe title="Preview" v-show="!!previewUrl && !showSpinner" :src="previewUrl" style="width:100%; height:100%;border: none;" @load="loading"/>
</b-col>

</template>
Expand All @@ -71,20 +75,28 @@ import store from '@/store';
import NoPreviewAvailable from '@/components/inspectors/NoPreviewAvailable';

export default {
props: ['nodeRegistry', 'visible'],
props: ['nodeRegistry', 'visible', 'previewConfigs'],
components: { NoPreviewAvailable },
data() {
return {
data: {},
previewUrl: null,
showSpinner: false,
spinner: require('@/assets/spiner.svg'),
selectedPreview: '1',
taskTitle: '',
screenTitle: '',
width: 400,
itemTitle: '',
width: 600,
isDragging: false,
currentPos: 400,
currentPos: 600,
};
},
watch: {
previewUrl(value, oldValue) {
if (value !== oldValue) {
this.showSpinner = true;
}
},
highlightedNode() {
document.activeElement.blur();
this.prepareData();
Expand All @@ -102,12 +114,24 @@ export default {
},
},
methods: {
loading() {
this.showSpinner = false;
},
prepareData() {
if (!this.highlightedNode) {
return {};
}

const defaultDataTransform = (node) => Object.entries(node.definition).reduce((data, [key, value]) => {
data[key] = value;
return data;
}, {});

this.data = defaultDataTransform(this.highlightedNode);
this.taskTitle = this.data?.name;

this.taskTitle = this?.highlightedNode?.definition?.name;
this.previewNode();
},

handleAssignmentChanges(currentValue, previousValue) {
Expand All @@ -120,8 +144,25 @@ export default {
onSelectedPreview(item) {
this.selectedPreview = item;
},
previewNode(node) {
this.taskTitle = node?.name;
previewNode(force = false) {
if (!this.highlightedNode || (!this.visible && !force)) {
return;
}

const previewConfig = this.previewConfigs.find(config => {
return config.matcher(this.data);
});

let clone = {};
for (let prop in this.data) {
if ((previewConfig?.receivingParams ?? []).includes(prop)) {
clone[prop] = this.data[prop];
}
}
const nodeData = encodeURI(JSON.stringify(clone));

this.previewUrl = previewConfig ? `${previewConfig.url}?node=${nodeData}` : null;
this.taskTitle = this.highlightedNode?.definition?.name;
this.showPanel = true;
},
onClose() {
Expand Down
10 changes: 8 additions & 2 deletions src/components/modeler/Modeler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
@previewResize="setInspectorButtonPosition"
:visible="isOpenPreview"
:nodeRegistry="nodeRegistry"
:previewConfigs="previewConfigs"
/>

<InspectorPanel
Expand Down Expand Up @@ -327,6 +328,7 @@ export default {
players: [],
showInspectorButton: true,
inspectorButtonRight: 65,
previewConfigs: [],
multiplayer: null,
isMultiplayer: false,
};
Expand Down Expand Up @@ -388,6 +390,9 @@ export default {
showComponent: () => store.getters.showComponent,
},
methods: {
registerPreview(config) {
this.previewConfigs.push(config);
},
handleToolbarAction(action) {
if (action.handler instanceof Function) {
action.handler(this);
Expand All @@ -397,8 +402,8 @@ export default {
this.showInspectorButton = !(value ?? true);
this.isOpenInspector = value;
},
handlePreview(node) {
this.$refs['preview-panel'].previewNode(node);
handlePreview() {
this.$refs['preview-panel'].previewNode(true);
this.handleTogglePreview(true) ;
},
handleTogglePreview(value) {
Expand Down Expand Up @@ -1483,6 +1488,7 @@ export default {
registerNode: this.registerNode,
registerStatusBar: this.registerStatusBar,
registerPmBlock: this.registerPmBlock,
registerPreview: this.registerPreview,
});

this.moddle = new BpmnModdle(this.extensions);
Expand Down