jamespot-front-business 1.1.67 → 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
@@ -476,6 +476,36 @@ const CommentListSlice = createSlice({
476
476
  discardComments: (state, action) => {
477
477
  state.comments = state.comments.filter((c) => c.idArticle !== action.payload.idArticle);
478
478
  },
479
+ hydrateComment: (state, action) => {
480
+ const { idArticle, list } = action.payload;
481
+ const hasList = state.comments.find((c) => c.idArticle === idArticle);
482
+ if (!hasList) {
483
+ state.comments = [
484
+ ...state.comments.filter((c) => c.idArticle !== idArticle),
485
+ {
486
+ idArticle,
487
+ list,
488
+ },
489
+ ];
490
+ return;
491
+ }
492
+ const initialUris = [];
493
+ const allUris = state.comments.reduce((uris, c) => {
494
+ return [...uris, ...c.list.map((el) => el.uri)];
495
+ }, initialUris);
496
+ const safeList = list.filter((el) => !allUris.includes(el.uri));
497
+ state.comments = state.comments.map((c) => {
498
+ return c.idArticle === idArticle
499
+ ? Object.assign(Object.assign({}, c), { list: [...c.list, ...safeList] }) : c;
500
+ });
501
+ },
502
+ updateComment: (state, action) => {
503
+ state.comments = state.comments.map((c) => {
504
+ const { idArticle, idComment, data } = action.payload;
505
+ return c.idArticle === idArticle
506
+ ? Object.assign(Object.assign({}, c), { list: c.list.map((comment) => comment.id === idComment ? Object.assign(Object.assign({}, comment), { description: data.description }) : comment) }) : c;
507
+ });
508
+ },
479
509
  },
480
510
  extraReducers: (builder) => {
481
511
  builder
@@ -2727,12 +2757,11 @@ const AUDIENCE = {
2727
2757
  ALL: '1',
2728
2758
  CUSTOM: '0',
2729
2759
  };
2730
- var StatusType$1;
2731
- (function (StatusType) {
2732
- StatusType["draft"] = "draft";
2733
- StatusType["installed"] = "installed";
2734
- StatusType["suspended"] = "suspended";
2735
- })(StatusType$1 || (StatusType$1 = {}));
2760
+ const StatusType$1 = {
2761
+ draft: 'draft',
2762
+ installed: 'installed',
2763
+ suspended: 'suspended',
2764
+ };
2736
2765
  const APP_STATUS_TYPE = {
2737
2766
  DRAFT: StatusType$1.draft,
2738
2767
  INSTALLED: StatusType$1.installed,
@@ -2743,51 +2772,50 @@ const STUDIO_VIEW = {
2743
2772
  NOT_SOLR: '0',
2744
2773
  };
2745
2774
  const viewsList = ['create', 'popup', 'edit', 'filter', 'list', 'view'];
2746
- var AppFormItemTypes;
2747
- (function (AppFormItemTypes) {
2748
- AppFormItemTypes["IMAGE"] = "IMAGE";
2749
- AppFormItemTypes["DESCRIPTION"] = "DESCRIPTION";
2750
- AppFormItemTypes["TEXT"] = "TEXT";
2751
- AppFormItemTypes["TEXTAREA"] = "TEXTAREA";
2752
- AppFormItemTypes["TEXTAREAHTML"] = "TEXTAREAHTML";
2753
- AppFormItemTypes["DATE"] = "DATE";
2754
- AppFormItemTypes["DATETIME"] = "DATETIME";
2755
- AppFormItemTypes["NUMBER"] = "NUMBER";
2756
- AppFormItemTypes["URL"] = "URL";
2757
- AppFormItemTypes["EMAIL"] = "EMAIL";
2758
- AppFormItemTypes["SELECT"] = "SELECT";
2759
- AppFormItemTypes["CHECKBOX"] = "CHECKBOX";
2760
- AppFormItemTypes["TOGGLE"] = "TOGGLE";
2761
- AppFormItemTypes["RADIO"] = "RADIO";
2762
- AppFormItemTypes["TAGS"] = "TAGS";
2763
- AppFormItemTypes["ADDFILEATTACHMENT"] = "ADDFILEATTACHMENT";
2764
- AppFormItemTypes["CODEHTML"] = "CODEHTML";
2765
- AppFormItemTypes["USERLINK"] = "USERLINK";
2766
- AppFormItemTypes["CONTENTLINK"] = "CONTENTLINK";
2767
- AppFormItemTypes["RANGE"] = "RANGE";
2768
- })(AppFormItemTypes || (AppFormItemTypes = {}));
2769
- var ExtraAppFieldsItemViews;
2770
- (function (ExtraAppFieldsItemViews) {
2771
- ExtraAppFieldsItemViews["TITLE"] = "TITLE";
2772
- ExtraAppFieldsItemViews["USER"] = "USER";
2773
- ExtraAppFieldsItemViews["PUBLISHTO"] = "PUBLISHTO";
2774
- ExtraAppFieldsItemViews["SENDALERTTOSUBSCRIBERS"] = "SENDALERTTOSUBSCRIBERS";
2775
- ExtraAppFieldsItemViews["RECEIVEACOPY"] = "RECEIVEACOPY";
2776
- ExtraAppFieldsItemViews["CREATIONDATE"] = "CREATIONDATE";
2777
- })(ExtraAppFieldsItemViews || (ExtraAppFieldsItemViews = {}));
2778
- var AppFieldFormPropertyTypes;
2779
- (function (AppFieldFormPropertyTypes) {
2780
- AppFieldFormPropertyTypes["LABEL"] = "label";
2781
- AppFieldFormPropertyTypes["DESCRIPTION"] = "description";
2782
- AppFieldFormPropertyTypes["RICHTEXT"] = "richtext";
2783
- AppFieldFormPropertyTypes["CHECKBOX"] = "checkbox";
2784
- AppFieldFormPropertyTypes["OPTIONS_EDITOR"] = "options_editor";
2785
- AppFieldFormPropertyTypes["TAXONOMY"] = "taxonomy";
2786
- AppFieldFormPropertyTypes["CONTENTTYPE"] = "contenttype";
2787
- })(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
+ };
2788
2814
  const AppFormUniqueList = [AppFormItemTypes.DESCRIPTION, AppFormItemTypes.IMAGE];
2815
+ const AppFormUniqueListCheck = AppFormUniqueList;
2789
2816
  const AppFormBannedFromViews$1 = new Map();
2790
2817
  AppFormBannedFromViews$1.set(AppFormItemTypes.IMAGE, ['list', 'filter', 'view']);
2818
+ AppFormBannedFromViews$1.set(AppFormItemTypes.CODEHTML, ['list', 'filter', 'view']);
2791
2819
  const MapExtraFieldsWithView = {
2792
2820
  create: {
2793
2821
  fixed: [ExtraAppFieldsItemViews.TITLE],
@@ -2825,6 +2853,7 @@ const AppColumnsDefaultTypes = [
2825
2853
  AppFormItemTypes.DESCRIPTION,
2826
2854
  ];
2827
2855
  const AppFormPrimaryList = [AppFormItemTypes.DESCRIPTION];
2856
+ const AppFormPrimaryListValues = AppFormPrimaryList;
2828
2857
  const AppFormFixedList$1 = [
2829
2858
  ExtraAppFieldsItemViews.TITLE,
2830
2859
  ExtraAppFieldsItemViews.PUBLISHTO,
@@ -2839,6 +2868,18 @@ const AppFormNoAsFieldList = [
2839
2868
  ];
2840
2869
  const AppFormFieldOnlyInView = [AppFormItemTypes.CODEHTML];
2841
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 = {}));
2842
2883
 
2843
2884
  var StatusType;
2844
2885
  (function (StatusType) {
@@ -3102,23 +3143,761 @@ function migrateJson(v1Json) {
3102
3143
  return v2;
3103
3144
  }
3104
3145
 
3105
- 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) {
3106
3868
  var _a, _b, _c, _d;
3107
3869
  const { version, dateCreation } = serverApp.manifest;
3108
3870
  const appTypeServer = serverApp.typeModel;
3109
3871
  const views = Object.assign({}, ...viewsList.map((view) => ({
3110
- [view]: [],
3872
+ [view]: {},
3111
3873
  })));
3112
3874
  const studioApp = {
3113
3875
  idApp: serverApp.idApp,
3114
3876
  status: _formatStatus(serverApp),
3115
3877
  studioVersion: 2,
3116
- 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
+ },
3117
3894
  fields: [],
3118
3895
  views,
3119
- installFor: serverApp.accessRightObjectList,
3896
+ installFor: serverApp.accessRightObjectList ? buildAudience(serverApp.accessRightObjectList) : [],
3120
3897
  audience: serverApp.checkAccess === false ? AUDIENCE.ALL : AUDIENCE.CUSTOM,
3121
3898
  };
3899
+ populateFieldsAndViews(serverApp, studioApp, state);
3900
+ studioApp.views = updateViewsFromFields(studioApp, studioApp.fields);
3122
3901
  const inWorkAppVersion = _findAssociatedDraft(serverApp.idApp, serverApps);
3123
3902
  if (!inWorkAppVersion)
3124
3903
  return studioApp;
@@ -3140,12 +3919,13 @@ function DraftAppStudioAdapter(serverApp) {
3140
3919
  manifest: parsedJson.manifest,
3141
3920
  fields: parsedJson.fields,
3142
3921
  views: parsedJson.views,
3922
+ syncViewFieldOrder: parsedJson.syncViewFieldOrder,
3143
3923
  audience: parsedJson.audience,
3144
3924
  installFor: parsedJson.installFor,
3145
3925
  };
3146
3926
  }
3147
3927
  else {
3148
- 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 });
3149
3929
  }
3150
3930
  }
3151
3931
  function _formatStatus(serverApp) {
@@ -3162,11 +3942,11 @@ function _findAssociatedDraft(idApp, serverApps) {
3162
3942
  function _findAssociatedInstalled(idApp, serverApps) {
3163
3943
  return !!serverApps.find((app) => app.idApp === idApp && app.status === StudioApplicationStatus.installed);
3164
3944
  }
3165
- function serverAppsToStudioApps(serverApps) {
3945
+ function serverAppsToStudioApps(serverApps, state) {
3166
3946
  const studioApps = serverApps
3167
3947
  .map((serverApp) => {
3168
3948
  if (serverApp.status === StudioApplicationStatus.installed) {
3169
- return InstalledAppStudioAdapter(serverApp, serverApps);
3949
+ return InstalledAppStudioAdapter(serverApp, serverApps, state);
3170
3950
  }
3171
3951
  else {
3172
3952
  if (_findAssociatedInstalled(serverApp.idApp, serverApps))
@@ -3232,7 +4012,13 @@ function renderAppView(viewSolr, listView) {
3232
4012
  if (viewSolr === STUDIO_VIEW.SOLR) {
3233
4013
  let xml = '<AppView>solr</AppView>';
3234
4014
  const formItemIdInList = [];
3235
- 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
+ }
3236
4022
  formItemIdInList.push(getAttrNameFormItem(field, fieldId));
3237
4023
  });
3238
4024
  xml += `<AppColumns>${formItemIdInList.join()}</AppColumns>`;
@@ -3242,8 +4028,12 @@ function renderAppView(viewSolr, listView) {
3242
4028
  }
3243
4029
  function renderAppSearch(searchView) {
3244
4030
  const formItemIdInFilter = [];
3245
- Object.entries(searchView).forEach(([fieldId, field]) => {
3246
- 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))
3247
4037
  formItemIdInFilter.push(getAttrNameFormItem(field, fieldId));
3248
4038
  });
3249
4039
  return `<AttrExposed>${formItemIdInFilter.join()}</AttrExposed>`;
@@ -3278,13 +4068,13 @@ function renderAudience(audience, installFor) {
3278
4068
  return '';
3279
4069
  }
3280
4070
  function renderPrimaryFields(fields) {
3281
- 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));
3282
4072
  if (primaryFields.length === 0)
3283
4073
  return '';
3284
4074
  return `<primaryFields>${primaryFields.map((field) => formItem2xml(field)).join('')}</primaryFields>`;
3285
4075
  }
3286
4076
  function renderCustomFields(fields) {
3287
- 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));
3288
4078
  const filteredCustomFields = customFields === null || customFields === void 0 ? void 0 : customFields.filter((field) => field.type !== AppFormItemTypes.IMAGE);
3289
4079
  if (filteredCustomFields.length === 0)
3290
4080
  return '';
@@ -3350,14 +4140,20 @@ function renderWidget(fieldType, fieldProperties) {
3350
4140
  const isMultiple = optionEditor.value.canSelectMultiple;
3351
4141
  const options = optionEditor.value.propertyOptions;
3352
4142
  const hasDefaultValue = optionEditor.value.defaultSelectOption;
3353
- const defaultValue = optionEditor.value.defaultSelectOptionValue;
4143
+ const defaultValue = optionEditor.value.defaultSelectOptionValue.value;
4144
+ const userCanModifiyByComment = optionEditor.value.userCanModifiyByComment;
3354
4145
  return `<widget form="select" ${isMultiple ? 'multiple="1"' : ''}>
3355
4146
  <options>
3356
4147
  ${options
3357
4148
  .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
3358
4149
  .join('')}
3359
4150
  </options>
3360
- ${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
+ : ''}
3361
4157
  </widget>`;
3362
4158
  }
3363
4159
  case AppFormItemTypes.RADIO: {
@@ -3496,9 +4292,7 @@ function renderFieldTypeToXmlType(fieldType) {
3496
4292
  case AppFormItemTypes.TAGS:
3497
4293
  return 'taxonomy';
3498
4294
  case AppFormItemTypes.TEXT:
3499
- case AppFormItemTypes.SELECT:
3500
4295
  case AppFormItemTypes.RADIO:
3501
- case AppFormItemTypes.CHECKBOX:
3502
4296
  case AppFormItemTypes.URL:
3503
4297
  case AppFormItemTypes.EMAIL:
3504
4298
  case AppFormItemTypes.ADDFILEATTACHMENT:
@@ -3507,6 +4301,8 @@ function renderFieldTypeToXmlType(fieldType) {
3507
4301
  case AppFormItemTypes.CONTENTLINK:
3508
4302
  return 'text';
3509
4303
  case AppFormItemTypes.TEXTAREA:
4304
+ case AppFormItemTypes.CHECKBOX:
4305
+ case AppFormItemTypes.SELECT:
3510
4306
  return 'longtext';
3511
4307
  case AppFormItemTypes.DATE:
3512
4308
  return 'date';
@@ -3547,7 +4343,9 @@ function renderDisplays(studioApp) {
3547
4343
  let toRet = '';
3548
4344
  Object.entries(studioApp.views).forEach(([viewName, viewContent]) => {
3549
4345
  if (Object.prototype.hasOwnProperty.call(internal2XmlView, viewName)) {
3550
- 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);
3551
4349
  toRet += `<display view="${internal2XmlView[viewName]}" mode="${viewName === 'view' ? 'view' : 'form'}">
3552
4350
  ${viewField.map(([fieldId, view]) => renderDisplayAttr(fieldId, view)).join('')}
3553
4351
  </display>`;
@@ -3599,16 +4397,21 @@ function renderDisplayAttr(fieldId, view) {
3599
4397
  xml += `<input type="hidden" name="${attrName}[]" value=${JSON.stringify(view.value.uri)}>`;
3600
4398
  }
3601
4399
  else if (view.type === AppFormItemTypes.SELECT) {
3602
- const values = view.value;
3603
4400
  const canSelectMultiple = (_a = view.properties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR)) === null || _a === void 0 ? void 0 : _a.value.canSelectMultiple;
3604
- values.forEach((value) => {
3605
- xml += `<input type="hidden" name="${attrName}${canSelectMultiple ? '[]' : ''}" value="${value.value}">`;
3606
- });
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
+ }
3607
4410
  }
3608
4411
  else if (view.type === AppFormItemTypes.CHECKBOX) {
3609
4412
  const values = view.value;
3610
4413
  values.forEach((value) => {
3611
- xml += `<input type="hidden" name="${attrName}[]" value="${value.value}">`;
4414
+ xml += `<input type="hidden" name="${attrName}[]" value="${value}">`;
3612
4415
  });
3613
4416
  }
3614
4417
  else if (view.type === AppFormItemTypes.DATE) {
@@ -3622,21 +4425,28 @@ function renderDisplayAttr(fieldId, view) {
3622
4425
  }
3623
4426
  else if (view.type === AppFormItemTypes.DATETIME) {
3624
4427
  const dateValue = new Date(view.value);
3625
- const xmlFixedValue = [
4428
+ const xmlFixedValue = `${[
3626
4429
  pad(dateValue.getDate()),
3627
4430
  pad(dateValue.getMonth() + 1),
3628
4431
  dateValue.getFullYear(),
3629
- pad(dateValue.getHours()),
3630
- pad(dateValue.getMinutes()),
3631
- pad(dateValue.getSeconds()),
3632
- ].join('/');
4432
+ ].join('/')} ${pad(dateValue.getHours())}:${pad(dateValue.getMinutes())}:${pad(dateValue.getSeconds())}`;
3633
4433
  xml += '<input type="hidden" name="' + attrName + '" value="' + xmlFixedValue + '">';
3634
4434
  }
3635
4435
  else if (view.type === AppFormItemTypes.TAGS) {
3636
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(',')}">`;
3637
4437
  }
3638
4438
  else if (view.type === AppFormItemTypes.DESCRIPTION || view.type === AppFormItemTypes.TEXTAREAHTML) {
3639
- 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
+ }
3640
4450
  }
3641
4451
  else {
3642
4452
  xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
@@ -3646,7 +4456,14 @@ function renderDisplayAttr(fieldId, view) {
3646
4456
  else {
3647
4457
  switch (view.type) {
3648
4458
  case AppFormItemTypes.CODEHTML: {
3649
- 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>`;
3650
4467
  break;
3651
4468
  }
3652
4469
  case AppFormItemTypes.IMAGE:
@@ -3673,12 +4490,12 @@ const initialState$1 = {
3673
4490
  installStudioAppStatus: 'idle',
3674
4491
  hasChanged: false,
3675
4492
  };
3676
- 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* () {
3677
4494
  const jApi = extra.jApi;
3678
4495
  const error = { error: 1, errorMsg: 'Error fetching application' };
3679
4496
  try {
3680
4497
  const studioApplicationBase = (yield jApi.application.get(idApp, status)).result;
3681
- const studioApplication = serverAppsToStudioApps([studioApplicationBase])[0];
4498
+ const studioApplication = serverAppsToStudioApps([studioApplicationBase], getState())[0];
3682
4499
  if (!studioApplication) {
3683
4500
  return rejectWithValue(error);
3684
4501
  }
@@ -3782,16 +4599,22 @@ const CurrentStudioAppSlice = createSlice({
3782
4599
  },
3783
4600
  });
3784
4601
 
3785
- function cloneStudioAppFromExistingApp(existingApp, author) {
3786
- const newApp = existingApp.inWorkVersion
3787
- ? 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)))
3788
4605
  : JSON.parse(JSON.stringify(existingApp));
3789
- const newAppId = v4();
3790
- const newAppName = `${existingApp.manifest.appName} Copie`;
3791
- newApp.idApp = newAppId;
3792
- newApp.status = APP_STATUS_TYPE.DRAFT;
3793
- newApp.manifest = Object.assign(Object.assign({}, newApp.manifest), { appName: newAppName, appShortName: newAppName, author: author || '', dateCreation: new Date().toISOString(), version: 0.1, articlesCount: 0 });
3794
- 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];
3795
4618
  }
3796
4619
 
3797
4620
  function createNewStudioApp$1({ author, appName }) {
@@ -3853,37 +4676,78 @@ function createNewStudioApp$1({ author, appName }) {
3853
4676
  attrExposed: [],
3854
4677
  articlesCount: 0,
3855
4678
  },
4679
+ syncViewFieldOrder: {
4680
+ create: true,
4681
+ popup: true,
4682
+ view: true,
4683
+ edit: true,
4684
+ list: true,
4685
+ filter: true,
4686
+ },
3856
4687
  fields: [],
3857
4688
  views,
3858
- audience: AUDIENCE.ALL,
4689
+ audience: AUDIENCE.CUSTOM,
3859
4690
  installFor: [],
3860
4691
  },
3861
4692
  };
3862
4693
  }
3863
4694
 
4695
+ function appLexicalSort(a, b) {
4696
+ return a.manifest.appName > b.manifest.appName ? 1 : -1;
4697
+ }
3864
4698
  const initialState = {
3865
4699
  loadingStudioAppsList: 'idle',
3866
4700
  deleteStudioAppStatus: 'idle',
3867
4701
  suspendStudioAppStatus: 'idle',
3868
4702
  restartStudioAppStatus: 'idle',
3869
4703
  cloneStudioAppStatus: 'idle',
4704
+ createInWorkAppStatus: 'idle',
3870
4705
  createNewStudioAppStatus: 'idle',
3871
4706
  };
3872
- 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* () {
3873
4708
  const jApi = extra.jApi;
3874
4709
  try {
3875
4710
  const { result } = yield jApi.application.list();
3876
- 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* () {
3877
4713
  const coreApp = (yield jApi.application.get(app.idApp, app.status)).result;
3878
4714
  const articlesCount = (yield jApi.article.count(app.idApp)).result;
3879
4715
  return Object.assign(Object.assign({}, coreApp), { articlesCount });
3880
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;
3881
4725
  }
3882
4726
  catch (_) {
3883
4727
  dispatch(Toast.actions.error({ label: 'GLOBAL_Technical_Error' }));
3884
4728
  throw rejectWithValue({ error: 1, errorMsg: 'Error retrieving applications' });
3885
4729
  }
3886
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
+ }
3887
4751
  const createNewStudioApp = createAsyncThunk('studio/createApp', ({ appName, callback }, { extra, dispatch, rejectWithValue, getState }) => __awaiter(void 0, void 0, void 0, function* () {
3888
4752
  var _a;
3889
4753
  const jApi = extra.jApi;
@@ -3936,12 +4800,20 @@ const restartStudioApp = createAsyncThunk('studio/restartStudioApp', ({ idApp },
3936
4800
  throw rejectWithValue({ error: 1, errorMsg: 'Error restarting application' });
3937
4801
  }
3938
4802
  }));
3939
- 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* () {
3940
4804
  var _b, _c;
3941
4805
  const jApi = extra.jApi;
3942
- 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);
3943
4807
  if (!existingStudioApp)
3944
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
+ }
3945
4817
  const currentUser = (_c = getState().userCurrent) === null || _c === void 0 ? void 0 : _c.uri;
3946
4818
  const [clonedStudioApp, newAppId] = cloneStudioAppFromExistingApp(existingStudioApp, currentUser);
3947
4819
  const clonedStudioAppReady = JSON.stringify(clonedStudioApp);
@@ -3955,12 +4827,33 @@ const cloneStudioApp = createAsyncThunk('studio/cloneStudioApp', ({ idApp }, { e
3955
4827
  return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
3956
4828
  }
3957
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
+ }));
3958
4851
  const StudioAppsListSlice = createSlice({
3959
4852
  name: 'studioAppsList',
3960
4853
  initialState,
3961
4854
  reducers: {
3962
4855
  setAppsList: (state, action) => {
3963
- state.studioAppsList = action.payload;
4856
+ state.studioAppsList = [...action.payload].sort(appLexicalSort);
3964
4857
  },
3965
4858
  },
3966
4859
  extraReducers: (builder) => {
@@ -3973,7 +4866,7 @@ const StudioAppsListSlice = createSlice({
3973
4866
  if (state.loadingStudioAppsList === 'pending') {
3974
4867
  state.loadingStudioAppsList = 'idle';
3975
4868
  }
3976
- state.studioAppsList = serverAppsToStudioApps(action.payload);
4869
+ state.studioAppsList = [...action.payload].sort(appLexicalSort);
3977
4870
  })
3978
4871
  .addCase(fetchStudioAppsList.rejected, (state) => {
3979
4872
  if (state.loadingStudioAppsList === 'pending')
@@ -3994,8 +4887,13 @@ const StudioAppsListSlice = createSlice({
3994
4887
  let { status } = action.meta.arg;
3995
4888
  if (status === APP_STATUS_TYPE.INSTALLED)
3996
4889
  status = APP_STATUS_TYPE.SUSPENDED;
3997
- 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
+ }
3998
4895
  return acc;
4896
+ }
3999
4897
  if (app.inWorkVersion &&
4000
4898
  app.inWorkVersion.idApp === idApp &&
4001
4899
  app.inWorkVersion.status === status) {
@@ -4051,38 +4949,65 @@ const StudioAppsListSlice = createSlice({
4051
4949
  })) !== null && _b !== void 0 ? _b : [];
4052
4950
  })
4053
4951
  .addCase(restartStudioApp.rejected, (state) => {
4054
- if (state.restartStudioAppStatus === 'pending')
4952
+ if (state.restartStudioAppStatus === 'pending') {
4055
4953
  state.restartStudioAppStatus = 'idle';
4954
+ }
4056
4955
  })
4057
4956
  .addCase(cloneStudioApp.pending, (state) => {
4058
- if (state.cloneStudioAppStatus === 'idle')
4957
+ if (state.cloneStudioAppStatus === 'idle') {
4059
4958
  state.cloneStudioAppStatus = 'pending';
4959
+ }
4060
4960
  })
4061
4961
  .addCase(cloneStudioApp.fulfilled, (state, action) => {
4062
4962
  var _a;
4063
4963
  if (state.cloneStudioAppStatus === 'pending') {
4064
4964
  state.cloneStudioAppStatus = 'idle';
4065
4965
  }
4066
- 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);
4067
4967
  })
4068
4968
  .addCase(cloneStudioApp.rejected, (state) => {
4069
- if (state.cloneStudioAppStatus === 'pending')
4969
+ if (state.cloneStudioAppStatus === 'pending') {
4070
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
+ }
4071
4994
  })
4072
4995
  .addCase(createNewStudioApp.pending, (state) => {
4073
- if (state.createNewStudioAppStatus === 'idle')
4996
+ if (state.createNewStudioAppStatus === 'idle') {
4074
4997
  state.createNewStudioAppStatus = 'pending';
4998
+ }
4075
4999
  })
4076
5000
  .addCase(createNewStudioApp.fulfilled, (state, action) => {
4077
5001
  var _a;
4078
5002
  if (state.createNewStudioAppStatus === 'pending') {
4079
5003
  state.createNewStudioAppStatus = 'idle';
4080
5004
  }
4081
- 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);
4082
5006
  })
4083
5007
  .addCase(createNewStudioApp.rejected, (state) => {
4084
- if (state.createNewStudioAppStatus === 'pending')
5008
+ if (state.createNewStudioAppStatus === 'pending') {
4085
5009
  state.createNewStudioAppStatus = 'idle';
5010
+ }
4086
5011
  });
4087
5012
  },
4088
5013
  });
@@ -4111,12 +5036,17 @@ const studio = {
4111
5036
  createNewStudioApp,
4112
5037
  fetchCurrentStudioApp,
4113
5038
  saveCurrentStudioApp,
4114
- installStudioApp }),
5039
+ installStudioApp,
5040
+ createInWorkStudioApp }),
4115
5041
  selectors: {
4116
5042
  selectStudioAppsList,
4117
5043
  selectCurrentStudioApp,
4118
5044
  },
5045
+ utils: {
5046
+ updateViewsFromFields,
5047
+ generateNewFormField,
5048
+ }
4119
5049
  };
4120
5050
 
4121
- 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 };
4122
5052
  //# sourceMappingURL=esm.js.map