jamespot-front-business 1.1.68 → 1.1.69

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
@@ -2757,12 +2757,11 @@ const AUDIENCE = {
2757
2757
  ALL: '1',
2758
2758
  CUSTOM: '0',
2759
2759
  };
2760
- var StatusType$1;
2761
- (function (StatusType) {
2762
- StatusType["draft"] = "draft";
2763
- StatusType["installed"] = "installed";
2764
- StatusType["suspended"] = "suspended";
2765
- })(StatusType$1 || (StatusType$1 = {}));
2760
+ const StatusType$1 = {
2761
+ draft: 'draft',
2762
+ installed: 'installed',
2763
+ suspended: 'suspended',
2764
+ };
2766
2765
  const APP_STATUS_TYPE = {
2767
2766
  DRAFT: StatusType$1.draft,
2768
2767
  INSTALLED: StatusType$1.installed,
@@ -2773,51 +2772,50 @@ const STUDIO_VIEW = {
2773
2772
  NOT_SOLR: '0',
2774
2773
  };
2775
2774
  const viewsList = ['create', 'popup', 'edit', 'filter', 'list', 'view'];
2776
- var AppFormItemTypes;
2777
- (function (AppFormItemTypes) {
2778
- AppFormItemTypes["IMAGE"] = "IMAGE";
2779
- AppFormItemTypes["DESCRIPTION"] = "DESCRIPTION";
2780
- AppFormItemTypes["TEXT"] = "TEXT";
2781
- AppFormItemTypes["TEXTAREA"] = "TEXTAREA";
2782
- AppFormItemTypes["TEXTAREAHTML"] = "TEXTAREAHTML";
2783
- AppFormItemTypes["DATE"] = "DATE";
2784
- AppFormItemTypes["DATETIME"] = "DATETIME";
2785
- AppFormItemTypes["NUMBER"] = "NUMBER";
2786
- AppFormItemTypes["URL"] = "URL";
2787
- AppFormItemTypes["EMAIL"] = "EMAIL";
2788
- AppFormItemTypes["SELECT"] = "SELECT";
2789
- AppFormItemTypes["CHECKBOX"] = "CHECKBOX";
2790
- AppFormItemTypes["TOGGLE"] = "TOGGLE";
2791
- AppFormItemTypes["RADIO"] = "RADIO";
2792
- AppFormItemTypes["TAGS"] = "TAGS";
2793
- AppFormItemTypes["ADDFILEATTACHMENT"] = "ADDFILEATTACHMENT";
2794
- AppFormItemTypes["CODEHTML"] = "CODEHTML";
2795
- AppFormItemTypes["USERLINK"] = "USERLINK";
2796
- AppFormItemTypes["CONTENTLINK"] = "CONTENTLINK";
2797
- AppFormItemTypes["RANGE"] = "RANGE";
2798
- })(AppFormItemTypes || (AppFormItemTypes = {}));
2799
- var ExtraAppFieldsItemViews;
2800
- (function (ExtraAppFieldsItemViews) {
2801
- ExtraAppFieldsItemViews["TITLE"] = "TITLE";
2802
- ExtraAppFieldsItemViews["USER"] = "USER";
2803
- ExtraAppFieldsItemViews["PUBLISHTO"] = "PUBLISHTO";
2804
- ExtraAppFieldsItemViews["SENDALERTTOSUBSCRIBERS"] = "SENDALERTTOSUBSCRIBERS";
2805
- ExtraAppFieldsItemViews["RECEIVEACOPY"] = "RECEIVEACOPY";
2806
- ExtraAppFieldsItemViews["CREATIONDATE"] = "CREATIONDATE";
2807
- })(ExtraAppFieldsItemViews || (ExtraAppFieldsItemViews = {}));
2808
- var AppFieldFormPropertyTypes;
2809
- (function (AppFieldFormPropertyTypes) {
2810
- AppFieldFormPropertyTypes["LABEL"] = "label";
2811
- AppFieldFormPropertyTypes["DESCRIPTION"] = "description";
2812
- AppFieldFormPropertyTypes["RICHTEXT"] = "richtext";
2813
- AppFieldFormPropertyTypes["CHECKBOX"] = "checkbox";
2814
- AppFieldFormPropertyTypes["OPTIONS_EDITOR"] = "options_editor";
2815
- AppFieldFormPropertyTypes["TAXONOMY"] = "taxonomy";
2816
- AppFieldFormPropertyTypes["CONTENTTYPE"] = "contenttype";
2817
- })(AppFieldFormPropertyTypes || (AppFieldFormPropertyTypes = {}));
2775
+ const AppFormItemTypes = {
2776
+ IMAGE: 'IMAGE',
2777
+ DESCRIPTION: 'DESCRIPTION',
2778
+ TEXT: 'TEXT',
2779
+ TEXTAREA: 'TEXTAREA',
2780
+ TEXTAREAHTML: 'TEXTAREAHTML',
2781
+ DATE: 'DATE',
2782
+ DATETIME: 'DATETIME',
2783
+ NUMBER: 'NUMBER',
2784
+ URL: 'URL',
2785
+ EMAIL: 'EMAIL',
2786
+ SELECT: 'SELECT',
2787
+ CHECKBOX: 'CHECKBOX',
2788
+ TOGGLE: 'TOGGLE',
2789
+ RADIO: 'RADIO',
2790
+ TAGS: 'TAGS',
2791
+ ADDFILEATTACHMENT: 'ADDFILEATTACHMENT',
2792
+ CODEHTML: 'CODEHTML',
2793
+ USERLINK: 'USERLINK',
2794
+ CONTENTLINK: 'CONTENTLINK',
2795
+ RANGE: 'RANGE',
2796
+ };
2797
+ const ExtraAppFieldsItemViews = {
2798
+ TITLE: 'TITLE',
2799
+ USER: 'USER',
2800
+ PUBLISHTO: 'PUBLISHTO',
2801
+ SENDALERTTOSUBSCRIBERS: 'SENDALERTTOSUBSCRIBERS',
2802
+ RECEIVEACOPY: 'RECEIVEACOPY',
2803
+ CREATIONDATE: 'CREATIONDATE',
2804
+ };
2805
+ const AppFieldFormPropertyTypes = {
2806
+ LABEL: 'label',
2807
+ DESCRIPTION: 'description',
2808
+ RICHTEXT: 'richtext',
2809
+ CHECKBOX: 'checkbox',
2810
+ OPTIONS_EDITOR: 'options_editor',
2811
+ TAXONOMY: 'taxonomy',
2812
+ CONTENTTYPE: 'contenttype',
2813
+ };
2818
2814
  const AppFormUniqueList = [AppFormItemTypes.DESCRIPTION, AppFormItemTypes.IMAGE];
2815
+ const AppFormUniqueListCheck = AppFormUniqueList;
2819
2816
  const AppFormBannedFromViews$1 = new Map();
2820
2817
  AppFormBannedFromViews$1.set(AppFormItemTypes.IMAGE, ['list', 'filter', 'view']);
2818
+ AppFormBannedFromViews$1.set(AppFormItemTypes.CODEHTML, ['list', 'filter', 'view']);
2821
2819
  const MapExtraFieldsWithView = {
2822
2820
  create: {
2823
2821
  fixed: [ExtraAppFieldsItemViews.TITLE],
@@ -2855,6 +2853,7 @@ const AppColumnsDefaultTypes = [
2855
2853
  AppFormItemTypes.DESCRIPTION,
2856
2854
  ];
2857
2855
  const AppFormPrimaryList = [AppFormItemTypes.DESCRIPTION];
2856
+ const AppFormPrimaryListValues = AppFormPrimaryList;
2858
2857
  const AppFormFixedList$1 = [
2859
2858
  ExtraAppFieldsItemViews.TITLE,
2860
2859
  ExtraAppFieldsItemViews.PUBLISHTO,
@@ -2869,6 +2868,18 @@ const AppFormNoAsFieldList = [
2869
2868
  ];
2870
2869
  const AppFormFieldOnlyInView = [AppFormItemTypes.CODEHTML];
2871
2870
  const AppFormNonPrimaryList = AppFormNoAsFieldList.concat(AppFormFieldOnlyInView).concat(AppFormPrimaryList);
2871
+ var Element;
2872
+ (function (Element) {
2873
+ Element["Attr"] = "attr";
2874
+ Element["PublishTo"] = "publishTo";
2875
+ })(Element || (Element = {}));
2876
+ var Description;
2877
+ (function (Description) {
2878
+ Description["Empty"] = "";
2879
+ Description["FieldTagDescription"] = "Field_Tag_Description";
2880
+ Description["FieldTitleDescription"] = "Field_Title_Description";
2881
+ Description["WWWDescCOM"] = "www.desc.com";
2882
+ })(Description || (Description = {}));
2872
2883
 
2873
2884
  var StatusType;
2874
2885
  (function (StatusType) {
@@ -3132,23 +3143,761 @@ function migrateJson(v1Json) {
3132
3143
  return v2;
3133
3144
  }
3134
3145
 
3135
- function InstalledAppStudioAdapter(serverApp, serverApps) {
3146
+ function generateNewFormField(type, viewsDefault = true) {
3147
+ return {
3148
+ id: v4(),
3149
+ type,
3150
+ properties: _setFieldProperties(type),
3151
+ mandatory: false,
3152
+ views: {
3153
+ create: viewsDefault,
3154
+ popup: viewsDefault,
3155
+ edit: viewsDefault,
3156
+ list: viewsDefault,
3157
+ filter: viewsDefault,
3158
+ view: viewsDefault,
3159
+ },
3160
+ isActive: true,
3161
+ isFixed: false,
3162
+ isOptional: false,
3163
+ value: null,
3164
+ isLockedValue: false,
3165
+ };
3166
+ }
3167
+ const taxonomyDefaultValue = {
3168
+ type: 'taxonomyOpen',
3169
+ id: 1,
3170
+ title: 'Mots-clés',
3171
+ };
3172
+ const contentTypeDefaultValue = {
3173
+ type: 'mpArticle',
3174
+ label: 'Article',
3175
+ };
3176
+ function _setFieldProperties(type) {
3177
+ switch (type) {
3178
+ case AppFormItemTypes.TEXT:
3179
+ case AppFormItemTypes.DESCRIPTION:
3180
+ case AppFormItemTypes.TEXTAREAHTML:
3181
+ case AppFormItemTypes.DATE:
3182
+ case AppFormItemTypes.DATETIME:
3183
+ case AppFormItemTypes.URL:
3184
+ case AppFormItemTypes.EMAIL:
3185
+ case AppFormItemTypes.TOGGLE:
3186
+ case AppFormItemTypes.USERLINK:
3187
+ return [
3188
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3189
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3190
+ ];
3191
+ case AppFormItemTypes.ADDFILEATTACHMENT:
3192
+ return [{ propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' }];
3193
+ case AppFormItemTypes.CODEHTML:
3194
+ return [{ propertyType: AppFieldFormPropertyTypes.RICHTEXT, value: '' }];
3195
+ case AppFormItemTypes.TEXTAREA:
3196
+ return [
3197
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3198
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3199
+ ];
3200
+ case AppFormItemTypes.NUMBER:
3201
+ return [
3202
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3203
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3204
+ {
3205
+ propertyType: AppFieldFormPropertyTypes.CHECKBOX,
3206
+ value: false,
3207
+ checkBoxOptions: [{ label: 'APPSTUDIO_FormEditProps_Digits', value: false }],
3208
+ },
3209
+ ];
3210
+ case AppFormItemTypes.SELECT:
3211
+ return [
3212
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3213
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3214
+ {
3215
+ propertyType: AppFieldFormPropertyTypes.OPTIONS_EDITOR,
3216
+ value: [],
3217
+ isOptionsEditorEnhanced: true,
3218
+ },
3219
+ ];
3220
+ case AppFormItemTypes.CHECKBOX:
3221
+ case AppFormItemTypes.RADIO:
3222
+ return [
3223
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3224
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3225
+ {
3226
+ propertyType: AppFieldFormPropertyTypes.OPTIONS_EDITOR,
3227
+ value: [],
3228
+ },
3229
+ ];
3230
+ case AppFormItemTypes.TAGS:
3231
+ return [
3232
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3233
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3234
+ {
3235
+ propertyType: AppFieldFormPropertyTypes.TAXONOMY,
3236
+ value: Object.assign({}, taxonomyDefaultValue),
3237
+ },
3238
+ ];
3239
+ case AppFormItemTypes.CONTENTLINK:
3240
+ return [
3241
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3242
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3243
+ {
3244
+ propertyType: AppFieldFormPropertyTypes.CONTENTTYPE,
3245
+ value: Object.assign({}, contentTypeDefaultValue),
3246
+ },
3247
+ ];
3248
+ default:
3249
+ return [];
3250
+ }
3251
+ }
3252
+
3253
+ function _initField(type, installedField) {
3254
+ const field = Object.assign(Object.assign({}, generateNewFormField(type, false)), { id: installedField.name, mandatory: installedField.mandatory });
3255
+ field.properties[0].value = installedField.label;
3256
+ field.properties[1].value = installedField.description;
3257
+ return field;
3258
+ }
3259
+ function _getOptions(installedOptions) {
3260
+ const options = [];
3261
+ Object.keys(installedOptions).forEach((optionKey) => {
3262
+ options.push({
3263
+ title: installedOptions[optionKey],
3264
+ value: optionKey,
3265
+ });
3266
+ });
3267
+ return options;
3268
+ }
3269
+ function createAddfileattachmentField(installedField) {
3270
+ const field = Object.assign(Object.assign({}, generateNewFormField(AppFormItemTypes.ADDFILEATTACHMENT, false)), { id: installedField.name, mandatory: installedField.mandatory });
3271
+ field.properties[0].value = installedField.label;
3272
+ return field;
3273
+ }
3274
+ function createHtmlField(formItem) {
3275
+ const field = Object.assign(Object.assign({}, generateNewFormField(AppFormItemTypes.CODEHTML, false)), { id: formItem.name });
3276
+ field.properties[0].value = formItem.properties.code;
3277
+ return field;
3278
+ }
3279
+ function createImageField() {
3280
+ const field = generateNewFormField(AppFormItemTypes.IMAGE, false);
3281
+ return field;
3282
+ }
3283
+ function createNumberField(installedField) {
3284
+ var _a;
3285
+ const field = _initField(AppFormItemTypes.NUMBER, installedField);
3286
+ field.properties[2].value = ((_a = installedField.widget.params) === null || _a === void 0 ? void 0 : _a.step) === '0.01';
3287
+ return field;
3288
+ }
3289
+ function createTagsField(installedField) {
3290
+ var _a, _b;
3291
+ const field = _initField(AppFormItemTypes.TAGS, installedField);
3292
+ field.properties[2].value.id = +((_b = (_a = installedField.widget.params) === null || _a === void 0 ? void 0 : _a.idTaxonomy) !== null && _b !== void 0 ? _b : 1);
3293
+ return field;
3294
+ }
3295
+ function createSelectField(installedField) {
3296
+ var _a, _b, _c, _d, _e;
3297
+ const field = _initField(AppFormItemTypes.SELECT, installedField);
3298
+ const defaultValue = ((_a = installedField.widget.params) === null || _a === void 0 ? void 0 : _a.defaultValue)
3299
+ ? {
3300
+ title: installedField.widget.options[(_b = installedField.widget.params) === null || _b === void 0 ? void 0 : _b.defaultValue],
3301
+ value: (_c = installedField.widget.params) === null || _c === void 0 ? void 0 : _c.defaultValue,
3302
+ }
3303
+ : undefined;
3304
+ const optionsEditorValue = {
3305
+ propertyOptions: _getOptions(installedField.widget.options),
3306
+ canSelectMultiple: installedField.widget.multiple === '1',
3307
+ userCanModifiyByComment: ((_d = installedField.widget.params) === null || _d === void 0 ? void 0 : _d.explain) === '1',
3308
+ defaultSelectOption: !!((_e = installedField.widget.params) === null || _e === void 0 ? void 0 : _e.defaultValue),
3309
+ defaultSelectOptionValue: defaultValue,
3310
+ };
3311
+ field.properties[2].value = optionsEditorValue;
3312
+ return field;
3313
+ }
3314
+ function createRadioField(installedField) {
3315
+ const field = _initField(AppFormItemTypes.RADIO, installedField);
3316
+ const optionsEditorValue = {
3317
+ propertyOptions: _getOptions(installedField.widget.options),
3318
+ };
3319
+ field.properties[2].value = optionsEditorValue;
3320
+ return field;
3321
+ }
3322
+ function createCheckboxField(installedField) {
3323
+ const field = createRadioField(installedField);
3324
+ field.type = AppFormItemTypes.CHECKBOX;
3325
+ return field;
3326
+ }
3327
+ function createContentLinkField(installedField, state) {
3328
+ var _a, _b;
3329
+ const field = _initField(AppFormItemTypes.CONTENTLINK, installedField);
3330
+ field.properties[2].value.type = (_a = installedField.widget.params.types) !== null && _a !== void 0 ? _a : 'mpArticle';
3331
+ const modelState = state.entities === undefined ? undefined : { entities: state.entities };
3332
+ const model = modelState ? Model.selectors.selectById(modelState, field.properties[2].value.type) : undefined;
3333
+ field.properties[2].value.label = (_b = model === null || model === void 0 ? void 0 : model.label) !== null && _b !== void 0 ? _b : 'Article';
3334
+ return field;
3335
+ }
3336
+ function createTextField(installedField) {
3337
+ const field = _initField(AppFormItemTypes.TEXT, installedField);
3338
+ return field;
3339
+ }
3340
+ function createDescriptionField(installedField) {
3341
+ const field = _initField(AppFormItemTypes.DESCRIPTION, installedField);
3342
+ return field;
3343
+ }
3344
+ function createTextareaHTMLField(installedField) {
3345
+ const field = _initField(AppFormItemTypes.TEXTAREAHTML, installedField);
3346
+ return field;
3347
+ }
3348
+ function createDateField(installedField) {
3349
+ const field = _initField(AppFormItemTypes.DATE, installedField);
3350
+ return field;
3351
+ }
3352
+ function createDatetimeField(installedField) {
3353
+ const field = _initField(AppFormItemTypes.DATETIME, installedField);
3354
+ return field;
3355
+ }
3356
+ function createUrlField(installedField) {
3357
+ const field = _initField(AppFormItemTypes.URL, installedField);
3358
+ return field;
3359
+ }
3360
+ function createEmailField(installedField) {
3361
+ const field = _initField(AppFormItemTypes.EMAIL, installedField);
3362
+ return field;
3363
+ }
3364
+ function createToggleField(installedField) {
3365
+ const field = _initField(AppFormItemTypes.TOGGLE, installedField);
3366
+ return field;
3367
+ }
3368
+ function createUserLinkField(installedField) {
3369
+ const field = _initField(AppFormItemTypes.USERLINK, installedField);
3370
+ return field;
3371
+ }
3372
+ function createTextAreaField(installedField) {
3373
+ const field = _initField(AppFormItemTypes.TEXTAREA, installedField);
3374
+ return field;
3375
+ }
3376
+
3377
+ const installedToV2ViewNames = {
3378
+ 'create-popup': 'popup',
3379
+ create: 'create',
3380
+ edit: 'edit',
3381
+ display: 'view',
3382
+ };
3383
+ const specialAttrName = ['title', 'alertAuthor', 'sendAlert'];
3384
+ const ignoredFields = ['edito'];
3385
+ function updateViewsFromFields(clonedApp, appFields) {
3386
+ return Object.assign({}, ...viewsList.map((view) => {
3387
+ const viewItems = {};
3388
+ Object.entries(clonedApp.views[view]).forEach(([fieldId, field]) => {
3389
+ if (field.isFixed) {
3390
+ viewItems[fieldId] = field;
3391
+ }
3392
+ if (field.isOptional) {
3393
+ viewItems[fieldId] = field;
3394
+ }
3395
+ });
3396
+ appFields.forEach((field, idx) => {
3397
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3398
+ const isFieldUsedInView = field.views[view];
3399
+ const isExistingField = Object.keys(clonedApp.views[view]).includes(field.id);
3400
+ const fieldType = field.type;
3401
+ if (AppFormBannedFromViews$1.get(fieldType) && ((_a = AppFormBannedFromViews$1.get(fieldType)) === null || _a === void 0 ? void 0 : _a.includes(view))) {
3402
+ return;
3403
+ }
3404
+ let fieldValue = undefined;
3405
+ if (fieldType === AppFormItemTypes.CODEHTML) {
3406
+ const richTextProperty = (_b = field.properties) === null || _b === void 0 ? void 0 : _b.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.RICHTEXT);
3407
+ if (richTextProperty === null || richTextProperty === void 0 ? void 0 : richTextProperty.value) {
3408
+ fieldValue = richTextProperty === null || richTextProperty === void 0 ? void 0 : richTextProperty.value;
3409
+ }
3410
+ }
3411
+ if (fieldType === AppFormItemTypes.SELECT) {
3412
+ const selectProperty = (_c = field.properties) === null || _c === void 0 ? void 0 : _c.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3413
+ if (isExistingField) {
3414
+ const exField = clonedApp.views[view][field.id];
3415
+ const exSelectProperty = (_d = exField.properties) === null || _d === void 0 ? void 0 : _d.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3416
+ const isMultivalued = !!((_e = selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value) === null || _e === void 0 ? void 0 : _e.canSelectMultiple);
3417
+ const exIsMultivalued = !!((_f = exSelectProperty === null || exSelectProperty === void 0 ? void 0 : exSelectProperty.value) === null || _f === void 0 ? void 0 : _f.canSelectMultiple);
3418
+ if (isMultivalued === exIsMultivalued) {
3419
+ fieldValue = exField.value;
3420
+ }
3421
+ }
3422
+ else {
3423
+ const isEnhancedSelect = !!(selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.isOptionsEditorEnhanced);
3424
+ const defaultValue = isEnhancedSelect && !!(selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value.defaultSelectOption)
3425
+ ? selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value.defaultSelectOptionValue
3426
+ : '';
3427
+ if (defaultValue) {
3428
+ fieldValue = defaultValue;
3429
+ }
3430
+ }
3431
+ }
3432
+ if (isExistingField) {
3433
+ const exField = clonedApp.views[view][field.id];
3434
+ 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 });
3435
+ }
3436
+ else {
3437
+ const existingFieldsLen = Object.values(clonedApp.views[view]).filter((v) => !v.isFixed && !v.isOptional).length;
3438
+ viewItems[field.id] = {
3439
+ type: field.type,
3440
+ properties: field.properties || [],
3441
+ isUsed: isFieldUsedInView,
3442
+ isOptional: false,
3443
+ isLockedValue: false,
3444
+ isFixed: false,
3445
+ value: fieldValue !== null && fieldValue !== void 0 ? fieldValue : null,
3446
+ pos: ((_h = clonedApp.syncViewFieldOrder) === null || _h === void 0 ? void 0 : _h[view]) ? idx : existingFieldsLen + idx,
3447
+ };
3448
+ }
3449
+ });
3450
+ return {
3451
+ [view]: viewItems,
3452
+ };
3453
+ }));
3454
+ }
3455
+ function buildAudience(accessRightObjectList) {
3456
+ return accessRightObjectList.map((accessRightObject) => {
3457
+ return {
3458
+ id: `${accessRightObject.type}/${accessRightObject.id}`,
3459
+ uri: `${accessRightObject.type}/${accessRightObject.id}`,
3460
+ shortUri: `${accessRightObject.type}/${accessRightObject.id}`,
3461
+ title: accessRightObject.title,
3462
+ name: accessRightObject.title,
3463
+ mainType: accessRightObject.type,
3464
+ type: accessRightObject.mainType,
3465
+ label: accessRightObject.type,
3466
+ cssClass: accessRightObject._cssClass,
3467
+ cssColor: accessRightObject._cssColor,
3468
+ class: accessRightObject._cssClass,
3469
+ Pseudo: accessRightObject.title,
3470
+ _url: accessRightObject._url,
3471
+ };
3472
+ });
3473
+ }
3474
+ function populateFieldsAndViews(app, appS, state) {
3475
+ const tables = app.typeModel.tables;
3476
+ const displays = app.typeModel.displays;
3477
+ if (!displays) {
3478
+ return;
3479
+ }
3480
+ const registeredFields = new Map();
3481
+ Object.entries(displays).forEach((displaysEntry) => {
3482
+ const [displayName, displayValue] = displaysEntry;
3483
+ if (Object.keys(installedToV2ViewNames).includes(displayName)) {
3484
+ buildView(appS, registeredFields, displayName, displayValue, tables, state);
3485
+ }
3486
+ });
3487
+ buildListView(appS, registeredFields, app.columns, tables, state);
3488
+ buildFilterView(appS, registeredFields, app.attrExposed, tables, state);
3489
+ }
3490
+ function buildView(appS, registeredFields, displayName, displayValue, tables, state) {
3491
+ const newName = installedToV2ViewNames[displayName];
3492
+ appS.views[newName] = {};
3493
+ displayValue.composants.forEach((viewComponent, index) => {
3494
+ let field = undefined;
3495
+ if (viewComponent.name && ignoredFields.includes(viewComponent.name)) {
3496
+ return;
3497
+ }
3498
+ const [fieldIdx, fixedInfo] = createOrGetField(appS, registeredFields, viewComponent, tables, state);
3499
+ if (fieldIdx === -1 && fixedInfo) {
3500
+ switch (fixedInfo.ref) {
3501
+ case 'title':
3502
+ addTitleToView(newName, appS, fixedInfo);
3503
+ break;
3504
+ case 'alertAuthor':
3505
+ addAlertAuthorToView(newName, appS, fixedInfo);
3506
+ break;
3507
+ case 'sendAlert':
3508
+ addSendAlertToView(newName, appS, fixedInfo);
3509
+ break;
3510
+ case 'publishTo':
3511
+ addPublishToToView(newName, appS, fixedInfo);
3512
+ break;
3513
+ default:
3514
+ console.error('fixed field info with unsupported ref ', fixedInfo);
3515
+ break;
3516
+ }
3517
+ }
3518
+ else if (fieldIdx !== -1) {
3519
+ field = appS.fields[fieldIdx];
3520
+ if (!field || !field.views) {
3521
+ throw new Error(`error converting installed app to V2: created field not found in fields array: ${fieldIdx}, ${fixedInfo}`);
3522
+ }
3523
+ field.views[newName] = true;
3524
+ addFieldToView(newName, field, appS, index, fixedInfo);
3525
+ }
3526
+ });
3527
+ }
3528
+ function buildListView(appS, registeredFields, columns, tables, state) {
3529
+ if (!columns) {
3530
+ return;
3531
+ }
3532
+ Object.keys(columns).forEach((fieldRef, index) => {
3533
+ addFieldToViewFromRef(appS, registeredFields, tables, 'list', fieldRef, index, state);
3534
+ });
3535
+ }
3536
+ function buildFilterView(appS, registeredFields, attrExposed, tables, state) {
3537
+ attrExposed.forEach((fieldRef, index) => {
3538
+ addFieldToViewFromRef(appS, registeredFields, tables, 'filter', fieldRef, index, state);
3539
+ });
3540
+ }
3541
+ function addFieldToViewFromRef(appS, registeredFields, tables, viewName, fieldRef, index, state) {
3542
+ switch (fieldRef) {
3543
+ case 'title':
3544
+ addTitleToView(viewName, appS, { ref: 'title', fixedValue: undefined });
3545
+ break;
3546
+ case 'iduser':
3547
+ case 'idUser':
3548
+ addUserToView(viewName, appS);
3549
+ break;
3550
+ case 'datecreation':
3551
+ case 'dateCreation':
3552
+ addDateCreationToView(viewName, appS);
3553
+ break;
3554
+ default:
3555
+ defaultFieldCreation(appS, registeredFields, tables, viewName, fieldRef, index, state);
3556
+ break;
3557
+ }
3558
+ }
3559
+ function defaultFieldCreation(appS, registeredFields, tables, viewName, fieldRef, index, state) {
3560
+ const fieldIndex = createOrGetFieldFromRef(appS, registeredFields, tables, fieldRef, state);
3561
+ const field = appS.fields[fieldIndex];
3562
+ if (!field || !field.views) {
3563
+ throw new Error(`error converting installed app to V2: unable to handle ${fieldRef} in list view`);
3564
+ }
3565
+ field.views[viewName] = true;
3566
+ addFieldToView(viewName, field, appS, index, undefined);
3567
+ }
3568
+ function createOrGetFieldFromRef(appS, registeredFields, tables, fieldRef, state) {
3569
+ const knownIndex = registeredFields.get(fieldRef);
3570
+ if (knownIndex !== undefined) {
3571
+ return knownIndex;
3572
+ }
3573
+ const [ref, indexCreated] = createStudioDefinedField(appS, fieldRef, tables, state);
3574
+ registeredFields.set(ref, indexCreated);
3575
+ return indexCreated;
3576
+ }
3577
+ function createOrGetField(appS, registeredFields, viewComponent, tables, state) {
3578
+ if (viewComponent.name !== undefined && viewComponent.element === 'attr') {
3579
+ if (specialAttrName.includes(viewComponent.name)) {
3580
+ return [-1, { ref: viewComponent.name, fixedValue: undefined }];
3581
+ }
3582
+ const knownIndex = registeredFields.get(viewComponent.name);
3583
+ if (knownIndex !== undefined) {
3584
+ return [knownIndex, undefined];
3585
+ }
3586
+ const [ref, indexCreated] = createStudioDefinedField(appS, viewComponent.name, tables, state);
3587
+ registeredFields.set(ref, indexCreated);
3588
+ return [indexCreated, undefined];
3589
+ }
3590
+ else if (viewComponent.element === 'html') {
3591
+ const htmlCode = viewComponent.html;
3592
+ if (htmlCode === undefined) {
3593
+ console.error('error while parsing studio installed html attr in a view: no html code');
3594
+ return [-1, undefined];
3595
+ }
3596
+ if (htmlCode.includes('<JAMESPOT.STUDIO.FIXED>')) {
3597
+ const startPos = htmlCode.indexOf('<JAMESPOT.STUDIO.FIXED>') + '<JAMESPOT.STUDIO.FIXED>'.length;
3598
+ const endPos = htmlCode.indexOf('</JAMESPOT.STUDIO.FIXED>');
3599
+ const formItemRefString = htmlCode.substring(startPos, endPos);
3600
+ try {
3601
+ const formItemRef = JSON.parse(formItemRefString);
3602
+ if ((formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref.toUpperCase()) in ExtraAppFieldsItemViews ||
3603
+ specialAttrName.includes(formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref)) {
3604
+ return [-1, formItemRef];
3605
+ }
3606
+ const knownIndex = registeredFields.get(formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref);
3607
+ if (knownIndex !== undefined) {
3608
+ return [knownIndex, formItemRef];
3609
+ }
3610
+ const [ref, indexCreated] = createStudioDefinedField(appS, formItemRef.ref, tables, state);
3611
+ registeredFields.set(ref, indexCreated);
3612
+ return [indexCreated, formItemRef];
3613
+ }
3614
+ catch (_) {
3615
+ console.error('error while parsing studio installed fixed attr in a view: json parsing failed');
3616
+ return [-1, undefined];
3617
+ }
3618
+ }
3619
+ else if (htmlCode.includes('<JAMESPOT.STUDIO.CODEHTML>')) {
3620
+ try {
3621
+ const startPosCode = htmlCode.indexOf('<JAMESPOT.STUDIO.CODEHTML>') + '<JAMESPOT.STUDIO.CODEHTML>'.length;
3622
+ const endPosCode = htmlCode.indexOf('</JAMESPOT.STUDIO.CODEHTML>');
3623
+ const formItemString = htmlCode.substring(startPosCode, endPosCode);
3624
+ const formItem = JSON.parse(formItemString);
3625
+ const knownIndex = registeredFields.get(formItem === null || formItem === void 0 ? void 0 : formItem.name);
3626
+ if (knownIndex !== undefined) {
3627
+ return [knownIndex, undefined];
3628
+ }
3629
+ const htmlField = createHtmlField(formItem);
3630
+ const indexCreated = appS.fields.push(htmlField) - 1;
3631
+ registeredFields.set(htmlField.id, indexCreated);
3632
+ return [indexCreated, undefined];
3633
+ }
3634
+ catch (_) {
3635
+ console.error('error while parsing studio installed codehtml attr in a view: json parsing failed');
3636
+ return [-1, undefined];
3637
+ }
3638
+ }
3639
+ else {
3640
+ console.error('error while parsing studio installed html attr in a view: unknown html format');
3641
+ return [-1, undefined];
3642
+ }
3643
+ }
3644
+ else if (viewComponent.element === 'image') {
3645
+ const knownIndex = registeredFields.get('image');
3646
+ if (knownIndex !== undefined) {
3647
+ return [knownIndex, undefined];
3648
+ }
3649
+ const imageField = createImageField();
3650
+ const indexCreated = appS.fields.push(imageField) - 1;
3651
+ registeredFields.set('image', indexCreated);
3652
+ return [indexCreated, undefined];
3653
+ }
3654
+ else if (viewComponent.element === 'publishTo') {
3655
+ return [-1, { ref: 'publishTo', fixedValue: undefined }];
3656
+ }
3657
+ else {
3658
+ console.error('error while parsing studio installed attr in a view: unknown attr :O');
3659
+ return [-1, undefined];
3660
+ }
3661
+ }
3662
+ function createStudioDefinedField(appS, ref, tables, state) {
3663
+ const installedField = getInstalledField(ref, tables);
3664
+ const type = getFormItemType(installedField);
3665
+ const v2Field = (function createField() {
3666
+ switch (type) {
3667
+ case AppFormItemTypes.ADDFILEATTACHMENT:
3668
+ return createAddfileattachmentField(installedField);
3669
+ case AppFormItemTypes.NUMBER:
3670
+ return createNumberField(installedField);
3671
+ case AppFormItemTypes.TAGS:
3672
+ return createTagsField(installedField);
3673
+ case AppFormItemTypes.SELECT:
3674
+ return createSelectField(installedField);
3675
+ case AppFormItemTypes.RADIO:
3676
+ return createRadioField(installedField);
3677
+ case AppFormItemTypes.CHECKBOX:
3678
+ return createCheckboxField(installedField);
3679
+ case AppFormItemTypes.CONTENTLINK:
3680
+ return createContentLinkField(installedField, state);
3681
+ case AppFormItemTypes.DESCRIPTION:
3682
+ return createDescriptionField(installedField);
3683
+ case AppFormItemTypes.TEXTAREAHTML:
3684
+ return createTextareaHTMLField(installedField);
3685
+ case AppFormItemTypes.DATE:
3686
+ return createDateField(installedField);
3687
+ case AppFormItemTypes.DATETIME:
3688
+ return createDatetimeField(installedField);
3689
+ case AppFormItemTypes.URL:
3690
+ return createUrlField(installedField);
3691
+ case AppFormItemTypes.EMAIL:
3692
+ return createEmailField(installedField);
3693
+ case AppFormItemTypes.TOGGLE:
3694
+ return createToggleField(installedField);
3695
+ case AppFormItemTypes.USERLINK:
3696
+ return createUserLinkField(installedField);
3697
+ case AppFormItemTypes.TEXTAREA:
3698
+ return createTextAreaField(installedField);
3699
+ case AppFormItemTypes.TEXT:
3700
+ default:
3701
+ return createTextField(installedField);
3702
+ }
3703
+ })();
3704
+ const index = appS.fields.push(v2Field) - 1;
3705
+ return [ref, index];
3706
+ }
3707
+ function getInstalledField(ref, tables) {
3708
+ var _a;
3709
+ let foundField = undefined;
3710
+ for (let i = 0; i < tables.length && !foundField; i++) {
3711
+ foundField = (_a = tables[i]) === null || _a === void 0 ? void 0 : _a.attributes.find((attr) => {
3712
+ return attr.name === ref;
3713
+ });
3714
+ }
3715
+ if (!foundField) {
3716
+ throw new Error('error converting installed app to V2: installed field not found in tables ' + ref);
3717
+ }
3718
+ return foundField;
3719
+ }
3720
+ function addFieldToView(viewName, field, appS, index, fixedInfo) {
3721
+ var _a;
3722
+ if (field.views) {
3723
+ field.views[viewName] = true;
3724
+ appS.views[viewName][field.id] = {
3725
+ type: field.type,
3726
+ properties: field.properties || [],
3727
+ isUsed: true,
3728
+ isOptional: false,
3729
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3730
+ isFixed: false,
3731
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : null,
3732
+ pos: index,
3733
+ };
3734
+ }
3735
+ }
3736
+ function getFormItemType(installedField) {
3737
+ var _a, _b, _c;
3738
+ switch (installedField.widget.type) {
3739
+ case 'number':
3740
+ return AppFormItemTypes.NUMBER;
3741
+ case 'taxonomy':
3742
+ return AppFormItemTypes.TAGS;
3743
+ case 'date':
3744
+ return AppFormItemTypes.DATE;
3745
+ case 'datetime':
3746
+ return AppFormItemTypes.DATETIME;
3747
+ case 'select':
3748
+ return AppFormItemTypes.SELECT;
3749
+ case 'radio':
3750
+ return AppFormItemTypes.RADIO;
3751
+ case 'url':
3752
+ return AppFormItemTypes.URL;
3753
+ case 'email':
3754
+ return AppFormItemTypes.EMAIL;
3755
+ case 'file':
3756
+ return AppFormItemTypes.ADDFILEATTACHMENT;
3757
+ case 'checkbox':
3758
+ if (((_a = installedField.widget.options) === null || _a === void 0 ? void 0 : _a['1']) === 'GLOBAL_Yes') {
3759
+ return AppFormItemTypes.TOGGLE;
3760
+ }
3761
+ return AppFormItemTypes.CHECKBOX;
3762
+ case 'uri':
3763
+ if (((_b = installedField.widget.params) === null || _b === void 0 ? void 0 : _b.views) === 'user') {
3764
+ return AppFormItemTypes.USERLINK;
3765
+ }
3766
+ if (((_c = installedField.widget.params) === null || _c === void 0 ? void 0 : _c.views) === 'article') {
3767
+ return AppFormItemTypes.CONTENTLINK;
3768
+ }
3769
+ break;
3770
+ case 'textarea':
3771
+ if (installedField.attrType === 'longtext') {
3772
+ return AppFormItemTypes.TEXTAREA;
3773
+ }
3774
+ if (installedField.attrType === 'html') {
3775
+ if (installedField.name === 'description') {
3776
+ return AppFormItemTypes.DESCRIPTION;
3777
+ }
3778
+ return AppFormItemTypes.TEXTAREAHTML;
3779
+ }
3780
+ break;
3781
+ case 'text':
3782
+ return AppFormItemTypes.TEXT;
3783
+ }
3784
+ throw new Error('error converting installed app to V2: installed field type not recognized for field ' + installedField.name);
3785
+ }
3786
+ function addTitleToView(newName, appS, fixedInfo) {
3787
+ var _a;
3788
+ const fieldId = 'title';
3789
+ appS.views[newName][fieldId] = {
3790
+ type: ExtraAppFieldsItemViews.TITLE,
3791
+ properties: [],
3792
+ isUsed: true,
3793
+ isOptional: false,
3794
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3795
+ isFixed: true,
3796
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : null,
3797
+ pos: 0,
3798
+ };
3799
+ }
3800
+ function addAlertAuthorToView(newName, appS, fixedInfo) {
3801
+ const fieldId = 'alertAuthor';
3802
+ appS.views[newName][fieldId] = {
3803
+ type: ExtraAppFieldsItemViews.RECEIVEACOPY,
3804
+ properties: [],
3805
+ isUsed: true,
3806
+ isOptional: true,
3807
+ isLockedValue: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined,
3808
+ isFixed: false,
3809
+ value: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined ? fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue : true,
3810
+ pos: 300,
3811
+ };
3812
+ }
3813
+ function addSendAlertToView(newName, appS, fixedInfo) {
3814
+ const fieldId = 'sendAlert';
3815
+ appS.views[newName][fieldId] = {
3816
+ type: ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS,
3817
+ properties: [],
3818
+ isUsed: true,
3819
+ isOptional: true,
3820
+ isLockedValue: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined,
3821
+ isFixed: false,
3822
+ value: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined ? fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue : true,
3823
+ pos: 200,
3824
+ };
3825
+ }
3826
+ function addPublishToToView(newName, appS, fixedInfo) {
3827
+ var _a;
3828
+ const fieldId = 'publishTo';
3829
+ appS.views[newName][fieldId] = {
3830
+ type: ExtraAppFieldsItemViews.PUBLISHTO,
3831
+ properties: [],
3832
+ isUsed: true,
3833
+ isOptional: true,
3834
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3835
+ isFixed: false,
3836
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : [],
3837
+ pos: 100,
3838
+ };
3839
+ }
3840
+ function addUserToView(newName, appS) {
3841
+ const fieldId = 'user';
3842
+ appS.views[newName][fieldId] = {
3843
+ type: ExtraAppFieldsItemViews.USER,
3844
+ properties: [],
3845
+ isUsed: true,
3846
+ isOptional: false,
3847
+ isLockedValue: false,
3848
+ isFixed: true,
3849
+ value: null,
3850
+ pos: 1,
3851
+ };
3852
+ }
3853
+ function addDateCreationToView(newName, appS) {
3854
+ const fieldId = 'dateCreation';
3855
+ appS.views[newName][fieldId] = {
3856
+ type: ExtraAppFieldsItemViews.CREATIONDATE,
3857
+ properties: [],
3858
+ isUsed: true,
3859
+ isOptional: true,
3860
+ isLockedValue: false,
3861
+ isFixed: false,
3862
+ value: null,
3863
+ pos: 100,
3864
+ };
3865
+ }
3866
+
3867
+ function InstalledAppStudioAdapter(serverApp, serverApps, state) {
3136
3868
  var _a, _b, _c, _d;
3137
3869
  const { version, dateCreation } = serverApp.manifest;
3138
3870
  const appTypeServer = serverApp.typeModel;
3139
3871
  const views = Object.assign({}, ...viewsList.map((view) => ({
3140
- [view]: [],
3872
+ [view]: {},
3141
3873
  })));
3142
3874
  const studioApp = {
3143
3875
  idApp: serverApp.idApp,
3144
3876
  status: _formatStatus(serverApp),
3145
3877
  studioVersion: 2,
3146
- manifest: Object.assign({ appShortName: serverApp.name, appName: serverApp.label, description: serverApp.description, author: serverApp.author, cssColor: (_a = appTypeServer.cssColor) !== null && _a !== void 0 ? _a : '#392994', cssClass: { label: (_b = appTypeServer.cssClass) !== null && _b !== void 0 ? _b : 'star', value: (_c = appTypeServer.cssClass) !== null && _c !== void 0 ? _c : 'star' }, version: version, dateCreation: dateCreation, checkAccess: serverApp.checkAccess, attrExposed: serverApp.attrExposed, viewSolr: serverApp.view, typeLabel: (_d = appTypeServer.typeLabel) !== null && _d !== void 0 ? _d : {} }, (serverApp.articlesCount && { articlesCount: serverApp.articlesCount })),
3878
+ manifest: {
3879
+ appShortName: serverApp.label,
3880
+ appName: serverApp.label,
3881
+ description: serverApp.description,
3882
+ author: serverApp.author,
3883
+ cssColor: (_a = appTypeServer.cssColor) !== null && _a !== void 0 ? _a : '#392994',
3884
+ cssClass: { label: (_b = appTypeServer.cssClass) !== null && _b !== void 0 ? _b : 'star', value: (_c = appTypeServer.cssClass) !== null && _c !== void 0 ? _c : 'star' },
3885
+ version: version,
3886
+ dateCreation: dateCreation,
3887
+ checkAccess: false,
3888
+ accessRightList: "",
3889
+ attrExposed: [],
3890
+ viewSolr: serverApp.view ? STUDIO_VIEW.SOLR : STUDIO_VIEW.NOT_SOLR,
3891
+ typeLabel: appTypeServer.typeLabel,
3892
+ articlesCount: (_d = serverApp.articlesCount) !== null && _d !== void 0 ? _d : 0,
3893
+ },
3147
3894
  fields: [],
3148
3895
  views,
3149
- installFor: serverApp.accessRightObjectList,
3896
+ installFor: serverApp.accessRightObjectList ? buildAudience(serverApp.accessRightObjectList) : [],
3150
3897
  audience: serverApp.checkAccess === false ? AUDIENCE.ALL : AUDIENCE.CUSTOM,
3151
3898
  };
3899
+ populateFieldsAndViews(serverApp, studioApp, state);
3900
+ studioApp.views = updateViewsFromFields(studioApp, studioApp.fields);
3152
3901
  const inWorkAppVersion = _findAssociatedDraft(serverApp.idApp, serverApps);
3153
3902
  if (!inWorkAppVersion)
3154
3903
  return studioApp;
@@ -3170,12 +3919,13 @@ function DraftAppStudioAdapter(serverApp) {
3170
3919
  manifest: parsedJson.manifest,
3171
3920
  fields: parsedJson.fields,
3172
3921
  views: parsedJson.views,
3922
+ syncViewFieldOrder: parsedJson.syncViewFieldOrder,
3173
3923
  audience: parsedJson.audience,
3174
3924
  installFor: parsedJson.installFor,
3175
3925
  };
3176
3926
  }
3177
3927
  else {
3178
- return Object.assign(Object.assign({}, migrateJson(JSON.parse(serverApp.value))), { status: _formatStatus(serverApp) });
3928
+ return Object.assign(Object.assign({}, migrateJson(parsedJson)), { status: _formatStatus(serverApp), migratedFrom: 1 });
3179
3929
  }
3180
3930
  }
3181
3931
  function _formatStatus(serverApp) {
@@ -3192,11 +3942,11 @@ function _findAssociatedDraft(idApp, serverApps) {
3192
3942
  function _findAssociatedInstalled(idApp, serverApps) {
3193
3943
  return !!serverApps.find((app) => app.idApp === idApp && app.status === StudioApplicationStatus.installed);
3194
3944
  }
3195
- function serverAppsToStudioApps(serverApps) {
3945
+ function serverAppsToStudioApps(serverApps, state) {
3196
3946
  const studioApps = serverApps
3197
3947
  .map((serverApp) => {
3198
3948
  if (serverApp.status === StudioApplicationStatus.installed) {
3199
- return InstalledAppStudioAdapter(serverApp, serverApps);
3949
+ return InstalledAppStudioAdapter(serverApp, serverApps, state);
3200
3950
  }
3201
3951
  else {
3202
3952
  if (_findAssociatedInstalled(serverApp.idApp, serverApps))
@@ -3262,7 +4012,13 @@ function renderAppView(viewSolr, listView) {
3262
4012
  if (viewSolr === STUDIO_VIEW.SOLR) {
3263
4013
  let xml = '<AppView>solr</AppView>';
3264
4014
  const formItemIdInList = [];
3265
- Object.entries(listView).forEach(([fieldId, field]) => {
4015
+ Object.entries(listView).sort((a, b) => a[1].pos - b[1].pos).forEach(([fieldId, field]) => {
4016
+ if (!field.isUsed) {
4017
+ return;
4018
+ }
4019
+ if ([AppFormItemTypes.IMAGE].includes(field.type)) {
4020
+ return;
4021
+ }
3266
4022
  formItemIdInList.push(getAttrNameFormItem(field, fieldId));
3267
4023
  });
3268
4024
  xml += `<AppColumns>${formItemIdInList.join()}</AppColumns>`;
@@ -3272,8 +4028,12 @@ function renderAppView(viewSolr, listView) {
3272
4028
  }
3273
4029
  function renderAppSearch(searchView) {
3274
4030
  const formItemIdInFilter = [];
3275
- Object.entries(searchView).forEach(([fieldId, field]) => {
3276
- if (![ExtraAppFieldsItemViews.TITLE, AppFormItemTypes.IMAGE].includes(field.type))
4031
+ Object.entries(searchView).sort((a, b) => a[1].pos - b[1].pos).forEach(([fieldId, field]) => {
4032
+ if (!field.isUsed) {
4033
+ return;
4034
+ }
4035
+ const list = [ExtraAppFieldsItemViews.TITLE, AppFormItemTypes.IMAGE];
4036
+ if (!list.includes(field.type))
3277
4037
  formItemIdInFilter.push(getAttrNameFormItem(field, fieldId));
3278
4038
  });
3279
4039
  return `<AttrExposed>${formItemIdInFilter.join()}</AttrExposed>`;
@@ -3308,13 +4068,13 @@ function renderAudience(audience, installFor) {
3308
4068
  return '';
3309
4069
  }
3310
4070
  function renderPrimaryFields(fields) {
3311
- const primaryFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => AppFormPrimaryList.includes(field.type));
4071
+ const primaryFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => AppFormPrimaryListValues.includes(field.type));
3312
4072
  if (primaryFields.length === 0)
3313
4073
  return '';
3314
4074
  return `<primaryFields>${primaryFields.map((field) => formItem2xml(field)).join('')}</primaryFields>`;
3315
4075
  }
3316
4076
  function renderCustomFields(fields) {
3317
- const customFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => !AppFormPrimaryList.includes(field.type));
4077
+ const customFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => !AppFormPrimaryListValues.includes(field.type));
3318
4078
  const filteredCustomFields = customFields === null || customFields === void 0 ? void 0 : customFields.filter((field) => field.type !== AppFormItemTypes.IMAGE);
3319
4079
  if (filteredCustomFields.length === 0)
3320
4080
  return '';
@@ -3380,14 +4140,20 @@ function renderWidget(fieldType, fieldProperties) {
3380
4140
  const isMultiple = optionEditor.value.canSelectMultiple;
3381
4141
  const options = optionEditor.value.propertyOptions;
3382
4142
  const hasDefaultValue = optionEditor.value.defaultSelectOption;
3383
- const defaultValue = optionEditor.value.defaultSelectOptionValue;
4143
+ const defaultValue = optionEditor.value.defaultSelectOptionValue.value;
4144
+ const userCanModifiyByComment = optionEditor.value.userCanModifiyByComment;
3384
4145
  return `<widget form="select" ${isMultiple ? 'multiple="1"' : ''}>
3385
4146
  <options>
3386
4147
  ${options
3387
4148
  .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
3388
4149
  .join('')}
3389
4150
  </options>
3390
- ${hasDefaultValue ? `<params><param key="defaultValue" value="${defaultValue}"/></params>` : ''}
4151
+ ${hasDefaultValue || userCanModifiyByComment
4152
+ ? `<params>
4153
+ ${hasDefaultValue ? `<param key="defaultValue" value="${defaultValue}"/>` : ''}
4154
+ ${userCanModifiyByComment ? `<param key="explain" value="1"/>` : ''}
4155
+ </params>`
4156
+ : ''}
3391
4157
  </widget>`;
3392
4158
  }
3393
4159
  case AppFormItemTypes.RADIO: {
@@ -3526,9 +4292,7 @@ function renderFieldTypeToXmlType(fieldType) {
3526
4292
  case AppFormItemTypes.TAGS:
3527
4293
  return 'taxonomy';
3528
4294
  case AppFormItemTypes.TEXT:
3529
- case AppFormItemTypes.SELECT:
3530
4295
  case AppFormItemTypes.RADIO:
3531
- case AppFormItemTypes.CHECKBOX:
3532
4296
  case AppFormItemTypes.URL:
3533
4297
  case AppFormItemTypes.EMAIL:
3534
4298
  case AppFormItemTypes.ADDFILEATTACHMENT:
@@ -3537,6 +4301,8 @@ function renderFieldTypeToXmlType(fieldType) {
3537
4301
  case AppFormItemTypes.CONTENTLINK:
3538
4302
  return 'text';
3539
4303
  case AppFormItemTypes.TEXTAREA:
4304
+ case AppFormItemTypes.CHECKBOX:
4305
+ case AppFormItemTypes.SELECT:
3540
4306
  return 'longtext';
3541
4307
  case AppFormItemTypes.DATE:
3542
4308
  return 'date';
@@ -3577,7 +4343,9 @@ function renderDisplays(studioApp) {
3577
4343
  let toRet = '';
3578
4344
  Object.entries(studioApp.views).forEach(([viewName, viewContent]) => {
3579
4345
  if (Object.prototype.hasOwnProperty.call(internal2XmlView, viewName)) {
3580
- const viewField = Object.entries(viewContent);
4346
+ const viewField = Object.entries(viewContent)
4347
+ .filter((a) => a[1].isUsed)
4348
+ .sort((a, b) => a[1].pos - b[1].pos);
3581
4349
  toRet += `<display view="${internal2XmlView[viewName]}" mode="${viewName === 'view' ? 'view' : 'form'}">
3582
4350
  ${viewField.map(([fieldId, view]) => renderDisplayAttr(fieldId, view)).join('')}
3583
4351
  </display>`;
@@ -3629,16 +4397,21 @@ function renderDisplayAttr(fieldId, view) {
3629
4397
  xml += `<input type="hidden" name="${attrName}[]" value=${JSON.stringify(view.value.uri)}>`;
3630
4398
  }
3631
4399
  else if (view.type === AppFormItemTypes.SELECT) {
3632
- const values = view.value;
3633
4400
  const canSelectMultiple = (_a = view.properties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR)) === null || _a === void 0 ? void 0 : _a.value.canSelectMultiple;
3634
- values.forEach((value) => {
3635
- xml += `<input type="hidden" name="${attrName}${canSelectMultiple ? '[]' : ''}" value="${value.value}">`;
3636
- });
4401
+ if (canSelectMultiple) {
4402
+ const values = view.value;
4403
+ values.forEach((value) => {
4404
+ xml += `<input type="hidden" name="${attrName}[]" value="${value.value}">`;
4405
+ });
4406
+ }
4407
+ else {
4408
+ xml += `<input type="hidden" name="${attrName}" value="${view.value.value}">`;
4409
+ }
3637
4410
  }
3638
4411
  else if (view.type === AppFormItemTypes.CHECKBOX) {
3639
4412
  const values = view.value;
3640
4413
  values.forEach((value) => {
3641
- xml += `<input type="hidden" name="${attrName}[]" value="${value.value}">`;
4414
+ xml += `<input type="hidden" name="${attrName}[]" value="${value}">`;
3642
4415
  });
3643
4416
  }
3644
4417
  else if (view.type === AppFormItemTypes.DATE) {
@@ -3652,21 +4425,28 @@ function renderDisplayAttr(fieldId, view) {
3652
4425
  }
3653
4426
  else if (view.type === AppFormItemTypes.DATETIME) {
3654
4427
  const dateValue = new Date(view.value);
3655
- const xmlFixedValue = [
4428
+ const xmlFixedValue = `${[
3656
4429
  pad(dateValue.getDate()),
3657
4430
  pad(dateValue.getMonth() + 1),
3658
4431
  dateValue.getFullYear(),
3659
- pad(dateValue.getHours()),
3660
- pad(dateValue.getMinutes()),
3661
- pad(dateValue.getSeconds()),
3662
- ].join('/');
4432
+ ].join('/')} ${pad(dateValue.getHours())}:${pad(dateValue.getMinutes())}:${pad(dateValue.getSeconds())}`;
3663
4433
  xml += '<input type="hidden" name="' + attrName + '" value="' + xmlFixedValue + '">';
3664
4434
  }
3665
4435
  else if (view.type === AppFormItemTypes.TAGS) {
3666
4436
  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(',')}">`;
3667
4437
  }
3668
4438
  else if (view.type === AppFormItemTypes.DESCRIPTION || view.type === AppFormItemTypes.TEXTAREAHTML) {
3669
- xml += `<input type="hidden" name="${attrName}" value="${view.value.html}">`;
4439
+ xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
4440
+ }
4441
+ else if (view.type === ExtraAppFieldsItemViews.RECEIVEACOPY) {
4442
+ if (view.value) {
4443
+ xml += `<input type="hidden" name="alertAuthor[jamespot]"><input type="hidden" name="alertAuthor[]" value="1">`;
4444
+ }
4445
+ }
4446
+ else if (view.type === ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS) {
4447
+ if (view.value) {
4448
+ xml += `<input type="hidden" name="sendAlert[jamespot]"><input type="hidden" name="sendAlert[]" value="1">`;
4449
+ }
3670
4450
  }
3671
4451
  else {
3672
4452
  xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
@@ -3676,7 +4456,14 @@ function renderDisplayAttr(fieldId, view) {
3676
4456
  else {
3677
4457
  switch (view.type) {
3678
4458
  case AppFormItemTypes.CODEHTML: {
3679
- xml += `<html><![CDATA[ <!-- <JAMESPOT.STUDIO.CODEHTML>${view.value}</JAMESPOT.STUDIO.CODEHTML><JAMESPOT.STUDIO.FIELD_POS>${view.pos}</JAMESPOT.STUDIO.FIELD_POS>-->${view.value}]]></html>`;
4459
+ const fieldToInclude = {
4460
+ id: fieldId,
4461
+ name: fieldId,
4462
+ properties: {
4463
+ code: view.value,
4464
+ },
4465
+ };
4466
+ 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>`;
3680
4467
  break;
3681
4468
  }
3682
4469
  case AppFormItemTypes.IMAGE:
@@ -3703,12 +4490,12 @@ const initialState$1 = {
3703
4490
  installStudioAppStatus: 'idle',
3704
4491
  hasChanged: false,
3705
4492
  };
3706
- const fetchCurrentStudioApp = createAsyncThunk('studio/fetchCurrentStudioApp', ({ idApp, status }, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
4493
+ const fetchCurrentStudioApp = createAsyncThunk('studio/fetchCurrentStudioApp', ({ idApp, status }, { extra, rejectWithValue, getState }) => __awaiter(void 0, void 0, void 0, function* () {
3707
4494
  const jApi = extra.jApi;
3708
4495
  const error = { error: 1, errorMsg: 'Error fetching application' };
3709
4496
  try {
3710
4497
  const studioApplicationBase = (yield jApi.application.get(idApp, status)).result;
3711
- const studioApplication = serverAppsToStudioApps([studioApplicationBase])[0];
4498
+ const studioApplication = serverAppsToStudioApps([studioApplicationBase], getState())[0];
3712
4499
  if (!studioApplication) {
3713
4500
  return rejectWithValue(error);
3714
4501
  }
@@ -3812,16 +4599,22 @@ const CurrentStudioAppSlice = createSlice({
3812
4599
  },
3813
4600
  });
3814
4601
 
3815
- function cloneStudioAppFromExistingApp(existingApp, author) {
3816
- const newApp = existingApp.inWorkVersion
3817
- ? JSON.parse(JSON.stringify(existingApp.inWorkVersion))
4602
+ function cloneStudioAppFromExistingApp(existingApp, author, inWorkVersion) {
4603
+ const newApp = existingApp.studioVersion !== 2
4604
+ ? JSON.parse(JSON.stringify(migrateJson(existingApp)))
3818
4605
  : JSON.parse(JSON.stringify(existingApp));
3819
- const newAppId = v4();
3820
- const newAppName = `${existingApp.manifest.appName} Copie`;
3821
- newApp.idApp = newAppId;
3822
- newApp.status = APP_STATUS_TYPE.DRAFT;
3823
- newApp.manifest = Object.assign(Object.assign({}, newApp.manifest), { appName: newAppName, appShortName: newAppName, author: author || '', dateCreation: new Date().toISOString(), version: 0.1, articlesCount: 0 });
3824
- return [newApp, newAppId];
4606
+ delete newApp.inWorkVersion;
4607
+ if (!inWorkVersion) {
4608
+ const newAppId = v4();
4609
+ const newAppName = `${existingApp.manifest.appName} Copie`;
4610
+ newApp.idApp = newAppId;
4611
+ newApp.status = APP_STATUS_TYPE.DRAFT;
4612
+ newApp.manifest = Object.assign(Object.assign({}, newApp.manifest), { appName: newAppName, appShortName: newAppName, author: author || newApp.manifest.author || '', dateCreation: new Date().toISOString(), version: 0.1, articlesCount: 0 });
4613
+ }
4614
+ else {
4615
+ newApp.manifest.version = newApp.manifest.version + 0.1;
4616
+ }
4617
+ return [newApp, newApp.idApp];
3825
4618
  }
3826
4619
 
3827
4620
  function createNewStudioApp$1({ author, appName }) {
@@ -3883,37 +4676,78 @@ function createNewStudioApp$1({ author, appName }) {
3883
4676
  attrExposed: [],
3884
4677
  articlesCount: 0,
3885
4678
  },
4679
+ syncViewFieldOrder: {
4680
+ create: true,
4681
+ popup: true,
4682
+ view: true,
4683
+ edit: true,
4684
+ list: true,
4685
+ filter: true,
4686
+ },
3886
4687
  fields: [],
3887
4688
  views,
3888
- audience: AUDIENCE.ALL,
4689
+ audience: AUDIENCE.CUSTOM,
3889
4690
  installFor: [],
3890
4691
  },
3891
4692
  };
3892
4693
  }
3893
4694
 
4695
+ function appLexicalSort(a, b) {
4696
+ return a.manifest.appName > b.manifest.appName ? 1 : -1;
4697
+ }
3894
4698
  const initialState = {
3895
4699
  loadingStudioAppsList: 'idle',
3896
4700
  deleteStudioAppStatus: 'idle',
3897
4701
  suspendStudioAppStatus: 'idle',
3898
4702
  restartStudioAppStatus: 'idle',
3899
4703
  cloneStudioAppStatus: 'idle',
4704
+ createInWorkAppStatus: 'idle',
3900
4705
  createNewStudioAppStatus: 'idle',
3901
4706
  };
3902
- const fetchStudioAppsList = createAsyncThunk('studio/appsList', (_, { extra, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
4707
+ const fetchStudioAppsList = createAsyncThunk('studio/appsList', (intl, { extra, rejectWithValue, dispatch, getState }) => __awaiter(void 0, void 0, void 0, function* () {
3903
4708
  const jApi = extra.jApi;
3904
4709
  try {
3905
4710
  const { result } = yield jApi.application.list();
3906
- return yield Promise.all(result.map((app) => __awaiter(void 0, void 0, void 0, function* () {
4711
+ const taxonomies = yield jApi.taxonomy.list();
4712
+ const apps = yield Promise.all(result.map((app) => __awaiter(void 0, void 0, void 0, function* () {
3907
4713
  const coreApp = (yield jApi.application.get(app.idApp, app.status)).result;
3908
4714
  const articlesCount = (yield jApi.article.count(app.idApp)).result;
3909
4715
  return Object.assign(Object.assign({}, coreApp), { articlesCount });
3910
4716
  })));
4717
+ const transformedApps = serverAppsToStudioApps(apps, getState());
4718
+ transformedApps.forEach((app) => __awaiter(void 0, void 0, void 0, function* () {
4719
+ app.fields = updateTaxonomies(app.fields, taxonomies, intl);
4720
+ if (app.inWorkVersion) {
4721
+ app.inWorkVersion.fields = updateTaxonomies(app.inWorkVersion.fields, taxonomies, intl);
4722
+ }
4723
+ }));
4724
+ return transformedApps;
3911
4725
  }
3912
4726
  catch (_) {
3913
4727
  dispatch(Toast.actions.error({ label: 'GLOBAL_Technical_Error' }));
3914
4728
  throw rejectWithValue({ error: 1, errorMsg: 'Error retrieving applications' });
3915
4729
  }
3916
4730
  }));
4731
+ function updateTaxonomies(fields, taxonomies, intl) {
4732
+ return fields.map((field) => {
4733
+ var _a;
4734
+ if (field.type !== AppFormItemTypes.TAGS) {
4735
+ return field;
4736
+ }
4737
+ const newField = JSON.parse(JSON.stringify(field));
4738
+ const newFieldTaxoProp = (_a = newField.properties) === null || _a === void 0 ? void 0 : _a.find((prop) => {
4739
+ return prop.propertyType === AppFieldFormPropertyTypes.TAXONOMY;
4740
+ });
4741
+ const taxo = taxonomies.find((taxo) => {
4742
+ return taxo.id === (newFieldTaxoProp === null || newFieldTaxoProp === void 0 ? void 0 : newFieldTaxoProp.value.id);
4743
+ });
4744
+ if (taxo && newFieldTaxoProp) {
4745
+ newFieldTaxoProp.value.title = intl.formatMessage({ id: taxo.title });
4746
+ newFieldTaxoProp.value.type = taxo.type;
4747
+ }
4748
+ return newField;
4749
+ });
4750
+ }
3917
4751
  const createNewStudioApp = createAsyncThunk('studio/createApp', ({ appName, callback }, { extra, dispatch, rejectWithValue, getState }) => __awaiter(void 0, void 0, void 0, function* () {
3918
4752
  var _a;
3919
4753
  const jApi = extra.jApi;
@@ -3966,12 +4800,20 @@ const restartStudioApp = createAsyncThunk('studio/restartStudioApp', ({ idApp },
3966
4800
  throw rejectWithValue({ error: 1, errorMsg: 'Error restarting application' });
3967
4801
  }
3968
4802
  }));
3969
- const cloneStudioApp = createAsyncThunk('studio/cloneStudioApp', ({ idApp }, { extra, getState, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
4803
+ const cloneStudioApp = createAsyncThunk('studio/cloneStudioApp', ({ idApp, inWork }, { extra, getState, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
3970
4804
  var _b, _c;
3971
4805
  const jApi = extra.jApi;
3972
- const existingStudioApp = (_b = getState().studio.studioAppsList.studioAppsList) === null || _b === void 0 ? void 0 : _b.find((app) => app.idApp === idApp);
4806
+ let existingStudioApp = (_b = getState().studio.studioAppsList.studioAppsList) === null || _b === void 0 ? void 0 : _b.find((app) => app.idApp === idApp);
3973
4807
  if (!existingStudioApp)
3974
4808
  return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
4809
+ if (inWork) {
4810
+ if (existingStudioApp.inWorkVersion !== undefined) {
4811
+ existingStudioApp = existingStudioApp.inWorkVersion;
4812
+ }
4813
+ else {
4814
+ return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
4815
+ }
4816
+ }
3975
4817
  const currentUser = (_c = getState().userCurrent) === null || _c === void 0 ? void 0 : _c.uri;
3976
4818
  const [clonedStudioApp, newAppId] = cloneStudioAppFromExistingApp(existingStudioApp, currentUser);
3977
4819
  const clonedStudioAppReady = JSON.stringify(clonedStudioApp);
@@ -3985,12 +4827,33 @@ const cloneStudioApp = createAsyncThunk('studio/cloneStudioApp', ({ idApp }, { e
3985
4827
  return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
3986
4828
  }
3987
4829
  }));
4830
+ const createInWorkStudioApp = createAsyncThunk('studio/createInWorkStudioApp', ({ idApp }, { extra, getState, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
4831
+ var _d, _e;
4832
+ const jApi = extra.jApi;
4833
+ const existingStudioApp = (_d = getState().studio.studioAppsList.studioAppsList) === null || _d === void 0 ? void 0 : _d.find((app) => app.idApp === idApp);
4834
+ if (!existingStudioApp ||
4835
+ ![APP_STATUS_TYPE.INSTALLED, APP_STATUS_TYPE.SUSPENDED].includes(existingStudioApp.status)) {
4836
+ return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
4837
+ }
4838
+ const currentUser = (_e = getState().userCurrent) === null || _e === void 0 ? void 0 : _e.uri;
4839
+ const [clonedStudioApp, newAppId] = cloneStudioAppFromExistingApp(existingStudioApp, currentUser, true);
4840
+ const clonedStudioAppReady = JSON.stringify(clonedStudioApp);
4841
+ try {
4842
+ yield jApi.application.save(newAppId, clonedStudioAppReady, 'saved');
4843
+ dispatch(Toast.actions.success({ label: 'APPSTUDIO_AppItem_CreateInWork' }));
4844
+ return clonedStudioApp;
4845
+ }
4846
+ catch (_) {
4847
+ dispatch(Toast.actions.error({ label: 'GLOBAL_Technical_Error' }));
4848
+ return rejectWithValue({ error: 1, errorMsg: 'Error creating in work version for application' });
4849
+ }
4850
+ }));
3988
4851
  const StudioAppsListSlice = createSlice({
3989
4852
  name: 'studioAppsList',
3990
4853
  initialState,
3991
4854
  reducers: {
3992
4855
  setAppsList: (state, action) => {
3993
- state.studioAppsList = action.payload;
4856
+ state.studioAppsList = [...action.payload].sort(appLexicalSort);
3994
4857
  },
3995
4858
  },
3996
4859
  extraReducers: (builder) => {
@@ -4003,7 +4866,7 @@ const StudioAppsListSlice = createSlice({
4003
4866
  if (state.loadingStudioAppsList === 'pending') {
4004
4867
  state.loadingStudioAppsList = 'idle';
4005
4868
  }
4006
- state.studioAppsList = serverAppsToStudioApps(action.payload);
4869
+ state.studioAppsList = [...action.payload].sort(appLexicalSort);
4007
4870
  })
4008
4871
  .addCase(fetchStudioAppsList.rejected, (state) => {
4009
4872
  if (state.loadingStudioAppsList === 'pending')
@@ -4024,8 +4887,13 @@ const StudioAppsListSlice = createSlice({
4024
4887
  let { status } = action.meta.arg;
4025
4888
  if (status === APP_STATUS_TYPE.INSTALLED)
4026
4889
  status = APP_STATUS_TYPE.SUSPENDED;
4027
- if (app.idApp === idApp && app.status === status)
4890
+ if (app.idApp === idApp && app.status === status) {
4891
+ if (app.inWorkVersion && app.status === APP_STATUS_TYPE.SUSPENDED) {
4892
+ app.inWorkVersion.status = APP_STATUS_TYPE.DRAFT;
4893
+ return [...acc, app.inWorkVersion];
4894
+ }
4028
4895
  return acc;
4896
+ }
4029
4897
  if (app.inWorkVersion &&
4030
4898
  app.inWorkVersion.idApp === idApp &&
4031
4899
  app.inWorkVersion.status === status) {
@@ -4081,38 +4949,65 @@ const StudioAppsListSlice = createSlice({
4081
4949
  })) !== null && _b !== void 0 ? _b : [];
4082
4950
  })
4083
4951
  .addCase(restartStudioApp.rejected, (state) => {
4084
- if (state.restartStudioAppStatus === 'pending')
4952
+ if (state.restartStudioAppStatus === 'pending') {
4085
4953
  state.restartStudioAppStatus = 'idle';
4954
+ }
4086
4955
  })
4087
4956
  .addCase(cloneStudioApp.pending, (state) => {
4088
- if (state.cloneStudioAppStatus === 'idle')
4957
+ if (state.cloneStudioAppStatus === 'idle') {
4089
4958
  state.cloneStudioAppStatus = 'pending';
4959
+ }
4090
4960
  })
4091
4961
  .addCase(cloneStudioApp.fulfilled, (state, action) => {
4092
4962
  var _a;
4093
4963
  if (state.cloneStudioAppStatus === 'pending') {
4094
4964
  state.cloneStudioAppStatus = 'idle';
4095
4965
  }
4096
- state.studioAppsList = [...((_a = state.studioAppsList) !== null && _a !== void 0 ? _a : []), action.payload];
4966
+ state.studioAppsList = [...((_a = state.studioAppsList) !== null && _a !== void 0 ? _a : []), action.payload].sort(appLexicalSort);
4097
4967
  })
4098
4968
  .addCase(cloneStudioApp.rejected, (state) => {
4099
- if (state.cloneStudioAppStatus === 'pending')
4969
+ if (state.cloneStudioAppStatus === 'pending') {
4100
4970
  state.cloneStudioAppStatus = 'idle';
4971
+ }
4972
+ })
4973
+ .addCase(createInWorkStudioApp.pending, (state) => {
4974
+ if (state.createInWorkAppStatus === 'idle') {
4975
+ state.createInWorkAppStatus = 'pending';
4976
+ }
4977
+ })
4978
+ .addCase(createInWorkStudioApp.fulfilled, (state, action) => {
4979
+ var _a;
4980
+ if (state.createInWorkAppStatus === 'pending') {
4981
+ state.createInWorkAppStatus = 'idle';
4982
+ }
4983
+ const app = (_a = state.studioAppsList) === null || _a === void 0 ? void 0 : _a.find((app) => {
4984
+ return app.idApp === action.payload.idApp;
4985
+ });
4986
+ if (app) {
4987
+ app.inWorkVersion = action.payload;
4988
+ }
4989
+ })
4990
+ .addCase(createInWorkStudioApp.rejected, (state) => {
4991
+ if (state.createInWorkAppStatus === 'pending') {
4992
+ state.createInWorkAppStatus = 'idle';
4993
+ }
4101
4994
  })
4102
4995
  .addCase(createNewStudioApp.pending, (state) => {
4103
- if (state.createNewStudioAppStatus === 'idle')
4996
+ if (state.createNewStudioAppStatus === 'idle') {
4104
4997
  state.createNewStudioAppStatus = 'pending';
4998
+ }
4105
4999
  })
4106
5000
  .addCase(createNewStudioApp.fulfilled, (state, action) => {
4107
5001
  var _a;
4108
5002
  if (state.createNewStudioAppStatus === 'pending') {
4109
5003
  state.createNewStudioAppStatus = 'idle';
4110
5004
  }
4111
- state.studioAppsList = [...((_a = state.studioAppsList) !== null && _a !== void 0 ? _a : []), action.payload];
5005
+ state.studioAppsList = [...((_a = state.studioAppsList) !== null && _a !== void 0 ? _a : []), action.payload].sort(appLexicalSort);
4112
5006
  })
4113
5007
  .addCase(createNewStudioApp.rejected, (state) => {
4114
- if (state.createNewStudioAppStatus === 'pending')
5008
+ if (state.createNewStudioAppStatus === 'pending') {
4115
5009
  state.createNewStudioAppStatus = 'idle';
5010
+ }
4116
5011
  });
4117
5012
  },
4118
5013
  });
@@ -4141,12 +5036,17 @@ const studio = {
4141
5036
  createNewStudioApp,
4142
5037
  fetchCurrentStudioApp,
4143
5038
  saveCurrentStudioApp,
4144
- installStudioApp }),
5039
+ installStudioApp,
5040
+ createInWorkStudioApp }),
4145
5041
  selectors: {
4146
5042
  selectStudioAppsList,
4147
5043
  selectCurrentStudioApp,
4148
5044
  },
5045
+ utils: {
5046
+ updateViewsFromFields,
5047
+ generateNewFormField,
5048
+ }
4149
5049
  };
4150
5050
 
4151
- export { APP_STATUS_TYPE, AUDIENCE, Animations, AppColumnsDefaultTypes, AppFieldFormPropertyTypes, AppFormBannedFromViews$1 as AppFormBannedFromViews, AppFormFieldOnlyInView, AppFormFixedList$1 as AppFormFixedList, AppFormItemTypes, AppFormNoAsFieldList, AppFormNonPrimaryList, AppFormPrimaryList, AppFormUniqueList, Application, AssetReservation, Bookmark, Comment, ExtraAppFieldsItemViews, Faq, Hook, MODE_EDIT, MODE_VIEW, MagicPad, MapExtraFieldsWithView, MediaLibrary, Model, Network, Platform, STUDIO_VIEW, Share, SocialActions, StatusType$1 as StatusType, TVDisplay, TinyMCE, Toast, UserCurrent, WedocApp, Widget, WidgetEditor, actions, animationsReducer, animationsSlice, fetchMediaLibraryConfig, fetchMediaLibraryFilesStats, fetchMediaLibraryFolders, fetchMediaLibraryFoldersStats, fetchMediaLibraryStats, fetchMediaLibraryUnclassifiedFiles, fetchPads, jland, magicPadSlice, mediaLibraryReducer, mediaLibrarySlice, slice$1 as slice, studio, updateWidgetContent, viewsList };
5051
+ export { APP_STATUS_TYPE, AUDIENCE, Animations, AppColumnsDefaultTypes, AppFieldFormPropertyTypes, AppFormBannedFromViews$1 as AppFormBannedFromViews, AppFormFieldOnlyInView, AppFormFixedList$1 as AppFormFixedList, AppFormItemTypes, AppFormNoAsFieldList, AppFormNonPrimaryList, AppFormPrimaryList, AppFormPrimaryListValues, AppFormUniqueList, AppFormUniqueListCheck, Application, AssetReservation, Bookmark, Comment, Description, Element, ExtraAppFieldsItemViews, Faq, Hook, MODE_EDIT, MODE_VIEW, MagicPad, MapExtraFieldsWithView, MediaLibrary, Model, Network, Platform, STUDIO_VIEW, Share, SocialActions, StatusType$1 as StatusType, TVDisplay, TinyMCE, Toast, UserCurrent, WedocApp, Widget, WidgetEditor, actions, animationsReducer, animationsSlice, fetchMediaLibraryConfig, fetchMediaLibraryFilesStats, fetchMediaLibraryFolders, fetchMediaLibraryFoldersStats, fetchMediaLibraryStats, fetchMediaLibraryUnclassifiedFiles, fetchPads, jland, magicPadSlice, mediaLibraryReducer, mediaLibrarySlice, slice$1 as slice, studio, updateWidgetContent, viewsList };
4152
5052
  //# sourceMappingURL=esm.js.map