Browse Source

Merge branch 'master' into cf-output

pull/14441/head
Viacheslav Klimov 6 months ago
committed by GitHub
parent
commit
3bd4e9a764
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 16
      ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.ts
  2. 2
      ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts
  3. 10
      ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts
  4. 23
      ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts
  5. 6
      ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.ts
  6. 4
      ui-ngx/src/app/modules/home/components/api-key/api-key-generated-dialog.component.html
  7. 17
      ui-ngx/src/app/modules/home/components/api-key/api-key-generated-dialog.component.scss
  8. 5
      ui-ngx/src/app/modules/home/components/api-key/api-key-generated-dialog.component.ts
  9. 2
      ui-ngx/src/app/shared/models/api-key.models.ts
  10. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

16
ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.ts

@ -67,7 +67,7 @@ export class AlarmRuleDialogComponent extends DialogComponent<AlarmRuleDialogCom
debugSettings: [],
entityId: this.fb.group({
entityType: this.fb.control<EntityType | AliasEntityType | null>(null, Validators.required),
id: ['', Validators.required],
id: [null as null | string, Validators.required],
}),
configuration: this.fb.group({
arguments: this.fb.control({}),
@ -101,7 +101,6 @@ export class AlarmRuleDialogComponent extends DialogComponent<AlarmRuleDialogCom
private destroyRef: DestroyRef,
private fb: FormBuilder) {
super(store, router, dialogRef);
this.observeIsLoading();
this.applyDialogData();
}
@ -178,19 +177,6 @@ export class AlarmRuleDialogComponent extends DialogComponent<AlarmRuleDialogCom
this.fieldFormGroup.patchValue({ configuration, type, debugSettings, entityId, ...value }, {emitEvent: false});
}
private observeIsLoading(): void {
this.isLoading$.pipe(takeUntilDestroyed()).subscribe(loading => {
if (loading) {
this.fieldFormGroup.disable({emitEvent: false});
} else {
this.fieldFormGroup.enable({emitEvent: false});
if (this.data.isDirty) {
this.fieldFormGroup.markAsDirty();
}
}
});
}
onTestScript(expression: string): Observable<string> {
const calculatedFieldId = this.data.value?.id?.id;
if (calculatedFieldId) {

2
ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts

@ -152,7 +152,7 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
this.cellActionDescriptors.push(
{
name: this.translate.instant('notification.copy-template'),
name: this.translate.instant('alarm-rule.copy'),
icon: 'content_copy',
isEnabled: () => true,
onAction: ($event, entity) => this.copyCalculatedField(entity)

10
ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts

@ -20,7 +20,7 @@ import {
FormBuilder,
NG_VALIDATORS,
NG_VALUE_ACCESSOR,
UntypedFormControl,
ValidationErrors,
Validator
} from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
@ -130,10 +130,10 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
}
public conditionSet() {
return this.modelValue && (this.modelValue.expression?.expression || this.modelValue.expression?.filters) || !this.required;
return this.modelValue && (this.modelValue.expression?.expression || this.modelValue.expression?.filters);
}
public validate(c: UntypedFormControl) {
public validate(): ValidationErrors | null {
return this.conditionSet() ? null : {
alarmRuleCondition: {
valid: false,
@ -166,11 +166,11 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali
private updateConditionInfo() {
this.alarmRuleConditionFormGroup.patchValue(
{
this.modelValue ? {
type: this.modelValue?.type,
expression: this.modelValue?.expression,
schedule: this.modelValue?.schedule,
}, {emitEvent: false}
} : null, {emitEvent: false}
);
this.updateScheduleText();
this.updateSpecText();

23
ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts

@ -20,8 +20,9 @@ import {
FormBuilder,
NG_VALIDATORS,
NG_VALUE_ACCESSOR,
UntypedFormControl,
Validator
ValidationErrors,
Validator,
Validators
} from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { isDefinedAndNotNull } from '@core/utils';
@ -76,7 +77,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
private modelValue: AlarmRule;
alarmRuleFormGroup = this.fb.group({
condition: this.fb.control<AlarmRuleCondition | null>(null),
condition: this.fb.control<AlarmRuleCondition | null>(null, Validators.required),
alarmDetails: [null],
dashboardId: [null]
});
@ -113,14 +114,12 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
}
writeValue(value: AlarmRule): void {
if (value) {
this.modelValue = value;
const model = this.modelValue ? {
...this.modelValue,
dashboardId: this.modelValue.dashboardId?.id
} : null;
this.alarmRuleFormGroup.patchValue(model, {emitEvent: false});
}
this.modelValue = value;
const model = this.modelValue ? {
...this.modelValue,
dashboardId: this.modelValue.dashboardId?.id
} : null;
this.alarmRuleFormGroup.patchValue(model, {emitEvent: false});
}
public openEditDetailsDialog($event: Event) {
@ -142,7 +141,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid
});
}
public validate(c: UntypedFormControl) {
public validate(): ValidationErrors | null {
return (!this.required && !this.modelValue || this.alarmRuleFormGroup.valid) ? null : {
alarmRule: {
valid: false,

6
ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.ts

@ -23,7 +23,7 @@ import {
NG_VALIDATORS,
NG_VALUE_ACCESSOR,
UntypedFormArray,
UntypedFormControl,
ValidationErrors,
Validator,
Validators
} from '@angular/forms';
@ -159,8 +159,8 @@ export class CreateCfAlarmRulesComponent implements ControlValueAccessor, Valida
return null;
}
public validate(c: UntypedFormControl) {
return this.createAlarmRulesFormArray().length ? null : {
public validate(): ValidationErrors | null {
return this.createAlarmRulesFormGroup.valid && this.createAlarmRulesFormArray().length > 0 ? null : {
createAlarmRules: {
valid: false,
},

4
ui-ngx/src/app/modules/home/components/api-key/api-key-generated-dialog.component.html

@ -96,6 +96,10 @@
<ng-template #executeCommand>
<div class="tb-form-panel stroked">
<div class="tb-form-panel-title" translate>device.connectivity.execute-following-command</div>
<div class="tb-form-hint tb-primary-fill insecure-url-warning flex gap-2" [class.hidden]="secureUrl">
<mat-icon class="tb-mat-24">warning</mat-icon>
<span>{{ 'api-key.generated-api-key-insecure-url' | translate }}</span>
</div>
<tb-markdown usePlainMarkdown containerClass="tb-command-code" [data]='createMarkDownCommand(apiKeyCommand)'></tb-markdown>
</div>
</ng-template>

17
ui-ngx/src/app/modules/home/components/api-key/api-key-generated-dialog.component.scss

@ -15,9 +15,8 @@
*/
@import '../../src/scss/constants';
:host{
:host {
display: grid;
width: 500px;
height: 100%;
max-width: 100%;
max-height: 100vh;
@ -26,6 +25,20 @@
.tb-install-instruction-text {
min-height: 42px;
}
.insecure-url-warning {
.mat-icon {
color: #FAA405;
}
}
@media #{$mat-sm} {
width: 470px;
}
@media #{$mat-gt-sm} {
width: 720px;
}
}
:host ::ng-deep {

5
ui-ngx/src/app/modules/home/components/api-key/api-key-generated-dialog.component.ts

@ -34,7 +34,10 @@ export interface ApiKeyGeneratedDialogData {
})
export class ApiKeyGeneratedDialogComponent extends DialogComponent<ApiKeyGeneratedDialogComponent, void> {
apiKeyCommand = userInfoCommand(this.data.apiKey.value);
private baseUrl = window.location.origin;
apiKeyCommand = userInfoCommand(this.baseUrl, this.data.apiKey.value);
secureUrl = this.baseUrl.startsWith('https');
selectedTab: number;
constructor(protected store: Store<AppState>,

2
ui-ngx/src/app/shared/models/api-key.models.ts

@ -19,7 +19,7 @@ import { HasTenantId } from '@shared/models/entity.models';
import { ApiKeyId } from '@shared/models/id/api-key-id';
import { UserId } from '@shared/models/id/user-id';
export const userInfoCommand = (key: string): string => `curl -X GET "${window.location.origin}/api/auth/user" -H "Content-Type: application/json" -H "X-Authorization: ApiKey ${key}"`
export const userInfoCommand = (baseUrl: string, apiKey: string): string => `curl -X GET "${baseUrl}/api/auth/user" -H "Content-Type: application/json" -H "X-Authorization: ApiKey ${apiKey}"`
export interface ApiKeyInfo extends BaseData<ApiKeyId>, HasTenantId {
enabled: boolean;

1
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -1012,6 +1012,7 @@
"generated-api-key-title": "API key generated. Let’s check connectivity!",
"generated-api-key-copy": "Make sure to copy and save your API key now as you will not be able to see it again.",
"generated-api-key-command": "Use the following instructions to check connectivity. As a result, you should receive the current user information:",
"generated-api-key-insecure-url": "Executing commands over an insecure HTTP connection will send your API key unencrypted, making it vulnerable to interception.",
"list": "{ count, plural, =1 {One API key} other {List of # API keys} }",
"manage": "Manage",
"manage-api-keys": "Manage API keys",

Loading…
Cancel
Save