Skip to content

Commit

Permalink
SHIBUI-701 integrated with schema endpoint for retrieving
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Nov 9, 2018
1 parent fc21e87 commit 0fd30ce
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
24 changes: 23 additions & 1 deletion ui/src/app/metadata/provider/effect/collection.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import { ClearProvider, ResetChanges } from '../action/entity.action';
import { ShowContentionAction } from '../../../contention/action/contention.action';
import { ContentionService } from '../../../contention/service/contention.service';
import { MetadataProvider } from '../../domain/model';
import { AddNotification } from '../../../notification/action/notification.action';
import { Notification, NotificationType } from '../../../notification/model/notification';
import { WizardActionTypes, SetDisabled } from '../../../wizard/action/wizard.action';


/* istanbul ignore next */
Expand Down Expand Up @@ -96,11 +99,30 @@ export class CollectionEffects {
.save(provider)
.pipe(
map(p => new AddProviderSuccess(p)),
catchError((e) => of(new AddProviderFail(e)))
catchError((e) => of(new AddProviderFail(e.error)))
)
)
);

@Effect()
createProviderFailDispatchNotification$ = this.actions$.pipe(
ofType<AddProviderFail>(ProviderCollectionActionTypes.ADD_PROVIDER_FAIL),
map(action => action.payload),
map(error => new AddNotification(
new Notification(
NotificationType.Danger,
`${error.errorCode}: ${ error.errorMessage }`,
8000
)
))
);
@Effect()
createProviderFailEnableForm$ = this.actions$.pipe(
ofType<AddProviderFail>(ProviderCollectionActionTypes.ADD_PROVIDER_FAIL),
map(action => action.payload),
map(error => new SetDisabled(false))
);

@Effect({ dispatch: false })
createProviderSuccessRedirect$ = this.actions$.pipe(
ofType<AddProviderSuccess>(ProviderCollectionActionTypes.ADD_PROVIDER_SUCCESS),
Expand Down
10 changes: 5 additions & 5 deletions ui/src/app/metadata/provider/model/file-system.provider.form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { BaseMetadataProviderEditor } from './base.provider.form';

export const FileSystemMetadataProviderWizard: Wizard<FileSystemMetadataProvider> = {
...BaseMetadataProviderEditor,
label: 'FileSystemMetadataProvider',
type: 'FileSystemMetadataResolver',
label: 'FilesystemMetadataProvider',
type: 'FilesystemMetadataResolver',
getValidators(namesList: string[] = [], xmlIdList: string[] = []): any {
const validators = BaseMetadataProviderEditor.getValidators(namesList);
validators['/xmlId'] = (value, property, form) => {
Expand All @@ -25,7 +25,7 @@ export const FileSystemMetadataProviderWizard: Wizard<FileSystemMetadataProvider
label: 'label.common-attributes',
index: 2,
initialValues: [],
schema: 'assets/schema/provider/file-system.schema.json',
schema: '/api/ui/MetadataResolver/FilesystemMetadataResolver',
fields: [
'xmlId',
'metadataFile'
Expand All @@ -46,7 +46,7 @@ export const FileSystemMetadataProviderWizard: Wizard<FileSystemMetadataProvider
label: 'label.reloading-attributes',
index: 3,
initialValues: [],
schema: 'assets/schema/provider/file-system.schema.json',
schema: '/api/ui/MetadataResolver/FilesystemMetadataResolver',
fields: [
'reloadableMetadataResolverAttributes'
],
Expand All @@ -65,7 +65,7 @@ export const FileSystemMetadataProviderWizard: Wizard<FileSystemMetadataProvider
label: 'label.finished',
index: 4,
initialValues: [],
schema: 'assets/schema/provider/file-system.schema.json',
schema: '/api/ui/MetadataResolver/FilesystemMetadataResolver',
fields: [
'enabled'
],
Expand Down
11 changes: 10 additions & 1 deletion ui/src/app/schema-form/widget/select/select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@
<translate-i18n *ngIf="schema.placeholder" [key]="schema.placeholder">{{ schema.placeholder }}</translate-i18n>
<translate-i18n *ngIf="!schema.placeholder" [key]="schema.title">{{ schema.title }}</translate-i18n>
</option>
<option *ngFor="let option of schema.oneOf" [ngValue]="option.enum[0]" [translate]="option.description">{{ option.description }}</option>
<ng-container *ngIf="schema.oneOf">
<option *ngFor="let option of schema.oneOf"
[ngValue]="option.enum[0]"
[translate]="option.description">
{{ option.description }}
</option>
</ng-container>
<ng-container *ngIf="options$ | async">
<option *ngFor="let option of options$ | async" [ngValue]="option.value" [translate]="option.label">{{ option.label }}</option>
</ng-container>
</select>
<select *ngIf="schema.type === 'array'" multiple [formControl]="control" [attr.name]="name" [attr.disabled]="schema.readOnly" class="form-control">
<option *ngFor="let option of schema.items.oneOf" [ngValue]="option.enum[0]" [translate]="option.description">{{ option.description }}</option>
Expand Down
16 changes: 16 additions & 0 deletions ui/src/app/schema-form/widget/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { Component, AfterViewInit } from '@angular/core';

import { SelectWidget } from 'ngx-schema-form';
import { SchemaService } from '../../service/schema.service';
import { map } from 'rxjs/operators';

@Component({
selector: 'select-component',
templateUrl: `./select.component.html`
})
export class CustomSelectComponent extends SelectWidget implements AfterViewInit {

options$: any;

constructor(
private widgetService: SchemaService
) {
Expand All @@ -21,6 +25,18 @@ export class CustomSelectComponent extends SelectWidget implements AfterViewInit
} else {
this.control.enable();
}

if (!(this.schema.widget instanceof String) && this.schema.widget.dataUrl) {
this.options$ = this.widgetService
.get(this.schema.widget.dataUrl)
.pipe(
map(opts =>
opts.map(opt =>
({ label: opt.replace('Resolver', 'Provider'), value: opt })
)
)
);
}
}

get required(): boolean {
Expand Down
19 changes: 3 additions & 16 deletions ui/src/assets/schema/provider/metadata-provider.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,9 @@
"placeholder": "label.select-metadata-type",
"type": "string",
"widget": {
"id": "select"
},
"oneOf": [
{
"enum": [
"FileBackedHttpMetadataResolver"
],
"description": "value.file-backed-http-metadata-provider"
},
{
"enum": [
"FileSystemMetadataResolver"
],
"description": "value.file-system-metadata-provider"
}
]
"id": "select",
"dataUrl": "/api/ui/MetadataResolver/types"
}
}
},
"required": [
Expand Down

0 comments on commit 0fd30ce

Please sign in to comment.