toUrlParams(context: CatalogSearchContext):
{[key: string]: string | string[]} {
- let params = {
+ const params = {
query: [],
fieldClass: [],
joinOp: [],
};
params.limit = context.pager.limit;
- if (context.pager.offset)
+ if (context.pager.offset) {
params.offset = context.pager.offset;
+ }
// These fields can be copied directly into place
- ['format','sort','available','global']
+ ['format', 'sort', 'available', 'global']
.forEach(field => {
if (context[field]) {
// Only propagate applied values to the URL.
});
context.query.forEach((q, idx) => {
- ['query', 'fieldClass','joinOp','matchOp'].forEach(field => {
+ ['query', 'fieldClass', 'joinOp', 'matchOp'].forEach(field => {
// Propagate all array-based fields regardless of
// whether a value is applied to ensure correct
// correlation between values.
// CCVM filters are encoded as comma-separated lists
Object.keys(context.ccvmFilters).forEach(code => {
if (context.ccvmFilters[code] &&
- context.ccvmFilters[code][0] != '') {
+ context.ccvmFilters[code][0] !== '') {
params[code] = context.ccvmFilters[code].join(',');
}
});
* Creates a new search context from the active route params.
*/
fromUrlParams(params: ParamMap): CatalogSearchContext {
- let context = new CatalogSearchContext();
+ const context = new CatalogSearchContext();
this.applyUrlParams(context, params);
context.reset();
// These fields can be copied directly into place
- ['format','sort','available','global']
+ ['format', 'sort', 'available', 'global']
.forEach(field => {
- let val = params.get(field);
- if (val !== null) context[field] = val;
+ const val = params.get(field);
+ if (val !== null) {
+ context[field] = val;
+ }
});
- if (params.get('limit'))
+ if (params.get('limit')) {
context.pager.limit = +params.get('limit');
+ }
- if (params.get('offset'))
+ if (params.get('offset')) {
context.pager.offset = +params.get('offset');
+ }
- ['query','fieldClass','joinOp','matchOp'].forEach(field => {
- let arr = params.getAll(field);
- if (arr && arr.length) context[field] = arr;
+ ['query', 'fieldClass', 'joinOp', 'matchOp'].forEach(field => {
+ const arr = params.getAll(field);
+ if (arr && arr.length) {
+ context[field] = arr;
+ }
});
CATALOG_CCVM_FILTERS.forEach(code => {
- let val = params.get(code);
+ const val = params.get(code);
if (val) {
context.ccvmFilters[code] = val.split(/,/);
} else {
});
params.getAll('facets').forEach(blob => {
- let facet = JSON.parse(blob);
+ const facet = JSON.parse(blob);
context.addFacet(new FacetFilter(facet.c, facet.n, facet.v));
});
- if (params.get('org'))
+ if (params.get('org')) {
context.searchOrg = this.org.get(+params.get('org'));
+ }
}
}
import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
interface CustomFieldTemplate {
- template: TemplateRef<any>,
+ template: TemplateRef<any>;
// Allow the caller to pass in a free-form context blob to
// be addedto the caller's custom template context, along
// with our stock context.
- context?: {[fields: string]: any}
+ context?: {[fields: string]: any};
}
interface CustomFieldContext {
// Current create/edit/view record
- record: EgIdlObject,
+ record: EgIdlObject;
// IDL field definition blob
- field: any,
+ field: any;
// additional context values passed via CustomFieldTemplate
[fields: string]: any;
}
@Component({
- selector: 'fm-record-editor',
+ selector: 'eg-fm-record-editor',
templateUrl: './fm-editor.component.html'
})
export class FmRecordEditorComponent
// 'update' for editing an existing record
// 'view' for viewing an existing record without editing
mode: 'create' | 'update' | 'view' = 'create';
- @Input() editMode(mode: 'create' | 'update' | 'view') {
- this.mode = mode;
- }
-
- // Record ID to view/update. Value is dynamic. Records are not
- // fetched until .open() is called.
recId: any;
- @Input() set recordId(id: any) {
- if (id) this.recId = id;
- }
-
// IDL record we are editing
// TODO: allow this to be update in real time by the caller?
record: EgIdlObject;
@Input() customFieldTemplates:
- {[fieldName:string] : CustomFieldTemplate} = {};
+ {[fieldName: string]: CustomFieldTemplate} = {};
// list of fields that should not be displayed
@Input() hiddenFieldsList: string[] = [];
// supports cases where whether a field is required or not depends
// on the current value of another field.
@Input() isRequiredOverride:
- {[field: string] : (field: string, record: EgIdlObject) => boolean};
+ {[field: string]: (field: string, record: EgIdlObject) => boolean};
// IDL record display label. Defaults to the IDL label.
@Input() recordLabel: string;
idlDef: any;
// Can we edit the primary key?
- pkeyIsEditable: boolean = false;
+ pkeyIsEditable = false;
// List of IDL field definitions. This is a subset of the full
// list of fields on the IDL, since some are hidden, virtual, etc.
fields: any[];
+ @Input() editMode(mode: 'create' | 'update' | 'view') {
+ this.mode = mode;
+ }
+
+ // Record ID to view/update. Value is dynamic. Records are not
+ // fetched until .open() is called.
+ @Input() set recordId(id: any) {
+ if (id) { this.recId = id; }
+ }
+
constructor(
private modal: NgbModal, // required for passing to parent
private idl: EgIdlService,
private auth: EgAuthService,
private pcrud: EgPcrudService) {
- super(modal)
+ super(modal);
}
// Avoid fetching data on init since that may lead to unnecessary
// Translate comma-separated string versions of various inputs
// to arrays.
private listifyInputs() {
- if (this.hiddenFields)
+ if (this.hiddenFields) {
this.hiddenFieldsList = this.hiddenFields.split(/,/);
- if (this.readonlyFields)
+ }
+ if (this.readonlyFields) {
this.readonlyFieldsList = this.readonlyFields.split(/,/);
- if (this.requiredFields)
+ }
+ if (this.requiredFields) {
this.requiredFieldsList = this.requiredFields.split(/,/);
- if (this.orgDefaultAllowed)
+ }
+ if (this.orgDefaultAllowed) {
this.orgDefaultAllowedList = this.orgDefaultAllowed.split(/,/);
+ }
}
private initRecord(): Promise<any> {
- if (this.mode == 'update' || this.mode == 'view') {
+ if (this.mode === 'update' || this.mode === 'view') {
return this.pcrud.retrieve(this.idlClass, this.recId)
.toPromise().then(rec => {
// with native JS values.
private convertDatatypesToJs() {
this.idlDef.fields.forEach(field => {
- if (field.datatype == 'bool') {
- if (this.record[field.name]() == 't') {
+ if (field.datatype === 'bool') {
+ if (this.record[field.name]() === 't') {
this.record[field.name](true);
- } else if (this.record[field.name]() == 'f') {
+ } else if (this.record[field.name]() === 'f') {
this.record[field.name](false);
}
}
// Modifies the provided FM record in place, replacing JS values
// with IDL-compatible values.
convertDatatypesToIdl(rec: EgIdlObject) {
- var fields = this.idlDef.fields;
+ const fields = this.idlDef.fields;
fields.forEach(field => {
- if (field.datatype == 'bool') {
- if (rec[field.name]() == true) {
+ if (field.datatype === 'bool') {
+ if (rec[field.name]() === true) {
rec[field.name]('t');
- //} else if (rec[field.name]() == false) {
+ // } else if (rec[field.name]() === false) {
} else { // TODO: some bools can be NULL
rec[field.name]('f');
}
- } else if (field.datatype == 'org_unit') {
- let org = rec[field.name]();
- if (org && typeof org == 'object') {
+ } else if (field.datatype === 'org_unit') {
+ const org = rec[field.name]();
+ if (org && typeof org === 'object') {
rec[field.name](org.id());
}
}
private flattenLinkedValues(cls: string, list: EgIdlObject[]): any[] {
- let idField = this.idl.classes[cls].pkey;
- let selector =
+ const idField = this.idl.classes[cls].pkey;
+ const selector =
this.idl.classes[cls].field_map[idField].selector || idField;
return list.map(item => {
- return {id: item[idField](), name: item[selector]()}
+ return {id: item[idField](), name: item[selector]()};
});
}
private getFieldList(): Promise<any> {
this.fields = this.idlDef.fields.filter(f =>
- f.virtual != 'true' &&
+ f.virtual !== 'true' &&
!this.hiddenFieldsList.includes(f.name)
);
- let promises = [];
+ const promises = [];
this.fields.forEach(field => {
- field.readOnly = this.mode == 'view'
+ field.readOnly = this.mode === 'view'
|| this.readonlyFieldsList.includes(field.name);
if (this.isRequiredOverride &&
field.name in this.isRequiredOverride) {
field.isRequired = () => {
return this.isRequiredOverride[field.name](field.name, this.record);
- }
+ };
} else {
field.isRequired = () => {
return field.required ||
this.requiredFieldsList.includes(field.name);
- }
+ };
}
- if (field.datatype == 'link') {
+ if (field.datatype === 'link') {
promises.push(
this.pcrud.retrieveAll(field.class, {}, {atomic : true})
.toPromise().then(list => {
this.flattenLinkedValues(field.class, list);
})
);
- } else if (field.datatype == 'org_unit') {
+ } else if (field.datatype === 'org_unit') {
field.orgDefaultAllowed =
this.orgDefaultAllowedList.includes(field.name);
}
}
save() {
- let recToSave = this.idl.clone(this.record);
+ const recToSave = this.idl.clone(this.record);
this.convertDatatypesToIdl(recToSave);
this.pcrud[this.mode]([recToSave]).toPromise().then(
result => this.close(result),