Add new alias Current Tenant (#2604)

This commit is contained in:
Vladyslav 2020-04-10 15:04:12 +03:00 committed by GitHub
parent 352b073062
commit 2a1fa76c2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 65 additions and 49 deletions

View File

@ -480,6 +480,7 @@ export class EntityService {
entityTypes.push(EntityType.DASHBOARD);
if (useAliasEntityTypes) {
entityTypes.push(AliasEntityType.CURRENT_CUSTOMER);
entityTypes.push(AliasEntityType.CURRENT_TENANT);
}
break;
case Authority.CUSTOMER_USER:
@ -1065,6 +1066,10 @@ export class EntityService {
if (authUser.authority === Authority.CUSTOMER_USER) {
entityId.id = authUser.customerId;
}
} else if (entityType === AliasEntityType.CURRENT_TENANT){
const authUser = getCurrentAuthUser(this.store);
entityId.entityType = EntityType.TENANT;
entityId.id = authUser.tenantId;
}
return entityId;
}

View File

@ -14,11 +14,8 @@
/// limitations under the License.
///
import { Component, Inject, InjectionToken, OnInit } from '@angular/core';
import { Timewindow } from '@shared/models/time/time.models';
import { Component, Inject, InjectionToken } from '@angular/core';
import { AliasInfo, IAliasController } from '@core/api/widget-api.models';
import { PageComponent } from '@shared/components/page.component';
import { TIMEWINDOW_PANEL_DATA, TimewindowPanelData } from '@shared/components/time/timewindow-panel.component';
import { deepClone } from '@core/utils';
export const ALIASES_ENTITY_SELECT_PANEL_DATA = new InjectionToken<any>('AliasesEntitySelectPanelData');

View File

@ -15,8 +15,8 @@
limitations under the License.
-->
<form #entityAliasForm="ngForm" [formGroup]="entityAliasFormGroup" (ngSubmit)="save()" style="width: 600px;">
<mat-toolbar fxLayout="row" color="primary">
<form #entityAliasForm="ngForm" [formGroup]="entityAliasFormGroup" (ngSubmit)="save()" style="min-width: 550px;">
<mat-toolbar color="primary">
<h2>{{ (isAdd ? 'alias.add' : 'alias.edit') | translate }}</h2>
<span fxFlex></span>
<button mat-button mat-icon-button

View File

@ -18,7 +18,7 @@
<div fxLayout="column" [formGroup]="entityFilterFormGroup" class="tb-entity-filter">
<mat-form-field class="mat-block">
<mat-label translate>alias.filter-type</mat-label>
<mat-select required matInput formControlName="type">
<mat-select required formControlName="type">
<mat-option *ngFor="let type of aliasFilterTypes" [value]="type">
{{aliasFilterTypeTranslations.get(type) | translate}}
</mat-option>

View File

@ -15,14 +15,7 @@
///
import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
import {
ControlValueAccessor,
FormBuilder, FormControl,
FormGroup,
NG_VALUE_ACCESSOR,
ValidatorFn,
Validators
} from '@angular/forms';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
import { AliasFilterType, aliasFilterTypeTranslationMap, EntityAliasFilter } from '@shared/models/alias.models';
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
import { TranslateService } from '@ngx-translate/core';

View File

@ -14,18 +14,18 @@
/// limitations under the License.
///
import {AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild} from '@angular/core';
import {ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR} from '@angular/forms';
import {Observable} from 'rxjs';
import {map, mergeMap, startWith, tap, share} from 'rxjs/operators';
import {Store} from '@ngrx/store';
import {AppState} from '@app/core/core.state';
import {TranslateService} from '@ngx-translate/core';
import {AliasEntityType, EntityType} from '@shared/models/entity-type.models';
import {BaseData} from '@shared/models/base-data';
import {EntityId} from '@shared/models/id/entity-id';
import {EntityService} from '@core/http/entity.service';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Observable } from 'rxjs';
import { map, mergeMap, share, tap } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { AppState } from '@app/core/core.state';
import { TranslateService } from '@ngx-translate/core';
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
import { BaseData } from '@shared/models/base-data';
import { EntityId } from '@shared/models/id/entity-id';
import { EntityService } from '@core/http/entity.service';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
@Component({
selector: 'tb-entity-autocomplete',
@ -164,6 +164,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
this.entityRequiredText = 'rulechain.rulechain-required';
break;
case EntityType.TENANT:
case AliasEntityType.CURRENT_TENANT:
this.entityText = 'tenant.tenant';
this.noEntitiesMatchingText = 'tenant.no-tenants-matching';
this.entityRequiredText = 'tenant.tenant-required';
@ -226,10 +227,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
this.searchText = '';
if (value != null) {
if (typeof value === 'string') {
let targetEntityType = this.entityTypeValue;
if (targetEntityType === AliasEntityType.CURRENT_CUSTOMER) {
targetEntityType = EntityType.CUSTOMER;
}
const targetEntityType = this.checkEntityType(this.entityTypeValue);
this.entityService.getEntity(targetEntityType, value, {ignoreLoading: true}).subscribe(
(entity) => {
this.modelValue = entity.id.id;
@ -237,7 +235,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
}
);
} else {
const targetEntityType = value.entityType as EntityType;
const targetEntityType = this.checkEntityType(value.entityType);
this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true}).subscribe(
(entity) => {
this.modelValue = entity.id.id;
@ -276,10 +274,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
fetchEntities(searchText?: string): Observable<Array<BaseData<EntityId>>> {
this.searchText = searchText;
let targetEntityType = this.entityTypeValue;
if (targetEntityType === AliasEntityType.CURRENT_CUSTOMER) {
targetEntityType = EntityType.CUSTOMER;
}
const targetEntityType = this.checkEntityType(this.entityTypeValue);
return this.entityService.getEntitiesByNameFilter(targetEntityType, searchText,
50, this.entitySubtypeValue, {ignoreLoading: true}).pipe(
map((data) => {
@ -310,4 +305,12 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
}, 0);
}
checkEntityType(entityType: EntityType | AliasEntityType): EntityType {
if (entityType === AliasEntityType.CURRENT_CUSTOMER) {
return EntityType.CUSTOMER;
} else if (entityType === AliasEntityType.CURRENT_TENANT) {
return EntityType.TENANT;
}
return entityType;
}
}

View File

@ -27,7 +27,7 @@
</tb-entity-type-select>
<tb-entity-autocomplete
fxFlex
*ngIf="modelValue.entityType"
*ngIf="modelValue.entityType && modelValue.entityType !== AliasEntityType.CURRENT_TENANT"
[required]="required"
[entityType]="modelValue.entityType"
formControlName="entityId">

View File

@ -14,15 +14,16 @@
/// limitations under the License.
///
import {AfterViewInit, Component, forwardRef, Input, OnInit} from '@angular/core';
import {ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR} from '@angular/forms';
import {Store} from '@ngrx/store';
import {AppState} from '@core/core.state';
import {TranslateService} from '@ngx-translate/core';
import {AliasEntityType, EntityType, entityTypeTranslations} from '@shared/models/entity-type.models';
import {EntityService} from '@core/http/entity.service';
import {EntityId} from '@shared/models/id/entity-id';
import {coerceBooleanProperty} from '@angular/cdk/coercion';
import { AfterViewInit, Component, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { TranslateService } from '@ngx-translate/core';
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
import { EntityService } from '@core/http/entity.service';
import { EntityId } from '@shared/models/id/entity-id';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { NULL_UUID } from '@shared/models/id/has-uuid';
@Component({
selector: 'tb-entity-select',
@ -60,6 +61,8 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
displayEntityTypeSelect: boolean;
AliasEntityType = AliasEntityType;
private readonly defaultEntityType: EntityType | AliasEntityType = null;
private propagateChange = (v: any) => { };
@ -94,6 +97,9 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
ngOnInit() {
this.entitySelectFormGroup.get('entityType').valueChanges.subscribe(
(value) => {
if(value === AliasEntityType.CURRENT_TENANT){
this.modelValue.id = NULL_UUID;
}
this.updateView(value, this.modelValue.id);
}
);
@ -139,7 +145,7 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
entityType,
id: this.modelValue.entityType !== entityType ? null : entityId
};
if (this.modelValue.entityType && this.modelValue.id) {
if (this.modelValue.entityType && (this.modelValue.id || this.modelValue.entityType === AliasEntityType.CURRENT_TENANT)) {
this.propagateChange(this.modelValue);
} else {
this.propagateChange(null);

View File

@ -49,7 +49,8 @@ export enum EntityType {
}
export enum AliasEntityType {
CURRENT_CUSTOMER = 'CURRENT_CUSTOMER'
CURRENT_CUSTOMER = 'CURRENT_CUSTOMER',
CURRENT_TENANT = 'CURRENT_TENANT'
}
export interface EntityTypeTranslation {
@ -218,9 +219,16 @@ export const entityTypeTranslations = new Map<EntityType | AliasEntityType, Enti
[
AliasEntityType.CURRENT_CUSTOMER,
{
type: 'entity.type-entity-view',
type: 'entity.type-current-customer',
list: 'entity.type-current-customer'
}
],
[
AliasEntityType.CURRENT_TENANT,
{
type: 'entity.type-current-tenant',
list: 'entity.type-current-tenant'
}
]
]
);

View File

@ -771,6 +771,7 @@
"list-of-rulenodes": "{ count, plural, 1 {Jeden uzel pravidla} other {Seznam # uzlů pravidel} }",
"rulenode-name-starts-with": "Uzly pravidel, jejichž název začíná '{{prefix}}'",
"type-current-customer": "Stávající zákazník",
"type-current-tenant": "Stávající tenant",
"search": "Vyhledat entity",
"selected-entities": "{ count, plural, 1 {1 entita} other {# entit} } zvoleno",
"entity-name": "Název entity",

View File

@ -830,6 +830,7 @@
"list-of-rulenodes": "{ count, plural, 1 {One rule node} other {List of # rule nodes} }",
"rulenode-name-starts-with": "Rule nodes whose names start with '{{prefix}}'",
"type-current-customer": "Current Customer",
"type-current-tenant": "Current Tenant",
"search": "Search entities",
"selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected",
"entity-name": "Entity name",

View File

@ -810,6 +810,7 @@
"list-of-rulenodes": "{ count, plural, 1 {Одно правило} other {Список из # правил} }",
"rulenode-name-starts-with": "Правила, чьи названия начинаются с '{{prefix}}'",
"type-current-customer": "Текущий клиент",
"type-current-tenant": "Текущий владелец",
"search": "Поиск объектов",
"selected-entities": "Выбран(ы) { count, plural, 1 {1 объект} few {# объекта} other {# объектов} }",
"entity-name": "Название объекта",

View File

@ -943,6 +943,7 @@
"list-of-rulenodes": "{ count, plural, 1 {Одне правило} other {Список # правил} }",
"rulenode-name-starts-with": "Список правил, імена яких починаються '{{prefix}}'",
"type-current-customer": "Поточний клієнт",
"type-current-tenant": "Поточний власник",
"search": "Пошук сутностей",
"selected-entities": "{ count, plural, 1 {1 сутність} other {# сутності} } вибрано",
"entity-name": "Ім'я сутності",