Commit 9198fbf5 authored by Jean Rabreau's avatar Jean Rabreau
Browse files

馃毀 targeting set loads its template

parent 468816ef
import authority from '@/assets/authAxios'
import i18n from '@/plugins/vue-i18n'
/**
* @typedef {Object} UsfLayout
* @property {string} id
* @property {boolean} [exist]
* @property {boolean} visible
* @property {boolean} [vertical]
* @property {boolean} [width]
* @property {string} component
* @property {string} parentId
* @property {UsfField[]} fields
*/
/**
* @typedef {Object} UsfInput
* @property {string} id
* @property {boolean} exist
* @property {boolean} visible
*/
/**
* @typedef {UsfInput|UsfLayout} UsfField
* @typedef {Object} UsfField
* @property {string} id -
* @property {string} name -
* @property {string} component - "Usf" prefixed form builder name
* @property {boolean} exist -
* @property {boolean} visible -
* @property {string} parentId - parent id or "root"
* @property {UsfField[]} [fields] - layout children
* @property {boolean} [required] -
* @property {boolean} [vertical] - row direction
* @property {boolean} [width] - col width
*/
......@@ -73,6 +62,23 @@ const getPrivateFields = (fields, privateParent=false) => {
}, [])
}
/**
*
* @param {UsfField[]} fields
* @return {UsfField[]}
*/
const getInputFields = (fields) => {
return fields.reduce((names, field) => {
if (field.name) {
names.push(field)
}
if (field.fields) {
names.push(...getInputFields(field.fields))
}
return names
}, [])
}
export { TEMPLATE_SCOPE, LAYOUT_COMPONENTS, getPrivateFields }
......@@ -115,6 +121,7 @@ const Template = {
},
getters: {
current: state => state.current,
inputFields: state => getInputFields(state.current.fields),
projectList: state => state.projectList,
publicList: state => state.publicList,
templateList: state => state.templateList,
......
......@@ -20,7 +20,7 @@
</p>
<p
v-else-if="item.level"
@click="copyHere(item)"
@click="analyseForCopy(item.templateId)"
>
<v-icon
color="secondary"
......@@ -86,23 +86,22 @@ export default {
},
computed: {
...mapGetters('item', ['projectId', 'templateId']),
...mapState('set', {
sets: 'projectSets',
setsLength: 'projectSetsCount',
pages: 'pageCount',
}),
...mapGetters('template', ['current']),
...mapGetters('project', {
storedProject: 'projectId',
currentProject: 'current',
managedProjects: 'contributions'
}),
...mapState('set', ['projectSets']),
...mapGetters('template', ['inputFields']),
...mapGetters('project',
{
currentProject: 'current',
managedProjects: 'contributions'
}),
},
methods: {
...mapActions('item', ['itemDuplicate']),
...mapActions('project', ['loadProject', 'retrieveProjects']),
...mapActions('set', ['loadProjectSets']),
...mapActions('template', ['loadProjectTemplates']),
...mapActions('template', ['loadTemplate', 'loadProjectTemplates']),
async analyseForCopy(targetedTemplateId) {
await this.loadTemplate(targetedTemplateId)
},
async duplicate() {
await this.itemDuplicate()
this.$router.push({
......@@ -111,7 +110,7 @@ export default {
})
},
async displayProjectSets() {
if (this.projectId !== this.storedProject) {
if (this.projectId !== this.currentProject.id) {
await this.loadProject(this.projectId)
}
await this.loadProjectSets({size: 0})
......@@ -120,7 +119,7 @@ export default {
id: this.projectId,
title: this.currentProject.name,
level: 0,
children: this.sets.map(
children: this.projectSets.map(
s => ({
id: s.id,
title: s.title,
......@@ -153,7 +152,7 @@ export default {
},
async addSets(project) {
await this.loadProjectSets({projectId: project.id, size: 0})
project.children = this.sets.map(s => ({ level: 1, ...s}))
project.children = this.projectSets.map(s => ({ level: 1, ...s}))
},
onPagination(pagination){
this.loadProjectSets({ page: pagination.page, size: pagination.itemsPerPage});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment