Skip to content

Commit

Permalink
Saving progress 1
Browse files Browse the repository at this point in the history
  • Loading branch information
CarliPinell committed Oct 8, 2024
1 parent e35854c commit 3388ed5
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import VariableNameGenerator from "@/components/VariableNameGenerator";
import { LinkButton } from "./renderer";
import "../assets/css/tabs.css";
import FormCollectionRecordControl from "./renderer/form-collection-record-control.vue";
import FormCollectionViewControl from "./renderer/form-collection-view-control.vue";

const rendererComponents = {
...renderer,
Expand Down Expand Up @@ -165,6 +166,7 @@ export default {
Vue.component("FormListTable", FormListTable);
Vue.component("LinkButton", LinkButton);
Vue.component("FormCollectionRecordControl", FormCollectionRecordControl);
Vue.component("FormCollectionViewControl", FormCollectionViewControl);
const store = new Vuex.Store({
modules: {
globalErrorsModule,
Expand Down
6 changes: 6 additions & 0 deletions src/components/inspector/collection-records-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
data-cy="inspector-collection"
/>
</div>
<div v-if="collectionId > 0" class="screen-link mt-2">
<a :href="`/collections/${collectionId}`" target="_blank">
{{ $t("Open Collection") }}
<i class="ml-1 fas fa-external-link-alt" />
</a>
</div>
</div>
</template>

Expand Down
235 changes: 235 additions & 0 deletions src/components/renderer/form-collection-view-control.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
<template>
<vue-form-renderer
ref="collectionViewControl"
class="form-collection-record-control"
:placeholder="placeholder"
v-model="data"
mode="preview"
:config="validatedConfig"
:computed="computed"
:custom-css="customCss"
:watchers="watchers"
:_parent="_parent"
/>
</template>

<script>
import VueFormRenderer from "../vue-form-renderer.vue";
const globalObject = typeof window === "undefined" ? global : window;
const defaultConfig = [
{
name: "empty",
items: []
}
];
export default {
components: {
VueFormRenderer
},
props: {
name: String,
validationData: null,
_parent: null,
record: null,
collection: {
type: Object
},
taskdraft: Object,
},
data() {
return {
localData: {},
config: defaultConfig,
computed: [],
customCSS: null,
watchers: [],
screenTitle: null,
selCollectionId: Number,
selRecordId: Number,
selDisplayMode: String,
screenCollectionId: null,
placeholder: "Select a collection",
screenType: "",
hasMustache: false,
flagDraft: {},
taskDraft: {},
collectionmode: "View"
};
},
computed: {
validatedConfig() {
return this.config && this.config[0] ? this.config : defaultConfig;
},
data: {
get() {
if(this.hasMustache) {
this.clearDataObject();
}
return this.localData;
},
set(data) {
Object.keys(data).forEach((variable) => {
this.validationData && this.$set(this.validationData, variable, data[variable]);
});
if (this.collection) {
this.$set(this.collection, 'data', Array.isArray(data) ? data : [data]);
this.$set(this.collection, 'screen', this.screenCollectionId);
}
},
},
},
methods: {
isSubmitButton(item) {
return (
item.config &&
item.component === "FormButton" &&
item.config.event === "submit"
);
},
hideSubmitButtons(config) {
config.forEach((item) => {
//If the element has containers
if (Array.isArray(item)) {
this.hideSubmitButtons(item);
}
//If the element has items
if (item.items) {
this.hideSubmitButtons(item.items);
}
//hidden buttons
if (this.isSubmitButton(item)) {
item.config.hidden = true;
}
});
},
disableForm(config) {
config.forEach((item) => {
//If the element has containers
if (Array.isArray(item)) {
this.disableForm(item);
}
//If the element has items
if (item.items) {
this.disableForm(item.items);
}
//Disable element
if (item && item.config) {
item.config.disabled = true;
item.config.readonly = true;
item.config.editable = false;
}
});
},
loadScreen(id) {
this.config = defaultConfig;
this.computed = [];
this.customCSS = null;
this.watchers = [];
this.screenTitle = null;
if (id) {
this.$dataProvider.getScreen(id).then((response) => {
this.config = response.data.config;
this.hideSubmitButtons(this.config);
this.computed = response.data.computed;
this.customCSS = response.data.custom_css;
this.watchers = response.data.watchers;
this.screenTitle = response.data.title;
if (this.$attrs["disabled"]) {
this.disableForm(this.config);
}
});
}
},
callbackRecord() {
this.hasMustache = true;
this.loadRecordCollection(this.selCollectionId, 1, this.selDisplayMode);
},
errors() {
this.$refs.nestedScreen.isValid();
return this.$refs.nestedScreen.errors;
},
loadRecordCollection(collectionId, recordId, modeId) {
this.selCollectionId = collectionId;
this.selRecordId = recordId;
this.selDisplayMode = modeId;
this.$dataProvider
.getCollectionRecordsView(collectionId, recordId)
.then((response) => {
this.placeholder = "";
const respData = response.data;
const viewScreen = response.collection.read_screen_id;
//Choose screen id regarding of the display Mode
this.screenCollectionId = viewScreen;
this.loadScreen(this.screenCollectionId);
//This section validates if Collection has draft data
if(this.taskDraft?.draft?.data == null || this.taskDraft.draft.data === '') {
this.localData = respData;
}else{
this.localData = this.taskDraft.draft.data;
}
})
.catch(() => {
this.localData = {};
globalObject.ProcessMaker.alert(this.$t('This content does not exist. We could not locate indicated data'), "danger");
});;
},
isMustache(record) {
return /\{\{.*\}\}/.test(record);
},
clearDataObject() {
Object.keys(this.localData).forEach(key => {
if (key !== "id") {
this.localData[key] = "";
}
});
},
},
watch: {
collection(collection) {
if(collection) {
this.selCollectionId = collection.collectionId;
}
},
record(record) {
this.hasMustache = false;
if (record && !isNaN(record) && record > 0 && this.collection) {
this.selRecordId = record;
this.loadRecordCollection(this.selCollectionId, record, this.collectionmode);
} else {
if (this.isMustache(record)) {
this.callbackRecord();
}
this.localData = {};
}
}
},
mounted() {
this.$root.$on("taskdraft-input", (val)=>{
this.taskDraft = val;
});
if (this.collection && this.record) {
this.loadRecordCollection(this.collection.collectionId, this.record, this.collectionmode);
}
},
};
</script>
<style lang="scss">
.prevent-interaction.form-collection-view-control::after {
content: attr(placeholder);
}
</style>
1 change: 1 addition & 0 deletions src/components/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export { default as FormRequests } from "./form-requests.vue";
export { default as FormTasks } from "./form-tasks.vue";
export { default as LinkButton } from "./link-button.vue";
export { default as FormCollectionRecordControl } from "./form-collection-record-control.vue";
export { default as FormCollectionViewControl } from "./form-collection-view-control.vue";
41 changes: 41 additions & 0 deletions src/form-builder-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import FileDownload from './components/renderer/file-download';
import FormListTable from './components/renderer/form-list-table';
import FormAnalyticsChart from "./components/renderer/form-analytics-chart";
import FormCollectionRecordControl from './components/renderer/form-collection-record-control.vue';
import FormCollectionViewControl from './components/renderer/form-collection-view-control.vue';
import {DataTypeProperty, DataFormatProperty, DataTypeDateTimeProperty} from './VariableDataTypeProperties';
import {
FormInput,
Expand Down Expand Up @@ -1124,5 +1125,45 @@ export default [
},
],
},
},
{
editorComponent: FormCollectionViewControl,
editorBinding: 'FormCollectionViewControl',
rendererComponent: FormCollectionViewControl,
rendererBinding: 'FormCollectionViewControl',
control: {
popoverContent: "Create a Collection View Control",
order: 7.0,
group: 'Content Fields',
label: 'Collection Record View',
component: 'FormCollectionViewControl',
'editor-component': 'FormCollectionViewControl',
'editor-control': 'FormCollectionViewControl',
config: {
name: 'Collection View Control',
icon: 'fas fa-database',
label: 'Collection View Control',
},
inspector: [
{
type: "collectionRecordsList",
field: "collection",
config: {
label: 'Collection Name',
helper: 'Select a collection',
value: '',
}
},
{
type: 'FormInput',
field: 'record',
config: {
label: 'Record ID',
helper: 'Supports Mustache Variable and the Collection Record',
value: '',
},
}
],
},
}
];

0 comments on commit 3388ed5

Please sign in to comment.