monkey-front-core 0.0.469 → 0.0.471

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.
@@ -3143,6 +3143,108 @@ __decorate([
3143
3143
  })
3144
3144
  ], MonkeyEcxCommonsService.prototype, "getGenericData", null);
3145
3145
 
3146
+ class MonkeyEcxCommonsResolveBaseService extends MonkeyEcxCommonsService {
3147
+ constructor(monkeyecxService, tokenStorage, config) {
3148
+ super(monkeyecxService, tokenStorage);
3149
+ this.route = null;
3150
+ this.currentRoute = null;
3151
+ this.paginationService = inject(MonkeyEcxPaginationService);
3152
+ this.translateService = inject(TranslateService);
3153
+ this.router = inject(Router);
3154
+ this.store = inject(Store);
3155
+ this.monkeyDiscovery = inject(MonkeyEcxDiscoveryParamsService);
3156
+ const { actions } = config;
3157
+ this.action = actions;
3158
+ }
3159
+ async getData() {
3160
+ try {
3161
+ const { store, route, action, tokenStorage } = this;
3162
+ const { companyId, governmentId } = await tokenStorage?.getToken();
3163
+ if (!route)
3164
+ return;
3165
+ const url = MonkeyEcxUtils.replaceVariables(route, { companyId, governmentId });
3166
+ store.dispatch(action.load({ url }));
3167
+ }
3168
+ catch (e) {
3169
+ throw new Error(`MECX Core - Method getData -> ${e}`);
3170
+ }
3171
+ }
3172
+ async loadPage(actionType) {
3173
+ try {
3174
+ const { store, action } = this;
3175
+ store.dispatch(action.loadPagination({
3176
+ pagination: {
3177
+ action: actionType
3178
+ }
3179
+ }));
3180
+ }
3181
+ catch (e) {
3182
+ throw new Error(`MECX Core - Method loadPage -> ${e}`);
3183
+ }
3184
+ }
3185
+ /**
3186
+ * @description Inicializar a class genérica
3187
+ * @param (args: MonkeyEcxInitialResolverConfig)
3188
+ * => route é obrigátorio pois ele quem inicializa a store.
3189
+ * A searchClass só se faz necessaria quando for usar filtros
3190
+ */
3191
+ init(args) {
3192
+ try {
3193
+ const { searchClass, route } = args;
3194
+ this.route = route;
3195
+ if (searchClass) {
3196
+ // eslint-disable-next-line new-cap
3197
+ const searchInstance = new searchClass(this.__search);
3198
+ this.route = `${route}${searchInstance.buildParams()}`;
3199
+ this.__onSearchChanged$.next(searchInstance);
3200
+ }
3201
+ this.getData();
3202
+ }
3203
+ catch (e) {
3204
+ throw new Error(`${e?.message}`);
3205
+ }
3206
+ }
3207
+ resolve(route, state, otherArgs) {
3208
+ this.__search = route?.queryParams;
3209
+ const [currentRoute] = state?.url.split('?') || [null];
3210
+ this.currentRoute = currentRoute;
3211
+ super.resolve(route, state, otherArgs);
3212
+ }
3213
+ /**
3214
+ * @description Atualizar os filtros da tela
3215
+ * @param (search: T, route?: string)
3216
+ * => route é opcional, passar ele apenas se a rota for diferente do padrão
3217
+ */
3218
+ setSearch(search, route) {
3219
+ try {
3220
+ const { currentRoute, router } = this;
3221
+ this.setSearchByUrl(router, route || `${currentRoute}`, search);
3222
+ }
3223
+ catch (e) {
3224
+ throw new Error(`MECX Core - Method setSearch -> ${e}`);
3225
+ }
3226
+ }
3227
+ /**
3228
+ * @description Navegação para details.
3229
+ * Por padrão sera redirecionado para '${currentRoute}/details'
3230
+ * @param (detailsData: T, route?: string)
3231
+ * => route é opcional, passar ele apenas se a rota for diferente do padrão
3232
+ */
3233
+ navigateToDetails(detailsData, route) {
3234
+ try {
3235
+ const { router, currentRoute } = this;
3236
+ router.navigate([route || `${currentRoute}/details`], {
3237
+ state: {
3238
+ detailsData
3239
+ }
3240
+ });
3241
+ }
3242
+ catch (e) {
3243
+ throw new Error(`MECX Core - Method navigateToDetails -> ${e}`);
3244
+ }
3245
+ }
3246
+ }
3247
+
3146
3248
  class MonkeyEcxCommonsResolveService extends MonkeyEcxCommonsService {
3147
3249
  constructor(monkeyecxService, tokenStorage, config) {
3148
3250
  super(monkeyecxService, tokenStorage);
@@ -5538,6 +5640,170 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
5538
5640
  }]
5539
5641
  }], ctorParameters: function () { return [{ type: MonkeyEcxService }, { type: MonkeyEcxLoggedHandlingService }]; }, propDecorators: { doCall: [], doGenericCall: [] } });
5540
5642
 
5643
+ /**
5644
+ * Classe genérica que recebe duas interfaces como tipos genéricos.
5645
+ *
5646
+ * @typeparam T deve ser a mesma interface utilizada na Entity da Store
5647
+ * @typeparam K faz referência ao tipo de configuração.
5648
+ *
5649
+ * @description interfaces de configuração:
5650
+ * ```
5651
+ * MonkeyEcxCollectionStore e MonkeyEcxEntityStore
5652
+ * ```
5653
+ */
5654
+ class MonkeyEcxCommonsStoreBaseService extends MonkeyEcxCommonsService {
5655
+ constructor(monkeyecxService, tokenStorage, store, config) {
5656
+ super(monkeyecxService, tokenStorage);
5657
+ this.store = store;
5658
+ const { actions, selectors } = config;
5659
+ this.action = actions;
5660
+ this.selector = selectors;
5661
+ }
5662
+ handleResponseData(resp, updateLinks = true) {
5663
+ try {
5664
+ let data;
5665
+ if (resp?._embedded) {
5666
+ const { _embedded, _links, page } = resp;
5667
+ const key = Object.keys(_embedded)[0];
5668
+ data = _embedded[key];
5669
+ if (updateLinks) {
5670
+ this.updateLinks?.(_links);
5671
+ }
5672
+ this.updatePage?.(page);
5673
+ }
5674
+ else
5675
+ data = resp;
5676
+ this.update?.(data);
5677
+ }
5678
+ catch (e) {
5679
+ throw new Error(`MECX Core - Method handleResponseData -> ${e}`);
5680
+ }
5681
+ }
5682
+ updateControl(data) {
5683
+ try {
5684
+ this.store.dispatch(this.action.updateControl({
5685
+ data
5686
+ }));
5687
+ }
5688
+ catch (e) {
5689
+ throw new Error(`MECX Core - Method updateControl -> ${e}`);
5690
+ }
5691
+ }
5692
+ mappingData(args) {
5693
+ try {
5694
+ const handle = (item) => {
5695
+ let id = '';
5696
+ const { href } = new MonkeyEcxLinksModel(item)?.getAction('self') || {
5697
+ href: ''
5698
+ };
5699
+ if (href) {
5700
+ id = href.split('/').pop() || '';
5701
+ }
5702
+ return {
5703
+ ...item,
5704
+ id
5705
+ };
5706
+ };
5707
+ if (args instanceof Array) {
5708
+ return args.map((item) => {
5709
+ return handle(item);
5710
+ });
5711
+ }
5712
+ return handle(args);
5713
+ }
5714
+ catch (e) {
5715
+ throw new Error(`MECX Core - Method mappingData -> ${e}`);
5716
+ }
5717
+ }
5718
+ update(args) {
5719
+ try {
5720
+ let typeAction = 'updateOne';
5721
+ if (args instanceof Array) {
5722
+ typeAction = 'updateAll';
5723
+ }
5724
+ this.store.dispatch(this.action[typeAction]({
5725
+ data: this.mappingData(args)
5726
+ }));
5727
+ }
5728
+ catch (e) {
5729
+ throw new Error(`MECX Core - Method update -> ${e}`);
5730
+ }
5731
+ }
5732
+ updatePage(data) {
5733
+ try {
5734
+ this.store.dispatch(this.action.updatePage({
5735
+ data
5736
+ }));
5737
+ }
5738
+ catch (e) {
5739
+ throw new Error(`MECX Core - Method updatePage -> ${e}`);
5740
+ }
5741
+ }
5742
+ updateLinks(data) {
5743
+ try {
5744
+ this.store.dispatch(this.action.updateLinks({
5745
+ data
5746
+ }));
5747
+ }
5748
+ catch (e) {
5749
+ throw new Error(`MECX Core - Method updateLinks -> ${e}`);
5750
+ }
5751
+ }
5752
+ async loadData(url, updateLinks = true) {
5753
+ this.updateControl({ isLoading: true });
5754
+ try {
5755
+ const data = await this.monkeyecxService?.get(url).toPromise();
5756
+ this.handleResponseData(data, updateLinks);
5757
+ }
5758
+ catch (e) {
5759
+ throw new Error(`${e?.message}`);
5760
+ }
5761
+ this.updateControl({ isLoading: false });
5762
+ }
5763
+ async loadPageData(pagination) {
5764
+ const { store, selector } = this;
5765
+ const data = await store
5766
+ .select(selector.selectLinks())
5767
+ .pipe(take(1))
5768
+ .toPromise();
5769
+ const { action } = pagination;
5770
+ const { href } = new MonkeyEcxLinksModel({ _links: data }).getAction(action) || {
5771
+ href: ''
5772
+ };
5773
+ if (href) {
5774
+ this.loadData(href);
5775
+ }
5776
+ }
5777
+ /**
5778
+ * @description Neste método precisamos incluir a lógica para conferir se precisa limpar a
5779
+ * entidade ou não
5780
+ * E depois precisa invocar o método loadData
5781
+ * @param (url) ou de acordo com a action criada
5782
+ * @example
5783
+ * ```
5784
+ * const hasDifference = .....
5785
+ * if(hasDifference) {
5786
+ * store.dispatch(clear)
5787
+ * }
5788
+ *
5789
+ * this.loadData(...)
5790
+ * ```
5791
+ */
5792
+ load(args) {
5793
+ throw new Error('MECX Core - Method load not implemented.');
5794
+ }
5795
+ loadPage(args) {
5796
+ throw new Error('MECX Core - Method loadPage not implemented.');
5797
+ }
5798
+ }
5799
+ __decorate([
5800
+ MonkeyEcxCoreService({
5801
+ requestInProgress: {
5802
+ showProgress: true
5803
+ }
5804
+ })
5805
+ ], MonkeyEcxCommonsStoreBaseService.prototype, "loadData", null);
5806
+
5541
5807
  class MonkeyEcxCommonsActions {
5542
5808
  static getActions(actionName) {
5543
5809
  const clear = createAction(`[${actionName}] Clear All`, props());
@@ -5592,12 +5858,18 @@ class MonkeyEcxCommonsSelectors {
5592
5858
  };
5593
5859
  const selectLinks = (props) => {
5594
5860
  return createSelector(selectState, (state) => {
5595
- return state.links?.[props.identifier];
5861
+ if (props?.identifier) {
5862
+ return state.links?.[props.identifier];
5863
+ }
5864
+ return state.links;
5596
5865
  });
5597
5866
  };
5598
5867
  const selectPage = (props) => {
5599
5868
  return createSelector(selectState, (state) => {
5600
- return state.page?.[props.identifier];
5869
+ if (props?.identifier) {
5870
+ return state.page?.[props.identifier];
5871
+ }
5872
+ return state.page;
5601
5873
  });
5602
5874
  };
5603
5875
  const linksHasDifference = (props) => {
@@ -6360,5 +6632,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
6360
6632
  * Generated bundle index. Do not edit.
6361
6633
  */
6362
6634
 
6363
- export { AlertsComponent, AlertsModule, ClosedToMaintenanceComponent, ClosedToMaintenanceModule, CurrencyConfigComponent, CurrencyConfigModule, decoratorsUtils as DecoratorsUtils, Link, MonkeyEcxAlertsService, MonkeyEcxAuthGuard, MonkeyEcxAuthGuardByRole, MonkeyEcxAuthGuardCompany, MonkeyEcxAuthGuardLogin, MonkeyEcxAuthenticationService, MonkeyEcxBlobSecurePipe, MonkeyEcxCommonsActions, MonkeyEcxCommonsResolveService, MonkeyEcxCommonsSelectors, MonkeyEcxCommonsService, MonkeyEcxCommonsStoreService, MonkeyEcxConfigModule, MonkeyEcxConfigService, MonkeyEcxCookieStorageService, MonkeyEcxCoreCharts, MonkeyEcxCoreClearDecorators, MonkeyEcxCoreLog, MonkeyEcxCoreService, MonkeyEcxCoreServiceConstructor, MonkeyEcxCoreServicePaged, MonkeyEcxCoreServiceQueue, MonkeyEcxCurrencyConfigService, MonkeyEcxDirectivesModule, MonkeyEcxDiscoveryParamsService, MonkeyEcxDisplayFirstNamePipe, MonkeyEcxDisplayInitialsPipe, MonkeyEcxDisplaySupportPhone, MonkeyEcxDragDropDirective, MonkeyEcxErrorConfigService, MonkeyEcxErrorHandlingModule, MonkeyEcxErrorHandlingService, MonkeyEcxFeatureByProgramDirective, MonkeyEcxFeatureDirective, MonkeyEcxFeatureToggleService, MonkeyEcxFormatAddressPipe, MonkeyEcxFormatBeaufityJSONPipe, MonkeyEcxFormatCurrency, MonkeyEcxFormatCurrencyPipe, MonkeyEcxFormatDateGroupPipe, MonkeyEcxFormatDateTimelapsePipe, MonkeyEcxFormatDateUnixTimelapsePipe, MonkeyEcxFormatDocumentPipe, MonkeyEcxFormatDocumentTypePipe, MonkeyEcxFormatNumberPipe, MonkeyEcxFormatPhonePipe, MonkeyEcxFormatSizePipe, MonkeyEcxFormatTaxPipe, MonkeyEcxFormatUpper, MonkeyEcxFormatValue, MonkeyEcxFormatZipCodePipe, MonkeyEcxHandlingService, MonkeyEcxHttpConfigErrorInterceptor, MonkeyEcxHttpConfigHeaderInterceptor, MonkeyEcxHttpConfigInterceptorModule, MonkeyEcxHttpConfigLoadingInProgressInterceptor, MonkeyEcxHttpConfigQueueInterceptor, MonkeyEcxHttpErrorHandlingService, MonkeyEcxLinksModel, MonkeyEcxLoggedHandlingService, MonkeyEcxLogsConfigService, MonkeyEcxMaintenanceConfigService, MonkeyEcxModel, MonkeyEcxOnlyAlphaNumericDirective, MonkeyEcxOnlyNumbersDirective, MonkeyEcxOthersErrorsHandlingService, MonkeyEcxPaginationService, MonkeyEcxPipesModule, MonkeyEcxPopoverDirective, MonkeyEcxPopoverOptionsDirective, MonkeyEcxProgressBarComponent, MonkeyEcxProgressBarModule, MonkeyEcxProgressBarService, MonkeyEcxRequestDownloadHandlingService, MonkeyEcxRequestDownloadedHandlingService, MonkeyEcxRequestPagedHandling, MonkeyEcxRequestQueueHandlingService, MonkeyEcxRequestQueueModalHandlingService, MonkeyEcxRequestScheduleService, MonkeyEcxSecurityConsoleConfigService, MonkeyEcxSecurityDirective, MonkeyEcxService, MonkeyEcxServiceDownload, MonkeyEcxServiceUpload, MonkeyEcxServiceWorkerConfigService, MonkeyEcxSpecificationSearch, MonkeyEcxTextTruncatePipe, MonkeyEcxTokenStorageService, MonkeyEcxTooltipDirective, MonkeyEcxTruncateQtdPipe, MonkeyEcxUtils, MonkeyEcxi18nConfigService, MonkeyFrontCoreModule, OpSearch, POPOVER_OPTIONS, statics as Statics, validateUtils as ValidateUtils, Validators, VersionChangedComponent, VersionChangedModule, comboValidator, dateRangeValidator, dateStartEndValidator, dateValidator, differentFromZero, documentValidator, documentValidatorByType, emailValidator, passwordConfirmValidator, registerValidator, requiredWithTrimValidator, index as store, trueValidator, urlValidator, valueGreaterThanZero, zipCodeValidator };
6635
+ export { AlertsComponent, AlertsModule, ClosedToMaintenanceComponent, ClosedToMaintenanceModule, CurrencyConfigComponent, CurrencyConfigModule, decoratorsUtils as DecoratorsUtils, Link, MonkeyEcxAlertsService, MonkeyEcxAuthGuard, MonkeyEcxAuthGuardByRole, MonkeyEcxAuthGuardCompany, MonkeyEcxAuthGuardLogin, MonkeyEcxAuthenticationService, MonkeyEcxBlobSecurePipe, MonkeyEcxCommonsActions, MonkeyEcxCommonsResolveBaseService, MonkeyEcxCommonsResolveService, MonkeyEcxCommonsSelectors, MonkeyEcxCommonsService, MonkeyEcxCommonsStoreBaseService, MonkeyEcxCommonsStoreService, MonkeyEcxConfigModule, MonkeyEcxConfigService, MonkeyEcxCookieStorageService, MonkeyEcxCoreCharts, MonkeyEcxCoreClearDecorators, MonkeyEcxCoreLog, MonkeyEcxCoreService, MonkeyEcxCoreServiceConstructor, MonkeyEcxCoreServicePaged, MonkeyEcxCoreServiceQueue, MonkeyEcxCurrencyConfigService, MonkeyEcxDirectivesModule, MonkeyEcxDiscoveryParamsService, MonkeyEcxDisplayFirstNamePipe, MonkeyEcxDisplayInitialsPipe, MonkeyEcxDisplaySupportPhone, MonkeyEcxDragDropDirective, MonkeyEcxErrorConfigService, MonkeyEcxErrorHandlingModule, MonkeyEcxErrorHandlingService, MonkeyEcxFeatureByProgramDirective, MonkeyEcxFeatureDirective, MonkeyEcxFeatureToggleService, MonkeyEcxFormatAddressPipe, MonkeyEcxFormatBeaufityJSONPipe, MonkeyEcxFormatCurrency, MonkeyEcxFormatCurrencyPipe, MonkeyEcxFormatDateGroupPipe, MonkeyEcxFormatDateTimelapsePipe, MonkeyEcxFormatDateUnixTimelapsePipe, MonkeyEcxFormatDocumentPipe, MonkeyEcxFormatDocumentTypePipe, MonkeyEcxFormatNumberPipe, MonkeyEcxFormatPhonePipe, MonkeyEcxFormatSizePipe, MonkeyEcxFormatTaxPipe, MonkeyEcxFormatUpper, MonkeyEcxFormatValue, MonkeyEcxFormatZipCodePipe, MonkeyEcxHandlingService, MonkeyEcxHttpConfigErrorInterceptor, MonkeyEcxHttpConfigHeaderInterceptor, MonkeyEcxHttpConfigInterceptorModule, MonkeyEcxHttpConfigLoadingInProgressInterceptor, MonkeyEcxHttpConfigQueueInterceptor, MonkeyEcxHttpErrorHandlingService, MonkeyEcxLinksModel, MonkeyEcxLoggedHandlingService, MonkeyEcxLogsConfigService, MonkeyEcxMaintenanceConfigService, MonkeyEcxModel, MonkeyEcxOnlyAlphaNumericDirective, MonkeyEcxOnlyNumbersDirective, MonkeyEcxOthersErrorsHandlingService, MonkeyEcxPaginationService, MonkeyEcxPipesModule, MonkeyEcxPopoverDirective, MonkeyEcxPopoverOptionsDirective, MonkeyEcxProgressBarComponent, MonkeyEcxProgressBarModule, MonkeyEcxProgressBarService, MonkeyEcxRequestDownloadHandlingService, MonkeyEcxRequestDownloadedHandlingService, MonkeyEcxRequestPagedHandling, MonkeyEcxRequestQueueHandlingService, MonkeyEcxRequestQueueModalHandlingService, MonkeyEcxRequestScheduleService, MonkeyEcxSecurityConsoleConfigService, MonkeyEcxSecurityDirective, MonkeyEcxService, MonkeyEcxServiceDownload, MonkeyEcxServiceUpload, MonkeyEcxServiceWorkerConfigService, MonkeyEcxSpecificationSearch, MonkeyEcxTextTruncatePipe, MonkeyEcxTokenStorageService, MonkeyEcxTooltipDirective, MonkeyEcxTruncateQtdPipe, MonkeyEcxUtils, MonkeyEcxi18nConfigService, MonkeyFrontCoreModule, OpSearch, POPOVER_OPTIONS, statics as Statics, validateUtils as ValidateUtils, Validators, VersionChangedComponent, VersionChangedModule, comboValidator, dateRangeValidator, dateStartEndValidator, dateValidator, differentFromZero, documentValidator, documentValidatorByType, emailValidator, passwordConfirmValidator, registerValidator, requiredWithTrimValidator, index as store, trueValidator, urlValidator, valueGreaterThanZero, zipCodeValidator };
6364
6636
  //# sourceMappingURL=monkey-front-core.mjs.map