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 { ...@@ -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> { async copy(model: ArtifactDataReference): Promise<ArtifactDataReference> {
const companyModel = await this.companyModelService.get(model.id); const companyModel = await this.companyModelService.get(model.id);
companyModel.resetDatabaseState(); companyModel.resetDatabaseState();
......
...@@ -27,6 +27,8 @@ export interface MetaModelApi { ...@@ -27,6 +27,8 @@ export interface MetaModelApi {
reference: Reference reference: Reference
): void; ): void;
getName(model: ArtifactDataReference): Promise<string | undefined>;
copy(model: ArtifactDataReference): Promise<ArtifactDataReference>; copy(model: ArtifactDataReference): Promise<ArtifactDataReference>;
remove(model: ArtifactDataReference): Promise<void>; remove(model: ArtifactDataReference): Promise<void>;
......
...@@ -41,7 +41,18 @@ ...@@ -41,7 +41,18 @@
</div> </div>
<div class="form-group" *ngIf="definitionControl.value"> <div class="form-group" *ngIf="definitionControl.value">
<label for="name">Name</label> <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>
<div class="form-group" *ngIf="showNotes"> <div class="form-group" *ngIf="showNotes">
<label for="externalOutputArtifactData">Note</label> <label for="externalOutputArtifactData">Note</label>
......
...@@ -4,6 +4,9 @@ import { Artifact } from '../../development-process-registry/method-elements/art ...@@ -4,6 +4,9 @@ import { Artifact } from '../../development-process-registry/method-elements/art
import { RunningArtifact } from '../../development-process-registry/running-process/running-artifact'; import { RunningArtifact } from '../../development-process-registry/running-process/running-artifact';
import { OutputArtifactMappingFormValue } from '../shared/output-artifact-mapping-form.service'; import { OutputArtifactMappingFormValue } from '../shared/output-artifact-mapping-form.service';
import { Subscription } from 'rxjs'; 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({ @Component({
selector: 'app-running-process-select-output-artifact', selector: 'app-running-process-select-output-artifact',
...@@ -14,13 +17,24 @@ export class RunningProcessSelectOutputArtifactComponent ...@@ -14,13 +17,24 @@ export class RunningProcessSelectOutputArtifactComponent
implements OnInit, OnDestroy implements OnInit, OnDestroy
{ {
@Input() artifact!: Artifact; @Input() artifact!: Artifact;
@Input() internalArtifact?: StepArtifact;
@Input() processArtifacts!: RunningArtifact[]; @Input() processArtifacts!: RunningArtifact[];
private artifactIsDefinitionChangeSubscription?: Subscription;
private artifactSelectionChangeSubscription?: Subscription; private artifactSelectionChangeSubscription?: Subscription;
constructor(private controlContainer: ControlContainer) {} constructor(
private controlContainer: ControlContainer,
private metaModelService: MetaModelService
) {}
ngOnInit(): void { ngOnInit(): void {
this.artifactIsDefinitionChangeSubscription =
this.definitionControl.valueChanges.subscribe(async (value) => {
if (value && !this.artifactNameControl.value) {
await this.setDefaultName();
}
});
this.artifactSelectionChangeSubscription = this.artifactSelectionChangeSubscription =
this.artifactControl.valueChanges.subscribe((value: number) => this.artifactControl.valueChanges.subscribe((value: number) =>
this.loadData(value) this.loadData(value)
...@@ -28,6 +42,9 @@ export class RunningProcessSelectOutputArtifactComponent ...@@ -28,6 +42,9 @@ export class RunningProcessSelectOutputArtifactComponent
} }
ngOnDestroy(): void { ngOnDestroy(): void {
if (this.artifactIsDefinitionChangeSubscription != null) {
this.artifactIsDefinitionChangeSubscription.unsubscribe();
}
if (this.artifactSelectionChangeSubscription != null) { if (this.artifactSelectionChangeSubscription != null) {
this.artifactSelectionChangeSubscription.unsubscribe(); this.artifactSelectionChangeSubscription.unsubscribe();
} }
...@@ -45,6 +62,23 @@ export class RunningProcessSelectOutputArtifactComponent ...@@ -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 { get formGroup(): FormGroup {
return this.controlContainer.control as FormGroup; return this.controlContainer.control as FormGroup;
} }
...@@ -53,6 +87,10 @@ export class RunningProcessSelectOutputArtifactComponent ...@@ -53,6 +87,10 @@ export class RunningProcessSelectOutputArtifactComponent
return this.formGroup.get('isDefinition'); return this.formGroup.get('isDefinition');
} }
get artifactNameControl(): AbstractControl {
return this.formGroup.get('artifactName');
}
get artifactControl(): AbstractControl { get artifactControl(): AbstractControl {
return this.formGroup.get('artifact'); return this.formGroup.get('artifact');
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
*ngFor="let artifact of outputArtifacts; let index = index" *ngFor="let artifact of outputArtifacts; let index = index"
formGroupName="{{ index }}" formGroupName="{{ index }}"
[artifact]="artifact" [artifact]="artifact"
[internalArtifact]="internalOutputArtifacts[index]"
[processArtifacts]="runningProcess.artifacts" [processArtifacts]="runningProcess.artifacts"
></app-running-process-select-output-artifact> ></app-running-process-select-output-artifact>
</div> </div>
......
...@@ -21,6 +21,7 @@ import { RunningMethod } from '../../development-process-registry/running-proces ...@@ -21,6 +21,7 @@ import { RunningMethod } from '../../development-process-registry/running-proces
import { OutputArtifactMapping } from '../../development-process-registry/running-process/output-artifact-mapping'; import { OutputArtifactMapping } from '../../development-process-registry/running-process/output-artifact-mapping';
import { equalsListGeneric } from '../../shared/utils'; import { equalsListGeneric } from '../../shared/utils';
import { ArtifactDataType } from '../../development-process-registry/running-process/artifact-data'; import { ArtifactDataType } from '../../development-process-registry/running-process/artifact-data';
import { StepArtifact } from '../../development-process-registry/running-process/step-artifact';
@Component({ @Component({
selector: 'app-running-process-select-output-artifacts', selector: 'app-running-process-select-output-artifacts',
...@@ -37,6 +38,7 @@ export class RunningProcessSelectOutputArtifactsComponent ...@@ -37,6 +38,7 @@ export class RunningProcessSelectOutputArtifactsComponent
@Output() updateOutputArtifacts = new EventEmitter<FormArray>(); @Output() updateOutputArtifacts = new EventEmitter<FormArray>();
outputArtifacts: Artifact[]; outputArtifacts: Artifact[];
internalOutputArtifacts: StepArtifact[];
form: FormGroup; form: FormGroup;
changed = false; changed = false;
...@@ -72,6 +74,7 @@ export class RunningProcessSelectOutputArtifactsComponent ...@@ -72,6 +74,7 @@ export class RunningProcessSelectOutputArtifactsComponent
.getList(decision.method.outputArtifacts) .getList(decision.method.outputArtifacts)
.elements.forEach((element) => artifacts.push(...element.elements)); .elements.forEach((element) => artifacts.push(...element.elements));
this.outputArtifacts = artifacts; this.outputArtifacts = artifacts;
this.internalOutputArtifacts = this.runningMethod.getOutputArtifacts();
this.loadForm(artifacts, this.runningMethod.outputArtifacts); 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