UNPKG

@koalarx/ui

Version:

Koala UI is a modern and accessible component library designed to speed up interface development in Angular projects. With simple integration and clear documentation, you can easily build robust and visually appealing applications.

99 lines (93 loc) 3.4 kB
import * as i0 from '@angular/core'; import { inject, Injectable } from '@angular/core'; import { AppConfig } from '@koalarx/ui/core/config'; import { Snackbar } from '@koalarx/ui/shared/components/snackbar'; function isEmpty(value) { return value === null || value === undefined || value === ''; } function generateQuerySelector(elem) { const { tagName, id, className, parentElement } = elem; let str = ''; if (id !== '' && id.match(/^[a-z].*/)) { str += `#${id}`; return str; } str = tagName.toLowerCase(); if (className) { str += '.' + className .replace(/(^\s)/gm, '') .replace(/(\s{2,})/gm, ' ') .split(/\s/) .filter((c) => !/[[,\],:]/.test(c)) .join('.'); } const needNthPart = (el) => { let sib = el.previousElementSibling; if (!el.className) { return true; } while (sib) { if (el.className !== sib.className) { return false; } sib = sib.previousElementSibling; } return false; }; const getNthPart = (el) => { let childIndex = 1; let sib = el.previousElementSibling; while (sib) { childIndex++; sib = sib.previousElementSibling; } return `:nth-child(${childIndex})`; }; if (needNthPart(elem)) { str += getNthPart(elem); } if (!parentElement) { return str; } return `${generateQuerySelector(parentElement)} > ${str}`; } class HttpErrorFeedbackAlert { snackbar = inject(Snackbar); appConfig = inject(AppConfig); tapError(error) { const httpClientErrorsMiddleware = this.appConfig.httpClientErrorsMiddleware; const translations = this.appConfig.translation.feedbackRequestInterceptor; const statusCode = error.status.toString(); if (statusCode.charAt(0) === '4') { console.warn(error); this.snackbar.warning(httpClientErrorsMiddleware?.handleError(error) ?? translations[statusCode]); return; } else if (statusCode.charAt(0) === '5') { console.error(error); this.snackbar.error(httpClientErrorsMiddleware?.handleError(error) ?? translations[statusCode]); return; } else { console.info(error); this.snackbar.info(httpClientErrorsMiddleware?.handleError(error) ?? translations.unknowError); return; } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: HttpErrorFeedbackAlert, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: HttpErrorFeedbackAlert, providedIn: 'root' }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: HttpErrorFeedbackAlert, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); /** * Generated bundle index. Do not edit. */ export { HttpErrorFeedbackAlert, generateQuerySelector, isEmpty }; //# sourceMappingURL=koalarx-ui-shared-utils.mjs.map