Browse Source

remove snq package

resolves #4294
pull/9942/head
mehmet-erim 5 years ago
parent
commit
6d034450bc
  1. 9
      npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts
  2. 11
      npm/ng-packs/packages/account/src/lib/components/login/login.component.ts
  3. 9
      npm/ng-packs/packages/account/src/lib/components/register/register.component.ts
  4. 1
      npm/ng-packs/packages/core/ng-package.json
  5. 3
      npm/ng-packs/packages/core/src/lib/directives/replaceable-template.directive.ts
  6. 15
      npm/ng-packs/packages/core/src/lib/directives/visibility.directive.ts
  7. 7
      npm/ng-packs/packages/core/src/lib/services/permission.service.ts
  8. 11
      npm/ng-packs/packages/core/src/lib/states/config.state.ts
  9. 3
      npm/ng-packs/packages/core/src/lib/utils/localization-utils.ts
  10. 15
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts
  11. 10
      npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/languages.component.ts
  12. 3
      npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts
  13. 3
      npm/ng-packs/packages/theme-shared/src/lib/directives/table-sort.directive.ts
  14. 3
      npm/ng-packs/packages/theme-shared/src/lib/utils/date-parser-formatter.ts

9
npm/ng-packs/packages/account/src/lib/components/change-password/change-password.component.ts

@ -1,10 +1,9 @@
import { Profile, ProfileService } from '@abp/ng.core';
import { ProfileService } from '@abp/ng.core';
import { getPasswordValidators, ToasterService } from '@abp/ng.theme.shared';
import { Component, Injector, Input, OnInit } from '@angular/core';
import { Component, Injector, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { comparePasswords, Validation } from '@ngx-validate/core';
import { finalize } from 'rxjs/operators';
import snq from 'snq';
import { Account } from '../../models/account';
import { ManageProfileStateService } from '../../services/manage-profile.state.service';
@ -91,9 +90,7 @@ export class ChangePasswordComponent
}
},
error: err => {
this.toasterService.error(
snq(() => err.error.error.message, 'AbpAccount::DefaultErrorMessage'),
);
this.toasterService.error(err.error?.error?.message || 'AbpAccount::DefaultErrorMessage');
},
});
}

11
npm/ng-packs/packages/account/src/lib/components/login/login.component.ts

@ -1,11 +1,9 @@
import { ConfigStateService, AuthService } from '@abp/ng.core';
import { AuthService, ConfigStateService } from '@abp/ng.core';
import { ToasterService } from '@abp/ng.theme.shared';
import { Component, Injector, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Store } from '@ngxs/store';
import { throwError } from 'rxjs';
import { catchError, finalize } from 'rxjs/operators';
import snq from 'snq';
import { eAccountComponents } from '../../enums/components';
import { getRedirectUrl } from '../../utils/auth-utils';
@ -66,9 +64,10 @@ export class LoginComponent implements OnInit {
.pipe(
catchError(err => {
this.toasterService.error(
snq(() => err.error.error_description) ||
snq(() => err.error.error.message, 'AbpAccount::DefaultErrorMessage'),
'Error',
err.error?.error_description ||
err.error?.error.message ||
'AbpAccount::DefaultErrorMessage',
null,
{ life: 7000 },
);
return throwError(err);

9
npm/ng-packs/packages/account/src/lib/components/register/register.component.ts

@ -4,7 +4,6 @@ import { Component, Injector, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { throwError } from 'rxjs';
import { catchError, finalize, switchMap } from 'rxjs/operators';
import snq from 'snq';
import { eAccountComponents } from '../../enums/components';
import { AccountService } from '../../proxy/account/account.service';
import { RegisterDto } from '../../proxy/account/models';
@ -88,11 +87,13 @@ export class RegisterComponent implements OnInit {
),
catchError(err => {
this.toasterService.error(
snq(() => err.error.error_description) ||
snq(() => err.error.error.message, 'AbpAccount::DefaultErrorMessage'),
'Error',
err.error?.error_description ||
err.error?.error.message ||
'AbpAccount::DefaultErrorMessage',
null,
{ life: 7000 },
);
return throwError(err);
}),
finalize(() => (this.inProgress = false)),

1
npm/ng-packs/packages/core/ng-package.json

@ -10,7 +10,6 @@
"angular-oauth2-oidc",
"just-compare",
"just-clone",
"snq",
"ts-toolbelt"
]
}

3
npm/ng-packs/packages/core/src/lib/directives/replaceable-template.directive.ts

@ -13,7 +13,6 @@ import {
import compare from 'just-compare';
import { Subscription } from 'rxjs';
import { filter } from 'rxjs/operators';
import snq from 'snq';
import { ABP } from '../models/common';
import { ReplaceableComponents } from '../models/replaceable-components';
import { ReplaceableComponentsService } from '../services/replaceable-components.service';
@ -99,7 +98,7 @@ export class ReplaceableTemplateDirective implements OnInit, OnChanges {
}
ngOnChanges(changes: SimpleChanges) {
if (snq(() => changes.data.currentValue.inputs) && this.defaultComponentRef) {
if (changes?.data?.currentValue?.inputs && this.defaultComponentRef) {
this.setDefaultComponentInputs();
}
}

15
npm/ng-packs/packages/core/src/lib/directives/visibility.directive.ts

@ -1,6 +1,5 @@
import { AfterViewInit, Directive, ElementRef, Input, Optional, Renderer2 } from '@angular/core';
import { Subject } from 'rxjs';
import snq from 'snq';
/**
*
@ -26,10 +25,8 @@ export class VisibilityDirective implements AfterViewInit {
mutations.forEach(mutation => {
if (!mutation.target) return;
const htmlNodes = snq(
() => Array.from(mutation.target.childNodes).filter(node => node instanceof HTMLElement),
[],
);
const htmlNodes =
Array.from(mutation.target.childNodes).filter(node => node instanceof HTMLElement) || [];
if (!htmlNodes.length) {
this.removeFromDOM();
@ -42,11 +39,9 @@ export class VisibilityDirective implements AfterViewInit {
});
setTimeout(() => {
const htmlNodes = snq(
() =>
Array.from(this.focusedElement.childNodes).filter(node => node instanceof HTMLElement),
[],
);
const htmlNodes =
Array.from(this.focusedElement.childNodes).filter(node => node instanceof HTMLElement) ||
[];
if (!htmlNodes.length) this.removeFromDOM();
}, 0);

7
npm/ng-packs/packages/core/src/lib/services/permission.service.ts

@ -1,9 +1,8 @@
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import snq from 'snq';
import { ABP } from '../models/common';
import { ApplicationConfigurationDto } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models';
import { ConfigStateService } from './config-state.service';
import { ABP } from '../models/common';
@Injectable({ providedIn: 'root' })
export class PermissionService {
@ -70,10 +69,10 @@ export class PermissionService {
}
protected mapToPolicies(applicationConfiguration: ApplicationConfigurationDto) {
return snq(() => applicationConfiguration.auth.grantedPolicies, {});
return applicationConfiguration?.auth?.grantedPolicies || {};
}
protected getPolicy(key: string, grantedPolicies: Record<string, boolean>) {
return snq(() => grantedPolicies[key], false);
return grantedPolicies[key] || false;
}
}

11
npm/ng-packs/packages/core/src/lib/states/config.state.ts

@ -4,7 +4,6 @@ import { Action, createSelector, Selector, State, StateContext, Store } from '@n
import compare from 'just-compare';
import { throwError } from 'rxjs';
import { catchError, distinctUntilChanged } from 'rxjs/operators';
import snq from 'snq';
import { GetAppConfiguration, PatchConfigState, SetEnvironment } from '../actions/config.actions';
import { RestOccurError } from '../actions/rest.actions';
import { Config } from '../models/config';
@ -76,7 +75,7 @@ export class ConfigState {
static getFeature(key: string) {
const selector = createSelector([ConfigState], (state: Config.State) => {
return snq(() => state.features.values[key]);
return state.features.values[key];
});
return selector;
@ -84,7 +83,7 @@ export class ConfigState {
static getSetting(key: string) {
const selector = createSelector([ConfigState], (state: Config.State) => {
return snq(() => state.setting.values[key]);
return state.setting.values[key];
});
return selector;
@ -92,7 +91,7 @@ export class ConfigState {
static getSettings(keyword?: string) {
const selector = createSelector([ConfigState], (state: Config.State) => {
const settings = snq(() => state.setting.values, {});
const settings = state.setting.values || {};
if (!keyword) return settings;
@ -113,7 +112,7 @@ export class ConfigState {
static getGrantedPolicy(key: string) {
const selector = createSelector([ConfigState], (state: Config.State): boolean => {
if (!key) return true;
const getPolicy = (k: string) => snq(() => state.auth.grantedPolicies[k], false);
const getPolicy = (k: string) => state.auth.grantedPolicies[k] || false;
const orRegexp = /\|\|/g;
const andRegexp = /&&/g;
@ -180,7 +179,7 @@ export class ConfigState {
const sourceName =
keys[0] ||
snq(() => state.environment.localization.defaultResourceName) ||
state.environment.localization?.defaultResourceName ||
state.localization.defaultResourceName;
const sourceKey = keys[1];

3
npm/ng-packs/packages/core/src/lib/utils/localization-utils.ts

@ -1,4 +1,3 @@
import snq from 'snq';
import { ApplicationLocalizationConfigurationDto } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models';
// This will not be necessary when only Angukar 9.1+ is supported
@ -14,7 +13,7 @@ export function createLocalizer(localization: ApplicationLocalizationConfigurati
return (resourceName: string, key: string, defaultValue: string) => {
if (resourceName === '_') return key;
const resource = snq(() => localization.values[resourceName]);
const resource = localization?.values?.[resourceName];
if (!resource) return defaultValue;

15
npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

@ -18,7 +18,6 @@ import { AbstractControl, FormArray, FormBuilder, FormGroup } from '@angular/for
import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { finalize, pluck, switchMap, take } from 'rxjs/operators';
import snq from 'snq';
import {
CreateUser,
DeleteUser,
@ -83,7 +82,7 @@ export class UsersComponent implements OnInit {
};
get roleGroups(): FormGroup[] {
return snq(() => (this.form.get('roleNames') as FormArray).controls as FormGroup[], []);
return ((this.form.get('roleNames') as FormArray)?.controls as FormGroup[]) || [];
}
constructor(
@ -112,7 +111,7 @@ export class UsersComponent implements OnInit {
this.fb.group({
[role.name]: [
this.selected.id
? !!snq(() => this.selectedUserRoles.find(userRole => userRole.id === role.id))
? !!this.selectedUserRoles?.find(userRole => userRole.id === role.id)
: role.isDefault,
],
}),
@ -152,12 +151,10 @@ export class UsersComponent implements OnInit {
if (!this.form.valid || this.modalBusy) return;
this.modalBusy = true;
const { roleNames } = this.form.value;
const mappedRoleNames = snq(
() =>
roleNames.filter(role => !!role[Object.keys(role)[0]]).map(role => Object.keys(role)[0]),
[],
);
const { roleNames = [] } = this.form.value;
const mappedRoleNames =
roleNames.filter(role => !!role[Object.keys(role)[0]]).map(role => Object.keys(role)[0]) ||
[];
this.store
.dispatch(

10
npm/ng-packs/packages/theme-basic/src/lib/components/nav-items/languages.component.ts

@ -2,7 +2,6 @@ import { ConfigStateService, LanguageInfo, SessionStateService } from '@abp/ng.c
import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import snq from 'snq';
@Component({
selector: 'abp-languages',
@ -53,10 +52,7 @@ export class LanguagesComponent {
return this.languages$.pipe(
map(
languages =>
snq(
() => languages.find(lang => lang.cultureName === this.selectedLangCulture).displayName,
),
'',
languages?.find(lang => lang.cultureName === this.selectedLangCulture).displayName || '',
),
);
}
@ -64,9 +60,7 @@ export class LanguagesComponent {
get dropdownLanguages$(): Observable<LanguageInfo[]> {
return this.languages$.pipe(
map(
languages =>
snq(() => languages.filter(lang => lang.cultureName !== this.selectedLangCulture)),
[],
languages => languages?.filter(lang => lang.cultureName !== this.selectedLangCulture) || [],
),
);
}

3
npm/ng-packs/packages/theme-shared/extensions/src/lib/components/extensible-form/extensible-form-prop.component.ts

@ -22,7 +22,6 @@ import {
import { NgbDateAdapter, NgbTimeAdapter } from '@ng-bootstrap/ng-bootstrap';
import { Observable, of } from 'rxjs';
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
import snq from 'snq';
import { DateAdapter } from '../../adapters/date.adapter';
import { TimeAdapter } from '../../adapters/time.adapter';
import { EXTRA_PROPERTIES_KEY } from '../../constants/extra-properties';
@ -171,7 +170,7 @@ export class ExtensibleFormPropComponent implements OnChanges, AfterViewInit {
}
ngOnChanges({ prop }: SimpleChanges) {
const currentProp = snq<FormProp>(() => prop.currentValue);
const currentProp = prop?.currentValue;
const { options, readonly, disabled, validators } = currentProp || {};
if (options) this.options$ = options(this.data);

3
npm/ng-packs/packages/theme-shared/src/lib/directives/table-sort.directive.ts

@ -10,7 +10,6 @@ import {
SimpleChanges,
} from '@angular/core';
import clone from 'just-clone';
import snq from 'snq';
import { TableComponent } from '../components/table/table.component';
export interface TableSortOptions {
@ -35,7 +34,7 @@ export class TableSortDirective implements OnChanges {
get table(): TableComponent | any {
return (
this.abpTable || snq(() => this.cdRef['_view'].component) || snq(() => this.cdRef['context']) // 'context' for ivy
this.abpTable || this.cdRef['_view'].component || this.cdRef['context'] // 'context' for ivy
);
}

3
npm/ng-packs/packages/theme-shared/src/lib/utils/date-parser-formatter.ts

@ -2,7 +2,6 @@ import { ApplicationLocalizationConfigurationDto, ConfigStateService } from '@ab
import { formatDate } from '@angular/common';
import { Inject, Injectable, LOCALE_ID } from '@angular/core';
import { NgbDateParserFormatter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
import snq from 'snq';
function isNumber(value: any): boolean {
return !isNaN(toInteger(value));
@ -48,7 +47,7 @@ export class DateParserFormatter extends NgbDateParserFormatter {
this.configState.getOne('localization');
const dateFormat =
snq(() => localization.currentCulture.dateTimeFormat.shortDatePattern) || 'yyyy-MM-dd';
localization.currentCulture?.dateTimeFormat?.shortDatePattern || 'yyyy-MM-dd';
return formatDate(new Date(date.year, date.month - 1, date.day), dateFormat, this.locale);
}

Loading…
Cancel
Save