Skip to content

Commit

Permalink
publicly expose mappingObjectTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecarenzo committed Feb 26, 2024
1 parent b09e188 commit db6fbbc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
35 changes: 15 additions & 20 deletions src/mappings_editor/src/assets/scripts/MappingFile/MappingFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ export class MappingFile {
public readonly scoreValues: ListProperty;

/**
* The file's internal mapping objects.
* The file's mapping object template.
*/
private _mappingObjects: Map<string, MappingObject>;
public readonly mappingObjectTemplate: MappingObject;

/**
* The file's mapping object template.
* The file's internal mapping objects.
*/
private readonly _mappingObjectTemplate: MappingObject;
private _mappingObjects: Map<string, MappingObject>;


/**
Expand All @@ -113,20 +113,6 @@ export class MappingFile {
return this._mappingObjects;
}

/**
* The file's default mapping type.
*/
public get defaultMappingType(): string | null {
return this._mappingObjectTemplate.mappingType.exportValue;
}

/**
* The file's default mapping status.
*/
public get defaultMappingStatus(): string | null {
return this._mappingObjectTemplate.mappingStatus.exportValue;
}


/**
* Creates a new {@link MappingFile}.
Expand Down Expand Up @@ -157,8 +143,8 @@ export class MappingFile {
this.mappingStatuses = template.mappingStatus.options;
this.scoreCategories = template.scoreCategory.options;
this.scoreValues = template.scoreValue.options;
this.mappingObjectTemplate = template;
this._mappingObjects = new Map<string, MappingObject>();
this._mappingObjectTemplate = template;
// Configure source information
const sourceListing = template.sourceObject.framework;
this.sourceFrameworkListing = sourceListing;
Expand Down Expand Up @@ -186,7 +172,7 @@ export class MappingFile {
* The new mapping object.
*/
public createMappingObject(): MappingObject {
return this._mappingObjectTemplate.duplicate();
return this.mappingObjectTemplate.duplicate();
}

/**
Expand Down Expand Up @@ -228,6 +214,9 @@ export class MappingFile {
* The mapping object to insert.
*/
public insertMappingObject(object: MappingObject) {
if(object.id === this.mappingObjectTemplate.id) {
throw new Error(`Mapping file cannot contain the mapping object template.`);
}
if(this._mappingObjects.has(object.id)) {
throw new Error(`Mapping file already contains object '${ object.id }'.`);
}
Expand Down Expand Up @@ -259,6 +248,9 @@ export class MappingFile {
public insertMappingObjectAfter(object: MappingObject, destination?: string): void;
public insertMappingObjectAfter(object: MappingObject, destination?: MappingObject | string) {
const id = typeof destination === "string" ? destination : (destination?.id ?? null)
if(object.id === this.mappingObjectTemplate.id) {
throw new Error(`Mapping file cannot contain the mapping object template.`);
}
if(this._mappingObjects.has(object.id)) {
throw new Error(`Mapping file already contains object '${ object.id }'.`);
}
Expand Down Expand Up @@ -295,6 +287,9 @@ export class MappingFile {
const id = typeof destination === "string" ? destination : (destination?.id ?? null)
const newEntries: [string, MappingObject][] = [];
for(const obj of objects){
if(obj.id === this.mappingObjectTemplate.id) {
throw new Error(`Mapping file cannot contain the mapping object template.`);
}
if(this._mappingObjects.has(obj.id)) {
throw new Error(`Mapping file already contains object '${ obj.id }'.`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export class MappingFileAuthority {
}

// Compile file
const defaultObject = file.mappingObjectTemplate;
return {
version : file.version,
source_framework : file.sourceFramework,
Expand All @@ -385,8 +386,8 @@ export class MappingFileAuthority {
score_categories : Object.fromEntries(score_categories),
score_values : Object.fromEntries(score_values),
mapping_objects,
default_mapping_type : file.defaultMappingType,
default_mapping_status : file.defaultMappingStatus
default_mapping_type : defaultObject.mappingType.exportValue,
default_mapping_status : defaultObject.mappingStatus.exportValue
}

}
Expand Down

0 comments on commit db6fbbc

Please sign in to comment.