@masterteam/work-center 0.0.100 → 0.0.101

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.
@@ -11,7 +11,7 @@ import { PropertyFilterBuilder } from '@masterteam/components/property-filter-bu
11
11
  import { StatisticCard } from '@masterteam/components/statistic-card';
12
12
  import * as i1$1 from 'primeng/skeleton';
13
13
  import { SkeletonModule } from 'primeng/skeleton';
14
- import { catchError, EMPTY, map, take, firstValueFrom, of, isObservable } from 'rxjs';
14
+ import { take, firstValueFrom, catchError, of, isObservable, map } from 'rxjs';
15
15
  import { ModalRef } from '@masterteam/components/dialog';
16
16
  import { DrawerController } from '@masterteam/components/dynamic-drawer';
17
17
  import { ClientForm, ClientFormWarningsDialog } from '@masterteam/forms/client-form';
@@ -24,8 +24,8 @@ import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http
24
24
  import { Router, ActivatedRoute } from '@angular/router';
25
25
  import { Drawer } from '@masterteam/components/drawer';
26
26
  import { RuntimeActionContextStore, RuntimeActionRunner, RUNTIME_ACTION_CONFIRM_DIALOG, hasActionFormFields, buildActionPayload, resolveActionLabel, hasActionInputFields } from '@masterteam/components/runtime-action';
27
- import { Action, Selector, State, Store, select } from '@ngxs/store';
28
- import { handleApiRequest } from '@masterteam/components';
27
+ import { WorkCenterFacade, decodeWorkCenterRouteContextKey, WORK_CENTER_LEVEL_NAME_KEY } from '@masterteam/work-center/state';
28
+ export * from '@masterteam/work-center/state';
29
29
  import { ClientInstancePreview } from '@masterteam/client-components/client-instance-preview';
30
30
  import { Tabs } from '@masterteam/components/tabs';
31
31
  import { StructureBuilder } from '@masterteam/structure-builder';
@@ -207,18 +207,18 @@ class WorkCenterGroupValue {
207
207
  return (counts?.get(label) ?? this.params().node.allLeafChildren?.length ?? 0);
208
208
  }, ...(ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []));
209
209
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: WorkCenterGroupValue, deps: [], target: i0.ɵɵFactoryTarget.Component });
210
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: WorkCenterGroupValue, isStandalone: true, selector: "ng-component", inputs: { params: { classPropertyName: "params", publicName: "params", isSignal: true, isRequired: true, transformFunction: null } }, host: { styleAttribute: "display:inline-flex;align-items:center;gap:6px" }, ngImport: i0, template: `@if (entity(); as value) {
211
- <mt-entity-preview [data]="value" />
212
- }
210
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: WorkCenterGroupValue, isStandalone: true, selector: "ng-component", inputs: { params: { classPropertyName: "params", publicName: "params", isSignal: true, isRequired: true, transformFunction: null } }, host: { styleAttribute: "display:inline-flex;align-items:center;gap:6px" }, ngImport: i0, template: `@if (entity(); as value) {
211
+ <mt-entity-preview [data]="value" />
212
+ }
213
213
  <span>({{ count() }})</span>`, isInline: true, dependencies: [{ kind: "component", type: EntityPreview, selector: "mt-entity-preview", inputs: ["data", "attachmentShape"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
214
214
  }
215
215
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: WorkCenterGroupValue, decorators: [{
216
216
  type: Component,
217
217
  args: [{
218
218
  imports: [EntityPreview],
219
- template: `@if (entity(); as value) {
220
- <mt-entity-preview [data]="value" />
221
- }
219
+ template: `@if (entity(); as value) {
220
+ <mt-entity-preview [data]="value" />
221
+ }
222
222
  <span>({{ count() }})</span>`,
223
223
  host: { style: 'display:inline-flex;align-items:center;gap:6px' },
224
224
  changeDetection: ChangeDetectionStrategy.OnPush,
@@ -452,1226 +452,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
452
452
  args: [{ selector: 'mt-work-center-grid', imports: [MtStandardGridComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: "<mt-standard-grid\n [rows]=\"visibleRows()\"\n [columns]=\"definitions()\"\n [rowId]=\"rowId\"\n [label]=\"label()\"\n [loading]=\"loading()\"\n height=\"auto\"\n [search]=\"search()\"\n [server]=\"serverPage()\"\n [exportName]=\"label()\"\n (gridReady)=\"onReady($event.api)\"\n (filterChanged)=\"filters($event)\"\n (sortChanged)=\"sorted($event)\"\n (paginationChanged)=\"paged($event)\"\n (viewChanged)=\"viewChanged()\"\n (rowClicked)=\"rowClick.emit($event)\"\n/>\n" }]
453
453
  }], ctorParameters: () => [], propDecorators: { rows: [{ type: i0.Input, args: [{ isSignal: true, alias: "rows", required: true }] }], columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: true }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: true }] }], schema: [{ type: i0.Input, args: [{ isSignal: true, alias: "schema", required: false }] }], group: [{ type: i0.Input, args: [{ isSignal: true, alias: "group", required: false }] }], total: [{ type: i0.Input, args: [{ isSignal: true, alias: "total", required: false }] }], loading: [{ type: i0.Input, args: [{ isSignal: true, alias: "loading", required: false }] }], filterRules: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterRules", required: false }] }], groupCounts: [{ type: i0.Input, args: [{ isSignal: true, alias: "groupCounts", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], viewKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewKey", required: true }] }], rowClick: [{ type: i0.Output, args: ["rowClick"] }], filtersChange: [{ type: i0.Output, args: ["filtersChange"] }], groupChange: [{ type: i0.Output, args: ["groupChange"] }], queryChange: [{ type: i0.Output, args: ["queryChange"] }] } });
454
454
 
455
- class EnterArea {
456
- area;
457
- static type = '[WorkCenter] Enter Area';
458
- constructor(area) {
459
- this.area = area;
460
- }
461
- }
462
- class HydrateFromContext {
463
- area;
464
- patch;
465
- static type = '[WorkCenter] Hydrate From Context';
466
- constructor(area, patch) {
467
- this.area = area;
468
- this.patch = patch;
469
- }
470
- }
471
- class SetParams {
472
- area;
473
- inputs;
474
- static type = '[WorkCenter] Set Params';
475
- constructor(area, inputs) {
476
- this.area = area;
477
- this.inputs = inputs;
478
- }
479
- }
480
- class SetLookups {
481
- lookups;
482
- static type = '[WorkCenter] Set Lookups';
483
- constructor(lookups) {
484
- this.lookups = lookups;
485
- }
486
- }
487
- class LoadRuntime {
488
- area;
489
- reason;
490
- static type = '[WorkCenter] Load Runtime';
491
- constructor(area, reason = 'manual') {
492
- this.area = area;
493
- this.reason = reason;
494
- }
495
- }
496
- /**
497
- * Replaces the header filter slice (rules from
498
- * `mt-property-filter-builder`). Resets `page` to 1 and triggers a
499
- * BE reload with the merged `headerFilters` + `columnFilters` payload.
500
- */
501
- class ApplyHeaderFilters {
502
- area;
503
- filters;
504
- static type = '[WorkCenter] Apply Header Filters';
505
- constructor(area, filters) {
506
- this.area = area;
507
- this.filters = filters;
508
- }
509
- }
510
- /**
511
- * Replaces the in-table column filter slice (rules translated from the
512
- * `mt-table` filters map). Resets `page` to 1 and triggers a BE reload
513
- * with the merged `headerFilters` + `columnFilters` payload.
514
- */
515
- class ApplyColumnFilters {
516
- area;
517
- filters;
518
- static type = '[WorkCenter] Apply Column Filters';
519
- constructor(area, filters) {
520
- this.area = area;
521
- this.filters = filters;
522
- }
523
- }
524
- /**
525
- * Switches the selected card and drops everything that was scoped to the
526
- * previous one: advanced filters, in-table column filters, grouping and the
527
- * sort that grouping implied. Each card brings its own columns and filter
528
- * schema, so carrying those over would filter on fields the new card doesn't
529
- * have and group by a column it doesn't show.
530
- */
531
- class SelectCard {
532
- area;
533
- selectedCardKey;
534
- static type = '[WorkCenter] Select Card';
535
- constructor(area, selectedCardKey) {
536
- this.area = area;
537
- this.selectedCardKey = selectedCardKey;
538
- }
539
- }
540
- /**
541
- * Sets the grouped column. Grouping is expressed to the backend as a single
542
- * sort on the same field, so this also rewrites `context.sort` and resets
543
- * `page` to 1 before reloading. `groupBy: null` clears both.
544
- */
545
- class SetGroupBy {
546
- area;
547
- groupBy;
548
- dir;
549
- static type = '[WorkCenter] Set Group By';
550
- constructor(area, groupBy, dir = 'asc') {
551
- this.area = area;
552
- this.groupBy = groupBy;
553
- this.dir = dir;
554
- }
555
- }
556
- /**
557
- * Clears both the header filter slice and the column filter slice in one
558
- * state update, triggering a single BE reload.
559
- */
560
- class ClearAllFilters {
561
- area;
562
- static type = '[WorkCenter] Clear All Filters';
563
- constructor(area) {
564
- this.area = area;
565
- }
566
- }
567
-
568
- var WorkCenterActionKey;
569
- (function (WorkCenterActionKey) {
570
- WorkCenterActionKey["LoadRuntime"] = "loadRuntime";
571
- })(WorkCenterActionKey || (WorkCenterActionKey = {}));
572
- const WORK_CENTER_QUERY_VERSION = 1;
573
- const WORK_CENTER_MAX_PAGE_SIZE = 100;
574
- const WORK_CENTER_MAX_FILTERS = 20;
575
- const WORK_CENTER_MAX_SORT = 5;
576
- /**
577
- * Backend column key carrying the row's LevelData display label
578
- * (`extra.levelDataName`). Grouping by it maps to a single backend sort on the
579
- * same key — see `WORK_CENTER_LEVEL_GROUP_FIELD` for the grouping identity.
580
- */
581
- const WORK_CENTER_LEVEL_NAME_KEY = 'levelDataName';
582
- /**
583
- * Synthetic per-row field holding the *identity* behind the Level Name column.
584
- * The visible label is ambiguous (two LevelData records may share a name), so
585
- * rows are bucketed by `context.levelDataId` instead — except rows with no
586
- * visible label, which get an empty identity so they all collapse into the one
587
- * shared "—" group the backend contract requires.
588
- */
589
- const WORK_CENTER_LEVEL_GROUP_FIELD = '__mtLevelGroup';
590
- /** Rendered in place of a missing / restricted LevelData label. */
591
- const WORK_CENTER_EMPTY_LABEL = '—';
592
- /**
593
- * Bootstrap `group` value meaning "the user turned grouping off". Needed
594
- * because an absent `group` means "not chosen yet" and falls back to the
595
- * default grouping — without a distinct value, clearing the group would be
596
- * undone by the next navigation.
597
- */
598
- const WORK_CENTER_GROUP_NONE = 'none';
599
-
600
- const AREA_COLORS = ['violet', 'blue', 'emerald', 'amber', 'teal'];
601
- /** Fallback accent rotation used only when the backend sends no stat color. */
602
- const KPI_COLORS = ['violet', 'blue', 'emerald', 'amber', 'teal'];
603
- /**
604
- * Default page size when bootstrapping a work-center area. Matches the table
605
- * paginator default so the first BE request asks for exactly one rendered
606
- * page.
607
- */
608
- const WORK_CENTER_DEFAULT_PAGE_SIZE = 20;
609
- const WORK_CENTER_LOCAL_FETCH_SIZE = WORK_CENTER_DEFAULT_PAGE_SIZE;
610
- const FILTER_OPERATORS = new Set([
611
- 'Eq',
612
- 'Neq',
613
- 'In',
614
- 'Contains',
615
- 'StartsWith',
616
- 'Gt',
617
- 'Gte',
618
- 'Lt',
619
- 'Lte',
620
- 'Between',
621
- 'IsNull',
622
- 'IsNotNull',
623
- ]);
624
- function clampPage(value, fallback = 1) {
625
- if (!Number.isFinite(value))
626
- return fallback;
627
- return Math.max(1, Math.floor(value));
628
- }
629
- function clampPageSize(value, fallback = WORK_CENTER_LOCAL_FETCH_SIZE) {
630
- if (!Number.isFinite(value))
631
- return fallback;
632
- const parsed = Math.floor(value);
633
- return Math.min(WORK_CENTER_MAX_PAGE_SIZE, Math.max(1, parsed));
634
- }
635
- function sanitizeSort(rules) {
636
- if (!Array.isArray(rules))
637
- return [];
638
- return rules
639
- .filter((rule) => typeof rule?.field === 'string' &&
640
- rule.field.length > 0 &&
641
- (rule.dir === 'asc' || rule.dir === 'desc'))
642
- .slice(0, WORK_CENTER_MAX_SORT);
643
- }
644
- function sanitizeFilters(filters) {
645
- if (!Array.isArray(filters))
646
- return [];
647
- return filters
648
- .filter((filter) => typeof filter?.field === 'string' &&
649
- filter.field.length > 0 &&
650
- typeof filter?.op === 'string' &&
651
- FILTER_OPERATORS.has(filter.op))
652
- .slice(0, WORK_CENTER_MAX_FILTERS);
653
- }
654
- function parseJson(value) {
655
- if (typeof value !== 'string')
656
- return value;
657
- if (!value.trim())
658
- return null;
659
- try {
660
- return JSON.parse(value);
661
- }
662
- catch {
663
- return null;
664
- }
665
- }
666
- function toOptionalInt(value) {
667
- if (value === null || value === undefined || value === '')
668
- return null;
669
- const parsed = Number(value);
670
- return Number.isFinite(parsed) ? Math.floor(parsed) : null;
671
- }
672
- function toSelectedCardKey(value) {
673
- if (typeof value !== 'string')
674
- return null;
675
- const parsed = value.trim();
676
- return parsed.length ? parsed : null;
677
- }
678
- function parseSortInput(value) {
679
- const parsed = parseJson(value);
680
- return Array.isArray(parsed)
681
- ? sanitizeSort(parsed)
682
- : [];
683
- }
684
- /**
685
- * Resolves the grouped column key from bootstrap inputs.
686
- *
687
- * A missing `group` keeps whatever state already has, so an unrelated
688
- * navigation doesn't drop the user's grouping. `WORK_CENTER_GROUP_NONE` is the
689
- * only way to express "turn it off" — a bare `null` can't, because it is also
690
- * what a host passes for an absent query param.
691
- */
692
- function resolveGroupByFromInputs(current, group) {
693
- if (!hasParamValue(group) || typeof group !== 'string') {
694
- return current;
695
- }
696
- const parsed = group.trim();
697
- if (!parsed || parsed === WORK_CENTER_GROUP_NONE) {
698
- return null;
699
- }
700
- return parsed;
701
- }
702
- /**
703
- * The card these inputs resolve to — the same rule `buildContextFromInputs`
704
- * applies, exposed so callers can detect a card switch before building the
705
- * context (what survives the switch depends on it).
706
- */
707
- function resolveSelectedCardKeyFromInputs(currentContext, inputs = {}) {
708
- return toSelectedCardKey(inputs.card) ?? currentContext.selectedCardKey;
709
- }
710
- function parseFiltersInput(value) {
711
- const parsed = parseJson(value);
712
- return Array.isArray(parsed)
713
- ? sanitizeFilters(parsed)
714
- : [];
715
- }
716
- function hasParamValue(value) {
717
- return value !== null && value !== undefined && value !== '';
718
- }
719
- function toLabel$1(value) {
720
- const segment = value.split('.').pop() ?? value;
721
- return segment
722
- .replace(/[_-]/g, ' ')
723
- .replace(/([a-z])([A-Z])/g, '$1 $2')
724
- .replace(/\s+/g, ' ')
725
- .trim()
726
- .replace(/\b\w/g, (char) => char.toUpperCase());
727
- }
728
- function toViewType(viewType, key) {
729
- if (viewType?.trim()) {
730
- return viewType;
731
- }
732
- return key.toLowerCase().includes('date') ? 'Date' : 'Text';
733
- }
734
- function normalizeColumnKey(key) {
735
- return key
736
- .trim()
737
- .toLowerCase()
738
- .replace(/[\s._-]+/g, '');
739
- }
740
- function resolveColumnWeight(key) {
741
- const normalizedKey = normalizeColumnKey(key);
742
- if (normalizedKey.includes('title'))
743
- return 26;
744
- if (normalizedKey.includes('subtitle') ||
745
- normalizedKey.includes('description')) {
746
- return 20;
747
- }
748
- if (normalizedKey.includes('status'))
749
- return 14;
750
- if (normalizedKey.includes('progress'))
751
- return 17;
752
- if (normalizedKey.includes('createdby') ||
753
- normalizedKey.includes('assignedto') ||
754
- normalizedKey.includes('owner') ||
755
- normalizedKey.includes('user')) {
756
- return 20;
757
- }
758
- if (normalizedKey.includes('duedate') ||
759
- normalizedKey.includes('createdat') ||
760
- normalizedKey.includes('updatedat') ||
761
- normalizedKey.endsWith('date')) {
762
- return 15;
763
- }
764
- if (normalizedKey.includes('priority'))
765
- return 12;
766
- return 16;
767
- }
768
- function applySmartColumnWidths(columns) {
769
- const dynamicWeightTotal = columns.reduce((total, column) => {
770
- return column.width?.trim()
771
- ? total
772
- : total + resolveColumnWeight(column.key);
773
- }, 0);
774
- if (!dynamicWeightTotal) {
775
- return columns;
776
- }
777
- return columns.map((column) => {
778
- if (column.width?.trim()) {
779
- return column;
780
- }
781
- const width = ((resolveColumnWeight(column.key) / dynamicWeightTotal) *
782
- 100).toFixed(2);
783
- return {
784
- ...column,
785
- width: `${width}%`,
786
- };
787
- });
788
- }
789
- function getValue(record, key) {
790
- return key.split('.').reduce((current, part) => {
791
- if (!current || typeof current !== 'object') {
792
- return undefined;
793
- }
794
- return current[part];
795
- }, record);
796
- }
797
- function flattenRuntimeRow(row) {
798
- const extra = row['extra'];
799
- if (!extra || typeof extra !== 'object' || Array.isArray(extra)) {
800
- return row;
801
- }
802
- return {
803
- ...extra,
804
- ...row,
805
- };
806
- }
807
- function toDisplayValue(value, column) {
808
- if (column.viewType !== 'Text') {
809
- return value;
810
- }
811
- if (!value || typeof value !== 'object') {
812
- return value;
813
- }
814
- const display = value['display'];
815
- return typeof display === 'string' ? display : value;
816
- }
817
- function buildColumnsFromProperties(properties) {
818
- return properties
819
- .filter((property) => typeof property?.key === 'string' && property.key.length > 0)
820
- .map((property) => ({
821
- ...property,
822
- key: property.key,
823
- label: property.name?.display ||
824
- property.name?.en ||
825
- property.name?.ar ||
826
- toLabel$1(property.key),
827
- type: 'entity',
828
- viewType: toViewType(property.viewType, property.key),
829
- ...withLevelNameGrouping(property.key),
830
- }));
831
- }
832
- /**
833
- * Level Name is a free-text column, so the table's cardinality heuristic would
834
- * never offer it in the group picker. The backend orders the whole result set
835
- * by that label before paging, which makes its groups contiguous and therefore
836
- * groupable — so opt it in explicitly and point the table at the identity
837
- * field instead of the ambiguous label.
838
- */
839
- function withLevelNameGrouping(key) {
840
- return key === WORK_CENTER_LEVEL_NAME_KEY
841
- ? { groupable: true, groupKey: WORK_CENTER_LEVEL_GROUP_FIELD }
842
- : {};
843
- }
844
- function buildColumns(columnsConfig) {
845
- const propertyColumns = buildColumnsFromProperties(columnsConfig?.properties ?? []);
846
- if (propertyColumns.length) {
847
- return applySmartColumnWidths(propertyColumns);
848
- }
849
- const keys = columnsConfig?.columns?.length ? columnsConfig.columns : [];
850
- return applySmartColumnWidths(keys.map((key) => ({
851
- key,
852
- label: toLabel$1(key),
853
- type: 'entity',
854
- viewType: toViewType(undefined, key),
855
- ...withLevelNameGrouping(key),
856
- })));
857
- }
858
- function toDisplayRows(rows, columns) {
859
- const hasLevelName = columns.some((column) => column.key === WORK_CENTER_LEVEL_NAME_KEY);
860
- return rows.map((row) => {
861
- const sourceRow = flattenRuntimeRow(row);
862
- const displayRow = { ...sourceRow };
863
- for (const column of columns) {
864
- const value = getValue(sourceRow, column.key);
865
- displayRow[column.key] = {
866
- ...column,
867
- value: toDisplayValue(value, column),
868
- };
869
- }
870
- if (hasLevelName) {
871
- applyLevelNameGrouping(displayRow, sourceRow);
872
- }
873
- return displayRow;
874
- });
875
- }
876
- /**
877
- * Adds the Level Name grouping identity to a display row and normalizes a
878
- * missing / restricted label to `—`.
879
- *
880
- * The backend omits `extra.levelDataName` when the record is missing, deleted,
881
- * or the user can't see it — those rows must share one group and must never
882
- * expose the numeric id as a label. Rows that do have a label are keyed by
883
- * `context.levelDataId` so two records with the same name stay separate.
884
- */
885
- function applyLevelNameGrouping(displayRow, sourceRow) {
886
- const cell = displayRow[WORK_CENTER_LEVEL_NAME_KEY];
887
- const label = typeof cell?.value === 'string' ? cell.value.trim() : '';
888
- if (!label) {
889
- displayRow[WORK_CENTER_LEVEL_NAME_KEY] = {
890
- ...cell,
891
- value: WORK_CENTER_EMPTY_LABEL,
892
- };
893
- displayRow[WORK_CENTER_LEVEL_GROUP_FIELD] = '';
894
- return;
895
- }
896
- const levelDataId = getValue(sourceRow, 'context.levelDataId');
897
- const hasId = levelDataId !== null && levelDataId !== undefined && levelDataId !== '';
898
- displayRow[WORK_CENTER_LEVEL_GROUP_FIELD] = hasId
899
- ? `id:${String(levelDataId)}`
900
- : `name:${label}`;
901
- }
902
- function buildMenuItems(cards) {
903
- const mapped = cards.map((card, index) => ({
904
- key: card.key,
905
- title: card.name?.display || card.name?.en || card.name?.ar || toLabel$1(card.key),
906
- subtitle: undefined,
907
- count: card.count ?? 0,
908
- color: AREA_COLORS[index % AREA_COLORS.length],
909
- icon: card.icon ?? 'custom.task',
910
- isAvailable: card.isAvailable !== false,
911
- }));
912
- const available = mapped.filter((card) => card.isAvailable);
913
- const source = available.length ? available : mapped;
914
- return source.map((card) => ({
915
- key: card.key,
916
- title: card.title,
917
- subtitle: undefined,
918
- count: card.count ?? 0,
919
- color: card.color,
920
- icon: card.icon ?? 'custom.task',
921
- }));
922
- }
923
- /**
924
- * KPI accent colors are owned by the backend (`stats[].color`) and used
925
- * verbatim. Only when the backend sends no color do we fall back to the
926
- * previous `KPI_COLORS` rotation by card position — never map a color from
927
- * the stat key or label.
928
- */
929
- function buildKpis(stats, fallbackIcon) {
930
- return stats.map((stat, index) => ({
931
- title: String(stat.count ?? 0),
932
- subTitle: stat.label.display,
933
- icon: (fallbackIcon ?? 'custom.task'),
934
- color: stat.color?.trim() || KPI_COLORS[index % KPI_COLORS.length],
935
- }));
936
- }
937
- /** The backend sort that renders a grouped column as contiguous rows. */
938
- function sortForGroup(groupBy) {
939
- return groupBy ? [{ field: groupBy, dir: 'asc' }] : [];
940
- }
941
- function createDefaultContext(area) {
942
- return {
943
- area,
944
- templateId: null,
945
- levelDataId: null,
946
- selectedCardKey: null,
947
- page: 1,
948
- pageSize: WORK_CENTER_LOCAL_FETCH_SIZE,
949
- sort: [],
950
- runtimeFilters: [],
951
- includeStats: true,
952
- };
953
- }
954
- function createDefaultAreaState(area) {
955
- return {
956
- context: createDefaultContext(area),
957
- headerFilters: [],
958
- columnFilters: [],
959
- groupBy: null,
960
- menuItems: [],
961
- rows: [],
962
- columns: [],
963
- kpis: [],
964
- runtimeFilterSchema: null,
965
- totalCount: 0,
966
- warnings: [],
967
- lastLoadedAt: null,
968
- };
969
- }
970
- /**
971
- * Combines header (property-filter-builder) and column (in-table) rules into
972
- * the single `runtimeFilters` payload the BE expects. Header rules come
973
- * first; a column rule with the same `(field, op)` pair replaces the matching
974
- * header rule.
975
- */
976
- function mergeRuntimeFilters(headerFilters, columnFilters) {
977
- const seen = new Map();
978
- const ordered = [];
979
- const push = (rule) => {
980
- const key = `${rule.field}::${rule.op}`;
981
- if (!seen.has(key))
982
- ordered.push(key);
983
- seen.set(key, rule);
984
- };
985
- (headerFilters ?? []).forEach(push);
986
- (columnFilters ?? []).forEach(push);
987
- return sanitizeFilters(ordered.map((key) => seen.get(key)));
988
- }
989
- const WORK_CENTER_DEFAULT_STATE = {
990
- activeArea: 'MyInbox',
991
- byArea: {
992
- MyInbox: createDefaultAreaState('MyInbox'),
993
- TasksCenter: createDefaultAreaState('TasksCenter'),
994
- Workspace: createDefaultAreaState('Workspace'),
995
- },
996
- lookups: [],
997
- loadingActive: [],
998
- errors: {},
999
- };
1000
- function normalizeContext(context) {
1001
- return {
1002
- ...context,
1003
- page: clampPage(context.page, 1),
1004
- pageSize: clampPageSize(context.pageSize, WORK_CENTER_LOCAL_FETCH_SIZE),
1005
- sort: sanitizeSort(context.sort),
1006
- runtimeFilters: sanitizeFilters(context.runtimeFilters),
1007
- };
1008
- }
1009
- function buildContextFromInputs(currentContext, area, inputs = {},
1010
- /**
1011
- * Already-resolved grouped column. Grouping is executed as a backend sort,
1012
- * so when the host supplies no explicit `sort` the grouped column defines
1013
- * it — that is what makes the default grouping reach the very first request
1014
- * instead of costing a second round trip.
1015
- */
1016
- groupBy = null) {
1017
- const parsedCardKey = toSelectedCardKey(inputs.card);
1018
- const parsedTemplateId = toOptionalInt(inputs.templateId);
1019
- const parsedLevelDataId = toOptionalInt(inputs.levelDataId);
1020
- const hasPageInput = hasParamValue(inputs.page);
1021
- const parsedPage = hasPageInput ? toOptionalInt(inputs.page) : null;
1022
- const parsedPageSize = toOptionalInt(inputs.pageSize);
1023
- return normalizeContext({
1024
- ...currentContext,
1025
- area,
1026
- selectedCardKey: parsedCardKey ?? currentContext.selectedCardKey,
1027
- page: hasPageInput ? (parsedPage ?? 1) : 1,
1028
- pageSize: parsedPageSize ?? currentContext.pageSize,
1029
- templateId: parsedTemplateId ?? currentContext.templateId,
1030
- levelDataId: parsedLevelDataId ?? currentContext.levelDataId,
1031
- sort: hasParamValue(inputs.sort)
1032
- ? parseSortInput(inputs.sort)
1033
- : groupBy
1034
- ? sortForGroup(groupBy)
1035
- : inputs.sort === null
1036
- ? []
1037
- : currentContext.sort,
1038
- runtimeFilters: hasParamValue(inputs.filters)
1039
- ? parseFiltersInput(inputs.filters)
1040
- : inputs.filters === null
1041
- ? []
1042
- : currentContext.runtimeFilters,
1043
- });
1044
- }
1045
- function isSameContext(left, right) {
1046
- return (left.area === right.area &&
1047
- left.templateId === right.templateId &&
1048
- left.levelDataId === right.levelDataId &&
1049
- left.selectedCardKey === right.selectedCardKey &&
1050
- left.page === right.page &&
1051
- left.pageSize === right.pageSize &&
1052
- left.includeStats === right.includeStats &&
1053
- JSON.stringify(left.sort) === JSON.stringify(right.sort) &&
1054
- JSON.stringify(left.runtimeFilters) === JSON.stringify(right.runtimeFilters));
1055
- }
1056
- function mapRuntimeResponse(current, response) {
1057
- const selectedCard = response.selectedCard;
1058
- const menuItems = buildMenuItems(response.cards);
1059
- const requestedCardKey = selectedCard?.key ?? current.context.selectedCardKey ?? null;
1060
- const selectedCardKey = requestedCardKey &&
1061
- response.cards.some((card) => card.key === requestedCardKey)
1062
- ? requestedCardKey
1063
- : (menuItems[0]?.key ?? response.cards[0]?.key ?? null);
1064
- const selectedCardFromList = selectedCardKey
1065
- ? (response.cards.find((card) => card.key === selectedCardKey) ?? null)
1066
- : null;
1067
- const selectedMenuItem = menuItems.find((item) => item.key === selectedCardKey);
1068
- const columns = buildColumns(selectedCard?.columnsConfig ?? selectedCardFromList?.columnsConfig);
1069
- const rows = toDisplayRows(selectedCard?.items ?? [], columns);
1070
- const kpis = buildKpis(selectedCard?.stats ?? [], selectedMenuItem?.icon ?? null);
1071
- // A card that doesn't advertise the grouped column can't be grouped by it —
1072
- // drop it here rather than letting the table discover the stale column and
1073
- // bounce a second request. The sort goes with it when it was the one the
1074
- // grouping asked for.
1075
- const groupBy = current.groupBy && columns.some((column) => column.key === current.groupBy)
1076
- ? current.groupBy
1077
- : null;
1078
- const droppedGroup = !groupBy && current.groupBy;
1079
- const sort = droppedGroup && isSortForGroup(current.context.sort, current.groupBy)
1080
- ? []
1081
- : current.context.sort;
1082
- return {
1083
- ...current,
1084
- groupBy,
1085
- menuItems,
1086
- rows,
1087
- columns,
1088
- kpis,
1089
- runtimeFilterSchema: selectedCard?.runtimeFilterSchema ??
1090
- selectedCardFromList?.runtimeFilterSchema ??
1091
- null,
1092
- totalCount: selectedCard?.pagination.totalCount ?? 0,
1093
- warnings: response.warnings ?? [],
1094
- lastLoadedAt: new Date().toISOString(),
1095
- context: {
1096
- ...current.context,
1097
- selectedCardKey,
1098
- sort,
1099
- page: selectedCard?.pagination.page ?? current.context.page,
1100
- pageSize: selectedCard?.pagination.pageSize ?? current.context.pageSize,
1101
- },
1102
- };
1103
- }
1104
- /** True when `sort` is exactly the single rule a grouping would produce. */
1105
- function isSortForGroup(sort, groupBy) {
1106
- return !!groupBy && sort.length === 1 && sort[0].field === groupBy;
1107
- }
1108
-
1109
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1110
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1111
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1112
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1113
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1114
- };
1115
- let WorkCenterState = class WorkCenterState {
1116
- http = inject(HttpClient);
1117
- static getState(state) {
1118
- return state;
1119
- }
1120
- static activeArea(state) {
1121
- return state.activeArea;
1122
- }
1123
- static activeSnapshot(activeArea, state) {
1124
- return state.byArea[activeArea];
1125
- }
1126
- static context(snapshot) {
1127
- return snapshot.context;
1128
- }
1129
- static menuItems(snapshot) {
1130
- return snapshot.menuItems;
1131
- }
1132
- static rows(snapshot) {
1133
- return snapshot.rows;
1134
- }
1135
- static columns(snapshot) {
1136
- return snapshot.columns;
1137
- }
1138
- static kpis(snapshot) {
1139
- return snapshot.kpis;
1140
- }
1141
- static runtimeFilterSchema(snapshot) {
1142
- return snapshot.runtimeFilterSchema;
1143
- }
1144
- static headerFilters(snapshot) {
1145
- return snapshot.headerFilters;
1146
- }
1147
- static columnFilters(snapshot) {
1148
- return snapshot.columnFilters;
1149
- }
1150
- static groupBy(snapshot) {
1151
- return snapshot.groupBy;
1152
- }
1153
- static totalCount(snapshot) {
1154
- return snapshot.totalCount;
1155
- }
1156
- static warnings(snapshot) {
1157
- return snapshot.warnings;
1158
- }
1159
- static lookups(state) {
1160
- return state.lookups;
1161
- }
1162
- static getLoadingActive(state) {
1163
- return state.loadingActive;
1164
- }
1165
- static getErrors(state) {
1166
- return state.errors;
1167
- }
1168
- enterArea(ctx, action) {
1169
- if (ctx.getState().activeArea === action.area)
1170
- return;
1171
- ctx.patchState({ activeArea: action.area });
1172
- }
1173
- hydrateFromContext(ctx, action) {
1174
- const state = ctx.getState();
1175
- const current = state.byArea[action.area];
1176
- const nextContext = normalizeContext({
1177
- ...current.context,
1178
- ...action.patch,
1179
- area: action.area,
1180
- });
1181
- if (state.activeArea === action.area &&
1182
- isSameContext(current.context, nextContext)) {
1183
- return;
1184
- }
1185
- // External `runtimeFilters` writes are treated as header-slice writes so
1186
- // the in-table column filter slice doesn't get stranded out of sync.
1187
- const filtersChanged = action.patch.runtimeFilters !== undefined;
1188
- const nextHeaderFilters = filtersChanged
1189
- ? nextContext.runtimeFilters
1190
- : current.headerFilters;
1191
- const nextColumnFilters = filtersChanged ? [] : current.columnFilters;
1192
- ctx.patchState({
1193
- activeArea: action.area,
1194
- byArea: {
1195
- ...state.byArea,
1196
- [action.area]: {
1197
- ...current,
1198
- headerFilters: nextHeaderFilters,
1199
- columnFilters: nextColumnFilters,
1200
- context: nextContext,
1201
- },
1202
- },
1203
- });
1204
- }
1205
- setParams(ctx, action) {
1206
- const state = ctx.getState();
1207
- const current = state.byArea[action.area];
1208
- // A card switch invalidates everything scoped to the previous card. The
1209
- // host usually drops those query params too, but a stale URL must not be
1210
- // able to re-apply a filter on a field the new card doesn't have.
1211
- const cardChanged = resolveSelectedCardKeyFromInputs(current.context, action.inputs) !==
1212
- current.context.selectedCardKey;
1213
- // Resolve grouping first: with no explicit `sort` input it is what defines
1214
- // the backend sort.
1215
- const nextGroupBy = resolveGroupByFromInputs(cardChanged ? null : current.groupBy, action.inputs?.group);
1216
- const builtContext = buildContextFromInputs(current.context, action.area, action.inputs, nextGroupBy);
1217
- const filtersFromInputs = action.inputs?.filters !== undefined;
1218
- const nextContext = cardChanged && !filtersFromInputs
1219
- ? { ...builtContext, runtimeFilters: [] }
1220
- : builtContext;
1221
- const areaChanged = state.activeArea !== action.area;
1222
- const contextChanged = !isSameContext(current.context, nextContext);
1223
- const groupChanged = nextGroupBy !== current.groupBy;
1224
- const runtimeLoading = state.loadingActive.includes(WorkCenterActionKey.LoadRuntime);
1225
- const shouldLoad = areaChanged || contextChanged || !runtimeLoading;
1226
- if (areaChanged || contextChanged || groupChanged) {
1227
- // URL-derived filters land on the header slice. Anything previously
1228
- // applied via the in-table column filters is dropped so the BE payload
1229
- // matches what the user sees on the page header.
1230
- const nextHeaderFilters = filtersFromInputs
1231
- ? nextContext.runtimeFilters
1232
- : cardChanged
1233
- ? []
1234
- : current.headerFilters;
1235
- const nextColumnFilters = filtersFromInputs || cardChanged ? [] : current.columnFilters;
1236
- ctx.patchState({
1237
- activeArea: action.area,
1238
- byArea: {
1239
- ...state.byArea,
1240
- [action.area]: {
1241
- ...current,
1242
- headerFilters: nextHeaderFilters,
1243
- columnFilters: nextColumnFilters,
1244
- groupBy: nextGroupBy,
1245
- context: nextContext,
1246
- },
1247
- },
1248
- });
1249
- }
1250
- if (!shouldLoad)
1251
- return;
1252
- return ctx.dispatch(new LoadRuntime(action.area, 'route-enter'));
1253
- }
1254
- setLookups(ctx, action) {
1255
- if (ctx.getState().lookups === action.lookups) {
1256
- return;
1257
- }
1258
- ctx.patchState({
1259
- lookups: Array.isArray(action.lookups) ? action.lookups : [],
1260
- });
1261
- }
1262
- applyHeaderFilters(ctx, action) {
1263
- return this.applyFilterSlice(ctx, action.area, {
1264
- headerFilters: action.filters,
1265
- });
1266
- }
1267
- applyColumnFilters(ctx, action) {
1268
- return this.applyFilterSlice(ctx, action.area, {
1269
- columnFilters: action.filters,
1270
- });
1271
- }
1272
- selectCard(ctx, action) {
1273
- const state = ctx.getState();
1274
- const current = state.byArea[action.area];
1275
- if (current.context.selectedCardKey === action.selectedCardKey) {
1276
- return;
1277
- }
1278
- ctx.patchState({
1279
- activeArea: action.area,
1280
- byArea: {
1281
- ...state.byArea,
1282
- [action.area]: {
1283
- ...current,
1284
- headerFilters: [],
1285
- columnFilters: [],
1286
- groupBy: null,
1287
- context: {
1288
- ...current.context,
1289
- selectedCardKey: action.selectedCardKey,
1290
- runtimeFilters: [],
1291
- sort: [],
1292
- page: 1,
1293
- },
1294
- },
1295
- },
1296
- });
1297
- return ctx.dispatch(new LoadRuntime(action.area, 'menu-change'));
1298
- }
1299
- /**
1300
- * Grouping is a backend concern: the table only renders contiguous rows, so
1301
- * the grouped column is pushed down as the single `context.sort` entry and
1302
- * pagination restarts at page 1. Clearing the group sends `sort: []`.
1303
- */
1304
- setGroupBy(ctx, action) {
1305
- const state = ctx.getState();
1306
- const current = state.byArea[action.area];
1307
- const nextGroupBy = action.groupBy?.trim() ? action.groupBy : null;
1308
- const nextSort = nextGroupBy
1309
- ? [{ field: nextGroupBy, dir: action.dir }]
1310
- : [];
1311
- const sameGroup = current.groupBy === nextGroupBy;
1312
- const sameSort = JSON.stringify(current.context.sort) === JSON.stringify(nextSort);
1313
- if (sameGroup && sameSort)
1314
- return;
1315
- ctx.patchState({
1316
- activeArea: action.area,
1317
- byArea: {
1318
- ...state.byArea,
1319
- [action.area]: {
1320
- ...current,
1321
- groupBy: nextGroupBy,
1322
- context: sameSort
1323
- ? current.context
1324
- : { ...current.context, sort: nextSort, page: 1 },
1325
- },
1326
- },
1327
- });
1328
- // A group change that doesn't move the backend order (already sorted by
1329
- // that field) is a pure render concern — no refetch.
1330
- if (sameSort)
1331
- return;
1332
- return ctx.dispatch(new LoadRuntime(action.area, 'group-change'));
1333
- }
1334
- clearAllFilters(ctx, action) {
1335
- return this.applyFilterSlice(ctx, action.area, {
1336
- headerFilters: [],
1337
- columnFilters: [],
1338
- });
1339
- }
1340
- applyFilterSlice(ctx, area, patch) {
1341
- const state = ctx.getState();
1342
- const current = state.byArea[area];
1343
- const headerFilters = patch.headerFilters ?? current.headerFilters;
1344
- const columnFilters = patch.columnFilters ?? current.columnFilters;
1345
- const runtimeFilters = mergeRuntimeFilters(headerFilters, columnFilters);
1346
- const sameHeader = JSON.stringify(headerFilters) === JSON.stringify(current.headerFilters);
1347
- const sameColumn = JSON.stringify(columnFilters) === JSON.stringify(current.columnFilters);
1348
- const sameMerged = JSON.stringify(runtimeFilters) ===
1349
- JSON.stringify(current.context.runtimeFilters);
1350
- if (sameHeader && sameColumn && sameMerged) {
1351
- return;
1352
- }
1353
- ctx.patchState({
1354
- activeArea: area,
1355
- byArea: {
1356
- ...state.byArea,
1357
- [area]: {
1358
- ...current,
1359
- headerFilters,
1360
- columnFilters,
1361
- context: {
1362
- ...current.context,
1363
- runtimeFilters,
1364
- page: 1,
1365
- },
1366
- },
1367
- },
1368
- });
1369
- return ctx.dispatch(new LoadRuntime(area, 'filters-change'));
1370
- }
1371
- loadRuntime(ctx, action) {
1372
- const state = ctx.getState();
1373
- const areaState = state.byArea[action.area];
1374
- const request = normalizeContext(areaState.context);
1375
- const nextAreaState = {
1376
- ...areaState,
1377
- rows: [],
1378
- kpis: [],
1379
- totalCount: 0,
1380
- };
1381
- ctx.patchState({
1382
- byArea: {
1383
- ...state.byArea,
1384
- [action.area]: nextAreaState,
1385
- },
1386
- });
1387
- return handleApiRequest({
1388
- ctx,
1389
- key: WorkCenterActionKey.LoadRuntime,
1390
- request$: this.getRuntime(request),
1391
- onSuccess: (response, latestState) => {
1392
- const current = latestState.byArea[action.area];
1393
- return {
1394
- byArea: {
1395
- ...latestState.byArea,
1396
- [action.area]: mapRuntimeResponse(current, response),
1397
- },
1398
- };
1399
- },
1400
- errorMessage: 'Failed to load Work Center runtime.',
1401
- }).pipe(catchError(() => EMPTY));
1402
- }
1403
- getRuntime(request) {
1404
- return this.http
1405
- .post('workcenter/runtime', request)
1406
- .pipe(map((response) => {
1407
- if (response.code === 1)
1408
- return response.data;
1409
- const fallbackError = 'Failed to load Work Center runtime.';
1410
- const message = response.errors?.message ??
1411
- response.message ??
1412
- fallbackError;
1413
- throw new Error(message);
1414
- }));
1415
- }
1416
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: WorkCenterState, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1417
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: WorkCenterState });
1418
- };
1419
- __decorate([
1420
- Action(EnterArea)
1421
- ], WorkCenterState.prototype, "enterArea", null);
1422
- __decorate([
1423
- Action(HydrateFromContext)
1424
- ], WorkCenterState.prototype, "hydrateFromContext", null);
1425
- __decorate([
1426
- Action(SetParams)
1427
- ], WorkCenterState.prototype, "setParams", null);
1428
- __decorate([
1429
- Action(SetLookups)
1430
- ], WorkCenterState.prototype, "setLookups", null);
1431
- __decorate([
1432
- Action(ApplyHeaderFilters)
1433
- ], WorkCenterState.prototype, "applyHeaderFilters", null);
1434
- __decorate([
1435
- Action(ApplyColumnFilters)
1436
- ], WorkCenterState.prototype, "applyColumnFilters", null);
1437
- __decorate([
1438
- Action(SelectCard)
1439
- ], WorkCenterState.prototype, "selectCard", null);
1440
- __decorate([
1441
- Action(SetGroupBy)
1442
- ], WorkCenterState.prototype, "setGroupBy", null);
1443
- __decorate([
1444
- Action(ClearAllFilters)
1445
- ], WorkCenterState.prototype, "clearAllFilters", null);
1446
- __decorate([
1447
- Action(LoadRuntime)
1448
- ], WorkCenterState.prototype, "loadRuntime", null);
1449
- __decorate([
1450
- Selector()
1451
- ], WorkCenterState, "getState", null);
1452
- __decorate([
1453
- Selector()
1454
- ], WorkCenterState, "activeArea", null);
1455
- __decorate([
1456
- Selector([WorkCenterState.activeArea, WorkCenterState.getState])
1457
- ], WorkCenterState, "activeSnapshot", null);
1458
- __decorate([
1459
- Selector([WorkCenterState.activeSnapshot])
1460
- ], WorkCenterState, "context", null);
1461
- __decorate([
1462
- Selector([WorkCenterState.activeSnapshot])
1463
- ], WorkCenterState, "menuItems", null);
1464
- __decorate([
1465
- Selector([WorkCenterState.activeSnapshot])
1466
- ], WorkCenterState, "rows", null);
1467
- __decorate([
1468
- Selector([WorkCenterState.activeSnapshot])
1469
- ], WorkCenterState, "columns", null);
1470
- __decorate([
1471
- Selector([WorkCenterState.activeSnapshot])
1472
- ], WorkCenterState, "kpis", null);
1473
- __decorate([
1474
- Selector([WorkCenterState.activeSnapshot])
1475
- ], WorkCenterState, "runtimeFilterSchema", null);
1476
- __decorate([
1477
- Selector([WorkCenterState.activeSnapshot])
1478
- ], WorkCenterState, "headerFilters", null);
1479
- __decorate([
1480
- Selector([WorkCenterState.activeSnapshot])
1481
- ], WorkCenterState, "columnFilters", null);
1482
- __decorate([
1483
- Selector([WorkCenterState.activeSnapshot])
1484
- ], WorkCenterState, "groupBy", null);
1485
- __decorate([
1486
- Selector([WorkCenterState.activeSnapshot])
1487
- ], WorkCenterState, "totalCount", null);
1488
- __decorate([
1489
- Selector([WorkCenterState.activeSnapshot])
1490
- ], WorkCenterState, "warnings", null);
1491
- __decorate([
1492
- Selector()
1493
- ], WorkCenterState, "lookups", null);
1494
- __decorate([
1495
- Selector()
1496
- ], WorkCenterState, "getLoadingActive", null);
1497
- __decorate([
1498
- Selector()
1499
- ], WorkCenterState, "getErrors", null);
1500
- WorkCenterState = __decorate([
1501
- State({
1502
- name: 'workCenter',
1503
- defaults: WORK_CENTER_DEFAULT_STATE,
1504
- })
1505
- ], WorkCenterState);
1506
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: WorkCenterState, decorators: [{
1507
- type: Injectable
1508
- }], propDecorators: { enterArea: [], hydrateFromContext: [], setParams: [], setLookups: [], applyHeaderFilters: [], applyColumnFilters: [], selectCard: [], setGroupBy: [], clearAllFilters: [], loadRuntime: [] } });
1509
-
1510
- class WorkCenterFacade {
1511
- store = inject(Store);
1512
- activeArea = select(WorkCenterState.activeArea);
1513
- context = select(WorkCenterState.context);
1514
- menuItems = select(WorkCenterState.menuItems);
1515
- rows = select(WorkCenterState.rows);
1516
- columns = select(WorkCenterState.columns);
1517
- kpis = select(WorkCenterState.kpis);
1518
- lookups = select(WorkCenterState.lookups);
1519
- runtimeFilterSchema = select(WorkCenterState.runtimeFilterSchema);
1520
- headerFilters = select(WorkCenterState.headerFilters);
1521
- columnFilters = select(WorkCenterState.columnFilters);
1522
- groupBy = select(WorkCenterState.groupBy);
1523
- totalCount = select(WorkCenterState.totalCount);
1524
- warnings = select(WorkCenterState.warnings);
1525
- loadingActive = select(WorkCenterState.getLoadingActive);
1526
- errors = select(WorkCenterState.getErrors);
1527
- loading = computed(() => this.loadingActive().includes(WorkCenterActionKey.LoadRuntime), ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
1528
- error = computed(() => this.errors()[WorkCenterActionKey.LoadRuntime] ?? null, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
1529
- /**
1530
- * Snapshot reads for callers that must observe state *immediately* after a
1531
- * dispatch — e.g. an output handler mirroring the runtime query into the URL.
1532
- * The `select()` signals above are the right choice everywhere else.
1533
- */
1534
- snapshotContext() {
1535
- return this.store.selectSnapshot(WorkCenterState.context);
1536
- }
1537
- snapshotGroupBy() {
1538
- return this.store.selectSnapshot(WorkCenterState.groupBy);
1539
- }
1540
- enterArea(area) {
1541
- return this.store.dispatch(new EnterArea(area));
1542
- }
1543
- hydrateContext(area, patch) {
1544
- return this.store.dispatch(new HydrateFromContext(area, patch));
1545
- }
1546
- setParams(area, inputs) {
1547
- return this.store.dispatch(new SetParams(area, inputs));
1548
- }
1549
- setLookups(lookups) {
1550
- return this.store.dispatch(new SetLookups(lookups));
1551
- }
1552
- /**
1553
- * Switches card and drops the previous card's filters, grouping and sort —
1554
- * each card has its own columns and filter schema.
1555
- */
1556
- selectCardAndLoad(area, selectedCardKey) {
1557
- return this.store.dispatch(new SelectCard(area, selectedCardKey));
1558
- }
1559
- applyTableLazyLoadAndLoad(area, event) {
1560
- const context = this.store.selectSnapshot(WorkCenterState.context);
1561
- const patch = {};
1562
- let changed = false;
1563
- const page = this.toPositiveInt(event?.currentPage);
1564
- if (page !== null && page !== context.page) {
1565
- patch.page = page;
1566
- changed = true;
1567
- }
1568
- const pageSize = this.toPositiveInt(event?.pageSize);
1569
- if (pageSize !== null) {
1570
- const normalizedPageSize = Math.min(WORK_CENTER_MAX_PAGE_SIZE, Math.max(1, pageSize));
1571
- if (normalizedPageSize !== context.pageSize) {
1572
- patch.pageSize = normalizedPageSize;
1573
- changed = true;
1574
- }
1575
- }
1576
- const sort = this.toSortFromLazyEvent(event);
1577
- if (sort && !this.isSameSort(sort, context.sort)) {
1578
- patch.sort = sort;
1579
- changed = true;
1580
- }
1581
- if (!changed) {
1582
- return;
1583
- }
1584
- return this.store.dispatch([
1585
- new HydrateFromContext(area, patch),
1586
- new LoadRuntime(area, 'table-lazy'),
1587
- ]);
1588
- }
1589
- applyRuntimeFiltersAndLoad(area, runtimeFilters) {
1590
- // Back-compat: any caller that previously set the entire `runtimeFilters`
1591
- // array now lands on the header slice. The in-table column filter slice is
1592
- // cleared so the merged payload matches what callers expect.
1593
- return this.store.dispatch(new ApplyHeaderFilters(area, runtimeFilters));
1594
- }
1595
- /**
1596
- * Replaces the property-filter-builder slice. Resets pagination to page 1
1597
- * and reloads with merged `headerFilters` + `columnFilters`.
1598
- */
1599
- applyHeaderFiltersAndLoad(area, runtimeFilters) {
1600
- return this.store.dispatch(new ApplyHeaderFilters(area, runtimeFilters));
1601
- }
1602
- /**
1603
- * Replaces the in-table column filter slice. Resets pagination to page 1
1604
- * and reloads with merged `headerFilters` + `columnFilters`.
1605
- */
1606
- applyColumnFiltersAndLoad(area, runtimeFilters) {
1607
- return this.store.dispatch(new ApplyColumnFilters(area, runtimeFilters));
1608
- }
1609
- /**
1610
- * Groups the table by `groupBy` (or clears grouping with `null`). Pushes the
1611
- * grouped column down as the single backend sort, resets to page 1 and
1612
- * reloads. Safe to call from the table's `groupByChange` — the lazy event
1613
- * that follows carries the same sort and is absorbed as a no-op.
1614
- */
1615
- setGroupByAndLoad(area, groupBy, dir = 'asc') {
1616
- return this.store.dispatch(new SetGroupBy(area, groupBy, dir));
1617
- }
1618
- /**
1619
- * Clears both header and column filter slices in one state update,
1620
- * triggering a single BE reload.
1621
- */
1622
- clearAllFiltersAndLoad(area) {
1623
- return this.store.dispatch(new ClearAllFilters(area));
1624
- }
1625
- loadRuntime(area, reason = 'manual') {
1626
- return this.store.dispatch(new LoadRuntime(area, reason));
1627
- }
1628
- toPositiveInt(value) {
1629
- const parsed = Number(value);
1630
- if (!Number.isFinite(parsed)) {
1631
- return null;
1632
- }
1633
- return Math.max(1, Math.floor(parsed));
1634
- }
1635
- /**
1636
- * `mt-table` always reports its sort on a lazy event, so a `null` field is an
1637
- * explicit "no sort" and must clear `context.sort` (the BE contract asks for
1638
- * `sort: []`). Only an event with no `sortField` key at all — nothing the
1639
- * current table emits — leaves the existing sort alone.
1640
- */
1641
- toSortFromLazyEvent(event) {
1642
- if (!event || !('sortField' in event)) {
1643
- return null;
1644
- }
1645
- const sortField = event.sortField;
1646
- if (typeof sortField !== 'string' || !sortField.length) {
1647
- return [];
1648
- }
1649
- return [
1650
- {
1651
- field: sortField,
1652
- dir: event.sortOrder === -1 ? 'desc' : 'asc',
1653
- },
1654
- ];
1655
- }
1656
- isSameSort(left, right) {
1657
- const leftValue = left ?? [];
1658
- const rightValue = right ?? [];
1659
- if (leftValue.length !== rightValue.length) {
1660
- return false;
1661
- }
1662
- return leftValue.every((rule, index) => rule.field === rightValue[index]?.field &&
1663
- rule.dir === rightValue[index]?.dir);
1664
- }
1665
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: WorkCenterFacade, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1666
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: WorkCenterFacade, providedIn: 'root' });
1667
- }
1668
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: WorkCenterFacade, decorators: [{
1669
- type: Injectable,
1670
- args: [{
1671
- providedIn: 'root',
1672
- }]
1673
- }] });
1674
-
1675
455
  /**
1676
456
  * Route-scoped channel for whether the modal body has content ready to commit
1677
457
  * and why an action is blocked.
@@ -4197,52 +2977,6 @@ function resolveHttpErrorMessage(error, fallback) {
4197
2977
  return httpError.error?.message ?? httpError.message ?? fallback;
4198
2978
  }
4199
2979
 
4200
- // Context keys contain `/`; keep them in one route segment without `%2F`/`%25`.
4201
- const ROUTE_CONTEXT_KEY_PREFIX = 'wc1.';
4202
- const HEX_PAIR_PATTERN = /^[\da-f]{2}$/i;
4203
- function encodeWorkCenterRouteContextKey(contextKey) {
4204
- const encoded = encodeURIComponent(contextKey);
4205
- let hex = '';
4206
- for (let index = 0; index < encoded.length; index += 1) {
4207
- if (encoded[index] === '%') {
4208
- hex += encoded.slice(index + 1, index + 3).toLowerCase();
4209
- index += 2;
4210
- continue;
4211
- }
4212
- hex += encoded.charCodeAt(index).toString(16).padStart(2, '0');
4213
- }
4214
- return `${ROUTE_CONTEXT_KEY_PREFIX}${hex}`;
4215
- }
4216
- function decodeWorkCenterRouteContextKey(value) {
4217
- if (!value) {
4218
- return null;
4219
- }
4220
- if (value.startsWith(ROUTE_CONTEXT_KEY_PREFIX)) {
4221
- return decodeRouteSafeContextKey(value.slice(ROUTE_CONTEXT_KEY_PREFIX.length));
4222
- }
4223
- try {
4224
- return decodeURIComponent(value);
4225
- }
4226
- catch {
4227
- return value;
4228
- }
4229
- }
4230
- function decodeRouteSafeContextKey(hex) {
4231
- if (hex.length % 2 !== 0) {
4232
- return null;
4233
- }
4234
- const parts = hex.match(/.{2}/g) ?? [];
4235
- if (parts.some((part) => !HEX_PAIR_PATTERN.test(part))) {
4236
- return null;
4237
- }
4238
- try {
4239
- return decodeURIComponent(parts.map((part) => `%${part.toUpperCase()}`).join(''));
4240
- }
4241
- catch {
4242
- return null;
4243
- }
4244
- }
4245
-
4246
2980
  // The drawer is absolute inside the host's page column, so its width is a share
4247
2981
  // of that column (%), not of the viewport (vw): a shell pane docked beside the
4248
2982
  // page (the Faris chat, an expanded nav) narrows the column, and a vw width
@@ -4935,11 +3669,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
4935
3669
  * Pure TypeScript - no Angular, no DOM.
4936
3670
  */
4937
3671
 
4938
- const APP_STATES = [WorkCenterState];
4939
-
4940
3672
  /**
4941
3673
  * Generated bundle index. Do not edit.
4942
3674
  */
4943
3675
 
4944
- export { APP_STATES, ApplyColumnFilters, ApplyHeaderFilters, ClearAllFilters, EnterArea, HydrateFromContext, LoadRuntime, SCHEDULE_PUBLISH_GROUP_ORDER, SCHEDULE_PUBLISH_OPERATION_KEY, SelectCard, SetGroupBy, SetLookups, SetParams, WORK_CENTER_ACTION_HANDLERS, WORK_CENTER_EMPTY_LABEL, WORK_CENTER_EXTRA_TABS, WORK_CENTER_GROUP_NONE, WORK_CENTER_HIDDEN_TABS, WORK_CENTER_LEVEL_GROUP_FIELD, WORK_CENTER_LEVEL_NAME_KEY, WORK_CENTER_MAX_FILTERS, WORK_CENTER_MAX_PAGE_SIZE, WORK_CENTER_MAX_SORT, WORK_CENTER_QUERY_VERSION, WORK_CENTER_TYPE_COMPONENTS, WorkCenterActionKey, WorkCenterClientFormModal, WorkCenterFacade, WorkCenterItemModal, WorkCenterItemModalRoute, WorkCenterPage, WorkCenterSchedulePublishType, WorkCenterState, decodeWorkCenterRouteContextKey, encodeWorkCenterRouteContextKey, groupSchedulePublishRows, insertWorkCenterExtraTabs, isSchedulePublishConflictRow, matchesSchedulePublishSearch, parseSchedulePublishChangedFields, readSchedulePublishChanges, removeWorkCenterHiddenTabs, resolveWorkCenterActionHandler, resolveWorkCenterExtraTabs, schedulePublishRowKey, sortSchedulePublishRows, summarizeSchedulePublish, windowSchedulePublishRows, workCenterFormTabOptions, workCenterInitialFormTab };
3676
+ export { SCHEDULE_PUBLISH_GROUP_ORDER, SCHEDULE_PUBLISH_OPERATION_KEY, WORK_CENTER_ACTION_HANDLERS, WORK_CENTER_EXTRA_TABS, WORK_CENTER_HIDDEN_TABS, WORK_CENTER_TYPE_COMPONENTS, WorkCenterClientFormModal, WorkCenterItemModal, WorkCenterItemModalRoute, WorkCenterPage, WorkCenterSchedulePublishType, groupSchedulePublishRows, insertWorkCenterExtraTabs, isSchedulePublishConflictRow, matchesSchedulePublishSearch, parseSchedulePublishChangedFields, readSchedulePublishChanges, removeWorkCenterHiddenTabs, resolveWorkCenterActionHandler, resolveWorkCenterExtraTabs, schedulePublishRowKey, sortSchedulePublishRows, summarizeSchedulePublish, windowSchedulePublishRows, workCenterFormTabOptions, workCenterInitialFormTab };
4945
3677
  //# sourceMappingURL=masterteam-work-center.mjs.map