Commit b0271a93 authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Add set default name for output artifacts that are internal

parent 3eb67888
......@@ -30,6 +30,14 @@ export class CanvasMetaModelApiService implements MetaModelApi {
}
}
async getName(model: ArtifactDataReference): Promise<string | undefined> {
const companyModel = await this.companyModelService.get(model.id);
if (companyModel.instances.length > 0) {
return companyModel.instances[0].name;
}
return undefined;
}
async copy(model: ArtifactDataReference): Promise<ArtifactDataReference> {
const companyModel = await this.companyModelService.get(model.id);
companyModel.resetDatabaseState();
......
......@@ -27,6 +27,8 @@ export interface MetaModelApi {
reference: Reference
): void;
getName(model: ArtifactDataReference): Promise<string | undefined>;
copy(model: ArtifactDataReference): Promise<ArtifactDataReference>;
remove(model: ArtifactDataReference): Promise<void>;
......
......@@ -41,7 +41,18 @@
</div>
<div class="form-group" *ngIf="definitionControl.value">
<label for="name">Name</label>
<input class="form-control" id="name" formControlName="artifactName" />
<div class="input-group">
<input class="form-control" id="name" formControlName="artifactName" />
<div *ngIf="artifact.internalArtifact" class="input-group-append">
<button
class="btn btn-outline-primary"
type="button"
(click)="setDefaultName()"
>
Set default name
</button>
</div>
</div>
</div>
<div class="form-group" *ngIf="showNotes">
<label for="externalOutputArtifactData">Note</label>
......
......@@ -4,6 +4,9 @@ import { Artifact } from '../../development-process-registry/method-elements/art
import { RunningArtifact } from '../../development-process-registry/running-process/running-artifact';
import { OutputArtifactMappingFormValue } from '../shared/output-artifact-mapping-form.service';
import { Subscription } from 'rxjs';
import { StepArtifact } from '../../development-process-registry/running-process/step-artifact';
import { MetaModelService } from '../../development-process-registry/meta-model.service';
import { ArtifactDataType } from '../../development-process-registry/running-process/artifact-data';
@Component({
selector: 'app-running-process-select-output-artifact',
......@@ -14,13 +17,24 @@ export class RunningProcessSelectOutputArtifactComponent
implements OnInit, OnDestroy
{
@Input() artifact!: Artifact;
@Input() internalArtifact?: StepArtifact;
@Input() processArtifacts!: RunningArtifact[];
private artifactIsDefinitionChangeSubscription?: Subscription;
private artifactSelectionChangeSubscription?: Subscription;
constructor(private controlContainer: ControlContainer) {}
constructor(
private controlContainer: ControlContainer,
private metaModelService: MetaModelService
) {}
ngOnInit(): void {
this.artifactIsDefinitionChangeSubscription =
this.definitionControl.valueChanges.subscribe(async (value) => {
if (value && !this.artifactNameControl.value) {
await this.setDefaultName();
}
});
this.artifactSelectionChangeSubscription =
this.artifactControl.valueChanges.subscribe((value: number) =>
this.loadData(value)
......@@ -28,6 +42,9 @@ export class RunningProcessSelectOutputArtifactComponent
}
ngOnDestroy(): void {
if (this.artifactIsDefinitionChangeSubscription != null) {
this.artifactIsDefinitionChangeSubscription.unsubscribe();
}
if (this.artifactSelectionChangeSubscription != null) {
this.artifactSelectionChangeSubscription.unsubscribe();
}
......@@ -45,6 +62,23 @@ export class RunningProcessSelectOutputArtifactComponent
);
}
async setDefaultName(): Promise<void> {
if (
this.internalArtifact != null &&
this.internalArtifact.data.type === ArtifactDataType.REFERENCE
) {
const api = this.metaModelService.getMetaModelApi(
this.internalArtifact.metaModelType
);
if (api != null) {
const name = await api.getName(this.internalArtifact.data.data);
if (name != null) {
this.artifactNameControl.setValue(name);
}
}
}
}
get formGroup(): FormGroup {
return this.controlContainer.control as FormGroup;
}
......@@ -53,6 +87,10 @@ export class RunningProcessSelectOutputArtifactComponent
return this.formGroup.get('isDefinition');
}
get artifactNameControl(): AbstractControl {
return this.formGroup.get('artifactName');
}
get artifactControl(): AbstractControl {
return this.formGroup.get('artifact');
}
......
......@@ -22,6 +22,7 @@
*ngFor="let artifact of outputArtifacts; let index = index"
formGroupName="{{ index }}"
[artifact]="artifact"
[internalArtifact]="internalOutputArtifacts[index]"
[processArtifacts]="runningProcess.artifacts"
></app-running-process-select-output-artifact>
</div>
......
......@@ -21,6 +21,7 @@ import { RunningMethod } from '../../development-process-registry/running-proces
import { OutputArtifactMapping } from '../../development-process-registry/running-process/output-artifact-mapping';
import { equalsListGeneric } from '../../shared/utils';
import { ArtifactDataType } from '../../development-process-registry/running-process/artifact-data';
import { StepArtifact } from '../../development-process-registry/running-process/step-artifact';
@Component({
selector: 'app-running-process-select-output-artifacts',
......@@ -37,6 +38,7 @@ export class RunningProcessSelectOutputArtifactsComponent
@Output() updateOutputArtifacts = new EventEmitter<FormArray>();
outputArtifacts: Artifact[];
internalOutputArtifacts: StepArtifact[];
form: FormGroup;
changed = false;
......@@ -72,6 +74,7 @@ export class RunningProcessSelectOutputArtifactsComponent
.getList(decision.method.outputArtifacts)
.elements.forEach((element) => artifacts.push(...element.elements));
this.outputArtifacts = artifacts;
this.internalOutputArtifacts = this.runningMethod.getOutputArtifacts();
this.loadForm(artifacts, this.runningMethod.outputArtifacts);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment