Browse Source

UI: delete queue-type-list and add to autocomplete description

pull/6534/head
fe-dev 4 years ago
parent
commit
7d7d48f42e
  1. 5
      ui-ngx/src/app/core/http/queue.service.ts
  2. 4
      ui-ngx/src/app/modules/common/modules-map.ts
  3. 4
      ui-ngx/src/app/modules/home/components/queue/queue-form.component.html
  4. 2
      ui-ngx/src/app/modules/home/components/queue/queue-form.component.scss
  5. 5
      ui-ngx/src/app/modules/home/components/queue/queue-form.component.ts
  6. 1
      ui-ngx/src/app/shared/components/queue/queue-autocomplete.component.html
  7. 5
      ui-ngx/src/app/shared/components/queue/queue-autocomplete.component.ts
  8. 49
      ui-ngx/src/app/shared/components/queue/queue-type-list.component.html
  9. 199
      ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts
  10. 4
      ui-ngx/src/app/shared/models/queue.models.ts
  11. 3
      ui-ngx/src/app/shared/shared.module.ts
  12. 4
      ui-ngx/src/assets/locale/locale.constant-en_US.json

5
ui-ngx/src/app/core/http/queue.service.ts

@ -31,11 +31,6 @@ export class QueueService {
private http: HttpClient
) { }
public getTenantQueuesNamesByServiceType(serviceType: ServiceType, config?: RequestConfig): Observable<Array<string>> {
return this.http.get<Array<string>>(`/api/queues?serviceType=${serviceType}`,
defaultHttpOptionsFromConfig(config));
}
public getQueueById(queueId: string, config?: RequestConfig): Observable<QueueInfo> {
return this.http.get<QueueInfo>(`/api/queues/${queueId}`, defaultHttpOptionsFromConfig(config));
}

4
ui-ngx/src/app/modules/common/modules-map.ts

@ -135,7 +135,7 @@ import * as EntitySelectComponent from '@shared/components/entity/entity-select.
import * as EntityKeysListComponent from '@shared/components/entity/entity-keys-list.component';
import * as EntityListSelectComponent from '@shared/components/entity/entity-list-select.component';
import * as EntityTypeListComponent from '@shared/components/entity/entity-type-list.component';
import * as QueueTypeListComponent from '@shared/components/queue/queue-type-list.component';
import * as QueueAutocompleteComponent from '@shared/components/queue/queue-autocomplete.component';
import * as RelationTypeAutocompleteComponent from '@shared/components/relation/relation-type-autocomplete.component';
import * as SocialSharePanelComponent from '@shared/components/socialshare-panel.component';
import * as JsonObjectEditComponent from '@shared/components/json-object-edit.component';
@ -419,7 +419,7 @@ class ModulesMap implements IModulesMap {
'@shared/components/entity/entity-keys-list.component': EntityKeysListComponent,
'@shared/components/entity/entity-list-select.component': EntityListSelectComponent,
'@shared/components/entity/entity-type-list.component': EntityTypeListComponent,
'@shared/components/queue/queue-type-list.component': QueueTypeListComponent,
'@shared/components/queue/queue-autocomplete.component': QueueAutocompleteComponent,
'@shared/components/relation/relation-type-autocomplete.component': RelationTypeAutocompleteComponent,
'@shared/components/socialshare-panel.component': SocialSharePanelComponent,
'@shared/components/json-object-edit.component': JsonObjectEditComponent,

4
ui-ngx/src/app/modules/home/components/queue/queue-form.component.html

@ -168,4 +168,8 @@
</ng-template>
</mat-expansion-panel>
</mat-accordion>
<mat-form-field class="mat-block" formGroupName="additionalInfo">
<mat-label translate>queue.description</mat-label>
<textarea matInput formControlName="description" rows="2"></textarea>
</mat-form-field>
</form>

2
ui-ngx/src/app/modules/home/components/queue/queue-form.component.scss

@ -15,6 +15,8 @@
*/
:host ::ng-deep {
.queue-strategy {
padding-bottom: 16px;
.mat-expansion-panel-body {
padding-bottom: 0 !important;
}

5
ui-ngx/src/app/modules/home/components/queue/queue-form.component.ts

@ -109,7 +109,10 @@ export class QueueFormComponent implements ControlValueAccessor, OnInit, Validat
pauseBetweenRetries: [3, [Validators.min(1), Validators.required]],
maxPauseBetweenRetries: [3, [Validators.min(1), Validators.required]],
}),
topic: ['']
topic: [''],
additionalInfo: this.fb.group({
description: ['']
})
});
this.queueFormGroup.valueChanges.subscribe(() => {
this.updateModel();

1
ui-ngx/src/app/shared/components/queue/queue-autocomplete.component.html

@ -33,6 +33,7 @@
[displayWith]="displayQueueFn">
<mat-option *ngFor="let queue of filteredQueues | async" [value]="queue">
<span [innerHTML]="queue.name | highlight:searchText"></span>
<small style="display: block;">{{getDescription(queue)}}</small>
</mat-option>
<mat-option *ngIf="!(filteredQueues | async)?.length" [value]="null" class="tb-not-found">
<div class="tb-not-found-content" (click)="$event.stopPropagation()">

5
ui-ngx/src/app/shared/components/queue/queue-autocomplete.component.ts

@ -205,6 +205,11 @@ export class QueueAutocompleteComponent implements ControlValueAccessor, OnInit
);
}
getDescription(value) {
return value.additionalInfo?.description ? value.additionalInfo.description :
`Submit Strategy: ${value.submitStrategy.type}, Processing Strategy: ${value.processingStrategy.type}`;
}
clear() {
this.selectQueueFormGroup.get('queueId').patchValue('', {emitEvent: true});
setTimeout(() => {

49
ui-ngx/src/app/shared/components/queue/queue-type-list.component.html

@ -1,49 +0,0 @@
<!--
Copyright © 2016-2022 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<mat-form-field [formGroup]="queueFormGroup" class="mat-block">
<mat-label>{{ 'queue.queue-name' | translate }}</mat-label>
<input matInput type="text" placeholder="{{ 'queue.select-name' | translate }}"
#queueInput
formControlName="queue"
(focusin)="onFocus()"
[required]="required"
[matAutocomplete]="queueAutocomplete">
<button *ngIf="queueFormGroup.get('queue').value && !disabled"
type="button"
matSuffix mat-button mat-icon-button aria-label="Clear"
(click)="clear()">
<mat-icon class="material-icons">close</mat-icon>
</button>
<mat-autocomplete
class="tb-autocomplete"
#queueAutocomplete="matAutocomplete"
[displayWith]="displayQueueFn">
<mat-option *ngFor="let queue of filteredQueues | async" [value]="queue">
<span [innerHTML]="queue.queueName | highlight:searchText"></span>
</mat-option>
<mat-option *ngIf="!(filteredQueues | async)?.length" [value]="null">
<span>
{{ translate.get('queue.no-queues-matching', {queue: searchText}) | async }}
</span>
</mat-option>
</mat-autocomplete>
<mat-error *ngIf="queueFormGroup.get('queue').hasError('required')">
{{ 'queue.name-required' | translate }}
</mat-error>
<mat-hint class="tb-hint" translate [fxShow]="!disabled">device-profile.select-queue-hint</mat-hint>
</mat-form-field>

199
ui-ngx/src/app/shared/components/queue/queue-type-list.component.ts

@ -1,199 +0,0 @@
///
/// Copyright © 2016-2022 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Observable, of } from 'rxjs';
import {
catchError,
debounceTime,
distinctUntilChanged,
map,
publishReplay,
refCount,
switchMap,
tap
} from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { AppState } from '@app/core/core.state';
import { TranslateService } from '@ngx-translate/core';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { QueueService } from '@core/http/queue.service';
import { ServiceType } from '@shared/models/queue.models';
interface Queue {
queueName: string;
}
@Component({
selector: 'tb-queue-type-list',
templateUrl: './queue-type-list.component.html',
styleUrls: [],
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => QueueTypeListComponent),
multi: true
}]
})
export class QueueTypeListComponent implements ControlValueAccessor, OnInit, AfterViewInit, OnDestroy {
queueFormGroup: FormGroup;
modelValue: Queue | null;
private requiredValue: boolean;
get required(): boolean {
return this.requiredValue;
}
@Input()
set required(value: boolean) {
this.requiredValue = coerceBooleanProperty(value);
}
@Input()
disabled: boolean;
@Input()
queueType: ServiceType;
@ViewChild('queueInput', {static: true}) queueInput: ElementRef<HTMLInputElement>;
filteredQueues: Observable<Array<Queue>>;
queues: Observable<Array<Queue>>;
searchText = '';
private dirty = false;
private propagateChange = (v: any) => { };
constructor(private store: Store<AppState>,
public translate: TranslateService,
private queueService: QueueService,
private fb: FormBuilder) {
this.queueFormGroup = this.fb.group({
queue: [null]
});
}
registerOnChange(fn: any): void {
this.propagateChange = fn;
}
registerOnTouched(fn: any): void {
}
ngOnInit() {
this.filteredQueues = this.queueFormGroup.get('queue').valueChanges
.pipe(
debounceTime(150),
distinctUntilChanged(),
tap(value => {
let modelValue;
if (typeof value === 'string' || !value) {
modelValue = null;
} else {
modelValue = value;
}
this.updateView(modelValue);
}),
map(value => value ? (typeof value === 'string' ? value : value.queueName) : ''),
switchMap(queue => this.fetchQueues(queue) )
);
}
ngAfterViewInit(): void {
}
ngOnDestroy(): void {
}
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
if (this.disabled) {
this.queueFormGroup.disable({emitEvent: false});
} else {
this.queueFormGroup.enable({emitEvent: false});
}
}
writeValue(value: string | null): void {
this.searchText = '';
this.modelValue = value ? { queueName: value } : null;
this.queueFormGroup.get('queue').patchValue(this.modelValue, {emitEvent: false});
this.dirty = true;
}
onFocus() {
if (this.dirty) {
this.queueFormGroup.get('queue').updateValueAndValidity({onlySelf: true, emitEvent: true});
this.dirty = false;
}
}
updateView(value: Queue | null) {
if (this.modelValue !== value) {
this.modelValue = value;
this.propagateChange(this.modelValue ? this.modelValue.queueName : null);
}
}
displayQueueFn(queue?: Queue): string | undefined {
return queue ? queue.queueName : undefined;
}
fetchQueues(searchText?: string): Observable<Array<Queue>> {
this.searchText = searchText;
return this.getQueues().pipe(
catchError(() => of([] as Array<Queue>)),
map(queues => {
const result = queues.filter( queue => {
return searchText ? queue.queueName.toUpperCase().startsWith(searchText.toUpperCase()) : true;
});
if (result.length) {
result.sort((q1, q2) => q1.queueName.localeCompare(q2.queueName));
}
return result;
})
);
}
getQueues(): Observable<Array<Queue>> {
if (!this.queues) {
this.queues = this.queueService.
getTenantQueuesNamesByServiceType(this.queueType, {ignoreLoading: true}).pipe(
map((queues) => {
return queues.map((queueName) => {
return { queueName };
});
}),
publishReplay(1),
refCount()
);
}
return this.queues;
}
clear() {
this.queueFormGroup.get('queue').patchValue(null, {emitEvent: true});
setTimeout(() => {
this.queueInput.nativeElement.blur();
this.queueInput.nativeElement.focus();
}, 0);
}
}

4
ui-ngx/src/app/shared/models/queue.models.ts

@ -61,5 +61,7 @@ export interface QueueInfo extends BaseData<QueueId> {
};
tenantId?: TenantId;
topic: string;
additionalInfo?: any;
additionalInfo: {
description?: string;
};
}

3
ui-ngx/src/app/shared/shared.module.ts

@ -136,7 +136,6 @@ import { JsonObjectEditDialogComponent } from '@shared/components/dialog/json-ob
import { HistorySelectorComponent } from '@shared/components/time/history-selector/history-selector.component';
import { EntityGatewaySelectComponent } from '@shared/components/entity/entity-gateway-select.component';
import { DndModule } from 'ngx-drag-drop';
import { QueueTypeListComponent } from '@shared/components/queue/queue-type-list.component';
import { QueueAutocompleteComponent } from '@shared/components/queue/queue-autocomplete.component';
import { ContactComponent } from '@shared/components/contact.component';
import { TimezoneSelectComponent } from '@shared/components/time/timezone-select.component';
@ -232,7 +231,6 @@ export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService)
EntityKeysListComponent,
EntityListSelectComponent,
EntityTypeListComponent,
QueueTypeListComponent,
QueueAutocompleteComponent,
RelationTypeAutocompleteComponent,
SocialSharePanelComponent,
@ -381,7 +379,6 @@ export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService)
EntityKeysListComponent,
EntityListSelectComponent,
EntityTypeListComponent,
QueueTypeListComponent,
QueueAutocompleteComponent,
RelationTypeAutocompleteComponent,
SocialSharePanelComponent,

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

@ -2757,6 +2757,7 @@
"select-name": "Select queue name",
"name": "Name",
"name-required": "Queue name is required!",
"queue-required": "Queue is required!",
"topic-required": "Queue topic is required!",
"poll-interval-required": "Poll interval is required!",
"poll-interval-min-value": "Poll interval value can't be less then 1",
@ -2801,7 +2802,8 @@
"max-pause-between-retries": "Maximal pause between retries",
"delete": "Delete queue",
"copyId": "Copy queue Id",
"idCopiedMessage": "Queue Id has been copied to clipboard"
"idCopiedMessage": "Queue Id has been copied to clipboard",
"description": "Description"
},
"tenant": {
"tenant": "Tenant",

Loading…
Cancel
Save