fix bug when creating new version or clone a dmp

This commit is contained in:
Bernaldo Mihasi 2023-09-21 09:33:27 +03:00
parent 3c0dce93a8
commit db08662cac
11 changed files with 413 additions and 6 deletions

View File

@ -260,7 +260,7 @@ public class DMPs extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<UUID>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
UUID cloneId = this.dataManagementPlanManager.clone(dataManagementPlan, principal);
UUID cloneId = this.dataManagementPlanManager.clone(id, dataManagementPlan, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(cloneId));
}

View File

@ -687,6 +687,9 @@ public class DataManagementPlanManager {
if (latestVersionDMP.get(0).getVersion().equals(oldDmp.getVersion())) {
DMP newDmp = dataManagementPlan.toDataModel();
newDmp.setProfile(oldDmp.getProfile());
newDmp.setProperties(oldDmp.getProperties());
newDmp.setDmpProperties(oldDmp.getDmpProperties());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
newDmp.setCreator(user);
if(this.dataManagementProfileManager.fieldInBlueprint(newDmp.getProfile(), SystemFieldType.ORGANIZATIONS, principal)) {
@ -735,6 +738,9 @@ public class DataManagementPlanManager {
}
DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
newDmp.setId(tempDmp.getId());
for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){
apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile);
}
// Assign creator.
//assignUser(newDmp, user);
@ -764,8 +770,12 @@ public class DataManagementPlanManager {
}
}
public UUID clone(DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
public UUID clone(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
DMP oldDmp = databaseRepository.getDmpDao().find(uuid);
DMP newDmp = dataManagementPlan.toDataModel();
newDmp.setProfile(oldDmp.getProfile());
newDmp.setProperties(oldDmp.getProperties());
newDmp.setDmpProperties(oldDmp.getDmpProperties());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
newDmp.setCreator(user);
@ -809,6 +819,9 @@ public class DataManagementPlanManager {
}
DMP tempDmp = databaseRepository.getDmpDao().createOrUpdate(newDmp);
newDmp.setId(tempDmp.getId());
for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){
apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile);
}
assignUser(newDmp, user);
copyDatasets(newDmp, databaseRepository.getDatasetDao());

View File

@ -259,7 +259,7 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
for (AssociatedProfile profile : this.profiles) {
DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
dmpDatasetProfile.setId(profile.getId());
dmpDatasetProfile.setId(null);
dmpDatasetProfile.setDmp(entity);
dmpDatasetProfile.setDatasetprofile(profile.toData());
dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));

View File

@ -42,6 +42,9 @@ import {ProjectFormModel} from "@app/ui/dmp/editor/grant-tab/project-form-model"
import {FunderFormModel} from "@app/ui/dmp/editor/grant-tab/funder-form-model";
import {ExtraPropertiesFormModel} from "@app/ui/dmp/editor/general-tab/extra-properties-form.model";
import {CloneDialogComponent} from "@app/ui/dmp/clone/clone-dialog/clone-dialog.component";
import { isNullOrUndefined } from '@app/utilities/enhancers/utils';
import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
@Component({
selector: 'app-drafts',
@ -82,6 +85,7 @@ export class DraftsComponent extends BaseComponent implements OnInit {
public enumUtils: EnumUtils,
private authentication: AuthService,
private dmpService: DmpService,
private dmpProfileService: DmpProfileService,
private dashboardService: DashboardService,
private language: TranslateService,
private dialog: MatDialog,
@ -233,6 +237,17 @@ export class DraftsComponent extends BaseComponent implements OnInit {
this.dmpModel.fromModel(data);
this.dmpModel.status = DmpStatus.Draft;
this.dmpFormGroup = this.dmpModel.buildForm();
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.checkForGrant(result.definition);
this.checkForFunder(result.definition);
this.checkForProject(result.definition);
});
}
if (!isNewVersion) {
this.dmpFormGroup.get('label').setValue(dmp.title + " New");
}
@ -240,6 +255,48 @@ export class DraftsComponent extends BaseComponent implements OnInit {
});
}
private checkForGrant(blueprint: DmpBlueprintDefinition) {
let hasGrant = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
));
if (!hasGrant) {
this.formGroup.removeControl('grant');
}
}
private checkForFunder(blueprint: DmpBlueprintDefinition) {
let hasFunder = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
));
if (!hasFunder) {
this.formGroup.removeControl('funder');
}
}
private checkForProject(blueprint: DmpBlueprintDefinition) {
let hasProject = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}
));
if (!hasProject) {
this.formGroup.removeControl('project');
}
}
openCloneDialog(isNewVersion: boolean) {
const dialogRef = this.dialog.open(CloneDialogComponent, {
maxWidth: '700px',

View File

@ -42,6 +42,9 @@ import { DmpModel } from '@app/core/model/dmp/dmp';
import { CloneDialogComponent } from '@app/ui/dmp/clone/clone-dialog/clone-dialog.component';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { HttpClient } from '@angular/common/http';
import { isNullOrUndefined } from '@app/utilities/enhancers/utils';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
@Component({
selector: 'app-recent-edited-activity',
@ -82,6 +85,7 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
public enumUtils: EnumUtils,
private authentication: AuthService,
private dmpService: DmpService,
private dmpProfileService: DmpProfileService,
private dashboardService: DashboardService,
private language: TranslateService,
private dialog: MatDialog,
@ -299,6 +303,17 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
this.dmpModel.fromModel(data);
this.dmpModel.status = DmpStatus.Draft;
this.dmpFormGroup = this.dmpModel.buildForm();
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.checkForGrant(result.definition);
this.checkForFunder(result.definition);
this.checkForProject(result.definition);
});
}
if (!isNewVersion) {
this.dmpFormGroup.get('label').setValue(dmp.title + " New");
}
@ -306,6 +321,48 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
});
}
private checkForGrant(blueprint: DmpBlueprintDefinition) {
let hasGrant = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
));
if (!hasGrant) {
this.formGroup.removeControl('grant');
}
}
private checkForFunder(blueprint: DmpBlueprintDefinition) {
let hasFunder = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
));
if (!hasFunder) {
this.formGroup.removeControl('funder');
}
}
private checkForProject(blueprint: DmpBlueprintDefinition) {
let hasProject = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}
));
if (!hasProject) {
this.formGroup.removeControl('project');
}
}
openCloneDialog(isNewVersion: boolean) {
const dialogRef = this.dialog.open(CloneDialogComponent, {
maxWidth: '700px',

View File

@ -34,6 +34,9 @@ import { FunderFormModel } from '@app/ui/dmp/editor/grant-tab/funder-form-model'
import { ProjectFormModel } from '@app/ui/dmp/editor/grant-tab/project-form-model';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { HttpClient } from '@angular/common/http';
import { isNullOrUndefined } from '@app/utilities/enhancers/utils';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
@Component({
selector: 'app-recent-edited-dmp-activity',
@ -75,6 +78,7 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O
public enumUtils: EnumUtils,
private authentication: AuthService,
private dmpService: DmpService,
private dmpProfileService: DmpProfileService,
private datasetService: DatasetService,
private language: TranslateService,
private dialog: MatDialog,
@ -252,6 +256,17 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O
this.dmpModel.fromModel(data);
this.dmpModel.status = DmpStatus.Draft;
this.dmpFormGroup = this.dmpModel.buildForm();
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.checkForGrant(result.definition);
this.checkForFunder(result.definition);
this.checkForProject(result.definition);
});
}
if (!isNewVersion) {
this.dmpFormGroup.get('label').setValue(dmp.label + " New");
}
@ -259,6 +274,48 @@ export class RecentEditedDmpActivityComponent extends BaseComponent implements O
});
}
private checkForGrant(blueprint: DmpBlueprintDefinition) {
let hasGrant = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
));
if (!hasGrant) {
this.formGroup.removeControl('grant');
}
}
private checkForFunder(blueprint: DmpBlueprintDefinition) {
let hasFunder = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
));
if (!hasFunder) {
this.formGroup.removeControl('funder');
}
}
private checkForProject(blueprint: DmpBlueprintDefinition) {
let hasProject = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}
));
if (!hasProject) {
this.formGroup.removeControl('project');
}
}
openCloneDialog(isNewVersion: boolean) {
const dialogRef = this.dialog.open(CloneDialogComponent, {
maxWidth: '700px',

View File

@ -29,6 +29,9 @@ import { DmpEditorModel } from '../editor/dmp-editor.model';
import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset-wizard-editor.model';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { isNullOrUndefined } from '@app/utilities/enhancers/utils';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
@Component({
@ -65,6 +68,7 @@ export class DmpCloneComponent extends BaseComponent implements OnInit {
private router: Router,
private language: TranslateService,
private dmpService: DmpService,
private dmpProfileService: DmpProfileService,
private authentication: AuthService,
private uiNotificationService: UiNotificationService,
private datasetService: DatasetService,
@ -90,6 +94,16 @@ export class DmpCloneComponent extends BaseComponent implements OnInit {
this.dmp.status = DmpStatus.Draft;
this.formGroup = this.dmp.buildForm();
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.checkForGrant(result.definition);
this.checkForFunder(result.definition);
this.checkForProject(result.definition);
});
}
this.datasets = this.formGroup.get('datasets') as FormArray;
this.parentDmpLabel = this.formGroup.get('label').value;
@ -128,6 +142,48 @@ export class DmpCloneComponent extends BaseComponent implements OnInit {
}
private checkForGrant(blueprint: DmpBlueprintDefinition) {
let hasGrant = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
));
if (!hasGrant) {
this.formGroup.removeControl('grant');
}
}
private checkForFunder(blueprint: DmpBlueprintDefinition) {
let hasFunder = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
));
if (!hasFunder) {
this.formGroup.removeControl('funder');
}
}
private checkForProject(blueprint: DmpBlueprintDefinition) {
let hasProject = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}
));
if (!hasProject) {
this.formGroup.removeControl('project');
}
}
public cancel(id: String): void {
if (id != null) {
this.router.navigate(['/plans/overview/' + id]);

View File

@ -835,7 +835,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
let hasGrant = false;
this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach(
field => {
if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.GRANT) {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
@ -849,7 +849,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
let hasFunder = false;
this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach(
field => {
if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.FUNDER) {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
@ -863,7 +863,7 @@ export class DmpEditorBlueprintComponent extends CheckDeactivateBaseComponent im
let hasProject = false;
this.selectedDmpBlueprintDefinition.sections.forEach(section => section.fields.forEach(
field => {
if (field.category === FieldCategory.SYSTEM && field.type === SystemFieldType.PROJECT) {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}

View File

@ -28,6 +28,9 @@ import { ExtraPropertiesFormModel } from '../../editor/general-tab/extra-propert
import { GrantTabModel } from '../../editor/grant-tab/grant-tab-model';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { HttpClient } from '@angular/common/http';
import { isNullOrUndefined } from '@app/utilities/enhancers/utils';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
@Component({
selector: 'app-dmp-listing-item-component',
@ -53,6 +56,7 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit {
private authentication: AuthService,
public enumUtils: EnumUtils,
private dmpService: DmpService,
private dmpProfileService: DmpProfileService,
private language: TranslateService,
private uiNotificationService: UiNotificationService,
private lockService: LockService,
@ -173,6 +177,16 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit {
this.dmpModel.status = DmpStatus.Draft;
this.dmpFormGroup = this.dmpModel.buildForm();
if (!isNullOrUndefined(this.dmpFormGroup.get('profile').value)) {
this.dmpProfileService.getSingleBlueprint(this.dmpFormGroup.get('profile').value.id)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.checkForGrant(result.definition);
this.checkForFunder(result.definition);
this.checkForProject(result.definition);
});
}
if (!isNewVersion) {
this.dmpFormGroup.get('label').setValue(dmp.label + " New");
}
@ -180,6 +194,48 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit {
});
}
private checkForGrant(blueprint: DmpBlueprintDefinition) {
let hasGrant = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
));
if (!hasGrant) {
this.dmpFormGroup.removeControl('grant');
}
}
private checkForFunder(blueprint: DmpBlueprintDefinition) {
let hasFunder = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
));
if (!hasFunder) {
this.dmpFormGroup.removeControl('funder');
}
}
private checkForProject(blueprint: DmpBlueprintDefinition) {
let hasProject = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}
));
if (!hasProject) {
this.dmpFormGroup.removeControl('project');
}
}
openCloneDialog(isNewVersion: boolean) {
const dialogRef = this.dialog.open(CloneDialogComponent, {
maxWidth: '700px',

View File

@ -47,6 +47,8 @@ import {DepositRepositoriesService} from '@app/core/services/deposit-repositorie
import {DepositConfigurationModel} from '@app/core/model/deposit/deposit-configuration';
import {DoiModel} from '@app/core/model/doi/doi';
import {isNullOrUndefined} from '@app/utilities/enhancers/utils';
import { DmpBlueprintDefinition, FieldCategory, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
@Component({
selector: 'app-dmp-overview',
@ -81,6 +83,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
private route: ActivatedRoute,
private router: Router,
private dmpService: DmpService,
private dmpProfileService: DmpProfileService,
private depositRepositoriesService: DepositRepositoriesService,
private translate: TranslateService,
private authentication: AuthService,
@ -207,6 +210,17 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
this.dmpModel.fromModel(data);
this.dmpModel.status = DmpStatus.Draft;
this.formGroup = this.dmpModel.buildForm();
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.checkForGrant(result.definition);
this.checkForFunder(result.definition);
this.checkForProject(result.definition);
});
}
if (!isNewVersion) {
this.formGroup.get('label').setValue(this.dmp.label + " New");
}
@ -214,6 +228,48 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
});
}
private checkForGrant(blueprint: DmpBlueprintDefinition) {
let hasGrant = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
));
if (!hasGrant) {
this.formGroup.removeControl('grant');
}
}
private checkForFunder(blueprint: DmpBlueprintDefinition) {
let hasFunder = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
));
if (!hasFunder) {
this.formGroup.removeControl('funder');
}
}
private checkForProject(blueprint: DmpBlueprintDefinition) {
let hasProject = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}
));
if (!hasProject) {
this.formGroup.removeControl('project');
}
}
openCloneDialog(isNewVersion: boolean) {
const dialogRef = this.dialog.open(CloneDialogComponent, {
maxWidth: '900px',

View File

@ -5,6 +5,8 @@ import { FormGroup } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { DmpModel } from '@app/core/model/dmp/dmp';
import { DmpBlueprintDefinition, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service';
import { DmpService } from '@app/core/services/dmp/dmp.service';
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { FunderFormModel } from '@app/ui/dmp/editor/grant-tab/funder-form-model';
@ -13,6 +15,7 @@ import { ProjectFormModel } from '@app/ui/dmp/editor/grant-tab/project-form-mode
import { DmpWizardEditorModel } from '@app/ui/dmp/wizard/dmp-wizard-editor.model';
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent';
import { isNullOrUndefined } from '@app/utilities/enhancers/utils';
import { BaseComponent } from '@common/base/base.component';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
import { TranslateService } from '@ngx-translate/core';
@ -35,6 +38,7 @@ export class DmpWizardComponent extends BaseComponent implements OnInit, IBreadC
constructor(
private dmpService: DmpService,
private dmpProfileService: DmpProfileService,
private language: TranslateService,
private snackBar: MatSnackBar,
private route: ActivatedRoute,
@ -58,6 +62,16 @@ export class DmpWizardComponent extends BaseComponent implements OnInit, IBreadC
this.dmp.fromModel(data);
this.formGroup = this.dmp.buildForm();
if (!isNullOrUndefined(this.formGroup.get('profile').value)) {
this.dmpProfileService.getSingleBlueprint(this.formGroup.get('profile').value.id)
.pipe(takeUntil(this._destroyed))
.subscribe(result => {
this.checkForGrant(result.definition);
this.checkForFunder(result.definition);
this.checkForProject(result.definition);
});
}
if (this.route.routeConfig.path.startsWith('new_version/')) {
this.formGroup.get('version').setValue(this.formGroup.get('version').value + 1);
this.formGroup.controls['label'].disable();
@ -75,6 +89,47 @@ export class DmpWizardComponent extends BaseComponent implements OnInit, IBreadC
});
}
private checkForGrant(blueprint: DmpBlueprintDefinition) {
let hasGrant = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.GRANT) {
hasGrant = true;
}
}
));
if (!hasGrant) {
this.formGroup.removeControl('grant');
}
}
private checkForFunder(blueprint: DmpBlueprintDefinition) {
let hasFunder = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.FUNDER) {
hasFunder = true;
}
}
));
if (!hasFunder) {
this.formGroup.removeControl('funder');
}
}
private checkForProject(blueprint: DmpBlueprintDefinition) {
let hasProject = false;
blueprint.sections.forEach(section => section.fields.forEach(
field => {
if (field.category as unknown === 'SYSTEM' && field.type === SystemFieldType.PROJECT) {
hasProject = true;
}
}
));
if (!hasProject) {
this.formGroup.removeControl('project');
}
}
submit() {
this.saving = true;