Skip to content

Commit

Permalink
Merge branch 'IIMAGE-9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo committed Feb 6, 2025
2 parents c30e4e5 + 074028e commit ae2702b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gradle Project settings
projectName = imageshop
version = 2.0.4
version = 2.0.5

# XP App values
appDisplayName = ImageShop
Expand Down
67 changes: 32 additions & 35 deletions src/main/resources/lib/modules/iimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ module.exports = {
translate
}

let connection = null

function getSitesWithIImageAppInstalled() {
const sites = libs.content.query({
query: `data.siteConfig.applicationKey = '${app.name}'`,
Expand Down Expand Up @@ -73,36 +71,39 @@ function getInputsAllowedToUploadImage(contentId) {
let partsWithImageSelector = []

if (connection) {
const n = connection.draft.get(contentId)
const parts = n.components ? libs.objects.forceArray(n.components).filter(c => c.type === 'part') : []

const processedParts = {}

parts.forEach(p => {
const descriptor = p.part.descriptor

const part = libs.schema.getComponent({ key: descriptor, type: 'PART' })

const form = explodeFieldSets(part.form)
const contentNode = connection.draft.get(contentId)

const filteredInputs = form.filter(item => item.formItemType === 'Input' && item.inputType === 'ImageSelector')

if (processedParts[part.displayName]) processedParts[part.displayName]++
else processedParts[part.displayName] = 1

filteredInputs.forEach(item => {
let label = `${item.label} (${part.displayName} PART)`

if (processedParts[part.displayName] > 1) label += ` (${processedParts[part.displayName]})`

partsWithImageSelector.push({
name: item.name,
label,
path: p.path,
type: 'PART'
if (contentNode) {
const parts = contentNode.components ? libs.objects.forceArray(contentNode.components).filter(c => c.type === 'part') : []

const processedParts = {}

parts.forEach(p => {
const descriptor = p.part.descriptor

const part = libs.schema.getComponent({ key: descriptor, type: 'PART' })

const form = explodeFieldSets(part.form)

const filteredInputs = form.filter(item => item.formItemType === 'Input' && item.inputType === 'ImageSelector')

if (processedParts[part.displayName]) processedParts[part.displayName]++
else processedParts[part.displayName] = 1

filteredInputs.forEach(item => {
let label = `${item.label} (${part.displayName} PART)`

if (processedParts[part.displayName] > 1) label += ` (${processedParts[part.displayName]})`

partsWithImageSelector.push({
name: item.name,
label,
path: p.path,
type: 'PART'
})
})
})
})
}
}

//Make fieldsets flat
Expand Down Expand Up @@ -214,7 +215,7 @@ function requestImageInfoAndModifyContent (params) {

const data = JSON.parse(response.body)

getConnection()
const connection = getConnection()

const draftContentVersion = connection.draft.getActiveVersion({ key: imageId })
const masterContentVersion = connection.master.getActiveVersion({ key: imageId })
Expand Down Expand Up @@ -269,12 +270,8 @@ function translate (key, values = []) {
function getConnection () {
const context = libs.context.get()

if (connection) return connection

connection = {
return {
draft: libs.node.connect({ repoId: context.repository, branch: 'draft' }),
master: libs.node.connect({ repoId: context.repository, branch: 'master' })
}

return connection
}

0 comments on commit ae2702b

Please sign in to comment.