scottyaslan commented on code in PR #8233: URL: https://github.com/apache/nifi/pull/8233#discussion_r1448167843
########## nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-frontend/src/main/nifi/src/app/pages/settings/ui/flow-analysis-rules/flow-analysis-rule-table/flow-analysis-rule-table.component.ts: ########## @@ -0,0 +1,261 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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, EventEmitter, Input, Output, ViewChild } from '@angular/core'; +import { MatButtonModule } from '@angular/material/button'; +import { MatDialogModule } from '@angular/material/dialog'; +import { RouterLink } from '@angular/router'; +import { NgClass, NgIf } from '@angular/common'; +import { MatTableDataSource, MatTableModule } from '@angular/material/table'; +import { MatSort, MatSortModule } from '@angular/material/sort'; +import { FlowAnalysisRuleEntity } from '../../../state/flow-analysis-rules'; +import { TextTip } from '../../../../../ui/common/tooltips/text-tip/text-tip.component'; +import { BulletinsTip } from '../../../../../ui/common/tooltips/bulletins-tip/bulletins-tip.component'; +import { ValidationErrorsTip } from '../../../../../ui/common/tooltips/validation-errors-tip/validation-errors-tip.component'; +import { NiFiCommon } from '../../../../../service/nifi-common.service'; +import { BulletinsTipInput, TextTipInput, ValidationErrorsTipInput } from '../../../../../state/shared'; +import { NifiTooltipDirective } from '../../../../../ui/common/tooltips/nifi-tooltip.directive'; +import { ReportingTaskEntity } from '../../../state/reporting-tasks'; + +@Component({ + selector: 'flow-analysis-rule-table', + standalone: true, + templateUrl: './flow-analysis-rule-table.component.html', + imports: [ + MatButtonModule, + MatDialogModule, + MatTableModule, + MatSortModule, + NgIf, + NgClass, + NifiTooltipDirective, + RouterLink + ], + styleUrls: ['./flow-analysis-rule-table.component.scss', '../../../../../../assets/styles/listing-table.scss'] +}) +export class FlowAnalysisRuleTable implements AfterViewInit { + @Input() set flowAnalysisRules(FlowAnalysisRuleEntities: FlowAnalysisRuleEntity[]) { + this.dataSource = new MatTableDataSource<FlowAnalysisRuleEntity>(FlowAnalysisRuleEntities); + this.dataSource.sort = this.sort; + this.dataSource.sortingDataAccessor = (data: FlowAnalysisRuleEntity, displayColumn: string) => { + if (displayColumn == 'name') { + return this.formatType(data); + } else if (displayColumn == 'type') { + return this.formatType(data); + } else if (displayColumn == 'bundle') { + return this.formatBundle(data); + } else if (displayColumn == 'state') { + return this.formatState(data); + } + return ''; + }; + } + @Input() selectedFlowAnalysisRuleId!: string; + @Input() definedByCurrentGroup!: (entity: FlowAnalysisRuleEntity) => boolean; + + @Output() selectFlowAnalysisRule: EventEmitter<FlowAnalysisRuleEntity> = new EventEmitter<FlowAnalysisRuleEntity>(); + @Output() deleteFlowAnalysisRule: EventEmitter<FlowAnalysisRuleEntity> = new EventEmitter<FlowAnalysisRuleEntity>(); + @Output() configureFlowAnalysisRule: EventEmitter<FlowAnalysisRuleEntity> = + new EventEmitter<FlowAnalysisRuleEntity>(); + @Output() enableFlowAnalysisRule: EventEmitter<FlowAnalysisRuleEntity> = new EventEmitter<FlowAnalysisRuleEntity>(); + @Output() disableFlowAnalysisRule: EventEmitter<FlowAnalysisRuleEntity> = + new EventEmitter<FlowAnalysisRuleEntity>(); + + protected readonly TextTip = TextTip; + protected readonly BulletinsTip = BulletinsTip; + protected readonly ValidationErrorsTip = ValidationErrorsTip; + + displayedColumns: string[] = ['moreDetails', 'name', 'type', 'bundle', 'state', 'actions']; + dataSource: MatTableDataSource<FlowAnalysisRuleEntity> = new MatTableDataSource<FlowAnalysisRuleEntity>(); + + @ViewChild(MatSort) sort!: MatSort; + + constructor(private nifiCommon: NiFiCommon) {} + + ngAfterViewInit(): void { + this.dataSource.sort = this.sort; + } + + canRead(entity: FlowAnalysisRuleEntity): boolean { + return entity.permissions.canRead; + } + + canWrite(entity: FlowAnalysisRuleEntity): boolean { + return entity.permissions.canWrite; + } + + canOperate(entity: FlowAnalysisRuleEntity): boolean { + if (this.canWrite(entity)) { + return true; + } + return !!entity.operatePermissions?.canWrite; + } + + hasComments(entity: FlowAnalysisRuleEntity): boolean { + return !this.nifiCommon.isBlank(entity.component.comments); + } + + getCommentsTipData(entity: FlowAnalysisRuleEntity): TextTipInput { + return { + text: entity.component.comments + }; + } + + hasErrors(entity: FlowAnalysisRuleEntity): boolean { + return !this.nifiCommon.isEmpty(entity.component.validationErrors); + } + + getValidationErrorsTipData(entity: FlowAnalysisRuleEntity): ValidationErrorsTipInput { + return { + isValidating: entity.status.validationStatus === 'VALIDATING', + validationErrors: entity.component.validationErrors + }; + } + + hasBulletins(entity: FlowAnalysisRuleEntity): boolean { + return !this.nifiCommon.isEmpty(entity.bulletins); + } + + getBulletinsTipData(entity: FlowAnalysisRuleEntity): BulletinsTipInput { + return { + bulletins: entity.bulletins + }; + } + + getStateIcon(entity: FlowAnalysisRuleEntity): string { + if (entity.status.validationStatus === 'VALIDATING') { + return 'validating fa fa-spin fa-circle-o-notch'; + } else if (entity.status.validationStatus === 'INVALID') { + return 'invalid fa fa-warning'; + } else { + if (entity.status.runStatus === 'DISABLED') { + return 'disabled icon icon-enable-false'; + } else if (entity.status.runStatus === 'DISABLING') { + return 'disabled icon icon-enable-false'; + } else if (entity.status.runStatus === 'ENABLED') { + return 'enabled fa fa-flash'; + } else if (entity.status.runStatus === 'ENABLING') { + return 'enabled fa fa-flash'; + } + } + return ''; + } + + formatState(entity: FlowAnalysisRuleEntity): string { + if (entity.status.validationStatus === 'VALIDATING') { + return 'Validating'; + } else if (entity.status.validationStatus === 'INVALID') { + return 'Invalid'; + } else { + if (entity.status.runStatus === 'DISABLED') { + return 'Disabled'; + } else if (entity.status.runStatus === 'DISABLING') { + return 'Disabling'; + } else if (entity.status.runStatus === 'ENABLED') { + return 'Enabled'; + } else if (entity.status.runStatus === 'ENABLING') { + return 'Enabling'; + } + } + return ''; + } + + formatType(entity: FlowAnalysisRuleEntity): string { + return this.nifiCommon.formatType(entity.component); + } + + formatBundle(entity: FlowAnalysisRuleEntity): string { + return this.nifiCommon.formatBundle(entity.component.bundle); + } + + isDisabled(entity: FlowAnalysisRuleEntity): boolean { + return entity.status.runStatus === 'DISABLED'; + } + + isEnabledOrEnabling(entity: FlowAnalysisRuleEntity): boolean { + return entity.status.runStatus === 'ENABLED' || entity.status.runStatus === 'ENABLING'; + } + + hasActiveThreads(entity: ReportingTaskEntity): boolean { + return entity.status?.activeThreadCount > 0; + } + + canConfigure(entity: FlowAnalysisRuleEntity): boolean { + return this.canRead(entity) && this.canWrite(entity); Review Comment: @mcgilman here also it seems in current NiFi the user can configure a rule even when disabled. Is this correct? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
