jupiter-dynamic-forms 1.14.0 → 1.14.2

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/index.mjs CHANGED
@@ -1908,6 +1908,7 @@ class DraftStorageService {
1908
1908
  periodEndDate,
1909
1909
  language,
1910
1910
  selectedRoleIds,
1911
+ // Store enhanced structure (with roleURI and order) or legacy string array
1911
1912
  customColumns: this.extractCustomColumns(allSections),
1912
1913
  typedMemberData,
1913
1914
  periodPreferences,
@@ -4983,10 +4984,17 @@ let JupiterFilterRolesDialog = class extends LitElement {
4983
4984
  this.availableRoles = [];
4984
4985
  this.selectedRoleIds = [];
4985
4986
  this.periodPreferences = {};
4987
+ this.mode = "user";
4986
4988
  this._tempSelectedRoles = /* @__PURE__ */ new Set();
4987
4989
  this._searchQuery = "";
4988
4990
  this._filteredRoles = [];
4989
4991
  this._tempPeriodPreferences = {};
4992
+ this._selectedAvailableRole = null;
4993
+ this._selectedChosenRole = null;
4994
+ this._chosenSearchQuery = "";
4995
+ this._draggedRoleId = null;
4996
+ this._dragOverRoleId = null;
4997
+ this._chosenRoleOrder = [];
4990
4998
  }
4991
4999
  connectedCallback() {
4992
5000
  super.connectedCallback();
@@ -5053,6 +5061,19 @@ let JupiterFilterRolesDialog = class extends LitElement {
5053
5061
  searchInput.focus();
5054
5062
  }
5055
5063
  }
5064
+ _handleChosenSearchInput(event) {
5065
+ const input = event.target;
5066
+ this._chosenSearchQuery = input.value;
5067
+ }
5068
+ _clearChosenSearch() {
5069
+ var _a;
5070
+ this._chosenSearchQuery = "";
5071
+ const searchInput = (_a = this.shadowRoot) == null ? void 0 : _a.querySelector(".chosen-search-input");
5072
+ if (searchInput) {
5073
+ searchInput.value = "";
5074
+ searchInput.focus();
5075
+ }
5076
+ }
5056
5077
  _highlightSearchTerm(text) {
5057
5078
  if (!this._searchQuery.trim()) {
5058
5079
  return text;
@@ -5069,6 +5090,7 @@ let JupiterFilterRolesDialog = class extends LitElement {
5069
5090
  }
5070
5091
  _initializeTempSelection() {
5071
5092
  this._tempSelectedRoles = new Set(this.selectedRoleIds);
5093
+ this._chosenRoleOrder = [...this.selectedRoleIds];
5072
5094
  }
5073
5095
  _initializePeriodPreferences() {
5074
5096
  const preferences = {};
@@ -5170,10 +5192,20 @@ let JupiterFilterRolesDialog = class extends LitElement {
5170
5192
  }));
5171
5193
  }
5172
5194
  _handleApply() {
5173
- const selectedRoles = Array.from(this._tempSelectedRoles);
5195
+ const orderedRolesWithMetadata = this._chosenRoleOrder.map((roleId, index) => {
5196
+ var _a;
5197
+ const role = this.availableRoles.find((r2) => r2.id === roleId);
5198
+ return {
5199
+ roleId,
5200
+ roleURI: ((_a = role == null ? void 0 : role.metadata) == null ? void 0 : _a.roleURI) || "",
5201
+ order: index
5202
+ };
5203
+ });
5204
+ console.log("✅ Apply Filter - Enhanced structure being emitted:", orderedRolesWithMetadata);
5205
+ console.log("📋 Order array:", this._chosenRoleOrder);
5174
5206
  this.dispatchEvent(new CustomEvent("roles-filter-apply", {
5175
5207
  detail: {
5176
- selectedRoleIds: selectedRoles,
5208
+ selectedRoleIds: orderedRolesWithMetadata,
5177
5209
  periodPreferences: this._tempPeriodPreferences
5178
5210
  },
5179
5211
  bubbles: true
@@ -5184,6 +5216,128 @@ let JupiterFilterRolesDialog = class extends LitElement {
5184
5216
  this._handleCancel();
5185
5217
  }
5186
5218
  }
5219
+ // Picklist methods for admin mode
5220
+ _handleAvailableRoleClick(roleId) {
5221
+ this._selectedAvailableRole = roleId;
5222
+ this._selectedChosenRole = null;
5223
+ this.requestUpdate();
5224
+ }
5225
+ _handleChosenRoleClick(roleId) {
5226
+ this._selectedChosenRole = roleId;
5227
+ this._selectedAvailableRole = null;
5228
+ this.requestUpdate();
5229
+ }
5230
+ _moveToChosen() {
5231
+ if (!this._selectedAvailableRole)
5232
+ return;
5233
+ const newSelection = new Set(this._tempSelectedRoles);
5234
+ newSelection.add(this._selectedAvailableRole);
5235
+ this._tempSelectedRoles = newSelection;
5236
+ if (!this._chosenRoleOrder.includes(this._selectedAvailableRole)) {
5237
+ this._chosenRoleOrder = [...this._chosenRoleOrder, this._selectedAvailableRole];
5238
+ }
5239
+ this._selectedAvailableRole = null;
5240
+ this.requestUpdate();
5241
+ }
5242
+ _moveToAvailable() {
5243
+ if (!this._selectedChosenRole)
5244
+ return;
5245
+ const newSelection = new Set(this._tempSelectedRoles);
5246
+ newSelection.delete(this._selectedChosenRole);
5247
+ this._tempSelectedRoles = newSelection;
5248
+ this._chosenRoleOrder = this._chosenRoleOrder.filter((id) => id !== this._selectedChosenRole);
5249
+ this._selectedChosenRole = null;
5250
+ this.requestUpdate();
5251
+ }
5252
+ _moveAllToChosen() {
5253
+ const newSelection = new Set(this._tempSelectedRoles);
5254
+ this._filteredRoles.forEach((role) => {
5255
+ newSelection.add(role.id);
5256
+ if (!this._chosenRoleOrder.includes(role.id)) {
5257
+ this._chosenRoleOrder.push(role.id);
5258
+ }
5259
+ });
5260
+ this._tempSelectedRoles = newSelection;
5261
+ this._selectedAvailableRole = null;
5262
+ this.requestUpdate();
5263
+ }
5264
+ _moveAllToAvailable() {
5265
+ this._tempSelectedRoles = /* @__PURE__ */ new Set();
5266
+ this._chosenRoleOrder = [];
5267
+ this._selectedChosenRole = null;
5268
+ this.requestUpdate();
5269
+ }
5270
+ _getAvailableRoles() {
5271
+ return this._filteredRoles.filter((role) => !this._tempSelectedRoles.has(role.id));
5272
+ }
5273
+ _getChosenRoles() {
5274
+ const chosenRoles = this.availableRoles.filter((role) => this._tempSelectedRoles.has(role.id));
5275
+ const orderedRoles = this._chosenRoleOrder.map((roleId) => chosenRoles.find((role) => role.id === roleId)).filter((role) => role !== void 0);
5276
+ const unorderedRoles = chosenRoles.filter((role) => !this._chosenRoleOrder.includes(role.id));
5277
+ const allOrderedRoles = [...orderedRoles, ...unorderedRoles];
5278
+ if (!this._chosenSearchQuery.trim()) {
5279
+ return allOrderedRoles;
5280
+ }
5281
+ const query = this._chosenSearchQuery.toLowerCase().trim();
5282
+ return allOrderedRoles.filter((role) => {
5283
+ var _a;
5284
+ const titleMatch = role.title.toLowerCase().includes(query);
5285
+ const idMatch = role.id.toLowerCase().includes(query);
5286
+ const descriptionMatch = ((_a = role.description) == null ? void 0 : _a.toLowerCase().includes(query)) || false;
5287
+ const uriMatch = this._searchInRoleURI(role, query);
5288
+ return titleMatch || idMatch || descriptionMatch || uriMatch;
5289
+ });
5290
+ }
5291
+ // Drag and drop handlers
5292
+ _handleDragStart(event, roleId) {
5293
+ this._draggedRoleId = roleId;
5294
+ if (event.dataTransfer) {
5295
+ event.dataTransfer.effectAllowed = "move";
5296
+ event.dataTransfer.setData("text/plain", roleId);
5297
+ }
5298
+ this.requestUpdate();
5299
+ }
5300
+ _handleDragOver(event, roleId) {
5301
+ event.preventDefault();
5302
+ if (event.dataTransfer) {
5303
+ event.dataTransfer.dropEffect = "move";
5304
+ }
5305
+ if (this._draggedRoleId && this._draggedRoleId !== roleId) {
5306
+ this._dragOverRoleId = roleId;
5307
+ this.requestUpdate();
5308
+ }
5309
+ }
5310
+ _handleDragLeave(event) {
5311
+ this._dragOverRoleId = null;
5312
+ this.requestUpdate();
5313
+ }
5314
+ _handleDrop(event, targetRoleId) {
5315
+ event.preventDefault();
5316
+ if (!this._draggedRoleId || this._draggedRoleId === targetRoleId) {
5317
+ this._draggedRoleId = null;
5318
+ this._dragOverRoleId = null;
5319
+ this.requestUpdate();
5320
+ return;
5321
+ }
5322
+ const newOrder = [...this._chosenRoleOrder];
5323
+ const draggedIndex = newOrder.indexOf(this._draggedRoleId);
5324
+ const targetIndex = newOrder.indexOf(targetRoleId);
5325
+ if (draggedIndex !== -1 && targetIndex !== -1) {
5326
+ newOrder.splice(draggedIndex, 1);
5327
+ const newTargetIndex = draggedIndex < targetIndex ? targetIndex - 1 : targetIndex;
5328
+ newOrder.splice(newTargetIndex, 0, this._draggedRoleId);
5329
+ this._chosenRoleOrder = newOrder;
5330
+ console.log("🔄 Reordered roles:", this._chosenRoleOrder);
5331
+ }
5332
+ this._draggedRoleId = null;
5333
+ this._dragOverRoleId = null;
5334
+ this.requestUpdate();
5335
+ }
5336
+ _handleDragEnd(event) {
5337
+ this._draggedRoleId = null;
5338
+ this._dragOverRoleId = null;
5339
+ this.requestUpdate();
5340
+ }
5187
5341
  render() {
5188
5342
  const selectedCount = this._tempSelectedRoles.size;
5189
5343
  const totalCount = this.availableRoles.length;
@@ -5202,6 +5356,152 @@ let JupiterFilterRolesDialog = class extends LitElement {
5202
5356
 
5203
5357
  <!-- Dialog Content -->
5204
5358
  <div class="dialog-content">
5359
+ ${this.mode === "admin" ? html`
5360
+ <!-- Admin Mode: Picklist Layout -->
5361
+ <div class="picklist-container">
5362
+ <!-- Available Roles Panel -->
5363
+ <div class="picklist-panel">
5364
+ <div class="picklist-header">
5365
+ Available Roles (${this._getAvailableRoles().length})
5366
+ </div>
5367
+ <div class="picklist-search">
5368
+ <div class="search-container">
5369
+ <input
5370
+ type="text"
5371
+ class="search-input"
5372
+ placeholder="${I18n.t("filter.searchPlaceholder")}"
5373
+ .value="${this._searchQuery}"
5374
+ @input="${this._handleSearchInput}"
5375
+ />
5376
+ ${this._searchQuery ? html`
5377
+ <button class="clear-search" @click="${this._clearSearch}" title="${I18n.t("filter.clearSearch")}">
5378
+ ×
5379
+ </button>
5380
+ ` : html`
5381
+ <svg class="search-icon" viewBox="0 0 24 24">
5382
+ <path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
5383
+ </svg>
5384
+ `}
5385
+ </div>
5386
+ </div>
5387
+ <div class="picklist-list">
5388
+ ${this._getAvailableRoles().map((role) => {
5389
+ var _a;
5390
+ return html`
5391
+ <div
5392
+ class="picklist-item ${this._selectedAvailableRole === role.id ? "selected" : ""}"
5393
+ @click="${() => this._handleAvailableRoleClick(role.id)}"
5394
+ @dblclick="${() => {
5395
+ this._handleAvailableRoleClick(role.id);
5396
+ this._moveToChosen();
5397
+ }}"
5398
+ >
5399
+ <div class="picklist-item-label">${role.title}</div>
5400
+ ${((_a = role.metadata) == null ? void 0 : _a.roleURI) ? html`
5401
+ <div class="picklist-item-value">${role.metadata.roleURI}</div>
5402
+ ` : ""}
5403
+ </div>
5404
+ `;
5405
+ })}
5406
+ </div>
5407
+ <div class="picklist-count">
5408
+ ${this._getAvailableRoles().length} role(s)
5409
+ </div>
5410
+ </div>
5411
+
5412
+ <!-- Control Buttons -->
5413
+ <div class="picklist-controls">
5414
+ <button
5415
+ class="picklist-button"
5416
+ @click="${this._moveToChosen}"
5417
+ ?disabled="${!this._selectedAvailableRole}"
5418
+ title="Add selected role"
5419
+ >
5420
+
5421
+ </button>
5422
+ <button
5423
+ class="picklist-button"
5424
+ @click="${this._moveAllToChosen}"
5425
+ ?disabled="${this._getAvailableRoles().length === 0}"
5426
+ title="Add all roles"
5427
+ >
5428
+ »
5429
+ </button>
5430
+ <button
5431
+ class="picklist-button"
5432
+ @click="${this._moveToAvailable}"
5433
+ ?disabled="${!this._selectedChosenRole}"
5434
+ title="Remove selected role"
5435
+ >
5436
+
5437
+ </button>
5438
+ <button
5439
+ class="picklist-button"
5440
+ @click="${this._moveAllToAvailable}"
5441
+ ?disabled="${this._tempSelectedRoles.size === 0}"
5442
+ title="Remove all roles"
5443
+ >
5444
+ «
5445
+ </button>
5446
+ </div>
5447
+
5448
+ <!-- Chosen Roles Panel -->
5449
+ <div class="picklist-panel">
5450
+ <div class="picklist-header">
5451
+ Chosen Roles (${this._tempSelectedRoles.size})
5452
+ </div>
5453
+ <div class="picklist-search">
5454
+ <div class="search-container">
5455
+ <input
5456
+ type="text"
5457
+ class="search-input chosen-search-input"
5458
+ placeholder="${I18n.t("filter.searchPlaceholder")}"
5459
+ .value="${this._chosenSearchQuery}"
5460
+ @input="${this._handleChosenSearchInput}"
5461
+ />
5462
+ ${this._chosenSearchQuery ? html`
5463
+ <button class="clear-search" @click="${this._clearChosenSearch}" title="${I18n.t("filter.clearSearch")}">
5464
+ ×
5465
+ </button>
5466
+ ` : html`
5467
+ <svg class="search-icon" viewBox="0 0 24 24">
5468
+ <path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
5469
+ </svg>
5470
+ `}
5471
+ </div>
5472
+ </div>
5473
+ <div class="picklist-list">
5474
+ ${this._getChosenRoles().map((role) => {
5475
+ var _a;
5476
+ return html`
5477
+ <div
5478
+ class="picklist-item ${this._selectedChosenRole === role.id ? "selected" : ""} ${this._draggedRoleId === role.id ? "dragging" : ""} ${this._dragOverRoleId === role.id ? "drag-over" : ""}"
5479
+ draggable="true"
5480
+ @click="${() => this._handleChosenRoleClick(role.id)}"
5481
+ @dblclick="${() => {
5482
+ this._handleChosenRoleClick(role.id);
5483
+ this._moveToAvailable();
5484
+ }}"
5485
+ @dragstart="${(e2) => this._handleDragStart(e2, role.id)}"
5486
+ @dragover="${(e2) => this._handleDragOver(e2, role.id)}"
5487
+ @dragleave="${(e2) => this._handleDragLeave(e2)}"
5488
+ @drop="${(e2) => this._handleDrop(e2, role.id)}"
5489
+ @dragend="${(e2) => this._handleDragEnd(e2)}"
5490
+ >
5491
+ <div class="picklist-item-label">${role.title}</div>
5492
+ ${((_a = role.metadata) == null ? void 0 : _a.roleURI) ? html`
5493
+ <div class="picklist-item-value">${role.metadata.roleURI}</div>
5494
+ ` : ""}
5495
+ </div>
5496
+ `;
5497
+ })}
5498
+ </div>
5499
+ <div class="picklist-count">
5500
+ ${this._tempSelectedRoles.size} role(s) selected
5501
+ </div>
5502
+ </div>
5503
+ </div>
5504
+ ` : html`
5205
5505
  <p class="description">
5206
5506
  ${I18n.t("filter.description")}
5207
5507
  </p>
@@ -5313,8 +5613,7 @@ let JupiterFilterRolesDialog = class extends LitElement {
5313
5613
  })}
5314
5614
  `}
5315
5615
  </div>
5316
-
5317
-
5616
+ `}
5318
5617
  </div>
5319
5618
 
5320
5619
  <!-- Dialog Actions -->
@@ -5659,6 +5958,126 @@ JupiterFilterRolesDialog.styles = css`
5659
5958
  opacity: 0.6;
5660
5959
  cursor: not-allowed;
5661
5960
  }
5961
+
5962
+ /* Picklist Styles for Admin Mode */
5963
+ .picklist-container {
5964
+ display: flex;
5965
+ gap: 16px;
5966
+ height: 500px;
5967
+ }
5968
+
5969
+ .picklist-panel {
5970
+ flex: 1;
5971
+ display: flex;
5972
+ flex-direction: column;
5973
+ border: 1px solid var(--jupiter-border-color, #ddd);
5974
+ border-radius: 4px;
5975
+ overflow: hidden;
5976
+ }
5977
+
5978
+ .picklist-header {
5979
+ padding: 12px;
5980
+ background: var(--jupiter-background-light, #f8f9fa);
5981
+ border-bottom: 1px solid var(--jupiter-border-color, #ddd);
5982
+ font-weight: 600;
5983
+ color: var(--jupiter-text-primary, #333);
5984
+ font-size: 14px;
5985
+ }
5986
+
5987
+ .picklist-search {
5988
+ padding: 12px;
5989
+ border-bottom: 1px solid var(--jupiter-border-color, #ddd);
5990
+ }
5991
+
5992
+ .picklist-list {
5993
+ flex: 1;
5994
+ overflow-y: auto;
5995
+ padding: 8px;
5996
+ }
5997
+
5998
+ .picklist-item {
5999
+ padding: 10px 12px;
6000
+ margin-bottom: 4px;
6001
+ border: 1px solid var(--jupiter-border-color, #ddd);
6002
+ border-radius: 4px;
6003
+ cursor: pointer;
6004
+ transition: all 0.2s ease;
6005
+ background: var(--jupiter-background, #fff);
6006
+ }
6007
+
6008
+ .picklist-item:hover {
6009
+ background: var(--jupiter-hover-background, #f5f5f5);
6010
+ border-color: var(--jupiter-primary-color, #1976d2);
6011
+ }
6012
+
6013
+ .picklist-item.selected {
6014
+ background: var(--jupiter-primary-color, #1976d2);
6015
+ color: white;
6016
+ border-color: var(--jupiter-primary-color, #1976d2);
6017
+ }
6018
+
6019
+ .picklist-item.dragging {
6020
+ opacity: 0.5;
6021
+ cursor: move;
6022
+ }
6023
+
6024
+ .picklist-item.drag-over {
6025
+ border-top: 3px solid var(--jupiter-primary-color, #1976d2);
6026
+ margin-top: 3px;
6027
+ }
6028
+
6029
+ .picklist-item[draggable="true"] {
6030
+ cursor: move;
6031
+ }
6032
+
6033
+ .picklist-item-label {
6034
+ font-weight: 500;
6035
+ font-size: 14px;
6036
+ margin-bottom: 4px;
6037
+ }
6038
+
6039
+ .picklist-item-value {
6040
+ font-size: 11px;
6041
+ opacity: 0.8;
6042
+ word-break: break-all;
6043
+ }
6044
+
6045
+ .picklist-controls {
6046
+ display: flex;
6047
+ flex-direction: column;
6048
+ justify-content: center;
6049
+ gap: 8px;
6050
+ padding: 0 8px;
6051
+ }
6052
+
6053
+ .picklist-button {
6054
+ background: var(--jupiter-primary-color, #1976d2);
6055
+ color: white;
6056
+ border: none;
6057
+ padding: 8px 16px;
6058
+ border-radius: 4px;
6059
+ cursor: pointer;
6060
+ font-size: 14px;
6061
+ transition: background-color 0.2s ease;
6062
+ }
6063
+
6064
+ .picklist-button:hover:not(:disabled) {
6065
+ background: var(--jupiter-primary-color-dark, #1565c0);
6066
+ }
6067
+
6068
+ .picklist-button:disabled {
6069
+ opacity: 0.4;
6070
+ cursor: not-allowed;
6071
+ }
6072
+
6073
+ .picklist-count {
6074
+ padding: 8px 12px;
6075
+ font-size: 12px;
6076
+ color: var(--jupiter-text-secondary, #666);
6077
+ background: var(--jupiter-background-light, #f8f9fa);
6078
+ border-top: 1px solid var(--jupiter-border-color, #ddd);
6079
+ text-align: center;
6080
+ }
5662
6081
  `;
5663
6082
  __decorateClass$1([
5664
6083
  n2({ type: Boolean, reflect: true })
@@ -5672,6 +6091,9 @@ __decorateClass$1([
5672
6091
  __decorateClass$1([
5673
6092
  n2({ type: Object })
5674
6093
  ], JupiterFilterRolesDialog.prototype, "periodPreferences", 2);
6094
+ __decorateClass$1([
6095
+ n2({ type: String })
6096
+ ], JupiterFilterRolesDialog.prototype, "mode", 2);
5675
6097
  __decorateClass$1([
5676
6098
  r()
5677
6099
  ], JupiterFilterRolesDialog.prototype, "_tempSelectedRoles", 2);
@@ -5684,6 +6106,24 @@ __decorateClass$1([
5684
6106
  __decorateClass$1([
5685
6107
  r()
5686
6108
  ], JupiterFilterRolesDialog.prototype, "_tempPeriodPreferences", 2);
6109
+ __decorateClass$1([
6110
+ r()
6111
+ ], JupiterFilterRolesDialog.prototype, "_selectedAvailableRole", 2);
6112
+ __decorateClass$1([
6113
+ r()
6114
+ ], JupiterFilterRolesDialog.prototype, "_selectedChosenRole", 2);
6115
+ __decorateClass$1([
6116
+ r()
6117
+ ], JupiterFilterRolesDialog.prototype, "_chosenSearchQuery", 2);
6118
+ __decorateClass$1([
6119
+ r()
6120
+ ], JupiterFilterRolesDialog.prototype, "_draggedRoleId", 2);
6121
+ __decorateClass$1([
6122
+ r()
6123
+ ], JupiterFilterRolesDialog.prototype, "_dragOverRoleId", 2);
6124
+ __decorateClass$1([
6125
+ r()
6126
+ ], JupiterFilterRolesDialog.prototype, "_chosenRoleOrder", 2);
5687
6127
  JupiterFilterRolesDialog = __decorateClass$1([
5688
6128
  t$1("jupiter-filter-roles-dialog")
5689
6129
  ], JupiterFilterRolesDialog);
@@ -5924,11 +6364,26 @@ let JupiterDynamicForm = class extends LitElement {
5924
6364
  });
5925
6365
  this._periodPreferences = preferences;
5926
6366
  }
6367
+ /**
6368
+ * Helper method to extract roleIds from _selectedRoleIds
6369
+ * Handles both legacy string[] and enhanced object[] structure
6370
+ */
6371
+ _getRoleIdsArray() {
6372
+ if (!Array.isArray(this._selectedRoleIds) || this._selectedRoleIds.length === 0) {
6373
+ return [];
6374
+ }
6375
+ if (typeof this._selectedRoleIds[0] === "string") {
6376
+ return this._selectedRoleIds;
6377
+ } else {
6378
+ return this._selectedRoleIds.map((item) => item.roleId);
6379
+ }
6380
+ }
5927
6381
  _applyRoleFilter() {
5928
6382
  if (!this._currentSchema || !this._allSections.length)
5929
6383
  return;
5930
- console.log(`🔍 Applying role filter: ${this._selectedRoleIds.length} selected out of ${this._allSections.length} total`);
5931
- if (this._selectedRoleIds.length === 0) {
6384
+ const roleIds = this._getRoleIdsArray();
6385
+ console.log(`🔍 Applying role filter: ${roleIds.length} selected out of ${this._allSections.length} total`);
6386
+ if (roleIds.length === 0) {
5932
6387
  console.log(`📝 No roles selected - showing empty form`);
5933
6388
  this._currentSchema = {
5934
6389
  ...this._currentSchema,
@@ -5939,17 +6394,38 @@ let JupiterDynamicForm = class extends LitElement {
5939
6394
  }
5940
6395
  this._preserveDataForHiddenSections();
5941
6396
  const filteredSections = this._allSections.filter(
5942
- (section2) => this._selectedRoleIds.includes(section2.id)
6397
+ (section2) => roleIds.includes(section2.id)
5943
6398
  );
5944
- console.log(`📊 Filtered sections: ${filteredSections.length} (IDs: ${filteredSections.map((s2) => s2.id).join(", ")})`);
5945
- this._restoreDataForVisibleSections(filteredSections);
6399
+ const orderedSections = this._sortSectionsByCustomOrder(filteredSections);
6400
+ console.log(`📊 Filtered sections: ${orderedSections.length}`);
6401
+ console.log(`📋 Custom order applied:`, orderedSections.map((s2) => s2.title));
6402
+ this._restoreDataForVisibleSections(orderedSections);
5946
6403
  this._currentSchema = {
5947
6404
  ...this._currentSchema,
5948
- sections: filteredSections
6405
+ sections: orderedSections
5949
6406
  };
5950
- console.log(`✅ Schema updated. Current sections count: ${this._currentSchema.sections.length}`);
6407
+ console.log(`✅ Schema updated with custom order. Current sections count: ${this._currentSchema.sections.length}`);
5951
6408
  this.requestUpdate();
5952
6409
  }
6410
+ /**
6411
+ * Sort sections according to custom order from _selectedRoleIds
6412
+ * Handles both enhanced structure and legacy string array
6413
+ */
6414
+ _sortSectionsByCustomOrder(sections) {
6415
+ if (Array.isArray(this._selectedRoleIds) && this._selectedRoleIds.length > 0 && typeof this._selectedRoleIds[0] === "object") {
6416
+ const enhancedRoles = this._selectedRoleIds;
6417
+ const orderMap = /* @__PURE__ */ new Map();
6418
+ enhancedRoles.forEach((role) => {
6419
+ orderMap.set(role.roleId, role.order);
6420
+ });
6421
+ return [...sections].sort((a2, b2) => {
6422
+ const orderA = orderMap.get(a2.id) ?? 999;
6423
+ const orderB = orderMap.get(b2.id) ?? 999;
6424
+ return orderA - orderB;
6425
+ });
6426
+ }
6427
+ return sections;
6428
+ }
5953
6429
  /**
5954
6430
  * Filter roles based on financialStatementsTypeAxis property
5955
6431
  * Rules:
@@ -6020,8 +6496,9 @@ let JupiterDynamicForm = class extends LitElement {
6020
6496
  _preserveDataForHiddenSections() {
6021
6497
  var _a;
6022
6498
  const currentlyVisibleSectionIds = ((_a = this._currentSchema) == null ? void 0 : _a.sections.map((s2) => s2.id)) || [];
6499
+ const selectedRoleIds = this._getRoleIdsArray();
6023
6500
  const sectionsThatWillBeHidden = currentlyVisibleSectionIds.filter(
6024
- (sectionId) => !this._selectedRoleIds.includes(sectionId)
6501
+ (sectionId) => !selectedRoleIds.includes(sectionId)
6025
6502
  );
6026
6503
  sectionsThatWillBeHidden.forEach((sectionId) => {
6027
6504
  const section2 = this._allSections.find((s2) => s2.id === sectionId);
@@ -6084,7 +6561,8 @@ let JupiterDynamicForm = class extends LitElement {
6084
6561
  }
6085
6562
  _handleFilterDialogCancel() {
6086
6563
  this._showFilterDialog = false;
6087
- console.log(`🚫 Filter dialog cancelled. Current selection: ${this._selectedRoleIds.length}/${this._allSections.length}`);
6564
+ const roleCount = this._getRoleIdsArray().length;
6565
+ console.log(`🚫 Filter dialog cancelled. Current selection: ${roleCount}/${this._allSections.length}`);
6088
6566
  }
6089
6567
  _handleRoleFilterApply(event) {
6090
6568
  const { selectedRoleIds, periodPreferences } = event.detail;
@@ -6100,6 +6578,7 @@ let JupiterDynamicForm = class extends LitElement {
6100
6578
  this.periodEndDate,
6101
6579
  this.language,
6102
6580
  this._selectedRoleIds,
6581
+ // Enhanced structure with roleURI and order
6103
6582
  this._allSections,
6104
6583
  this._typedMemberData,
6105
6584
  this._periodPreferences,
@@ -6121,12 +6600,15 @@ let JupiterDynamicForm = class extends LitElement {
6121
6600
  this._applyRoleFilter();
6122
6601
  }
6123
6602
  this._showFilterDialog = false;
6124
- console.log(`🎯 Applied role filter: ${selectedRoleIds.length}/${this._allSections.length} roles selected`);
6603
+ const roleCount = Array.isArray(this._selectedRoleIds) && this._selectedRoleIds.length > 0 ? typeof this._selectedRoleIds[0] === "string" ? this._selectedRoleIds.length : this._selectedRoleIds.length : 0;
6604
+ console.log(`🎯 Applied role filter: ${roleCount}/${this._allSections.length} roles selected`);
6605
+ console.log("📋 Enhanced selectedRoleIds structure:", this._selectedRoleIds);
6125
6606
  this.dispatchEvent(new CustomEvent("roles-filter-changed", {
6126
6607
  detail: {
6127
6608
  selectedRoleIds,
6609
+ // Enhanced structure with roleURI and order
6128
6610
  totalRoles: this._allSections.length,
6129
- visibleRoles: selectedRoleIds.length,
6611
+ visibleRoles: roleCount,
6130
6612
  periodPreferences
6131
6613
  },
6132
6614
  bubbles: true
@@ -6796,6 +7278,7 @@ let JupiterDynamicForm = class extends LitElement {
6796
7278
  console.log("📝 Form submission started...");
6797
7279
  this._submitted = true;
6798
7280
  if (this.mode === "admin") {
7281
+ this._handleSaveDraft();
6799
7282
  this._handleAdminModeSubmit();
6800
7283
  return;
6801
7284
  }
@@ -6830,6 +7313,7 @@ let JupiterDynamicForm = class extends LitElement {
6830
7313
  console.log(`✅ [Save Draft] No validation errors, proceeding with save...`);
6831
7314
  console.log("💾 Raw form data before submission generation:", this._formData);
6832
7315
  console.log("🏷️ Unit data before submission generation:", this._unitData);
7316
+ console.log("📋 Enhanced selectedRoleIds with roleURI and order:", this._selectedRoleIds);
6833
7317
  const draftData = this._generateSubmissionData();
6834
7318
  console.log("📤 Generated submission data:", draftData);
6835
7319
  console.log("📊 Submission data breakdown:");
@@ -6841,6 +7325,7 @@ let JupiterDynamicForm = class extends LitElement {
6841
7325
  this.periodEndDate,
6842
7326
  this.language,
6843
7327
  this._selectedRoleIds,
7328
+ // Enhanced structure: Array<{ roleId, roleURI, order }> or string[]
6844
7329
  this._allSections,
6845
7330
  this._typedMemberData,
6846
7331
  this._periodPreferences,
@@ -6848,6 +7333,7 @@ let JupiterDynamicForm = class extends LitElement {
6848
7333
  this._unitData
6849
7334
  );
6850
7335
  const saved = this._draftStorageService.saveDraft(draftData, metadata);
7336
+ console.log("💾 [Save Draft] Metadata saved with enhanced selectedRoleIds:", metadata.selectedRoleIds);
6851
7337
  this.dynaformsFacts = draftData;
6852
7338
  this.dynaformsMetadata = metadata;
6853
7339
  this.dispatchEvent(new CustomEvent("form-save-draft", {
@@ -6865,12 +7351,14 @@ let JupiterDynamicForm = class extends LitElement {
6865
7351
  bubbles: true,
6866
7352
  composed: true
6867
7353
  }));
7354
+ const roleCount = this._getRoleIdsArray().length;
6868
7355
  console.log("💾 Draft saved - localStorage + event emitted", {
6869
7356
  entries: draftData.length,
6870
7357
  saved,
6871
- roles: this._selectedRoleIds.length,
7358
+ roles: roleCount,
6872
7359
  customColumns: metadata.customColumns.length,
6873
- eventEmitted: true
7360
+ eventEmitted: true,
7361
+ enhancedRoleStructure: Array.isArray(this._selectedRoleIds) && this._selectedRoleIds.length > 0 && typeof this._selectedRoleIds[0] === "object"
6874
7362
  });
6875
7363
  }
6876
7364
  // ===========================================
@@ -7797,7 +8285,7 @@ let JupiterDynamicForm = class extends LitElement {
7797
8285
  });
7798
8286
  }
7799
8287
  _renderAdminModeContent(section2) {
7800
- var _a, _b, _c;
8288
+ var _a;
7801
8289
  if (!section2) {
7802
8290
  return html`
7803
8291
  <div class="admin-mode-container">
@@ -7805,10 +8293,7 @@ let JupiterDynamicForm = class extends LitElement {
7805
8293
  </div>
7806
8294
  `;
7807
8295
  }
7808
- const showPreviousYearChecked = ((_a = this._adminRoleConfigs[section2.id]) == null ? void 0 : _a.showPreviousYear) ?? section2.showPreviousYear ?? false;
7809
- const instantChecked = ((_b = this._adminRoleConfigs[section2.id]) == null ? void 0 : _b.instant) ?? section2.instant ?? false;
7810
- const durationChecked = ((_c = this._adminRoleConfigs[section2.id]) == null ? void 0 : _c.duration) ?? section2.duration ?? false;
7811
- const hasMixedPeriodTypes = section2.showPeriodControl === true;
8296
+ const showPreviousYearChecked = ((_a = this._periodPreferences[section2.id]) == null ? void 0 : _a.showPreviousYear) ?? section2.showPreviousYear ?? false;
7812
8297
  return html`
7813
8298
  <div class="admin-mode-container">
7814
8299
  <h2 class="admin-mode-title">Role Configuration: ${section2.title}</h2>
@@ -7824,32 +8309,6 @@ let JupiterDynamicForm = class extends LitElement {
7824
8309
  <label for="admin-prev-year-${section2.id}">Show Previous Year Column</label>
7825
8310
  </div>
7826
8311
  </div>
7827
-
7828
- ${hasMixedPeriodTypes ? html`
7829
- <div class="admin-role-item">
7830
- <div class="admin-role-checkbox">
7831
- <input
7832
- type="checkbox"
7833
- id="admin-instant-${section2.id}"
7834
- .checked="${instantChecked}"
7835
- @change="${(e2) => this._handleAdminCheckboxChange(section2.id, "instant", e2.target.checked)}"
7836
- />
7837
- <label for="admin-instant-${section2.id}">Show Instant Column</label>
7838
- </div>
7839
- </div>
7840
-
7841
- <div class="admin-role-item">
7842
- <div class="admin-role-checkbox">
7843
- <input
7844
- type="checkbox"
7845
- id="admin-duration-${section2.id}"
7846
- .checked="${durationChecked}"
7847
- @change="${(e2) => this._handleAdminCheckboxChange(section2.id, "duration", e2.target.checked)}"
7848
- />
7849
- <label for="admin-duration-${section2.id}">Show Duration Column</label>
7850
- </div>
7851
- </div>
7852
- ` : ""}
7853
8312
  </div>
7854
8313
  </div>
7855
8314
  `;
@@ -7863,6 +8322,20 @@ let JupiterDynamicForm = class extends LitElement {
7863
8322
  [field2]: checked
7864
8323
  }
7865
8324
  };
8325
+ const currentPeriodPref = this._periodPreferences[roleId] || {
8326
+ showDuration: true,
8327
+ showInstant: true,
8328
+ showPreviousYear: false
8329
+ };
8330
+ this._periodPreferences = {
8331
+ ...this._periodPreferences,
8332
+ [roleId]: {
8333
+ ...currentPeriodPref,
8334
+ [field2]: checked
8335
+ }
8336
+ };
8337
+ console.log(`✅ [Admin Mode] Updated ${field2} = ${checked} for role ${roleId}`);
8338
+ console.log(`📋 [Admin Mode] _periodPreferences now includes:`, this._periodPreferences[roleId]);
7866
8339
  }
7867
8340
  _handleAdminModeSubmit() {
7868
8341
  var _a, _b, _c, _d;
@@ -7883,24 +8356,33 @@ let JupiterDynamicForm = class extends LitElement {
7883
8356
  };
7884
8357
  if (config !== void 0 && isSelected) {
7885
8358
  updatedRole.showPreviousYear = config.showPreviousYear;
7886
- if (config.instant !== void 0) {
7887
- updatedRole.instant = config.instant;
7888
- }
7889
- if (config.duration !== void 0) {
7890
- updatedRole.duration = config.duration;
7891
- }
7892
8359
  }
7893
8360
  return updatedRole;
7894
8361
  });
8362
+ const savedMetadata = this.dynaformsMetadata || this._loadMetadataFromLocalStorage();
8363
+ console.log("📋 Updated Presentation Data:", updatedPresentationData);
8364
+ console.log("📋 Metadata from localStorage:", savedMetadata);
7895
8365
  this.dispatchEvent(new CustomEvent("admin-config-updated", {
7896
8366
  detail: {
7897
8367
  presentationData: updatedPresentationData,
7898
- roleConfigs: this._adminRoleConfigs
8368
+ roleConfigs: this._adminRoleConfigs,
8369
+ metadata: savedMetadata
7899
8370
  },
7900
8371
  bubbles: true,
7901
8372
  composed: true
7902
8373
  }));
7903
- console.log("✅ Admin configuration saved successfully");
8374
+ console.log("✅ Admin configuration saved successfully with metadata");
8375
+ }
8376
+ _loadMetadataFromLocalStorage() {
8377
+ try {
8378
+ const metadataStr = localStorage.getItem("jupiter-form-draft-metadata");
8379
+ if (metadataStr) {
8380
+ return JSON.parse(metadataStr);
8381
+ }
8382
+ } catch (error2) {
8383
+ console.error("Failed to load metadata from localStorage:", error2);
8384
+ }
8385
+ return null;
7904
8386
  }
7905
8387
  _renderAccordionLayout(schema, config, showValidationSummary, errorCount) {
7906
8388
  return html`
@@ -8144,13 +8626,15 @@ let JupiterDynamicForm = class extends LitElement {
8144
8626
  </button>
8145
8627
  ` : ""}
8146
8628
 
8147
- <button
8148
- class="btn-secondary"
8149
- @click="${this._handleSaveDraft}"
8150
- ?disabled="${this.disabled || this.readonly}"
8151
- >
8152
- ${I18n.t("form.saveDraft")}
8153
- </button>
8629
+ ${this.mode !== "admin" ? html`
8630
+ <button
8631
+ class="btn-secondary"
8632
+ @click="${this._handleSaveDraft}"
8633
+ ?disabled="${this.disabled || this.readonly}"
8634
+ >
8635
+ ${I18n.t("form.saveDraft")}
8636
+ </button>
8637
+ ` : ""}
8154
8638
 
8155
8639
  <button
8156
8640
  class="btn-primary"
@@ -8160,11 +8644,7 @@ let JupiterDynamicForm = class extends LitElement {
8160
8644
  ${I18n.t("form.submit")}
8161
8645
  </button>
8162
8646
 
8163
- <div class="form-meta">
8164
- <span>${I18n.t("form.errors")}: ${errorCount}</span>
8165
- <span>${I18n.t("form.modified")}: ${this._dirty ? I18n.t("form.yes") : I18n.t("form.no")}</span>
8166
- <span>${I18n.t("form.valid")}: ${this._valid ? I18n.t("form.yes") : I18n.t("form.no")}</span>
8167
- </div>
8647
+
8168
8648
  </div>
8169
8649
 
8170
8650
  <!-- Filter Roles Dialog -->
@@ -8172,8 +8652,9 @@ let JupiterDynamicForm = class extends LitElement {
8172
8652
  <jupiter-filter-roles-dialog
8173
8653
  ?open="${this._showFilterDialog}"
8174
8654
  .availableRoles="${this._allSections}"
8175
- .selectedRoleIds="${this._selectedRoleIds}"
8655
+ .selectedRoleIds="${this._getRoleIdsArray()}"
8176
8656
  .periodPreferences="${this._periodPreferences}"
8657
+ .mode="${this.mode}"
8177
8658
  @dialog-cancel="${this._handleFilterDialogCancel}"
8178
8659
  @roles-filter-apply="${this._handleRoleFilterApply}"
8179
8660
  @click="${this._handleFilterDialogCancel}"