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