jamespot-front-business 1.1.73 → 1.1.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs.js CHANGED
@@ -3401,1121 +3401,1124 @@ function createTextAreaField(installedField) {
3401
3401
  return field;
3402
3402
  }
3403
3403
 
3404
- const installedToV2ViewNames = {
3405
- 'create-popup': 'popup',
3406
- create: 'create',
3407
- edit: 'edit',
3408
- display: 'view',
3409
- };
3410
- const specialAttrName = ['title', 'alertAuthor', 'sendAlert'];
3411
- const ignoredFields = ['edito'];
3412
- function updateViewsFromFields(clonedApp, appFields) {
3413
- return Object.assign({}, ...viewsList.map((view) => {
3414
- const viewItems = {};
3415
- Object.entries(clonedApp.views[view]).forEach(([fieldId, field]) => {
3416
- if (field.isFixed) {
3417
- viewItems[fieldId] = field;
3418
- }
3419
- if (field.isOptional) {
3420
- viewItems[fieldId] = field;
3421
- }
3422
- });
3423
- appFields.forEach((field, idx) => {
3424
- var _a, _b, _c, _d, _e, _f, _g, _h;
3425
- const isFieldUsedInView = field.views[view];
3426
- const isExistingField = Object.keys(clonedApp.views[view]).includes(field.id);
3427
- const fieldType = field.type;
3428
- if (AppFormBannedFromViews$1.get(fieldType) && ((_a = AppFormBannedFromViews$1.get(fieldType)) === null || _a === void 0 ? void 0 : _a.includes(view))) {
3404
+ function appToXml(studioApp) {
3405
+ const { manifest, views, audience, installFor } = studioApp;
3406
+ return `<?xml version='1.0' encoding='utf-8'?>
3407
+ <Application>
3408
+ ${createAppManifest(manifest, views, audience, installFor, studioApp.idApp)}
3409
+ <Types>
3410
+ <objecttype
3411
+ label="${manifest.typeLabel}"
3412
+ labelPlural="${manifest.typeLabel}"
3413
+ labelLinkSingular="${manifest.typeLabel}"
3414
+ labelLinkPlural="${manifest.typeLabel}"
3415
+ name="${studioApp.idApp}"
3416
+ classImpl="JPBEContent"
3417
+ classCodeLocation="jamespot/jpro/objs/JPBEContent.php"
3418
+ cssClass="${manifest.cssClass.value}"
3419
+ cssColor="${manifest.cssColor}"
3420
+ searchtab="${studioApp.idApp}"
3421
+ searchtablabel="${manifest.typeLabel}"
3422
+ buttonlabel="${manifest.typeLabel}"
3423
+ extends="article">
3424
+ ${renderPrimaryFields(studioApp.fields)}
3425
+ ${renderCustomFields(studioApp.fields)}
3426
+ </objecttype>
3427
+ ${renderDisplays(studioApp)}
3428
+ </Types>
3429
+ </Application>`;
3430
+ }
3431
+ function createAppManifest(manifest, views, audience, installFor, idApp) {
3432
+ var _a;
3433
+ return `<Manifest>
3434
+ <ShowImport>true</ShowImport>
3435
+ <AppShortName>${idApp}</AppShortName>
3436
+ <AppName>${manifest.appName}</AppName>
3437
+ <Description>${manifest.description}</Description>
3438
+ <Version>${manifest.version + 1}</Version>
3439
+ <ManifestVersion>1.0</ManifestVersion>
3440
+ <StudioVersion>2</StudioVersion>
3441
+ <DateCreation>${manifest.dateCreation.toString().split('T')[0]}</DateCreation>
3442
+ <CssClass>${(_a = manifest.cssClass) === null || _a === void 0 ? void 0 : _a.label}</CssClass>
3443
+ <CssColor>${manifest.cssColor}</CssColor>
3444
+ <Categories>N.A.</Categories>
3445
+ <Editor>Jamespot</Editor>
3446
+ <EditorUrl>https://www.fr.jamespot.com/</EditorUrl>
3447
+ <Type>${idApp}</Type>
3448
+ ${renderAppView(manifest.viewSolr, views.list)}
3449
+ ${renderAppSearch(views.filter)}
3450
+ ${renderAudience(audience, installFor)}
3451
+ <Order>1</Order>
3452
+ </Manifest>`;
3453
+ }
3454
+ function renderAppView(viewSolr, listView) {
3455
+ if (viewSolr === STUDIO_VIEW.SOLR) {
3456
+ let xml = '<AppView>solr</AppView>';
3457
+ const formItemIdInList = [];
3458
+ Object.entries(listView)
3459
+ .sort((a, b) => a[1].pos - b[1].pos)
3460
+ .forEach(([fieldId, field]) => {
3461
+ if (!field.isUsed) {
3429
3462
  return;
3430
3463
  }
3431
- let fieldValue = undefined;
3432
- if (fieldType === AppFormItemTypes.CODEHTML) {
3433
- const richTextProperty = (_b = field.properties) === null || _b === void 0 ? void 0 : _b.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.RICHTEXT);
3434
- if (richTextProperty === null || richTextProperty === void 0 ? void 0 : richTextProperty.value) {
3435
- fieldValue = richTextProperty === null || richTextProperty === void 0 ? void 0 : richTextProperty.value;
3436
- }
3437
- }
3438
- if (fieldType === AppFormItemTypes.SELECT) {
3439
- const selectProperty = (_c = field.properties) === null || _c === void 0 ? void 0 : _c.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3440
- if (isExistingField) {
3441
- const exField = clonedApp.views[view][field.id];
3442
- const exSelectProperty = (_d = exField.properties) === null || _d === void 0 ? void 0 : _d.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3443
- const isMultivalued = !!((_e = selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value) === null || _e === void 0 ? void 0 : _e.canSelectMultiple);
3444
- const exIsMultivalued = !!((_f = exSelectProperty === null || exSelectProperty === void 0 ? void 0 : exSelectProperty.value) === null || _f === void 0 ? void 0 : _f.canSelectMultiple);
3445
- if (isMultivalued === exIsMultivalued) {
3446
- fieldValue = exField.value;
3447
- }
3448
- }
3449
- else {
3450
- const isEnhancedSelect = !!(selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.isOptionsEditorEnhanced);
3451
- const defaultValue = isEnhancedSelect && !!(selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value.defaultSelectOption)
3452
- ? selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value.defaultSelectOptionValue
3453
- : '';
3454
- if (defaultValue) {
3455
- fieldValue = defaultValue;
3456
- }
3457
- }
3458
- }
3459
- if (isExistingField) {
3460
- const exField = clonedApp.views[view][field.id];
3461
- viewItems[field.id] = Object.assign(Object.assign(Object.assign(Object.assign({}, exField), { properties: field.properties || exField.properties || [] }), (fieldValue !== undefined && { value: fieldValue })), { isUsed: isFieldUsedInView, pos: ((_g = clonedApp.syncViewFieldOrder) === null || _g === void 0 ? void 0 : _g[view]) ? idx : exField.pos, isLockedValue: (fieldValue !== undefined || exField.value !== undefined) && exField.isLockedValue });
3462
- }
3463
- else {
3464
- const existingFieldsLen = Object.values(clonedApp.views[view]).filter((v) => !v.isFixed && !v.isOptional).length;
3465
- viewItems[field.id] = {
3466
- type: field.type,
3467
- properties: field.properties || [],
3468
- isUsed: isFieldUsedInView,
3469
- isOptional: false,
3470
- isLockedValue: false,
3471
- isFixed: false,
3472
- value: fieldValue !== null && fieldValue !== void 0 ? fieldValue : null,
3473
- pos: ((_h = clonedApp.syncViewFieldOrder) === null || _h === void 0 ? void 0 : _h[view]) ? idx : existingFieldsLen + idx,
3474
- };
3464
+ if ([AppFormItemTypes.IMAGE].includes(field.type)) {
3465
+ return;
3475
3466
  }
3467
+ formItemIdInList.push(getAttrNameFormItem(field, fieldId));
3476
3468
  });
3477
- return {
3478
- [view]: viewItems,
3479
- };
3480
- }));
3481
- }
3482
- function buildAudience(accessRightObjectList) {
3483
- return accessRightObjectList.map((accessRightObject) => {
3484
- return {
3485
- id: `${accessRightObject.type}/${accessRightObject.id}`,
3486
- uri: `${accessRightObject.type}/${accessRightObject.id}`,
3487
- shortUri: `${accessRightObject.type}/${accessRightObject.id}`,
3488
- title: accessRightObject.title,
3489
- name: accessRightObject.title,
3490
- mainType: accessRightObject.type,
3491
- type: accessRightObject.mainType,
3492
- label: accessRightObject.type,
3493
- cssClass: accessRightObject._cssClass,
3494
- cssColor: accessRightObject._cssColor,
3495
- class: accessRightObject._cssClass,
3496
- Pseudo: accessRightObject.title,
3497
- _url: accessRightObject._url,
3498
- };
3499
- });
3500
- }
3501
- function populateFieldsAndViews(app, appS, state) {
3502
- const tables = app.typeModel.tables;
3503
- const displays = app.typeModel.displays;
3504
- if (!displays) {
3505
- return;
3469
+ xml += `<AppColumns>${formItemIdInList.join()}</AppColumns>`;
3470
+ return xml;
3506
3471
  }
3507
- const registeredFields = new Map();
3508
- Object.entries(displays).forEach((displaysEntry) => {
3509
- const [displayName, displayValue] = displaysEntry;
3510
- if (Object.keys(installedToV2ViewNames).includes(displayName)) {
3511
- buildView(appS, registeredFields, displayName, displayValue, tables, state);
3512
- }
3513
- });
3514
- buildListView(appS, registeredFields, app.columns, tables, state);
3515
- buildFilterView(appS, registeredFields, app.attrExposed, tables, state);
3472
+ return '';
3516
3473
  }
3517
- function buildView(appS, registeredFields, displayName, displayValue, tables, state) {
3518
- const newName = installedToV2ViewNames[displayName];
3519
- appS.views[newName] = {};
3520
- displayValue.composants.forEach((viewComponent, index) => {
3521
- let field = undefined;
3522
- if (viewComponent.name && ignoredFields.includes(viewComponent.name)) {
3474
+ function renderAppSearch(searchView) {
3475
+ const formItemIdInFilter = [];
3476
+ Object.entries(searchView)
3477
+ .sort((a, b) => a[1].pos - b[1].pos)
3478
+ .forEach(([fieldId, field]) => {
3479
+ if (!field.isUsed) {
3523
3480
  return;
3524
3481
  }
3525
- const [fieldIdx, fixedInfo] = createOrGetField(appS, registeredFields, viewComponent, tables, state);
3526
- if (fieldIdx === -1 && fixedInfo) {
3527
- switch (fixedInfo.ref) {
3528
- case 'title':
3529
- addTitleToView(newName, appS, fixedInfo);
3530
- break;
3531
- case 'alertAuthor':
3532
- addAlertAuthorToView(newName, appS, fixedInfo);
3533
- break;
3534
- case 'sendAlert':
3535
- addSendAlertToView(newName, appS, fixedInfo);
3536
- break;
3537
- case 'publishTo':
3538
- addPublishToToView(newName, appS, fixedInfo);
3539
- break;
3540
- default:
3541
- console.error('fixed field info with unsupported ref ', fixedInfo);
3542
- break;
3543
- }
3544
- }
3545
- else if (fieldIdx !== -1) {
3546
- field = appS.fields[fieldIdx];
3547
- if (!field || !field.views) {
3548
- throw new Error(`error converting installed app to V2: created field not found in fields array: ${fieldIdx}, ${fixedInfo}`);
3549
- }
3550
- field.views[newName] = true;
3551
- addFieldToView(newName, field, appS, index, fixedInfo);
3552
- }
3482
+ const list = [ExtraAppFieldsItemViews.TITLE, AppFormItemTypes.IMAGE];
3483
+ if (!list.includes(field.type))
3484
+ formItemIdInFilter.push(getAttrNameFormItem(field, fieldId));
3553
3485
  });
3486
+ return `<AttrExposed>${formItemIdInFilter.join()}</AttrExposed>`;
3554
3487
  }
3555
- function buildListView(appS, registeredFields, columns, tables, state) {
3556
- if (!columns) {
3557
- return;
3558
- }
3559
- Object.keys(columns).forEach((fieldRef, index) => {
3560
- addFieldToViewFromRef(appS, registeredFields, tables, 'list', fieldRef, index, state);
3561
- });
3488
+ function fieldType(fieldType) {
3489
+ if (fieldType === ExtraAppFieldsItemViews.TITLE)
3490
+ return 'title';
3491
+ if (fieldType === ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS)
3492
+ return 'sendAlert';
3493
+ if (fieldType === ExtraAppFieldsItemViews.RECEIVEACOPY)
3494
+ return 'alertAuthor';
3495
+ if (fieldType === ExtraAppFieldsItemViews.PUBLISHTO)
3496
+ return 'publishTo';
3497
+ if (fieldType === ExtraAppFieldsItemViews.USER)
3498
+ return 'idUser';
3499
+ if (fieldType === ExtraAppFieldsItemViews.CREATIONDATE)
3500
+ return 'dateCreation';
3501
+ if (fieldType === AppFormItemTypes.DESCRIPTION)
3502
+ return 'description';
3503
+ return fieldType;
3562
3504
  }
3563
- function buildFilterView(appS, registeredFields, attrExposed, tables, state) {
3564
- attrExposed.forEach((fieldRef, index) => {
3565
- addFieldToViewFromRef(appS, registeredFields, tables, 'filter', fieldRef, index, state);
3566
- });
3505
+ function getAttrNameFormItem(field, fieldId) {
3506
+ return (AppColumnsDefaultTypes.includes(field.type) ? fieldType(field.type) : uuid2Alpha(fieldId)).toLowerCase();
3567
3507
  }
3568
- function addFieldToViewFromRef(appS, registeredFields, tables, viewName, fieldRef, index, state) {
3569
- switch (fieldRef) {
3570
- case 'title':
3571
- addTitleToView(viewName, appS, { ref: 'title', fixedValue: undefined });
3572
- break;
3573
- case 'iduser':
3574
- case 'idUser':
3575
- addUserToView(viewName, appS);
3576
- break;
3577
- case 'datecreation':
3578
- case 'dateCreation':
3579
- addDateCreationToView(viewName, appS);
3580
- break;
3581
- default:
3582
- defaultFieldCreation(appS, registeredFields, tables, viewName, fieldRef, index, state);
3583
- break;
3508
+ function renderAudience(audience, installFor) {
3509
+ if (audience === AUDIENCE.ALL)
3510
+ return '<checkAccess>false</checkAccess>';
3511
+ else if (installFor.length > 0) {
3512
+ return `<checkAccess>true</checkAccess>
3513
+ <accessRightList>${installFor.map((user) => user.uri).join()}</accessRightList>`;
3584
3514
  }
3515
+ return '';
3585
3516
  }
3586
- function defaultFieldCreation(appS, registeredFields, tables, viewName, fieldRef, index, state) {
3587
- const fieldIndex = createOrGetFieldFromRef(appS, registeredFields, tables, fieldRef, state);
3588
- const field = appS.fields[fieldIndex];
3589
- if (!field || !field.views) {
3590
- throw new Error(`error converting installed app to V2: unable to handle ${fieldRef} in list view`);
3591
- }
3592
- field.views[viewName] = true;
3593
- addFieldToView(viewName, field, appS, index, undefined);
3517
+ function renderPrimaryFields(fields) {
3518
+ const primaryFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => AppFormPrimaryListValues.includes(field.type));
3519
+ if (primaryFields.length === 0)
3520
+ return '';
3521
+ return `<primaryFields>${primaryFields.map((field) => formItem2xml(field)).join('')}</primaryFields>`;
3594
3522
  }
3595
- function createOrGetFieldFromRef(appS, registeredFields, tables, fieldRef, state) {
3596
- const knownIndex = registeredFields.get(fieldRef);
3597
- if (knownIndex !== undefined) {
3598
- return knownIndex;
3599
- }
3600
- const [ref, indexCreated] = createStudioDefinedField(appS, fieldRef, tables, state);
3601
- registeredFields.set(ref, indexCreated);
3602
- return indexCreated;
3523
+ function renderCustomFields(fields) {
3524
+ const customFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => !AppFormPrimaryListValues.includes(field.type));
3525
+ const filteredCustomFields = customFields === null || customFields === void 0 ? void 0 : customFields.filter((field) => field.type !== AppFormItemTypes.IMAGE);
3526
+ if (filteredCustomFields.length === 0)
3527
+ return '';
3528
+ const articlesTablesItems = filteredCustomFields.filter((f) => f.type !== AppFormItemTypes.TAGS && !AppFormNonPrimaryList.includes(f.type));
3529
+ const linksTableItems = filteredCustomFields.filter((f) => f.type === AppFormItemTypes.TAGS);
3530
+ return `<custom>
3531
+ ${articlesTablesItems.length > 0
3532
+ ? `<articlemstable>
3533
+ ${articlesTablesItems.map((field) => formItem2xml(field)).join('')}
3534
+ </articlemstable>`
3535
+ : ''}
3536
+ ${linksTableItems.length > 0
3537
+ ? `<linkstable tablename="tag_links" sqlNameColumn="name" sqlSrcIdColumn="srcId" sqlSrcTypeColumn="srcType" sqlTargetIdColumn="targetId" sqlTargetTypeColumn="targetType">
3538
+ ${linksTableItems.map((field) => formItem2xml(field)).join('')}
3539
+ </linkstable>`
3540
+ : ''}</custom>`;
3603
3541
  }
3604
- function createOrGetField(appS, registeredFields, viewComponent, tables, state) {
3605
- if (viewComponent.name !== undefined && viewComponent.element === 'attr') {
3606
- if (specialAttrName.includes(viewComponent.name)) {
3607
- return [-1, { ref: viewComponent.name, fixedValue: undefined }];
3608
- }
3609
- const knownIndex = registeredFields.get(viewComponent.name);
3610
- if (knownIndex !== undefined) {
3611
- return [knownIndex, undefined];
3542
+ function formItem2xml(field) {
3543
+ return `<field
3544
+ type="${renderFieldTypeToXmlType(field.type)}"
3545
+ name="${getAttrNameFormItem(field, field.id)}"
3546
+ sqlname="${renderSqlName(field.type, field.id)}"
3547
+ ${field.properties && renderProperty(field.properties, AppFieldFormPropertyTypes.LABEL)}
3548
+ ${field.properties && renderProperty(field.properties, AppFieldFormPropertyTypes.DESCRIPTION)}
3549
+ mandatory="${field.mandatory}"
3550
+ solr.type="${renderSolrType(field.type)}"
3551
+ solr.used="true"
3552
+ solr.indexed="true"
3553
+ solr.stored="true"
3554
+ solr.searchable="true"
3555
+ solr.multiValued="${field.type === AppFormItemTypes.TAGS ||
3556
+ field.type === AppFormItemTypes.CHECKBOX ||
3557
+ field.type === AppFormItemTypes.SELECT
3558
+ ? true
3559
+ : false}"
3560
+ teaser="true"
3561
+ display="true"
3562
+ >
3563
+ ${renderWidget(field.type, field.properties)}
3564
+ </field>`;
3565
+ }
3566
+ function renderWidget(fieldType, fieldProperties) {
3567
+ var _a;
3568
+ switch (fieldType) {
3569
+ case AppFormItemTypes.DESCRIPTION:
3570
+ return '<widget form="textarea"><params><param key="class" value="mceEditor"></param><param key="mention" value="1"></param></params></widget>';
3571
+ case AppFormItemTypes.TEXT:
3572
+ return '<widget form="text"></widget>';
3573
+ case AppFormItemTypes.TEXTAREA:
3574
+ return '<widget form="textarea"></widget>';
3575
+ case AppFormItemTypes.TEXTAREAHTML:
3576
+ return '<widget form="textarea"><params><param key="class" value="mceEditor"></param></params></widget>';
3577
+ case AppFormItemTypes.DATE:
3578
+ return '<widget form="date" format="d/m/Y"></widget>';
3579
+ case AppFormItemTypes.DATETIME:
3580
+ return `<widget form="datetime" format="d/m/Y H:i:s"></widget>`;
3581
+ case AppFormItemTypes.NUMBER: {
3582
+ const isFloat = ((_a = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.CHECKBOX)) === null || _a === void 0 ? void 0 : _a.value) === true;
3583
+ return `<widget form="number">
3584
+ ${isFloat ? `<params><param value="0.01" key="step"/></params>` : ''}
3585
+ </widget>`;
3612
3586
  }
3613
- const [ref, indexCreated] = createStudioDefinedField(appS, viewComponent.name, tables, state);
3614
- registeredFields.set(ref, indexCreated);
3615
- return [indexCreated, undefined];
3616
- }
3617
- else if (viewComponent.element === 'html') {
3618
- const htmlCode = viewComponent.html;
3619
- if (htmlCode === undefined) {
3620
- console.error('error while parsing studio installed html attr in a view: no html code');
3621
- return [-1, undefined];
3587
+ case AppFormItemTypes.SELECT: {
3588
+ const optionEditor = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3589
+ if (!optionEditor)
3590
+ return '';
3591
+ const isMultiple = optionEditor.value.canSelectMultiple;
3592
+ const options = optionEditor.value.propertyOptions;
3593
+ const hasDefaultValue = optionEditor.value.defaultSelectOption;
3594
+ const defaultValue = optionEditor.value.defaultSelectOptionValue.value;
3595
+ const userCanModifiyByComment = optionEditor.value.userCanModifiyByComment;
3596
+ return `<widget form="select" ${isMultiple ? 'multiple="1"' : ''}>
3597
+ <options>
3598
+ ${options
3599
+ .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
3600
+ .join('')}
3601
+ </options>
3602
+ ${hasDefaultValue || userCanModifiyByComment
3603
+ ? `<params>
3604
+ ${hasDefaultValue ? `<param key="defaultValue" value="${defaultValue}"/>` : ''}
3605
+ ${userCanModifiyByComment ? `<param key="explain" value="1"/>` : ''}
3606
+ </params>`
3607
+ : ''}
3608
+ </widget>`;
3622
3609
  }
3623
- if (htmlCode.includes('<JAMESPOT.STUDIO.FIXED>')) {
3624
- const startPos = htmlCode.indexOf('<JAMESPOT.STUDIO.FIXED>') + '<JAMESPOT.STUDIO.FIXED>'.length;
3625
- const endPos = htmlCode.indexOf('</JAMESPOT.STUDIO.FIXED>');
3626
- const formItemRefString = htmlCode.substring(startPos, endPos);
3627
- try {
3628
- const formItemRef = JSON.parse(formItemRefString);
3629
- if ((formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref.toUpperCase()) in ExtraAppFieldsItemViews ||
3630
- specialAttrName.includes(formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref)) {
3631
- return [-1, formItemRef];
3632
- }
3633
- const knownIndex = registeredFields.get(formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref);
3634
- if (knownIndex !== undefined) {
3635
- return [knownIndex, formItemRef];
3636
- }
3637
- const [ref, indexCreated] = createStudioDefinedField(appS, formItemRef.ref, tables, state);
3638
- registeredFields.set(ref, indexCreated);
3639
- return [indexCreated, formItemRef];
3640
- }
3641
- catch (_) {
3642
- console.error('error while parsing studio installed fixed attr in a view: json parsing failed');
3643
- return [-1, undefined];
3644
- }
3610
+ case AppFormItemTypes.RADIO: {
3611
+ const optionEditor = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3612
+ if (!optionEditor)
3613
+ return '';
3614
+ const options = optionEditor.value.propertyOptions;
3615
+ return `<widget form="radio">
3616
+ <options>
3617
+ ${options
3618
+ .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
3619
+ .join('')}
3620
+ </options>
3621
+ </widget>`;
3645
3622
  }
3646
- else if (htmlCode.includes('<JAMESPOT.STUDIO.CODEHTML>')) {
3647
- try {
3648
- const startPosCode = htmlCode.indexOf('<JAMESPOT.STUDIO.CODEHTML>') + '<JAMESPOT.STUDIO.CODEHTML>'.length;
3649
- const endPosCode = htmlCode.indexOf('</JAMESPOT.STUDIO.CODEHTML>');
3650
- const formItemString = htmlCode.substring(startPosCode, endPosCode);
3651
- const formItem = JSON.parse(formItemString);
3652
- const knownIndex = registeredFields.get(formItem === null || formItem === void 0 ? void 0 : formItem.name);
3653
- if (knownIndex !== undefined) {
3654
- return [knownIndex, undefined];
3655
- }
3656
- const htmlField = createHtmlField(formItem);
3657
- const indexCreated = appS.fields.push(htmlField) - 1;
3658
- registeredFields.set(htmlField.id, indexCreated);
3659
- return [indexCreated, undefined];
3660
- }
3661
- catch (_) {
3662
- console.error('error while parsing studio installed codehtml attr in a view: json parsing failed');
3663
- return [-1, undefined];
3664
- }
3623
+ case AppFormItemTypes.TOGGLE:
3624
+ return `<widget form="checkbox">
3625
+ <options>
3626
+ <option value="1" label="GLOBAL_Yes"></option>
3627
+ </options>
3628
+ <params>
3629
+ <param key="jagCheckbox" value="1"></param>
3630
+ </params>
3631
+ </widget>`;
3632
+ case AppFormItemTypes.TAGS: {
3633
+ const taxonomy = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.TAXONOMY);
3634
+ if (!taxonomy)
3635
+ return '';
3636
+ const taxonomyId = taxonomy.value.id;
3637
+ return `<widget form="taxonomy">
3638
+ <params><param key="idTaxonomy" value="${taxonomyId}"></param></params>
3639
+ </widget>`;
3665
3640
  }
3666
- else {
3667
- console.error('error while parsing studio installed html attr in a view: unknown html format');
3668
- return [-1, undefined];
3641
+ case AppFormItemTypes.CHECKBOX: {
3642
+ const optionEditor = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3643
+ if (!optionEditor)
3644
+ return '';
3645
+ const options = optionEditor.value.propertyOptions;
3646
+ return `<widget form="checkbox" multiple="1">
3647
+ <options>
3648
+ ${options
3649
+ .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
3650
+ .join('')}
3651
+ </options>
3652
+ </widget>`;
3669
3653
  }
3670
- }
3671
- else if (viewComponent.element === 'image') {
3672
- const knownIndex = registeredFields.get('image');
3673
- if (knownIndex !== undefined) {
3674
- return [knownIndex, undefined];
3654
+ case AppFormItemTypes.ADDFILEATTACHMENT:
3655
+ return `<widget form="file" type="fileArticle" multiple="1"></widget>`;
3656
+ case AppFormItemTypes.URL:
3657
+ return `<widget form="url"></widget>`;
3658
+ case AppFormItemTypes.EMAIL:
3659
+ return `<widget form="email"></widget>`;
3660
+ case ExtraAppFieldsItemViews.USER:
3661
+ return `<widget form="idUser"></widget>`;
3662
+ case AppFormItemTypes.USERLINK:
3663
+ return `<widget form="uri">
3664
+ <params>
3665
+ <param key="mode" value="ng-view"></param>
3666
+ <param key="class" value="jcomplete"></param>
3667
+ <param key="namespace" value="jamespot"></param>
3668
+ <param key="types" value="user"></param>
3669
+ <param key="views" value="user"></param>
3670
+ <param key="jcomplete-url" value="/?action=ajax&amp;group=autocomplete&amp;function=user"></param>
3671
+ </params>
3672
+ </widget>`;
3673
+ case AppFormItemTypes.CONTENTLINK: {
3674
+ const contentType = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.CONTENTTYPE);
3675
+ if (!contentType)
3676
+ return '';
3677
+ const type = contentType.value.type;
3678
+ return `<widget form="uri">
3679
+ <params>
3680
+ <param key="mode" value="ng-view"></param>
3681
+ <param key="namespace" value="jamespot"></param>
3682
+ <param key="types" value="${type}"></param>
3683
+ <param key="views" value="article"></param>
3684
+ <param key="jcomplete-url" value="/?action=ajax&amp;group=autocomplete&amp;function=article&amp;types=[]=${type}"></param>
3685
+ </params>
3686
+ </widget>`;
3675
3687
  }
3676
- const imageField = createImageField();
3677
- const indexCreated = appS.fields.push(imageField) - 1;
3678
- registeredFields.set('image', indexCreated);
3679
- return [indexCreated, undefined];
3680
- }
3681
- else if (viewComponent.element === 'publishTo') {
3682
- return [-1, { ref: 'publishTo', fixedValue: undefined }];
3688
+ default:
3689
+ return '';
3683
3690
  }
3684
- else {
3685
- console.error('error while parsing studio installed attr in a view: unknown attr :O');
3686
- return [-1, undefined];
3691
+ }
3692
+ function renderProperty(properties, propertyToFind) {
3693
+ const labelProperty = properties === null || properties === void 0 ? void 0 : properties.find((property) => property.propertyType === propertyToFind);
3694
+ if (labelProperty) {
3695
+ return `${propertyToFind.toLowerCase()}="${labelProperty.value}"`;
3687
3696
  }
3697
+ return '';
3688
3698
  }
3689
- function createStudioDefinedField(appS, ref, tables, state) {
3690
- const installedField = getInstalledField(ref, tables);
3691
- const type = getFormItemType(installedField);
3692
- const v2Field = (function createField() {
3693
- switch (type) {
3694
- case AppFormItemTypes.ADDFILEATTACHMENT:
3695
- return createAddfileattachmentField(installedField);
3696
- case AppFormItemTypes.NUMBER:
3697
- return createNumberField(installedField);
3698
- case AppFormItemTypes.TAGS:
3699
- return createTagsField(installedField);
3700
- case AppFormItemTypes.SELECT:
3701
- return createSelectField(installedField);
3702
- case AppFormItemTypes.RADIO:
3703
- return createRadioField(installedField);
3704
- case AppFormItemTypes.CHECKBOX:
3705
- return createCheckboxField(installedField);
3706
- case AppFormItemTypes.CONTENTLINK:
3707
- return createContentLinkField(installedField, state);
3708
- case AppFormItemTypes.DESCRIPTION:
3709
- return createDescriptionField(installedField);
3710
- case AppFormItemTypes.TEXTAREAHTML:
3711
- return createTextareaHTMLField(installedField);
3712
- case AppFormItemTypes.DATE:
3713
- return createDateField(installedField);
3714
- case AppFormItemTypes.DATETIME:
3715
- return createDatetimeField(installedField);
3716
- case AppFormItemTypes.URL:
3717
- return createUrlField(installedField);
3718
- case AppFormItemTypes.EMAIL:
3719
- return createEmailField(installedField);
3720
- case AppFormItemTypes.TOGGLE:
3721
- return createToggleField(installedField);
3722
- case AppFormItemTypes.USERLINK:
3723
- return createUserLinkField(installedField);
3724
- case AppFormItemTypes.TEXTAREA:
3725
- return createTextAreaField(installedField);
3726
- case AppFormItemTypes.TEXT:
3727
- default:
3728
- return createTextField(installedField);
3699
+ function renderSqlName(fieldType, fieldId) {
3700
+ switch (fieldType) {
3701
+ case AppFormItemTypes.DESCRIPTION:
3702
+ return 'Description';
3703
+ case ExtraAppFieldsItemViews.USER:
3704
+ return 'IdUser';
3705
+ default:
3706
+ return uuid2Alpha(fieldId);
3707
+ }
3708
+ }
3709
+ function renderSolrType(fieldType) {
3710
+ switch (fieldType) {
3711
+ case AppFormItemTypes.DESCRIPTION:
3712
+ case AppFormItemTypes.TEXT:
3713
+ case AppFormItemTypes.TEXTAREA:
3714
+ case AppFormItemTypes.TEXTAREAHTML:
3715
+ case AppFormItemTypes.URL:
3716
+ case AppFormItemTypes.EMAIL:
3717
+ case AppFormItemTypes.USERLINK:
3718
+ case AppFormItemTypes.CONTENTLINK:
3719
+ case AppFormItemTypes.NUMBER:
3720
+ case AppFormItemTypes.ADDFILEATTACHMENT:
3721
+ return 'text';
3722
+ case AppFormItemTypes.DATE:
3723
+ case AppFormItemTypes.DATETIME:
3724
+ return 'date';
3725
+ case ExtraAppFieldsItemViews.USER:
3726
+ return 'integer';
3727
+ case AppFormItemTypes.SELECT:
3728
+ case AppFormItemTypes.RADIO:
3729
+ case AppFormItemTypes.TOGGLE:
3730
+ case AppFormItemTypes.CHECKBOX:
3731
+ case AppFormItemTypes.TAGS:
3732
+ return 'string';
3733
+ default:
3734
+ return '';
3735
+ }
3736
+ }
3737
+ function renderFieldTypeToXmlType(fieldType) {
3738
+ switch (fieldType) {
3739
+ default:
3740
+ case AppFormItemTypes.DESCRIPTION:
3741
+ case AppFormItemTypes.TEXTAREAHTML:
3742
+ return 'html';
3743
+ case AppFormItemTypes.TAGS:
3744
+ return 'taxonomy';
3745
+ case AppFormItemTypes.TEXT:
3746
+ case AppFormItemTypes.RADIO:
3747
+ case AppFormItemTypes.URL:
3748
+ case AppFormItemTypes.EMAIL:
3749
+ case AppFormItemTypes.ADDFILEATTACHMENT:
3750
+ case ExtraAppFieldsItemViews.USER:
3751
+ case AppFormItemTypes.USERLINK:
3752
+ case AppFormItemTypes.CONTENTLINK:
3753
+ return 'text';
3754
+ case AppFormItemTypes.TEXTAREA:
3755
+ case AppFormItemTypes.CHECKBOX:
3756
+ case AppFormItemTypes.SELECT:
3757
+ return 'longtext';
3758
+ case AppFormItemTypes.DATE:
3759
+ return 'date';
3760
+ case AppFormItemTypes.DATETIME: {
3761
+ return 'date';
3729
3762
  }
3730
- })();
3731
- const index = appS.fields.push(v2Field) - 1;
3732
- return [ref, index];
3763
+ case AppFormItemTypes.NUMBER:
3764
+ return 'float';
3765
+ }
3733
3766
  }
3734
- function getInstalledField(ref, tables) {
3735
- var _a;
3736
- let foundField = undefined;
3737
- for (let i = 0; i < tables.length && !foundField; i++) {
3738
- foundField = (_a = tables[i]) === null || _a === void 0 ? void 0 : _a.attributes.find((attr) => {
3739
- return attr.name === ref;
3740
- });
3767
+ const uuid2Alpha = (id) => {
3768
+ let alphaUuid = '';
3769
+ for (let i = 0; i < id.length; i++) {
3770
+ const c = id.charAt(i);
3771
+ if (c >= '0' && c <= '9')
3772
+ alphaUuid += numToAlpha(Number(c));
3773
+ else if (c >= 'a' && c <= 'z')
3774
+ alphaUuid += c;
3741
3775
  }
3742
- if (!foundField) {
3743
- throw new Error('error converting installed app to V2: installed field not found in tables ' + ref);
3776
+ return alphaUuid;
3777
+ };
3778
+ const numToAlpha = (num) => {
3779
+ let s = '', t;
3780
+ while (num > 0) {
3781
+ t = (num - 1) % 26;
3782
+ s = String.fromCharCode(97 + t) + s;
3783
+ num = ((num - t) / 26) | 0;
3744
3784
  }
3745
- return foundField;
3785
+ return s;
3786
+ };
3787
+ const internal2XmlView = {
3788
+ create: 'create',
3789
+ popup: 'create-popup',
3790
+ edit: 'edit',
3791
+ view: 'display',
3792
+ };
3793
+ function renderDisplays(studioApp) {
3794
+ let toRet = '';
3795
+ Object.entries(studioApp.views).forEach(([viewName, viewContent]) => {
3796
+ if (Object.prototype.hasOwnProperty.call(internal2XmlView, viewName)) {
3797
+ const viewField = Object.entries(viewContent)
3798
+ .filter((a) => a[1].isUsed)
3799
+ .sort((a, b) => a[1].pos - b[1].pos);
3800
+ toRet += `<display view="${internal2XmlView[viewName]}" mode="${viewName === 'view' ? 'view' : 'form'}">
3801
+ ${viewField.map(([fieldId, view]) => renderDisplayAttr(fieldId, view)).join('')}
3802
+ </display>`;
3803
+ }
3804
+ });
3805
+ if (toRet.length > 0) {
3806
+ toRet = `<displays type="${studioApp.idApp}">${toRet}</displays>`;
3807
+ }
3808
+ return toRet;
3746
3809
  }
3747
- function addFieldToView(viewName, field, appS, index, fixedInfo) {
3748
- var _a;
3749
- if (field.views) {
3750
- field.views[viewName] = true;
3751
- appS.views[viewName][field.id] = {
3752
- type: field.type,
3753
- properties: field.properties || [],
3754
- isUsed: true,
3755
- isOptional: false,
3756
- isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3757
- isFixed: false,
3758
- value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : null,
3759
- pos: index,
3760
- };
3810
+ function getDisplayName(fieldId, view) {
3811
+ switch (view.type) {
3812
+ case ExtraAppFieldsItemViews.TITLE:
3813
+ return 'title';
3814
+ case ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS:
3815
+ return 'sendAlert';
3816
+ case ExtraAppFieldsItemViews.RECEIVEACOPY:
3817
+ return 'alertAuthor';
3818
+ case ExtraAppFieldsItemViews.PUBLISHTO:
3819
+ return 'publishTo';
3820
+ case ExtraAppFieldsItemViews.USER:
3821
+ return 'idUser';
3822
+ case ExtraAppFieldsItemViews.CREATIONDATE:
3823
+ return 'dateCreation';
3824
+ case AppFormItemTypes.DESCRIPTION:
3825
+ return 'description';
3826
+ default:
3827
+ return uuid2Alpha(fieldId);
3761
3828
  }
3762
3829
  }
3763
- function getFormItemType(installedField) {
3830
+ function renderDisplayAttr(fieldId, view) {
3764
3831
  var _a, _b, _c;
3765
- switch (installedField.widget.type) {
3766
- case 'number':
3767
- return AppFormItemTypes.NUMBER;
3768
- case 'taxonomy':
3769
- return AppFormItemTypes.TAGS;
3770
- case 'date':
3771
- return AppFormItemTypes.DATE;
3772
- case 'datetime':
3773
- return AppFormItemTypes.DATETIME;
3774
- case 'select':
3775
- return AppFormItemTypes.SELECT;
3776
- case 'radio':
3777
- return AppFormItemTypes.RADIO;
3778
- case 'url':
3779
- return AppFormItemTypes.URL;
3780
- case 'email':
3781
- return AppFormItemTypes.EMAIL;
3782
- case 'file':
3783
- return AppFormItemTypes.ADDFILEATTACHMENT;
3784
- case 'checkbox':
3785
- if (((_a = installedField.widget.options) === null || _a === void 0 ? void 0 : _a['1']) === 'GLOBAL_Yes') {
3786
- return AppFormItemTypes.TOGGLE;
3787
- }
3788
- return AppFormItemTypes.CHECKBOX;
3789
- case 'uri':
3790
- if (((_b = installedField.widget.params) === null || _b === void 0 ? void 0 : _b.views) === 'user') {
3791
- return AppFormItemTypes.USERLINK;
3792
- }
3793
- if (((_c = installedField.widget.params) === null || _c === void 0 ? void 0 : _c.views) === 'article') {
3794
- return AppFormItemTypes.CONTENTLINK;
3832
+ let xml = '';
3833
+ const attrName = getDisplayName(fieldId, view);
3834
+ const isFixed = view.isLockedValue;
3835
+ if (isFixed) {
3836
+ const formItemRefWithName = {
3837
+ ref: attrName,
3838
+ fixedValue: view.value,
3839
+ };
3840
+ xml += `<html><![CDATA[ <!-- <JAMESPOT.STUDIO.FIXED>${JSON.stringify(formItemRefWithName)}</JAMESPOT.STUDIO.FIXED> -->`;
3841
+ if (view.type === ExtraAppFieldsItemViews.PUBLISHTO) {
3842
+ const uris = view.value.map((user) => user.uri).join(',');
3843
+ xml += `<input type="hidden" name="publishTo" value="${uris}">`;
3844
+ }
3845
+ else if (view.type === ExtraAppFieldsItemViews.USER ||
3846
+ view.type === AppFormItemTypes.USERLINK ||
3847
+ view.type === AppFormItemTypes.CONTENTLINK) {
3848
+ xml += `<input type="hidden" name="${attrName}[]" value=${JSON.stringify(view.value.uri)}>`;
3849
+ }
3850
+ else if (view.type === AppFormItemTypes.SELECT) {
3851
+ const canSelectMultiple = (_a = view.properties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR)) === null || _a === void 0 ? void 0 : _a.value.canSelectMultiple;
3852
+ if (canSelectMultiple) {
3853
+ const values = view.value;
3854
+ values.forEach((value) => {
3855
+ xml += `<input type="hidden" name="${attrName}[]" value="${value.value}">`;
3856
+ });
3795
3857
  }
3796
- break;
3797
- case 'textarea':
3798
- if (installedField.attrType === 'longtext') {
3799
- return AppFormItemTypes.TEXTAREA;
3858
+ else {
3859
+ xml += `<input type="hidden" name="${attrName}" value="${view.value.value}">`;
3800
3860
  }
3801
- if (installedField.attrType === 'html') {
3802
- if (installedField.name === 'description') {
3803
- return AppFormItemTypes.DESCRIPTION;
3804
- }
3805
- return AppFormItemTypes.TEXTAREAHTML;
3861
+ }
3862
+ else if (view.type === AppFormItemTypes.CHECKBOX) {
3863
+ const values = view.value;
3864
+ values.forEach((value) => {
3865
+ xml += `<input type="hidden" name="${attrName}[]" value="${value}">`;
3866
+ });
3867
+ }
3868
+ else if (view.type === AppFormItemTypes.DATE) {
3869
+ const dateValue = new Date(view.value);
3870
+ const xmlFixedValue = [
3871
+ pad(dateValue.getDate()),
3872
+ pad(dateValue.getMonth() + 1),
3873
+ dateValue.getFullYear(),
3874
+ ].join('/');
3875
+ xml += '<input type="hidden" name="' + attrName + '" value="' + xmlFixedValue + '">';
3876
+ }
3877
+ else if (view.type === AppFormItemTypes.DATETIME) {
3878
+ const dateValue = new Date(view.value);
3879
+ const xmlFixedValue = `${[
3880
+ pad(dateValue.getDate()),
3881
+ pad(dateValue.getMonth() + 1),
3882
+ dateValue.getFullYear(),
3883
+ ].join('/')} ${pad(dateValue.getHours())}:${pad(dateValue.getMinutes())}:${pad(dateValue.getSeconds())}`;
3884
+ xml += '<input type="hidden" name="' + attrName + '" value="' + xmlFixedValue + '">';
3885
+ }
3886
+ else if (view.type === AppFormItemTypes.TAGS) {
3887
+ xml += `<input type="hidden" name="${attrName}" value="${(_c = (_b = view.value) === null || _b === void 0 ? void 0 : _b.map((v) => v.uri)) === null || _c === void 0 ? void 0 : _c.join(',')}">`;
3888
+ }
3889
+ else if (view.type === AppFormItemTypes.DESCRIPTION || view.type === AppFormItemTypes.TEXTAREAHTML) {
3890
+ xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
3891
+ }
3892
+ else if (view.type === ExtraAppFieldsItemViews.RECEIVEACOPY) {
3893
+ if (view.value) {
3894
+ xml += `<input type="hidden" name="alertAuthor[jamespot]"><input type="hidden" name="alertAuthor[]" value="1">`;
3806
3895
  }
3807
- break;
3808
- case 'text':
3809
- return AppFormItemTypes.TEXT;
3810
- }
3811
- throw new Error('error converting installed app to V2: installed field type not recognized for field ' + installedField.name);
3812
- }
3813
- function addTitleToView(newName, appS, fixedInfo) {
3814
- var _a;
3815
- const fieldId = 'title';
3816
- appS.views[newName][fieldId] = {
3817
- type: ExtraAppFieldsItemViews.TITLE,
3818
- properties: [],
3819
- isUsed: true,
3820
- isOptional: false,
3821
- isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3822
- isFixed: true,
3823
- value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : null,
3824
- pos: 0,
3825
- };
3826
- }
3827
- function addAlertAuthorToView(newName, appS, fixedInfo) {
3828
- const fieldId = 'alertAuthor';
3829
- appS.views[newName][fieldId] = {
3830
- type: ExtraAppFieldsItemViews.RECEIVEACOPY,
3831
- properties: [],
3832
- isUsed: true,
3833
- isOptional: true,
3834
- isLockedValue: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined,
3835
- isFixed: false,
3836
- value: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined ? fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue : true,
3837
- pos: 300,
3838
- };
3839
- }
3840
- function addSendAlertToView(newName, appS, fixedInfo) {
3841
- const fieldId = 'sendAlert';
3842
- appS.views[newName][fieldId] = {
3843
- type: ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS,
3844
- properties: [],
3845
- isUsed: true,
3846
- isOptional: true,
3847
- isLockedValue: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined,
3848
- isFixed: false,
3849
- value: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined ? fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue : true,
3850
- pos: 200,
3851
- };
3852
- }
3853
- function addPublishToToView(newName, appS, fixedInfo) {
3854
- var _a;
3855
- const fieldId = 'publishTo';
3856
- appS.views[newName][fieldId] = {
3857
- type: ExtraAppFieldsItemViews.PUBLISHTO,
3858
- properties: [],
3859
- isUsed: true,
3860
- isOptional: true,
3861
- isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3862
- isFixed: false,
3863
- value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : [],
3864
- pos: 100,
3865
- };
3866
- }
3867
- function addUserToView(newName, appS) {
3868
- const fieldId = 'user';
3869
- appS.views[newName][fieldId] = {
3870
- type: ExtraAppFieldsItemViews.USER,
3871
- properties: [],
3872
- isUsed: true,
3873
- isOptional: false,
3874
- isLockedValue: false,
3875
- isFixed: true,
3876
- value: null,
3877
- pos: 1,
3878
- };
3879
- }
3880
- function addDateCreationToView(newName, appS) {
3881
- const fieldId = 'dateCreation';
3882
- appS.views[newName][fieldId] = {
3883
- type: ExtraAppFieldsItemViews.CREATIONDATE,
3884
- properties: [],
3885
- isUsed: true,
3886
- isOptional: true,
3887
- isLockedValue: false,
3888
- isFixed: false,
3889
- value: null,
3890
- pos: 100,
3891
- };
3892
- }
3893
-
3894
- function InstalledAppStudioAdapter(serverApp, serverApps, state) {
3895
- var _a, _b, _c, _d;
3896
- const { version, dateCreation } = serverApp.manifest;
3897
- const appTypeServer = serverApp.typeModel;
3898
- const views = Object.assign({}, ...viewsList.map((view) => ({
3899
- [view]: {},
3900
- })));
3901
- const studioApp = {
3902
- idApp: serverApp.idApp,
3903
- status: _formatStatus(serverApp),
3904
- studioVersion: 2,
3905
- manifest: {
3906
- appShortName: serverApp.label,
3907
- appName: serverApp.label,
3908
- description: serverApp.description,
3909
- author: serverApp.author,
3910
- cssColor: (_a = appTypeServer.cssColor) !== null && _a !== void 0 ? _a : '#392994',
3911
- cssClass: { label: (_b = appTypeServer.cssClass) !== null && _b !== void 0 ? _b : 'star', value: (_c = appTypeServer.cssClass) !== null && _c !== void 0 ? _c : 'star' },
3912
- version: version,
3913
- dateCreation: dateCreation,
3914
- checkAccess: false,
3915
- accessRightList: "",
3916
- attrExposed: [],
3917
- viewSolr: serverApp.view ? STUDIO_VIEW.SOLR : STUDIO_VIEW.NOT_SOLR,
3918
- typeLabel: appTypeServer.typeLabel,
3919
- articlesCount: (_d = serverApp.articlesCount) !== null && _d !== void 0 ? _d : 0,
3920
- },
3921
- fields: [],
3922
- views,
3923
- installFor: serverApp.accessRightObjectList ? buildAudience(serverApp.accessRightObjectList) : [],
3924
- audience: serverApp.checkAccess === false ? AUDIENCE.ALL : AUDIENCE.CUSTOM,
3925
- };
3926
- populateFieldsAndViews(serverApp, studioApp, state);
3927
- studioApp.views = updateViewsFromFields(studioApp, studioApp.fields);
3928
- const inWorkAppVersion = _findAssociatedDraft(serverApp.idApp, serverApps);
3929
- if (!inWorkAppVersion)
3930
- return studioApp;
3931
- const inWorkApp = DraftAppStudioAdapter(inWorkAppVersion);
3932
- if (!inWorkApp)
3933
- return studioApp;
3934
- studioApp.inWorkVersion = inWorkApp;
3935
- return studioApp;
3936
- }
3937
- function DraftAppStudioAdapter(serverApp) {
3938
- if (!serverApp.value)
3939
- return undefined;
3940
- const parsedJson = JSON.parse(serverApp.value);
3941
- if (parsedJson.studioVersion == 2) {
3942
- return {
3943
- idApp: serverApp.idApp,
3944
- studioVersion: 2,
3945
- status: _formatStatus(serverApp),
3946
- manifest: parsedJson.manifest,
3947
- fields: parsedJson.fields,
3948
- views: parsedJson.views,
3949
- syncViewFieldOrder: parsedJson.syncViewFieldOrder,
3950
- audience: parsedJson.audience,
3951
- installFor: parsedJson.installFor,
3952
- };
3896
+ }
3897
+ else if (view.type === ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS) {
3898
+ if (view.value) {
3899
+ xml += `<input type="hidden" name="sendAlert[jamespot]"><input type="hidden" name="sendAlert[]" value="1">`;
3900
+ }
3901
+ }
3902
+ else {
3903
+ xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
3904
+ }
3905
+ xml += ']]></html>';
3953
3906
  }
3954
3907
  else {
3955
- return Object.assign(Object.assign({}, migrateJson(parsedJson)), { status: _formatStatus(serverApp), migratedFrom: 1 });
3908
+ switch (view.type) {
3909
+ case AppFormItemTypes.CODEHTML: {
3910
+ const fieldToInclude = {
3911
+ id: fieldId,
3912
+ name: fieldId,
3913
+ properties: {
3914
+ code: view.value,
3915
+ },
3916
+ };
3917
+ xml += `<html><![CDATA[ <!-- <JAMESPOT.STUDIO.CODEHTML>${JSON.stringify(fieldToInclude)}</JAMESPOT.STUDIO.CODEHTML><JAMESPOT.STUDIO.FIELD_POS>${view.pos}</JAMESPOT.STUDIO.FIELD_POS>-->${view.value}]]></html>`;
3918
+ break;
3919
+ }
3920
+ case AppFormItemTypes.IMAGE:
3921
+ xml += '<image />';
3922
+ break;
3923
+ case ExtraAppFieldsItemViews.PUBLISHTO:
3924
+ xml += '<publishTo />';
3925
+ break;
3926
+ default:
3927
+ xml += "<attr name='" + attrName + "' />";
3928
+ break;
3929
+ }
3956
3930
  }
3931
+ return xml;
3957
3932
  }
3958
- function _formatStatus(serverApp) {
3959
- return serverApp.status === jamespot.StudioApplicationStatus.installed
3960
- ? serverApp.suspended
3961
- ? StatusType$1.suspended
3962
- : StatusType$1.installed
3963
- : StatusType$1.draft;
3964
- }
3965
- function _findAssociatedDraft(idApp, serverApps) {
3966
- const draft = serverApps.find((app) => app.idApp === idApp && app.status === jamespot.StudioApplicationStatus.saved);
3967
- return draft;
3968
- }
3969
- function _findAssociatedInstalled(idApp, serverApps) {
3970
- return !!serverApps.find((app) => app.idApp === idApp && app.status === jamespot.StudioApplicationStatus.installed);
3971
- }
3972
- function serverAppsToStudioApps(serverApps, state) {
3973
- const studioApps = serverApps
3974
- .map((serverApp) => {
3975
- if (serverApp.status === jamespot.StudioApplicationStatus.installed) {
3976
- return InstalledAppStudioAdapter(serverApp, serverApps, state);
3977
- }
3978
- else {
3979
- if (_findAssociatedInstalled(serverApp.idApp, serverApps))
3980
- return undefined;
3981
- return DraftAppStudioAdapter(serverApp);
3982
- }
3983
- })
3984
- .filter((app) => app !== undefined);
3985
- return studioApps;
3933
+ function pad(s) {
3934
+ return s < 10 ? '0' + s : s;
3986
3935
  }
3987
3936
 
3988
- function appToXml(studioApp) {
3989
- const { manifest, views, audience, installFor } = studioApp;
3990
- return `<?xml version='1.0' encoding='utf-8'?>
3991
- <Application>
3992
- ${createAppManifest(manifest, views, audience, installFor, studioApp.idApp)}
3993
- <Types>
3994
- <objecttype
3995
- label="${manifest.typeLabel}"
3996
- labelPlural="${manifest.typeLabel}"
3997
- labelLinkSingular="${manifest.typeLabel}"
3998
- labelLinkPlural="${manifest.typeLabel}"
3999
- name="${studioApp.idApp}"
4000
- classImpl="JPBEContent"
4001
- classCodeLocation="jamespot/jpro/objs/JPBEContent.php"
4002
- cssClass="${manifest.cssClass.value}"
4003
- cssColor="${manifest.cssColor}"
4004
- searchtab="${studioApp.idApp}"
4005
- searchtablabel="${manifest.typeLabel}"
4006
- buttonlabel="${manifest.typeLabel}"
4007
- extends="article">
4008
- ${renderPrimaryFields(studioApp.fields)}
4009
- ${renderCustomFields(studioApp.fields)}
4010
- </objecttype>
4011
- ${renderDisplays(studioApp)}
4012
- </Types>
4013
- </Application>`;
4014
- }
4015
- function createAppManifest(manifest, views, audience, installFor, idApp) {
4016
- var _a;
4017
- return `<Manifest>
4018
- <ShowImport>true</ShowImport>
4019
- <AppShortName>${idApp}</AppShortName>
4020
- <AppName>${manifest.appName}</AppName>
4021
- <Description>${manifest.description}</Description>
4022
- <Version>${manifest.version + 1}</Version>
4023
- <ManifestVersion>1.0</ManifestVersion>
4024
- <StudioVersion>2</StudioVersion>
4025
- <DateCreation>${manifest.dateCreation.toString().split('T')[0]}</DateCreation>
4026
- <CssClass>${(_a = manifest.cssClass) === null || _a === void 0 ? void 0 : _a.label}</CssClass>
4027
- <CssColor>${manifest.cssColor}</CssColor>
4028
- <Categories>N.A.</Categories>
4029
- <Editor>Jamespot</Editor>
4030
- <EditorUrl>https://www.fr.jamespot.com/</EditorUrl>
4031
- <Type>${idApp}</Type>
4032
- ${renderAppView(manifest.viewSolr, views.list)}
4033
- ${renderAppSearch(views.filter)}
4034
- ${renderAudience(audience, installFor)}
4035
- <Order>1</Order>
4036
- </Manifest>`;
4037
- }
4038
- function renderAppView(viewSolr, listView) {
4039
- if (viewSolr === STUDIO_VIEW.SOLR) {
4040
- let xml = '<AppView>solr</AppView>';
4041
- const formItemIdInList = [];
4042
- Object.entries(listView)
4043
- .sort((a, b) => a[1].pos - b[1].pos)
4044
- .forEach(([fieldId, field]) => {
4045
- if (!field.isUsed) {
4046
- return;
3937
+ const installedToV2ViewNames = {
3938
+ 'create-popup': 'popup',
3939
+ create: 'create',
3940
+ edit: 'edit',
3941
+ display: 'view',
3942
+ };
3943
+ const specialAttrName = ['title', 'alertAuthor', 'sendAlert'];
3944
+ const ignoredFields = ['edito'];
3945
+ function updateViewsFromFields(clonedApp, appFields) {
3946
+ return Object.assign({}, ...viewsList.map((view) => {
3947
+ const viewItems = {};
3948
+ Object.entries(clonedApp.views[view]).forEach(([fieldId, field]) => {
3949
+ if (field.isFixed) {
3950
+ viewItems[fieldId] = field;
4047
3951
  }
4048
- if ([AppFormItemTypes.IMAGE].includes(field.type)) {
3952
+ if (field.isOptional) {
3953
+ viewItems[fieldId] = field;
3954
+ }
3955
+ });
3956
+ appFields.forEach((field, idx) => {
3957
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3958
+ const isFieldUsedInView = field.views[view];
3959
+ const isExistingField = Object.keys(clonedApp.views[view]).includes(field.id);
3960
+ const fieldType = field.type;
3961
+ if (AppFormBannedFromViews$1.get(fieldType) && ((_a = AppFormBannedFromViews$1.get(fieldType)) === null || _a === void 0 ? void 0 : _a.includes(view))) {
4049
3962
  return;
4050
3963
  }
4051
- formItemIdInList.push(getAttrNameFormItem(field, fieldId));
3964
+ let fieldValue = undefined;
3965
+ if (fieldType === AppFormItemTypes.CODEHTML) {
3966
+ const richTextProperty = (_b = field.properties) === null || _b === void 0 ? void 0 : _b.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.RICHTEXT);
3967
+ if (richTextProperty === null || richTextProperty === void 0 ? void 0 : richTextProperty.value) {
3968
+ fieldValue = richTextProperty === null || richTextProperty === void 0 ? void 0 : richTextProperty.value;
3969
+ }
3970
+ }
3971
+ if (fieldType === AppFormItemTypes.SELECT) {
3972
+ const selectProperty = (_c = field.properties) === null || _c === void 0 ? void 0 : _c.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3973
+ if (isExistingField) {
3974
+ const exField = clonedApp.views[view][field.id];
3975
+ const exSelectProperty = (_d = exField.properties) === null || _d === void 0 ? void 0 : _d.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3976
+ const isMultivalued = !!((_e = selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value) === null || _e === void 0 ? void 0 : _e.canSelectMultiple);
3977
+ const exIsMultivalued = !!((_f = exSelectProperty === null || exSelectProperty === void 0 ? void 0 : exSelectProperty.value) === null || _f === void 0 ? void 0 : _f.canSelectMultiple);
3978
+ if (isMultivalued === exIsMultivalued) {
3979
+ fieldValue = exField.value;
3980
+ }
3981
+ }
3982
+ else {
3983
+ const isEnhancedSelect = !!(selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.isOptionsEditorEnhanced);
3984
+ const defaultValue = isEnhancedSelect && !!(selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value.defaultSelectOption)
3985
+ ? selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value.defaultSelectOptionValue
3986
+ : '';
3987
+ if (defaultValue) {
3988
+ fieldValue = defaultValue;
3989
+ }
3990
+ }
3991
+ }
3992
+ if (isExistingField) {
3993
+ const exField = clonedApp.views[view][field.id];
3994
+ viewItems[field.id] = Object.assign(Object.assign(Object.assign(Object.assign({}, exField), { properties: field.properties || exField.properties || [] }), (fieldValue !== undefined && { value: fieldValue })), { isUsed: isFieldUsedInView, pos: ((_g = clonedApp.syncViewFieldOrder) === null || _g === void 0 ? void 0 : _g[view]) ? idx : exField.pos, isLockedValue: (fieldValue !== undefined || exField.value !== undefined) && exField.isLockedValue });
3995
+ }
3996
+ else {
3997
+ const existingFieldsLen = Object.values(clonedApp.views[view]).filter((v) => !v.isFixed && !v.isOptional).length;
3998
+ viewItems[field.id] = {
3999
+ type: field.type,
4000
+ properties: field.properties || [],
4001
+ isUsed: isFieldUsedInView,
4002
+ isOptional: false,
4003
+ isLockedValue: false,
4004
+ isFixed: false,
4005
+ value: fieldValue !== null && fieldValue !== void 0 ? fieldValue : null,
4006
+ pos: ((_h = clonedApp.syncViewFieldOrder) === null || _h === void 0 ? void 0 : _h[view]) ? idx : existingFieldsLen + idx,
4007
+ };
4008
+ }
4052
4009
  });
4053
- xml += `<AppColumns>${formItemIdInList.join()}</AppColumns>`;
4054
- return xml;
4010
+ return {
4011
+ [view]: viewItems,
4012
+ };
4013
+ }));
4014
+ }
4015
+ function buildAudience(accessRightObjectList) {
4016
+ return accessRightObjectList.map((accessRightObject) => {
4017
+ return {
4018
+ id: `${accessRightObject.type}/${accessRightObject.id}`,
4019
+ uri: `${accessRightObject.type}/${accessRightObject.id}`,
4020
+ shortUri: `${accessRightObject.type}/${accessRightObject.id}`,
4021
+ title: accessRightObject.title,
4022
+ name: accessRightObject.title,
4023
+ mainType: accessRightObject.type,
4024
+ type: accessRightObject.mainType,
4025
+ label: accessRightObject.type,
4026
+ cssClass: accessRightObject._cssClass,
4027
+ cssColor: accessRightObject._cssColor,
4028
+ class: accessRightObject._cssClass,
4029
+ Pseudo: accessRightObject.title,
4030
+ _url: accessRightObject._url,
4031
+ };
4032
+ });
4033
+ }
4034
+ function populateFieldsAndViews(app, appS, state) {
4035
+ const tables = app.typeModel.tables;
4036
+ const displays = app.typeModel.displays;
4037
+ if (!displays) {
4038
+ return;
4055
4039
  }
4056
- return '';
4040
+ const registeredFields = new Map();
4041
+ Object.entries(displays).forEach((displaysEntry) => {
4042
+ const [displayName, displayValue] = displaysEntry;
4043
+ if (Object.keys(installedToV2ViewNames).includes(displayName)) {
4044
+ buildView(appS, registeredFields, displayName, displayValue, tables, state);
4045
+ }
4046
+ });
4047
+ buildListView(appS, registeredFields, app.columns, tables, state);
4048
+ buildFilterView(appS, registeredFields, app.attrExposed, tables, state);
4057
4049
  }
4058
- function renderAppSearch(searchView) {
4059
- const formItemIdInFilter = [];
4060
- Object.entries(searchView)
4061
- .sort((a, b) => a[1].pos - b[1].pos)
4062
- .forEach(([fieldId, field]) => {
4063
- if (!field.isUsed) {
4050
+ function buildView(appS, registeredFields, displayName, displayValue, tables, state) {
4051
+ const newName = installedToV2ViewNames[displayName];
4052
+ appS.views[newName] = {};
4053
+ displayValue.composants.forEach((viewComponent, index) => {
4054
+ let field = undefined;
4055
+ if (viewComponent.name && ignoredFields.includes(viewComponent.name)) {
4064
4056
  return;
4065
4057
  }
4066
- const list = [ExtraAppFieldsItemViews.TITLE, AppFormItemTypes.IMAGE];
4067
- if (!list.includes(field.type))
4068
- formItemIdInFilter.push(getAttrNameFormItem(field, fieldId));
4058
+ const [fieldIdx, fixedInfo] = createOrGetField(appS, registeredFields, viewComponent, tables, state);
4059
+ if (fieldIdx === -1 && fixedInfo) {
4060
+ switch (fixedInfo.ref) {
4061
+ case 'title':
4062
+ addTitleToView(newName, appS, fixedInfo);
4063
+ break;
4064
+ case 'alertAuthor':
4065
+ addAlertAuthorToView(newName, appS, fixedInfo);
4066
+ break;
4067
+ case 'sendAlert':
4068
+ addSendAlertToView(newName, appS, fixedInfo);
4069
+ break;
4070
+ case 'publishTo':
4071
+ addPublishToToView(newName, appS, fixedInfo);
4072
+ break;
4073
+ default:
4074
+ console.error('fixed field info with unsupported ref ', fixedInfo);
4075
+ break;
4076
+ }
4077
+ }
4078
+ else if (fieldIdx !== -1) {
4079
+ field = appS.fields[fieldIdx];
4080
+ if (!field || !field.views) {
4081
+ throw new Error(`error converting installed app to V2: created field not found in fields array: ${fieldIdx}, ${fixedInfo}`);
4082
+ }
4083
+ field.views[newName] = true;
4084
+ addFieldToView(newName, field, appS, index, fixedInfo);
4085
+ }
4069
4086
  });
4070
- return `<AttrExposed>${formItemIdInFilter.join()}</AttrExposed>`;
4071
4087
  }
4072
- function getAttrNameFormItem(field, fieldId) {
4073
- function fieldType() {
4074
- if (field.type === ExtraAppFieldsItemViews.TITLE)
4075
- return 'title';
4076
- if (field.type === ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS)
4077
- return 'sendAlert';
4078
- if (field.type === ExtraAppFieldsItemViews.RECEIVEACOPY)
4079
- return 'alertAuthor';
4080
- if (field.type === ExtraAppFieldsItemViews.PUBLISHTO)
4081
- return 'publishTo';
4082
- if (field.type === ExtraAppFieldsItemViews.USER)
4083
- return 'idUser';
4084
- if (field.type === ExtraAppFieldsItemViews.CREATIONDATE)
4085
- return 'dateCreation';
4086
- if (field.type === AppFormItemTypes.DESCRIPTION)
4087
- return 'description';
4088
- return field.type;
4088
+ function buildListView(appS, registeredFields, columns, tables, state) {
4089
+ if (!columns) {
4090
+ return;
4089
4091
  }
4090
- return (AppColumnsDefaultTypes.includes(field.type) ? fieldType() : uuid2Alpha(fieldId)).toLowerCase();
4092
+ Object.keys(columns).forEach((fieldRef, index) => {
4093
+ addFieldToViewFromRef(appS, registeredFields, tables, 'list', fieldRef, index, state);
4094
+ });
4091
4095
  }
4092
- function renderAudience(audience, installFor) {
4093
- if (audience === AUDIENCE.ALL)
4094
- return '<checkAccess>false</checkAccess>';
4095
- else if (installFor.length > 0) {
4096
- return `<checkAccess>true</checkAccess>
4097
- <accessRightList>${installFor.map((user) => user.uri).join()}</accessRightList>`;
4098
- }
4099
- return '';
4096
+ function buildFilterView(appS, registeredFields, attrExposed, tables, state) {
4097
+ attrExposed.forEach((fieldRef, index) => {
4098
+ addFieldToViewFromRef(appS, registeredFields, tables, 'filter', fieldRef, index, state);
4099
+ });
4100
4100
  }
4101
- function renderPrimaryFields(fields) {
4102
- const primaryFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => AppFormPrimaryListValues.includes(field.type));
4103
- if (primaryFields.length === 0)
4104
- return '';
4105
- return `<primaryFields>${primaryFields.map((field) => formItem2xml(field)).join('')}</primaryFields>`;
4101
+ function addFieldToViewFromRef(appS, registeredFields, tables, viewName, fieldRef, index, state) {
4102
+ switch (fieldRef) {
4103
+ case 'title':
4104
+ addTitleToView(viewName, appS, { ref: 'title', fixedValue: undefined });
4105
+ break;
4106
+ case 'iduser':
4107
+ case 'idUser':
4108
+ addUserToView(viewName, appS);
4109
+ break;
4110
+ case 'datecreation':
4111
+ case 'dateCreation':
4112
+ addDateCreationToView(viewName, appS);
4113
+ break;
4114
+ default:
4115
+ defaultFieldCreation(appS, registeredFields, tables, viewName, fieldRef, index, state);
4116
+ break;
4117
+ }
4106
4118
  }
4107
- function renderCustomFields(fields) {
4108
- const customFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => !AppFormPrimaryListValues.includes(field.type));
4109
- const filteredCustomFields = customFields === null || customFields === void 0 ? void 0 : customFields.filter((field) => field.type !== AppFormItemTypes.IMAGE);
4110
- if (filteredCustomFields.length === 0)
4111
- return '';
4112
- const articlesTablesItems = filteredCustomFields.filter((f) => f.type !== AppFormItemTypes.TAGS && !AppFormNonPrimaryList.includes(f.type));
4113
- const linksTableItems = filteredCustomFields.filter((f) => f.type === AppFormItemTypes.TAGS);
4114
- return `<custom>
4115
- ${articlesTablesItems.length > 0
4116
- ? `<articlemstable>
4117
- ${articlesTablesItems.map((field) => formItem2xml(field)).join('')}
4118
- </articlemstable>`
4119
- : ''}
4120
- ${linksTableItems.length > 0
4121
- ? `<linkstable tablename="tag_links" sqlNameColumn="name" sqlSrcIdColumn="srcId" sqlSrcTypeColumn="srcType" sqlTargetIdColumn="targetId" sqlTargetTypeColumn="targetType">
4122
- ${linksTableItems.map((field) => formItem2xml(field)).join('')}
4123
- </linkstable>`
4124
- : ''}</custom>`;
4119
+ function defaultFieldCreation(appS, registeredFields, tables, viewName, fieldRef, index, state) {
4120
+ const fieldIndex = createOrGetFieldFromRef(appS, registeredFields, tables, fieldRef, state);
4121
+ const field = appS.fields[fieldIndex];
4122
+ if (!field || !field.views) {
4123
+ throw new Error(`error converting installed app to V2: unable to handle ${fieldRef} in list view`);
4124
+ }
4125
+ field.views[viewName] = true;
4126
+ addFieldToView(viewName, field, appS, index, undefined);
4125
4127
  }
4126
- function formItem2xml(field) {
4127
- return `<field
4128
- type="${renderFieldTypeToXmlType(field.type)}"
4129
- name="${getAttrNameFormItem(field, field.id)}"
4130
- sqlname="${renderSqlName(field.type, field.id)}"
4131
- ${field.properties && renderProperty(field.properties, AppFieldFormPropertyTypes.LABEL)}
4132
- ${field.properties && renderProperty(field.properties, AppFieldFormPropertyTypes.DESCRIPTION)}
4133
- mandatory="${field.mandatory}"
4134
- solr.type="${renderSolrType(field.type)}"
4135
- solr.used="true"
4136
- solr.indexed="true"
4137
- solr.stored="true"
4138
- solr.searchable="true"
4139
- solr.multiValued="${field.type === AppFormItemTypes.TAGS ||
4140
- field.type === AppFormItemTypes.CHECKBOX ||
4141
- field.type === AppFormItemTypes.SELECT
4142
- ? true
4143
- : false}"
4144
- teaser="true"
4145
- display="true"
4146
- >
4147
- ${renderWidget(field.type, field.properties)}
4148
- </field>`;
4128
+ function createOrGetFieldFromRef(appS, registeredFields, tables, fieldRef, state) {
4129
+ const knownIndex = registeredFields.get(fieldRef);
4130
+ if (knownIndex !== undefined) {
4131
+ return knownIndex;
4132
+ }
4133
+ const [ref, indexCreated] = createStudioDefinedField(appS, fieldRef, tables, state);
4134
+ registeredFields.set(ref, indexCreated);
4135
+ return indexCreated;
4149
4136
  }
4150
- function renderWidget(fieldType, fieldProperties) {
4151
- var _a;
4152
- switch (fieldType) {
4153
- case AppFormItemTypes.DESCRIPTION:
4154
- return '<widget form="textarea"><params><param key="class" value="mceEditor"></param><param key="mention" value="1"></param></params></widget>';
4155
- case AppFormItemTypes.TEXT:
4156
- return '<widget form="text"></widget>';
4157
- case AppFormItemTypes.TEXTAREA:
4158
- return '<widget form="textarea"></widget>';
4159
- case AppFormItemTypes.TEXTAREAHTML:
4160
- return '<widget form="textarea"><params><param key="class" value="mceEditor"></param></params></widget>';
4161
- case AppFormItemTypes.DATE:
4162
- return '<widget form="date" format="d/m/Y"></widget>';
4163
- case AppFormItemTypes.DATETIME:
4164
- return `<widget form="datetime" format="d/m/Y H:i:s"></widget>`;
4165
- case AppFormItemTypes.NUMBER: {
4166
- const isFloat = ((_a = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.CHECKBOX)) === null || _a === void 0 ? void 0 : _a.value) === true;
4167
- return `<widget form="number">
4168
- ${isFloat ? `<params><param value="0.01" key="step"/></params>` : ''}
4169
- </widget>`;
4137
+ function createOrGetField(appS, registeredFields, viewComponent, tables, state) {
4138
+ if (viewComponent.name !== undefined && viewComponent.element === 'attr') {
4139
+ if (specialAttrName.includes(viewComponent.name)) {
4140
+ return [-1, { ref: viewComponent.name, fixedValue: undefined }];
4170
4141
  }
4171
- case AppFormItemTypes.SELECT: {
4172
- const optionEditor = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
4173
- if (!optionEditor)
4174
- return '';
4175
- const isMultiple = optionEditor.value.canSelectMultiple;
4176
- const options = optionEditor.value.propertyOptions;
4177
- const hasDefaultValue = optionEditor.value.defaultSelectOption;
4178
- const defaultValue = optionEditor.value.defaultSelectOptionValue.value;
4179
- const userCanModifiyByComment = optionEditor.value.userCanModifiyByComment;
4180
- return `<widget form="select" ${isMultiple ? 'multiple="1"' : ''}>
4181
- <options>
4182
- ${options
4183
- .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
4184
- .join('')}
4185
- </options>
4186
- ${hasDefaultValue || userCanModifiyByComment
4187
- ? `<params>
4188
- ${hasDefaultValue ? `<param key="defaultValue" value="${defaultValue}"/>` : ''}
4189
- ${userCanModifiyByComment ? `<param key="explain" value="1"/>` : ''}
4190
- </params>`
4191
- : ''}
4192
- </widget>`;
4142
+ const knownIndex = registeredFields.get(viewComponent.name);
4143
+ if (knownIndex !== undefined) {
4144
+ return [knownIndex, undefined];
4193
4145
  }
4194
- case AppFormItemTypes.RADIO: {
4195
- const optionEditor = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
4196
- if (!optionEditor)
4197
- return '';
4198
- const options = optionEditor.value.propertyOptions;
4199
- return `<widget form="radio">
4200
- <options>
4201
- ${options
4202
- .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
4203
- .join('')}
4204
- </options>
4205
- </widget>`;
4146
+ const [ref, indexCreated] = createStudioDefinedField(appS, viewComponent.name, tables, state);
4147
+ registeredFields.set(ref, indexCreated);
4148
+ return [indexCreated, undefined];
4149
+ }
4150
+ else if (viewComponent.element === 'html') {
4151
+ const htmlCode = viewComponent.html;
4152
+ if (htmlCode === undefined) {
4153
+ console.error('error while parsing studio installed html attr in a view: no html code');
4154
+ return [-1, undefined];
4206
4155
  }
4207
- case AppFormItemTypes.TOGGLE:
4208
- return `<widget form="checkbox">
4209
- <options>
4210
- <option value="1" label="GLOBAL_Yes"></option>
4211
- </options>
4212
- <params>
4213
- <param key="jagCheckbox" value="1"></param>
4214
- </params>
4215
- </widget>`;
4216
- case AppFormItemTypes.TAGS: {
4217
- const taxonomy = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.TAXONOMY);
4218
- if (!taxonomy)
4219
- return '';
4220
- const taxonomyId = taxonomy.value.id;
4221
- return `<widget form="taxonomy">
4222
- <params><param key="idTaxonomy" value="${taxonomyId}"></param></params>
4223
- </widget>`;
4156
+ if (htmlCode.includes('<JAMESPOT.STUDIO.FIXED>')) {
4157
+ const startPos = htmlCode.indexOf('<JAMESPOT.STUDIO.FIXED>') + '<JAMESPOT.STUDIO.FIXED>'.length;
4158
+ const endPos = htmlCode.indexOf('</JAMESPOT.STUDIO.FIXED>');
4159
+ const formItemRefString = htmlCode.substring(startPos, endPos);
4160
+ try {
4161
+ const formItemRef = JSON.parse(formItemRefString);
4162
+ if ((formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref.toUpperCase()) in ExtraAppFieldsItemViews) {
4163
+ const ref = formItemRef.ref.toUpperCase();
4164
+ return [-1, Object.assign(Object.assign({}, formItemRef), { ref: fieldType(ref) })];
4165
+ }
4166
+ if (specialAttrName.includes(formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref)) {
4167
+ return [-1, formItemRef];
4168
+ }
4169
+ const knownIndex = registeredFields.get(formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref);
4170
+ if (knownIndex !== undefined) {
4171
+ return [knownIndex, formItemRef];
4172
+ }
4173
+ const [ref, indexCreated] = createStudioDefinedField(appS, formItemRef.ref, tables, state);
4174
+ registeredFields.set(ref, indexCreated);
4175
+ return [indexCreated, formItemRef];
4176
+ }
4177
+ catch (_) {
4178
+ console.error('error while parsing studio installed fixed attr in a view: json parsing failed');
4179
+ return [-1, undefined];
4180
+ }
4224
4181
  }
4225
- case AppFormItemTypes.CHECKBOX: {
4226
- const optionEditor = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
4227
- if (!optionEditor)
4228
- return '';
4229
- const options = optionEditor.value.propertyOptions;
4230
- return `<widget form="checkbox" multiple="1">
4231
- <options>
4232
- ${options
4233
- .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
4234
- .join('')}
4235
- </options>
4236
- </widget>`;
4182
+ else if (htmlCode.includes('<JAMESPOT.STUDIO.CODEHTML>')) {
4183
+ try {
4184
+ const startPosCode = htmlCode.indexOf('<JAMESPOT.STUDIO.CODEHTML>') + '<JAMESPOT.STUDIO.CODEHTML>'.length;
4185
+ const endPosCode = htmlCode.indexOf('</JAMESPOT.STUDIO.CODEHTML>');
4186
+ const formItemString = htmlCode.substring(startPosCode, endPosCode);
4187
+ const formItem = JSON.parse(formItemString);
4188
+ const knownIndex = registeredFields.get(formItem === null || formItem === void 0 ? void 0 : formItem.name);
4189
+ if (knownIndex !== undefined) {
4190
+ return [knownIndex, undefined];
4191
+ }
4192
+ const htmlField = createHtmlField(formItem);
4193
+ const indexCreated = appS.fields.push(htmlField) - 1;
4194
+ registeredFields.set(htmlField.id, indexCreated);
4195
+ return [indexCreated, undefined];
4196
+ }
4197
+ catch (_) {
4198
+ console.error('error while parsing studio installed codehtml attr in a view: json parsing failed');
4199
+ return [-1, undefined];
4200
+ }
4237
4201
  }
4238
- case AppFormItemTypes.ADDFILEATTACHMENT:
4239
- return `<widget form="file" type="fileArticle" multiple="1"></widget>`;
4240
- case AppFormItemTypes.URL:
4241
- return `<widget form="url"></widget>`;
4242
- case AppFormItemTypes.EMAIL:
4243
- return `<widget form="email"></widget>`;
4244
- case ExtraAppFieldsItemViews.USER:
4245
- return `<widget form="idUser"></widget>`;
4246
- case AppFormItemTypes.USERLINK:
4247
- return `<widget form="uri">
4248
- <params>
4249
- <param key="mode" value="ng-view"></param>
4250
- <param key="class" value="jcomplete"></param>
4251
- <param key="namespace" value="jamespot"></param>
4252
- <param key="types" value="user"></param>
4253
- <param key="views" value="user"></param>
4254
- <param key="jcomplete-url" value="/?action=ajax&amp;group=autocomplete&amp;function=user"></param>
4255
- </params>
4256
- </widget>`;
4257
- case AppFormItemTypes.CONTENTLINK: {
4258
- const contentType = fieldProperties === null || fieldProperties === void 0 ? void 0 : fieldProperties.find((property) => property.propertyType === AppFieldFormPropertyTypes.CONTENTTYPE);
4259
- if (!contentType)
4260
- return '';
4261
- const type = contentType.value.type;
4262
- return `<widget form="uri">
4263
- <params>
4264
- <param key="mode" value="ng-view"></param>
4265
- <param key="namespace" value="jamespot"></param>
4266
- <param key="types" value="${type}"></param>
4267
- <param key="views" value="article"></param>
4268
- <param key="jcomplete-url" value="/?action=ajax&amp;group=autocomplete&amp;function=article&amp;types=[]=${type}"></param>
4269
- </params>
4270
- </widget>`;
4202
+ else {
4203
+ console.error('error while parsing studio installed html attr in a view: unknown html format');
4204
+ return [-1, undefined];
4271
4205
  }
4272
- default:
4273
- return '';
4206
+ }
4207
+ else if (viewComponent.element === 'image') {
4208
+ const knownIndex = registeredFields.get('image');
4209
+ if (knownIndex !== undefined) {
4210
+ return [knownIndex, undefined];
4211
+ }
4212
+ const imageField = createImageField();
4213
+ const indexCreated = appS.fields.push(imageField) - 1;
4214
+ registeredFields.set('image', indexCreated);
4215
+ return [indexCreated, undefined];
4216
+ }
4217
+ else if (viewComponent.element === 'publishTo') {
4218
+ return [-1, { ref: 'publishTo', fixedValue: undefined }];
4219
+ }
4220
+ else {
4221
+ console.error('error while parsing studio installed attr in a view: unknown attr :O');
4222
+ return [-1, undefined];
4274
4223
  }
4275
4224
  }
4276
- function renderProperty(properties, propertyToFind) {
4277
- const labelProperty = properties === null || properties === void 0 ? void 0 : properties.find((property) => property.propertyType === propertyToFind);
4278
- if (labelProperty) {
4279
- return `${propertyToFind.toLowerCase()}="${labelProperty.value}"`;
4225
+ function createStudioDefinedField(appS, ref, tables, state) {
4226
+ const installedField = getInstalledField(ref, tables);
4227
+ const type = getFormItemType(installedField);
4228
+ const v2Field = (function createField() {
4229
+ switch (type) {
4230
+ case AppFormItemTypes.ADDFILEATTACHMENT:
4231
+ return createAddfileattachmentField(installedField);
4232
+ case AppFormItemTypes.NUMBER:
4233
+ return createNumberField(installedField);
4234
+ case AppFormItemTypes.TAGS:
4235
+ return createTagsField(installedField);
4236
+ case AppFormItemTypes.SELECT:
4237
+ return createSelectField(installedField);
4238
+ case AppFormItemTypes.RADIO:
4239
+ return createRadioField(installedField);
4240
+ case AppFormItemTypes.CHECKBOX:
4241
+ return createCheckboxField(installedField);
4242
+ case AppFormItemTypes.CONTENTLINK:
4243
+ return createContentLinkField(installedField, state);
4244
+ case AppFormItemTypes.DESCRIPTION:
4245
+ return createDescriptionField(installedField);
4246
+ case AppFormItemTypes.TEXTAREAHTML:
4247
+ return createTextareaHTMLField(installedField);
4248
+ case AppFormItemTypes.DATE:
4249
+ return createDateField(installedField);
4250
+ case AppFormItemTypes.DATETIME:
4251
+ return createDatetimeField(installedField);
4252
+ case AppFormItemTypes.URL:
4253
+ return createUrlField(installedField);
4254
+ case AppFormItemTypes.EMAIL:
4255
+ return createEmailField(installedField);
4256
+ case AppFormItemTypes.TOGGLE:
4257
+ return createToggleField(installedField);
4258
+ case AppFormItemTypes.USERLINK:
4259
+ return createUserLinkField(installedField);
4260
+ case AppFormItemTypes.TEXTAREA:
4261
+ return createTextAreaField(installedField);
4262
+ case AppFormItemTypes.TEXT:
4263
+ default:
4264
+ return createTextField(installedField);
4265
+ }
4266
+ })();
4267
+ const index = appS.fields.push(v2Field) - 1;
4268
+ return [ref, index];
4269
+ }
4270
+ function getInstalledField(ref, tables) {
4271
+ var _a;
4272
+ let foundField = undefined;
4273
+ for (let i = 0; i < tables.length && !foundField; i++) {
4274
+ foundField = (_a = tables[i]) === null || _a === void 0 ? void 0 : _a.attributes.find((attr) => {
4275
+ return attr.name === ref;
4276
+ });
4280
4277
  }
4281
- return '';
4278
+ if (!foundField) {
4279
+ throw new Error('error converting installed app to V2: installed field not found in tables ' + ref);
4280
+ }
4281
+ return foundField;
4282
4282
  }
4283
- function renderSqlName(fieldType, fieldId) {
4284
- switch (fieldType) {
4285
- case AppFormItemTypes.DESCRIPTION:
4286
- return 'Description';
4287
- case ExtraAppFieldsItemViews.USER:
4288
- return 'IdUser';
4289
- default:
4290
- return uuid2Alpha(fieldId);
4283
+ function addFieldToView(viewName, field, appS, index, fixedInfo) {
4284
+ var _a;
4285
+ if (field.views) {
4286
+ field.views[viewName] = true;
4287
+ appS.views[viewName][field.id] = {
4288
+ type: field.type,
4289
+ properties: field.properties || [],
4290
+ isUsed: true,
4291
+ isOptional: false,
4292
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
4293
+ isFixed: false,
4294
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : null,
4295
+ pos: index,
4296
+ };
4297
+ }
4298
+ }
4299
+ function getFormItemType(installedField) {
4300
+ var _a, _b, _c;
4301
+ switch (installedField.widget.type) {
4302
+ case 'number':
4303
+ return AppFormItemTypes.NUMBER;
4304
+ case 'taxonomy':
4305
+ return AppFormItemTypes.TAGS;
4306
+ case 'date':
4307
+ return AppFormItemTypes.DATE;
4308
+ case 'datetime':
4309
+ return AppFormItemTypes.DATETIME;
4310
+ case 'select':
4311
+ return AppFormItemTypes.SELECT;
4312
+ case 'radio':
4313
+ return AppFormItemTypes.RADIO;
4314
+ case 'url':
4315
+ return AppFormItemTypes.URL;
4316
+ case 'email':
4317
+ return AppFormItemTypes.EMAIL;
4318
+ case 'file':
4319
+ return AppFormItemTypes.ADDFILEATTACHMENT;
4320
+ case 'checkbox':
4321
+ if (((_a = installedField.widget.options) === null || _a === void 0 ? void 0 : _a['1']) === 'GLOBAL_Yes') {
4322
+ return AppFormItemTypes.TOGGLE;
4323
+ }
4324
+ return AppFormItemTypes.CHECKBOX;
4325
+ case 'uri':
4326
+ if (((_b = installedField.widget.params) === null || _b === void 0 ? void 0 : _b.views) === 'user') {
4327
+ return AppFormItemTypes.USERLINK;
4328
+ }
4329
+ if (((_c = installedField.widget.params) === null || _c === void 0 ? void 0 : _c.views) === 'article') {
4330
+ return AppFormItemTypes.CONTENTLINK;
4331
+ }
4332
+ break;
4333
+ case 'textarea':
4334
+ if (installedField.attrType === 'longtext') {
4335
+ return AppFormItemTypes.TEXTAREA;
4336
+ }
4337
+ if (installedField.attrType === 'html') {
4338
+ if (installedField.name === 'description') {
4339
+ return AppFormItemTypes.DESCRIPTION;
4340
+ }
4341
+ return AppFormItemTypes.TEXTAREAHTML;
4342
+ }
4343
+ break;
4344
+ case 'text':
4345
+ return AppFormItemTypes.TEXT;
4346
+ }
4347
+ throw new Error('error converting installed app to V2: installed field type not recognized for field ' + installedField.name);
4348
+ }
4349
+ function addTitleToView(newName, appS, fixedInfo) {
4350
+ var _a;
4351
+ const fieldId = 'title';
4352
+ appS.views[newName][fieldId] = {
4353
+ type: ExtraAppFieldsItemViews.TITLE,
4354
+ properties: [],
4355
+ isUsed: true,
4356
+ isOptional: false,
4357
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
4358
+ isFixed: true,
4359
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : null,
4360
+ pos: 0,
4361
+ };
4362
+ }
4363
+ function addAlertAuthorToView(newName, appS, fixedInfo) {
4364
+ const fieldId = 'alertAuthor';
4365
+ appS.views[newName][fieldId] = {
4366
+ type: ExtraAppFieldsItemViews.RECEIVEACOPY,
4367
+ properties: [],
4368
+ isUsed: true,
4369
+ isOptional: true,
4370
+ isLockedValue: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined,
4371
+ isFixed: false,
4372
+ value: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined ? fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue : true,
4373
+ pos: 300,
4374
+ };
4375
+ }
4376
+ function addSendAlertToView(newName, appS, fixedInfo) {
4377
+ const fieldId = 'sendAlert';
4378
+ appS.views[newName][fieldId] = {
4379
+ type: ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS,
4380
+ properties: [],
4381
+ isUsed: true,
4382
+ isOptional: true,
4383
+ isLockedValue: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined,
4384
+ isFixed: false,
4385
+ value: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined ? fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue : true,
4386
+ pos: 200,
4387
+ };
4388
+ }
4389
+ function addPublishToToView(newName, appS, fixedInfo) {
4390
+ var _a;
4391
+ const fieldId = 'publishTo';
4392
+ appS.views[newName][fieldId] = {
4393
+ type: ExtraAppFieldsItemViews.PUBLISHTO,
4394
+ properties: [],
4395
+ isUsed: true,
4396
+ isOptional: true,
4397
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
4398
+ isFixed: false,
4399
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : [],
4400
+ pos: 100,
4401
+ };
4402
+ }
4403
+ function addUserToView(newName, appS) {
4404
+ const fieldId = 'user';
4405
+ appS.views[newName][fieldId] = {
4406
+ type: ExtraAppFieldsItemViews.USER,
4407
+ properties: [],
4408
+ isUsed: true,
4409
+ isOptional: false,
4410
+ isLockedValue: false,
4411
+ isFixed: true,
4412
+ value: null,
4413
+ pos: 1,
4414
+ };
4415
+ }
4416
+ function addDateCreationToView(newName, appS) {
4417
+ const fieldId = 'dateCreation';
4418
+ appS.views[newName][fieldId] = {
4419
+ type: ExtraAppFieldsItemViews.CREATIONDATE,
4420
+ properties: [],
4421
+ isUsed: true,
4422
+ isOptional: true,
4423
+ isLockedValue: false,
4424
+ isFixed: false,
4425
+ value: null,
4426
+ pos: 100,
4427
+ };
4428
+ }
4429
+
4430
+ function InstalledAppStudioAdapter(serverApp, serverApps, state) {
4431
+ var _a, _b, _c, _d;
4432
+ const { version, dateCreation } = serverApp.manifest;
4433
+ const appTypeServer = serverApp.typeModel;
4434
+ const views = Object.assign({}, ...viewsList.map((view) => ({
4435
+ [view]: {},
4436
+ })));
4437
+ const studioApp = {
4438
+ idApp: serverApp.idApp,
4439
+ status: _formatStatus(serverApp),
4440
+ studioVersion: 2,
4441
+ manifest: {
4442
+ appShortName: serverApp.label,
4443
+ appName: serverApp.label,
4444
+ description: serverApp.description,
4445
+ author: serverApp.author,
4446
+ cssColor: (_a = appTypeServer.cssColor) !== null && _a !== void 0 ? _a : '#392994',
4447
+ cssClass: { label: (_b = appTypeServer.cssClass) !== null && _b !== void 0 ? _b : 'star', value: (_c = appTypeServer.cssClass) !== null && _c !== void 0 ? _c : 'star' },
4448
+ version: version,
4449
+ dateCreation: dateCreation,
4450
+ checkAccess: false,
4451
+ accessRightList: "",
4452
+ attrExposed: [],
4453
+ viewSolr: serverApp.view ? STUDIO_VIEW.SOLR : STUDIO_VIEW.NOT_SOLR,
4454
+ typeLabel: appTypeServer.typeLabel,
4455
+ articlesCount: (_d = serverApp.articlesCount) !== null && _d !== void 0 ? _d : 0,
4456
+ },
4457
+ fields: [],
4458
+ views,
4459
+ installFor: serverApp.accessRightObjectList ? buildAudience(serverApp.accessRightObjectList) : [],
4460
+ audience: serverApp.checkAccess === false ? AUDIENCE.ALL : AUDIENCE.CUSTOM,
4461
+ };
4462
+ populateFieldsAndViews(serverApp, studioApp, state);
4463
+ studioApp.views = updateViewsFromFields(studioApp, studioApp.fields);
4464
+ const inWorkAppVersion = _findAssociatedDraft(serverApp.idApp, serverApps);
4465
+ if (!inWorkAppVersion)
4466
+ return studioApp;
4467
+ const inWorkApp = DraftAppStudioAdapter(inWorkAppVersion);
4468
+ if (!inWorkApp)
4469
+ return studioApp;
4470
+ studioApp.inWorkVersion = inWorkApp;
4471
+ return studioApp;
4472
+ }
4473
+ function DraftAppStudioAdapter(serverApp) {
4474
+ if (!serverApp.value)
4475
+ return undefined;
4476
+ const parsedJson = JSON.parse(serverApp.value);
4477
+ if (parsedJson.studioVersion == 2) {
4478
+ return {
4479
+ idApp: serverApp.idApp,
4480
+ studioVersion: 2,
4481
+ status: _formatStatus(serverApp),
4482
+ manifest: parsedJson.manifest,
4483
+ fields: parsedJson.fields,
4484
+ views: parsedJson.views,
4485
+ syncViewFieldOrder: parsedJson.syncViewFieldOrder,
4486
+ audience: parsedJson.audience,
4487
+ installFor: parsedJson.installFor,
4488
+ };
4291
4489
  }
4292
- }
4293
- function renderSolrType(fieldType) {
4294
- switch (fieldType) {
4295
- case AppFormItemTypes.DESCRIPTION:
4296
- case AppFormItemTypes.TEXT:
4297
- case AppFormItemTypes.TEXTAREA:
4298
- case AppFormItemTypes.TEXTAREAHTML:
4299
- case AppFormItemTypes.URL:
4300
- case AppFormItemTypes.EMAIL:
4301
- case AppFormItemTypes.USERLINK:
4302
- case AppFormItemTypes.CONTENTLINK:
4303
- case AppFormItemTypes.NUMBER:
4304
- case AppFormItemTypes.ADDFILEATTACHMENT:
4305
- return 'text';
4306
- case AppFormItemTypes.DATE:
4307
- case AppFormItemTypes.DATETIME:
4308
- return 'date';
4309
- case ExtraAppFieldsItemViews.USER:
4310
- return 'integer';
4311
- case AppFormItemTypes.SELECT:
4312
- case AppFormItemTypes.RADIO:
4313
- case AppFormItemTypes.TOGGLE:
4314
- case AppFormItemTypes.CHECKBOX:
4315
- case AppFormItemTypes.TAGS:
4316
- return 'string';
4317
- default:
4318
- return '';
4490
+ else {
4491
+ return Object.assign(Object.assign({}, migrateJson(parsedJson)), { status: _formatStatus(serverApp), migratedFrom: 1 });
4319
4492
  }
4320
4493
  }
4321
- function renderFieldTypeToXmlType(fieldType) {
4322
- switch (fieldType) {
4323
- default:
4324
- case AppFormItemTypes.DESCRIPTION:
4325
- case AppFormItemTypes.TEXTAREAHTML:
4326
- return 'html';
4327
- case AppFormItemTypes.TAGS:
4328
- return 'taxonomy';
4329
- case AppFormItemTypes.TEXT:
4330
- case AppFormItemTypes.RADIO:
4331
- case AppFormItemTypes.URL:
4332
- case AppFormItemTypes.EMAIL:
4333
- case AppFormItemTypes.ADDFILEATTACHMENT:
4334
- case ExtraAppFieldsItemViews.USER:
4335
- case AppFormItemTypes.USERLINK:
4336
- case AppFormItemTypes.CONTENTLINK:
4337
- return 'text';
4338
- case AppFormItemTypes.TEXTAREA:
4339
- case AppFormItemTypes.CHECKBOX:
4340
- case AppFormItemTypes.SELECT:
4341
- return 'longtext';
4342
- case AppFormItemTypes.DATE:
4343
- return 'date';
4344
- case AppFormItemTypes.DATETIME: {
4345
- return 'date';
4346
- }
4347
- case AppFormItemTypes.NUMBER:
4348
- return 'float';
4349
- }
4494
+ function _formatStatus(serverApp) {
4495
+ return serverApp.status === jamespot.StudioApplicationStatus.installed
4496
+ ? serverApp.suspended
4497
+ ? StatusType$1.suspended
4498
+ : StatusType$1.installed
4499
+ : StatusType$1.draft;
4350
4500
  }
4351
- const uuid2Alpha = (id) => {
4352
- let alphaUuid = '';
4353
- for (let i = 0; i < id.length; i++) {
4354
- const c = id.charAt(i);
4355
- if (c >= '0' && c <= '9')
4356
- alphaUuid += numToAlpha(Number(c));
4357
- else if (c >= 'a' && c <= 'z')
4358
- alphaUuid += c;
4359
- }
4360
- return alphaUuid;
4361
- };
4362
- const numToAlpha = (num) => {
4363
- let s = '', t;
4364
- while (num > 0) {
4365
- t = (num - 1) % 26;
4366
- s = String.fromCharCode(97 + t) + s;
4367
- num = ((num - t) / 26) | 0;
4368
- }
4369
- return s;
4370
- };
4371
- const internal2XmlView = {
4372
- create: 'create',
4373
- popup: 'create-popup',
4374
- edit: 'edit',
4375
- view: 'display',
4376
- };
4377
- function renderDisplays(studioApp) {
4378
- let toRet = '';
4379
- Object.entries(studioApp.views).forEach(([viewName, viewContent]) => {
4380
- if (Object.prototype.hasOwnProperty.call(internal2XmlView, viewName)) {
4381
- const viewField = Object.entries(viewContent)
4382
- .filter((a) => a[1].isUsed)
4383
- .sort((a, b) => a[1].pos - b[1].pos);
4384
- toRet += `<display view="${internal2XmlView[viewName]}" mode="${viewName === 'view' ? 'view' : 'form'}">
4385
- ${viewField.map(([fieldId, view]) => renderDisplayAttr(fieldId, view)).join('')}
4386
- </display>`;
4387
- }
4388
- });
4389
- if (toRet.length > 0) {
4390
- toRet = `<displays type="${studioApp.idApp}">${toRet}</displays>`;
4391
- }
4392
- return toRet;
4501
+ function _findAssociatedDraft(idApp, serverApps) {
4502
+ const draft = serverApps.find((app) => app.idApp === idApp && app.status === jamespot.StudioApplicationStatus.saved);
4503
+ return draft;
4393
4504
  }
4394
- function getDisplayName(fieldId, view) {
4395
- switch (view.type) {
4396
- case ExtraAppFieldsItemViews.TITLE:
4397
- return 'title';
4398
- case ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS:
4399
- return 'sendAlert';
4400
- case ExtraAppFieldsItemViews.RECEIVEACOPY:
4401
- return 'alertAuthor';
4402
- case ExtraAppFieldsItemViews.PUBLISHTO:
4403
- return 'publishTo';
4404
- case ExtraAppFieldsItemViews.USER:
4405
- return 'idUser';
4406
- case ExtraAppFieldsItemViews.CREATIONDATE:
4407
- return 'dateCreation';
4408
- case AppFormItemTypes.DESCRIPTION:
4409
- return 'description';
4410
- default:
4411
- return uuid2Alpha(fieldId);
4412
- }
4505
+ function _findAssociatedInstalled(idApp, serverApps) {
4506
+ return !!serverApps.find((app) => app.idApp === idApp && app.status === jamespot.StudioApplicationStatus.installed);
4413
4507
  }
4414
- function renderDisplayAttr(fieldId, view) {
4415
- var _a, _b, _c;
4416
- let xml = '';
4417
- const attrName = getDisplayName(fieldId, view);
4418
- const isFixed = view.isLockedValue;
4419
- if (isFixed) {
4420
- const formItemRefWithName = {
4421
- ref: attrName,
4422
- fixedValue: view.value,
4423
- };
4424
- xml += `<html><![CDATA[ <!-- <JAMESPOT.STUDIO.FIXED>${JSON.stringify(formItemRefWithName)}</JAMESPOT.STUDIO.FIXED> -->`;
4425
- if (view.type === ExtraAppFieldsItemViews.PUBLISHTO) {
4426
- const uris = view.value.map((user) => user.uri).join(',');
4427
- xml += `<input type="hidden" name="publishTo" value="${uris}">`;
4428
- }
4429
- else if (view.type === ExtraAppFieldsItemViews.USER ||
4430
- view.type === AppFormItemTypes.USERLINK ||
4431
- view.type === AppFormItemTypes.CONTENTLINK) {
4432
- xml += `<input type="hidden" name="${attrName}[]" value=${JSON.stringify(view.value.uri)}>`;
4433
- }
4434
- else if (view.type === AppFormItemTypes.SELECT) {
4435
- const canSelectMultiple = (_a = view.properties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR)) === null || _a === void 0 ? void 0 : _a.value.canSelectMultiple;
4436
- if (canSelectMultiple) {
4437
- const values = view.value;
4438
- values.forEach((value) => {
4439
- xml += `<input type="hidden" name="${attrName}[]" value="${value.value}">`;
4440
- });
4441
- }
4442
- else {
4443
- xml += `<input type="hidden" name="${attrName}" value="${view.value.value}">`;
4444
- }
4445
- }
4446
- else if (view.type === AppFormItemTypes.CHECKBOX) {
4447
- const values = view.value;
4448
- values.forEach((value) => {
4449
- xml += `<input type="hidden" name="${attrName}[]" value="${value}">`;
4450
- });
4451
- }
4452
- else if (view.type === AppFormItemTypes.DATE) {
4453
- const dateValue = new Date(view.value);
4454
- const xmlFixedValue = [
4455
- pad(dateValue.getDate()),
4456
- pad(dateValue.getMonth() + 1),
4457
- dateValue.getFullYear(),
4458
- ].join('/');
4459
- xml += '<input type="hidden" name="' + attrName + '" value="' + xmlFixedValue + '">';
4460
- }
4461
- else if (view.type === AppFormItemTypes.DATETIME) {
4462
- const dateValue = new Date(view.value);
4463
- const xmlFixedValue = `${[
4464
- pad(dateValue.getDate()),
4465
- pad(dateValue.getMonth() + 1),
4466
- dateValue.getFullYear(),
4467
- ].join('/')} ${pad(dateValue.getHours())}:${pad(dateValue.getMinutes())}:${pad(dateValue.getSeconds())}`;
4468
- xml += '<input type="hidden" name="' + attrName + '" value="' + xmlFixedValue + '">';
4469
- }
4470
- else if (view.type === AppFormItemTypes.TAGS) {
4471
- xml += `<input type="hidden" name="${attrName}" value="${(_c = (_b = view.value) === null || _b === void 0 ? void 0 : _b.map((v) => v.uri)) === null || _c === void 0 ? void 0 : _c.join(',')}">`;
4472
- }
4473
- else if (view.type === AppFormItemTypes.DESCRIPTION || view.type === AppFormItemTypes.TEXTAREAHTML) {
4474
- xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
4475
- }
4476
- else if (view.type === ExtraAppFieldsItemViews.RECEIVEACOPY) {
4477
- if (view.value) {
4478
- xml += `<input type="hidden" name="alertAuthor[jamespot]"><input type="hidden" name="alertAuthor[]" value="1">`;
4479
- }
4480
- }
4481
- else if (view.type === ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS) {
4482
- if (view.value) {
4483
- xml += `<input type="hidden" name="sendAlert[jamespot]"><input type="hidden" name="sendAlert[]" value="1">`;
4484
- }
4508
+ function serverAppsToStudioApps(serverApps, state) {
4509
+ const studioApps = serverApps
4510
+ .map((serverApp) => {
4511
+ if (serverApp.status === jamespot.StudioApplicationStatus.installed) {
4512
+ return InstalledAppStudioAdapter(serverApp, serverApps, state);
4485
4513
  }
4486
4514
  else {
4487
- xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
4488
- }
4489
- xml += ']]></html>';
4490
- }
4491
- else {
4492
- switch (view.type) {
4493
- case AppFormItemTypes.CODEHTML: {
4494
- const fieldToInclude = {
4495
- id: fieldId,
4496
- name: fieldId,
4497
- properties: {
4498
- code: view.value,
4499
- },
4500
- };
4501
- xml += `<html><![CDATA[ <!-- <JAMESPOT.STUDIO.CODEHTML>${JSON.stringify(fieldToInclude)}</JAMESPOT.STUDIO.CODEHTML><JAMESPOT.STUDIO.FIELD_POS>${view.pos}</JAMESPOT.STUDIO.FIELD_POS>-->${view.value}]]></html>`;
4502
- break;
4503
- }
4504
- case AppFormItemTypes.IMAGE:
4505
- xml += '<image />';
4506
- break;
4507
- case ExtraAppFieldsItemViews.PUBLISHTO:
4508
- xml += '<publishTo />';
4509
- break;
4510
- default:
4511
- xml += "<attr name='" + attrName + "' />";
4512
- break;
4515
+ if (_findAssociatedInstalled(serverApp.idApp, serverApps))
4516
+ return undefined;
4517
+ return DraftAppStudioAdapter(serverApp);
4513
4518
  }
4514
- }
4515
- return xml;
4516
- }
4517
- function pad(s) {
4518
- return s < 10 ? '0' + s : s;
4519
+ })
4520
+ .filter((app) => app !== undefined);
4521
+ return studioApps;
4519
4522
  }
4520
4523
 
4521
4524
  const initialState$1 = {