Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NAB-327] - Release 4.0.0 #6

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ <h2 mat-dialog-title>Edit model</h2>
<input type="text" matInput [(ngModel)]="model.model.id" [formControl]="idCtrl">
<mat-error *ngIf="idCtrl.errors && idCtrl.errors.required">Id is required</mat-error>
</mat-form-field>
<mat-form-field fxFlex>
<mat-label>Version</mat-label>
<input type="text" matInput [(ngModel)]="model.model.version" [formControl]="versionCtrl">
<!-- TODO: should be version required? -->
<!-- <mat-error *ngIf="versionCtrl.errors && versionCtrl.errors.required">Version is required</mat-error>-->
<mat-error *ngIf="versionCtrl.errors && versionCtrl.errors.format">Version must be in format Major.Minor.Patch</mat-error>
</mat-form-field>
<mat-form-field fxFlex>
<mat-label>Title</mat-label>
<input type="text" matInput [(ngModel)]="model.model.title.value" [formControl]="titleCtrl">
Expand Down Expand Up @@ -37,7 +44,7 @@ <h2 mat-dialog-title>Edit model</h2>
<span>Permissions ({{this.modelService.numberOfPermissions()}})</span>
</button>
<button mat-flat-button color="primary" [mat-dialog-close]="model"
[disabled]="idCtrl.invalid || initialsCtrl.invalid || titleCtrl.invalid">
[disabled]="idCtrl.invalid || versionCtrl.invalid || initialsCtrl.invalid || titleCtrl.invalid">
<mat-icon>done</mat-icon>
<span>Save</span>
</button>
Expand Down
22 changes: 20 additions & 2 deletions src/app/dialogs/dialog-model-edit/dialog-model-edit.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Component, Inject, OnInit} from '@angular/core';
import {Component, Inject} from '@angular/core';
import {ChangedPetriNet} from './changed-petri-net';
import {MAT_DIALOG_DATA, MatDialog} from '@angular/material/dialog';
import {ModelService} from '../../modeler/services/model/model.service';
import {Router} from '@angular/router';
import {DialogManageRolesComponent, RoleRefType} from '../dialog-manage-roles/dialog-manage-roles.component';
import {DataType} from '@netgrif/petriflow';
import {FormControl, Validators} from '@angular/forms';
import {FormControl, ValidatorFn, Validators} from '@angular/forms';

@Component({
selector: 'nab-dialog-model-edit',
Expand All @@ -16,6 +16,7 @@ export class DialogModelEditComponent {

public model: ChangedPetriNet;
public idCtrl: FormControl;
public versionCtrl: FormControl;
public titleCtrl: FormControl;
public initialsCtrl: FormControl;

Expand All @@ -27,6 +28,10 @@ export class DialogModelEditComponent {
) {
this.model = data;
this.idCtrl = new FormControl('', [Validators.required]);
this.versionCtrl = new FormControl('', [
// Validators.required,
this.validVersion()
]);
this.titleCtrl = new FormControl('', [Validators.required]);
this.initialsCtrl = new FormControl('', [Validators.required]);
}
Expand All @@ -48,4 +53,17 @@ export class DialogModelEditComponent {
// TODO: NAB-327 open process view
this.router.navigate(['modeler/actions']);
}

private validVersion(): ValidatorFn {
return (fc: FormControl): { [key: string]: any } | null => {
const version = fc.value as string;
if (!version || version.length === 0) {
return null;
}
if (version.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/)) {
return null;
}
return ({format: true})
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export class EditModelMenuItem extends MenuItem {
width: '50%',
data: new ChangedPetriNet(tool.model.id, tool.model.clone())
}, (changedModel: ChangedPetriNet) => {
tool.modelService.updateModel(changedModel);
if (changedModel != undefined) {
tool.modelService.updateModel(changedModel);
}
});
}
);
Expand Down
1 change: 1 addition & 0 deletions src/app/modeler/services/model/model-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export class ModelConfig {
public static FILE_NAME = 'newmodel.xml';
public static IDENTIFIER = 'new_model';
public static VERSION = '1.0.0';
public static TITLE = 'New Model';
public static ICON = 'device_hub';
public static INITIALS = 'NEW';
Expand Down
1 change: 1 addition & 0 deletions src/app/modeler/services/model/model.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class ModelService implements ModelSource {
newModel(): PetriNet {
const model = new PetriNet();
model.id = ModelConfig.IDENTIFIER;
model.version = ModelConfig.VERSION;
model.title = new I18nString(ModelConfig.TITLE);
model.initials = ModelConfig.INITIALS;
model.icon = ModelConfig.ICON;
Expand Down
1 change: 1 addition & 0 deletions src/assets/mortgage_simple.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://netgrif.github.io/petriflow/petriflow.schema.xsd">
<id>mortgage</id>
<version>1.0.0</version>
<initials>MTG</initials>
<title>Mortgage</title>
<defaultRole>true</defaultRole>
Expand Down
Loading