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