nm-job-parameters
src/app/shared/widgets/jobs/parameters/job-parameters.component.ts
This class represents the job parameters widget.
selector | nm-job-parameters |
styleUrls | job-parameters.component.scss |
templateUrl | ./job-parameters.component.html |
Widget inputs |
Widget outputs |
Properties |
|
Methods |
constructor(translateService: TranslateService)
|
||||||
Parameters :
|
addDummyValue |
addDummyValue()
|
Returns :
void
|
Protected configureWidget | ||||||
configureWidget(configuration: WidgetConfig)
|
||||||
Decorators : WidgetConfigure
|
||||||
Parameters :
Returns :
void
|
deleteJobParameters |
deleteJobParameters()
|
Returns :
void
|
setDataLoaded |
setDataLoaded()
|
Returns :
void
|
setSelectedParams | ||||||
setSelectedParams(selectedParameters: any)
|
||||||
Parameters :
Returns :
void
|
Public _confirmed |
_confirmed:
|
Type : boolean
|
Default value : false
|
Public _id |
_id:
|
Type : string
|
Decorators : WidgetId
|
Private changeIcon |
changeIcon:
|
Type : Subject<string>
|
Default value : new Subject<string>()
|
Public configuration |
configuration:
|
Type : WidgetConfig
|
Decorators : WidgetConfiguration
|
Public deleteIcon |
deleteIcon:
|
Type : string
|
Default value : HalService.iconForAction("delete")
|
Public fetchParameters |
fetchParameters:
|
Type : Subject<any>
|
Default value : new Subject<any>()
|
Decorators : WidgetInput
|
Sets the input uri to get the data for the list |
Public jobParameters |
jobParameters:
|
Default value : new Subject<boolean>()
|
Decorators : WidgetInput
|
Channel to get cuurent job settings configurations |
Public jobParametersOutput |
jobParametersOutput:
|
Default value : new Subject<any>()
|
Decorators : WidgetOutput
|
Emits cuurent job settings configurations |
Public loadParametersChannel |
loadParametersChannel:
|
Default value : new Subject<any>()
|
Decorators : WidgetInput
|
Sets loaded parameters |
Public parameterNumber |
parameterNumber:
|
Type : string
|
Public parameters |
parameters:
|
Default value : new Subject<any>()
|
Public params |
params:
|
Type : any[]
|
Default value : []
|
Public selectedIndex |
selectedIndex:
|
Type : number
|
Default value : 0
|
Public selectedParameters |
selectedParameters:
|
Type : null
|
Default value : null
|
Private unsubscribe |
unsubscribe:
|
Default value : NgUnsubscribe.create()
|
Public uri |
uri:
|
Type : string
|
Public valueParameter |
valueParameter:
|
Type : string
|
import { Component } from "@angular/core";
import { Subject } from "rxjs";
import { TranslateService } from "@ngx-translate/core";
import { takeUntil } from "rxjs/operators";
import { NgUnsubscribe } from "../../../../shared/ng-unsubscribe";
import { WidgetConfig } from "../../widget.configuration";
import { HalService } from "../../../components/hal/hal.service";
import {
WidgetComponent,
WidgetConfiguration,
WidgetId,
WidgetInput,
WidgetOutput,
WidgetConfigure,
} from "../../widget.metadata";
import { Attributes } from "../../../components/edit-attribute/attribute";
/**
* This class represents the job parameters widget.
*/
@WidgetComponent("nm-job-parameters")
@Component({
selector: "nm-job-parameters",
templateUrl: "./job-parameters.component.html",
styleUrls: ["./job-parameters.component.scss"],
})
export class JobParametersWidget {
private unsubscribe = NgUnsubscribe.create();
@WidgetConfiguration()
public configuration: WidgetConfig;
@WidgetId()
public _id: string;
/**
* Sets the input uri to get the data for the list
*/
@WidgetInput()
public fetchParameters: Subject<any> = new Subject<any>();
/**
* Channel to get cuurent job settings configurations
*/
@WidgetInput()
public jobParameters = new Subject<boolean>();
/**
* Emits cuurent job settings configurations
*/
@WidgetOutput("jobParameters")
public jobParametersOutput = new Subject<any>();
/**
* Sets loaded parameters
*/
@WidgetInput("loadParameters")
public loadParametersChannel = new Subject<any>();
public deleteIcon: string = HalService.iconForAction("delete");
public parameters = new Subject<any>();
public selectedIndex: number = 0;
public params: any[] = [];
public valueParameter: string;
public parameterNumber: string;
public selectedParameters = null;
public _confirmed: boolean = false;
private changeIcon: Subject<string> = new Subject<string>();
public uri: string;
constructor(private translateService: TranslateService) {}
@WidgetConfigure()
protected configureWidget(configuration: WidgetConfig) {
this.uri = this.configuration.configuration.jobUrl;
this.changeIcon
.pipe(takeUntil(this.unsubscribe))
.subscribe((icon) => (this.deleteIcon = icon));
this.fetchParameters
.pipe(takeUntil(this.unsubscribe))
.subscribe(() => this.jobParametersOutput.next(this.params));
this.loadParametersChannel
.pipe(takeUntil(this.unsubscribe))
.subscribe((params) => {
if (!params) {
return;
}
const rowPrototype = Attributes.createRowPrototype();
this.params = params.map((param) =>
Attributes.mapRowAttributes(param, rowPrototype)
);
this.parameters.next(this.params);
});
}
setDataLoaded() {
if (this.params) {
this.parameters.next(this.params);
}
}
setSelectedParams(selectedParameters: any) {
if (selectedParameters.count > 0) {
this.selectedParameters = selectedParameters.rows;
} else {
this.selectedParameters = null;
}
}
addDummyValue() {
this.valueParameter = null;
this.parameterNumber =
this.translateService.instant(
"web.processes.jobs.parameters.dialog.parameter"
) + " " + String(this.params.length + 1);
const newValue = {
pimRef: String(this.params.length + 1),
name: this.parameterNumber,
value: {
identifier: "value",
pimRef: null,
supplier: null,
tooltip: this.valueParameter,
description: "*value*",
"read-only": false,
type: "PLAIN_STRING",
value: this.valueParameter,
source: [
{
value: this.valueParameter,
},
],
},
};
this.params.push(
Attributes.mapRowAttributes(newValue, Attributes.createRowPrototype())
);
this.parameters.next(this.params);
}
deleteJobParameters() {
this.params = this.params.filter(
(parameter) => !this.selectedParameters.includes(parameter.pimRef)
);
this.selectedParameters = null;
this.parameters.next(this.params);
}
}
<div>
<nm-data-list-component
[configuration]="configuration.configuration"
[uri]="uri"
[data]="parameters"
(dataLoaded)="setDataLoaded()"
(selectedItems)="setSelectedParams($event)"
[autoFocus]="true"
>
</nm-data-list-component>
<br />
<div class="ui-widget-content ui-helper-clearfix">
<nm-delete-button
class="deleteButton"
[isDisabled]="selectedParameters === null"
[placholder]="'label.delete' | translate"
(action)="deleteJobParameters()"
></nm-delete-button>
<button type="button" mat-button (click)="addDummyValue()">
{{ "button.add" | translate }}
</button>
</div>
</div>