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

Show version numbers in view/edit profiles dropdown #494

Merged
merged 5 commits into from
Apr 4, 2022
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 @@ -44,7 +44,7 @@ export class AddProfileModalComponent implements OnInit {
profiles.body.forEach((profile) => {
const prof: any = [];
prof['display'] = `${profile.displayName} (${profile.version})`;
prof['value'] = `${profile.namespace}/${profile.name}`;
prof['value'] = `${profile.namespace}/${profile.name}/${profile.version}`;
this.allUnusedProfiles.push(prof);
this.showProfileSelector = true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ <h4 mat-dialog-title>Edit Profile - {{ data.profileName }}</h4>
>
</mdm-model-selector-tree>
</div>
<mat-error *ngIf="getValidationError(field.fieldName)">
{{ getValidationError(field.fieldName).message }}
<mat-error *ngIf="getValidationError(field.metadataPropertyName)">
{{ getValidationError(field.metadataPropertyName).message }}
</mat-error>
</td>
</tr>
Expand Down Expand Up @@ -228,7 +228,6 @@ <h4 mat-dialog-title>Edit Profile - {{ data.profileName }}</h4>
type="submit"
class="custom"
(click)="save()"
[disabled]="userForm.invalid"
>
{{ okBtnText }}
</button>
Expand Down
20 changes: 14 additions & 6 deletions src/app/modals/edit-profile-modal/edit-profile-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { MarkdownParserService } from '@mdm/utility/markdown/markdown-parser/mar
import { EMPTY } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { EditProfileModalConfiguration, EditProfileModalResult } from './edit-profile-modal.model';
import {EditingService} from '@mdm/services/editing.service';
@Component({
selector: 'mdm-edit-profile-modal',
templateUrl: './edit-profile-modal.component.html',
Expand All @@ -44,6 +45,7 @@ export class EditProfileModalComponent implements OnInit {
okBtnText: string;
validationErrors: ProfileValidationErrorList = {
total: 0,
fieldTotal: 0,
errors: []
};

Expand All @@ -63,7 +65,8 @@ export class EditProfileModalComponent implements OnInit {
@Inject(MAT_DIALOG_DATA) public data: EditProfileModalConfiguration,
private markdownParser: MarkdownParserService,
protected resources: MdmResourcesService,
private dialog: MatDialog) {
private dialog: MatDialog,
protected editing: EditingService) {
data.profile.sections.forEach((section) => {
section.fields.forEach((field) => {
if (data.isNew && field.defaultValue) {
Expand Down Expand Up @@ -116,7 +119,11 @@ export class EditProfileModalComponent implements OnInit {
}

onCancel() {
this.dialogRef.close({ status: ModalDialogStatus.Cancel });
this.editing.confirmCancelAsync().subscribe((confirm) => {
if (confirm) {
this.dialogRef.close({ status: ModalDialogStatus.Cancel });
}
});
}

validate() {
Expand All @@ -126,7 +133,8 @@ export class EditProfileModalComponent implements OnInit {
this.data.profile.name,
this.data.catalogueItem.domainType,
this.data.catalogueItem.id,
this.profileData
this.profileData,
this.data.profile.version
)
.pipe(
catchError((error: HttpErrorResponse) => {
Expand All @@ -142,12 +150,12 @@ export class EditProfileModalComponent implements OnInit {
});
}

getValidationError(fieldName: string): ProfileValidationError | undefined {
if (this.validationErrors.total === 0) {
getValidationError(metadataPropertyName: string): ProfileValidationError | undefined {
if (this.validationErrors.fieldTotal === 0) {
return undefined;
}

return this.validationErrors.errors.find(e => e.fieldName === fieldName);
return this.validationErrors.errors.find(e => e.metadataPropertyName === metadataPropertyName);
}

sortBy(items: []) {
Expand Down
144 changes: 93 additions & 51 deletions src/app/shared/profile-data-view/profile-data-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,42 @@ limitations under the License.

SPDX-License-Identifier: Apache-2.0
*/
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { CatalogueItem, CatalogueItemDomainType, catalogueItemToMultiFacetAware, DoiState, DoiStatusResponse, DoiSubmissionState, Finalisable, isDataType, MdmResponse, Modelable, ModelableDetail, MultiFacetAwareDomainType, Profile, ProfileResponse, ProfileSummaryIndexResponse, SecurableModel, Uuid } from '@maurodatamapper/mdm-resources';
import { ModalDialogStatus } from '@mdm/constants/modal-dialog-status';
import { AddProfileModalComponent } from '@mdm/modals/add-profile-modal/add-profile-modal.component';
import { DefaultProfileEditorModalComponent } from '@mdm/modals/default-profile-editor-modal/default-profile-editor-modal.component';
import { EditProfileModalComponent } from '@mdm/modals/edit-profile-modal/edit-profile-modal.component';
import { EditProfileModalConfiguration, EditProfileModalResult } from '@mdm/modals/edit-profile-modal/edit-profile-modal.model';
import { DefaultProfileItem, DefaultProfileModalConfiguration, DefaultProfileModalResponse } from '@mdm/model/defaultProfileModel';
import { MdmHttpHandlerOptions, MdmResourcesService } from '@mdm/modules/resources';
import { MessageHandlerService, SecurityHandlerService, SharedService } from '@mdm/services';
import { EditingService } from '@mdm/services/editing.service';
import { EMPTY, Observable, from, zip, Subject } from 'rxjs';
import { catchError, filter, map, switchMap, mergeMap, tap } from 'rxjs/operators';
import { doiProfileNamespace, getDefaultProfileData, ProfileDataViewType, ProfileSummaryListItem } from './profile-data-view.model';
import { GridService } from '@mdm/services/grid.service';
import { ApiProperty, ApiPropertyIndexResponse } from '@maurodatamapper/mdm-resources';
import {Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges} from '@angular/core';
import {MatDialog} from '@angular/material/dialog';
import {
ApiProperty,
ApiPropertyIndexResponse,
CatalogueItem,
CatalogueItemDomainType,
catalogueItemToMultiFacetAware,
DoiState,
DoiStatusResponse,
DoiSubmissionState,
Finalisable,
isDataType,
MdmResponse,
Modelable,
ModelableDetail,
MultiFacetAwareDomainType,
Profile,
ProfileResponse,
ProfileSummaryIndexResponse,
SecurableModel,
Uuid
} from '@maurodatamapper/mdm-resources';
import {ModalDialogStatus} from '@mdm/constants/modal-dialog-status';
import {AddProfileModalComponent} from '@mdm/modals/add-profile-modal/add-profile-modal.component';
import {DefaultProfileEditorModalComponent} from '@mdm/modals/default-profile-editor-modal/default-profile-editor-modal.component';
import {EditProfileModalComponent} from '@mdm/modals/edit-profile-modal/edit-profile-modal.component';
import {EditProfileModalConfiguration, EditProfileModalResult} from '@mdm/modals/edit-profile-modal/edit-profile-modal.model';
import {DefaultProfileItem, DefaultProfileModalConfiguration, DefaultProfileModalResponse} from '@mdm/model/defaultProfileModel';
import {MdmHttpHandlerOptions, MdmResourcesService} from '@mdm/modules/resources';
import {MessageHandlerService, SecurityHandlerService, SharedService} from '@mdm/services';
import {EditingService} from '@mdm/services/editing.service';
import {EMPTY, from, Observable, Subject, zip} from 'rxjs';
import {catchError, filter, map, mergeMap, switchMap, tap} from 'rxjs/operators';
import {doiProfileNamespace, getDefaultProfileData, ProfileDataViewType, ProfileSummaryListItem} from './profile-data-view.model';
import {GridService} from '@mdm/services/grid.service';

@Component({
selector: 'mdm-profile-data-view',
Expand All @@ -58,8 +77,11 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
isEditablePostFinalise = false;
isReadableByEveryone = false;
doiState: DoiState = 'not submitted';
defaultProfileDomainName: string;
otherProperty: any;
defaultProfileMetadataNamespace: string;
defaultProfileView: string;
otherDefaultProfileView: string;

private readonly defaultProfileNamespacePropertyKey = 'ui.default.profile.namespace';

get isCurrentViewCustomProfile() {
return this.currentView !== 'default' && this.currentView !== 'other' && this.currentView !== 'addnew';
Expand Down Expand Up @@ -157,6 +179,8 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
.concat(this.unusedProfiles)
.find(item => item.value === this.currentView);

const oldProfile: Profile = JSON.parse(JSON.stringify(this.currentProfile));

this.editing
.openDialog<EditProfileModalComponent, EditProfileModalConfiguration, EditProfileModalResult>(
EditProfileModalComponent,
Expand All @@ -174,9 +198,12 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
.pipe(
tap(result => {
if (!result.profile && isNew) {
this.currentView = 'default';
this.currentView = this.lastView;
this.changeProfile();
}
if (result.status !== ModalDialogStatus.Ok && !isNew) {
this.currentProfile = oldProfile;
}
}),
filter(result => result.status === ModalDialogStatus.Ok),
switchMap(result => {
Expand All @@ -186,7 +213,8 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
this.catalogueItem.id,
selected.namespace,
selected.name,
result.profile);
result.profile,
selected.version);
}),
catchError(error => {
this.messageHandler.showError('There was a problem saving the profile.', error);
Expand Down Expand Up @@ -229,7 +257,8 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
this.catalogueItem.domainType,
this.catalogueItem.id,
this.currentProfile.namespace,
this.currentProfile.name
this.currentProfile.name,
this.currentProfile.version
);
}),
catchError(error => {
Expand All @@ -238,8 +267,15 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
})
)
.subscribe(() => {
let notCurrentOtherDefaultProfileView: string;
if (this.otherDefaultProfileView !== undefined && this.currentView !== this.otherDefaultProfileView) {
notCurrentOtherDefaultProfileView = this.otherDefaultProfileView;
}
this.messageHandler.showSuccess('Profile removed successfully');
this.currentView = 'default';
this.currentView = this.usedProfiles.find(e => e.value === this.defaultProfileView &&
!(e.namespace === this.currentProfile.namespace && e.name === this.currentProfile.name && e.version === this.currentProfile.version)
)?.value
?? notCurrentOtherDefaultProfileView ?? 'default';
this.loadUsedProfiles(this.catalogueItem.domainType, this.catalogueItem.id);
this.loadUnusedProfiles(this.catalogueItem.domainType, this.catalogueItem.id);
this.changeProfile();
Expand Down Expand Up @@ -275,22 +311,27 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
this.usedProfiles = items;

// Set a default value
this.otherProperty = this.loadDefaultProfilePropertyValue(domainType, id)
this.loadDefaultProfilePropertyValue(domainType, id)
.subscribe(defaultValues => {
if (defaultValues && (defaultValues.length > 0)) {
this.otherProperty = defaultValues[0].value;
this.defaultProfileView = defaultValues[0].value;
if (defaultValues.length > 1) {
this.otherDefaultProfileView = defaultValues[1].value;
} else {
this.otherDefaultProfileView = undefined;
}
}

if (!this.lastView && this.otherProperty) {
if (!this.currentView && this.defaultProfileView) {
// Get the item in usedProfiles that matches the otherProperties value
this.currentView = this.usedProfiles.find(e => e.display === this.otherProperty)?.value ?? 'default';
} else {
this.currentView = this.usedProfiles.find(e => e.value === this.defaultProfileView)?.value ?? 'default';
} else if (!this.currentView) {
this.currentView = 'default';
}
this.changeProfile();
});
} else {
if (!this.lastView) {
this.usedProfiles = items;
if (!this.currentView) {
this.currentView = 'default';
}
}
Expand Down Expand Up @@ -359,10 +400,11 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
map((response: ProfileSummaryIndexResponse) => {
return response.body.map(summary => {
return {
display: summary.displayName,
value: `${summary.namespace}/${summary.name}`,
display: `${summary.displayName} (${summary.version})`,
value: `${summary.namespace}/${summary.name}/${summary.version}`,
namespace: summary.namespace,
name: summary.name
name: summary.name,
version: summary.version
};
});
})
Expand Down Expand Up @@ -394,11 +436,11 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
private selectCustomProfile() {
this.lastView = this.currentView;

const [namespace, name] = this.getNamespaceAndName(this.currentView);
const [namespace, name, version] = this.getNamespaceNameAndVersion(this.currentView);

if (namespace && name) {
if (namespace && name && version) {
this.resources.profile
.profile(this.catalogueItem.domainType, this.catalogueItem.id, namespace, name)
.profile(this.catalogueItem.domainType, this.catalogueItem.id, namespace, name, version)
.pipe(
catchError(error => {
this.messageHandler.showError('There was a problem getting the selected profile.', error);
Expand All @@ -409,6 +451,7 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
this.currentProfile = response.body;
this.currentProfile.namespace = namespace;
this.currentProfile.name = name;
this.currentProfile.version = version;
});
}
}
Expand All @@ -428,9 +471,9 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
.afterClosed()
.subscribe((newProfile) => {
if (newProfile) {
const [namespace, name] = this.getNamespaceAndName(newProfile);
const [namespace, name, version] = this.getNamespaceNameAndVersion(newProfile);
this.resources.profile
.profile(this.catalogueItem.domainType, this.catalogueItem.id, namespace, name, '')
.profile(this.catalogueItem.domainType, this.catalogueItem.id, namespace, name, version)
.pipe(
catchError(error => {
this.messageHandler.showError('There was a problem getting the selected profile.', error);
Expand All @@ -452,9 +495,9 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
});
}

private getNamespaceAndName(viewName: string): [string, string] {
private getNamespaceNameAndVersion(viewName: string): [string, string, string] {
const split = viewName.split('/');
return [split[0], split[1]];
return [split[0], split[1], split[2]];
}

private getDoiStatus() {
Expand Down Expand Up @@ -598,7 +641,7 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
}

private loadDefaultCustomProfile(properties: ApiProperty[]) {
this.defaultProfileDomainName = this.getContentProperty(properties, 'ui.default.profile.namespace');
this.defaultProfileMetadataNamespace = this.getContentProperty(properties, this.defaultProfileNamespacePropertyKey);
}

private getContentProperty(properties: ApiProperty[], key: string): string {
Expand Down Expand Up @@ -648,15 +691,14 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
let responses = [];
const subject = new Subject<any>();
observable.subscribe({
next: property => {
for (const property_item of property) {
if (property_item !== undefined ) {
responses = responses.concat(
property_item.filter(o => (
this.usedProfiles.findIndex(e => e.display === o.value) !== -1
))
);
}
next: defaultProfileProperties => {
const namespace = defaultProfileProperties[0].find(property => property.key === 'namespace');
const name = defaultProfileProperties[0].find(property => property.key === 'name');
const version = defaultProfileProperties[0].find(property => property.key === 'version');
if (namespace !== undefined && name !== undefined && version !== undefined) {
responses = this.usedProfiles.filter(usedProfile =>
usedProfile.namespace === namespace.value && usedProfile.name === name.value && usedProfile.version === version.value
).concat(responses);
}
},
complete: () => {
Expand All @@ -683,7 +725,7 @@ export class ProfileDataViewComponent implements OnInit, OnChanges {
map((data: any) => {
const tempItems = data.body.items;
const items = tempItems.filter( o => (
o.namespace === this.defaultProfileDomainName)
o.namespace === this.defaultProfileMetadataNamespace)
);
return items;
})
Expand Down
3 changes: 2 additions & 1 deletion src/app/shared/profile-data-view/profile-data-view.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/

import { Container, DataTypeReference, Modelable, ModelableDetail } from '@maurodatamapper/mdm-resources';
import {Container, DataTypeReference, Modelable, ModelableDetail, Version} from '@maurodatamapper/mdm-resources';
import { DefaultProfileControls, DefaultProfileItem, ProfileControlTypes } from '@mdm/model/defaultProfileModel';

export type ProfileDataViewType = 'default' | 'other' | 'addnew';
Expand All @@ -29,6 +29,7 @@ export interface ProfileSummaryListItem {
value: string;
namespace: string;
name: string;
version: Version;
}

export const showControl = (controls: string[], controlName: string): boolean => {
Expand Down