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

Feature/embedded selection #428

Merged
merged 3 commits into from
Apr 2, 2024
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
310 changes: 173 additions & 137 deletions builds/respec-1edtech.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/respec-1edtech.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/1edtech/mps.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import serviceModelTemplate from "./templates/serviceModelTemplate.js";
import { showError } from "../core/utils.js";
import stereoTypeTemplate from "./templates/stereoTypeTemplate.js";
import { sub } from "../core/pubsubhub.js";
import embeddedSelectionTemplate from "./templates/embeddedSelectionTemplate.js";

export const name = "1edtech/mps";

Expand Down Expand Up @@ -220,6 +221,15 @@ async function getModel(config, source, id) {

}
isExtensible
generalizations {
id
name
documentation {
description
notes
issues
}
}
}
services {
... on RestService {
Expand Down Expand Up @@ -445,6 +455,9 @@ async function processClass(config, section, classModel) {
case "Vocabulary":
wrapper = enumerationTemplate(classModel, title);
break;
case "EmbeddedSelection":
wrapper = embeddedSelectionTemplate(classModel, title);
break;
default:
wrapper = classTemplate(config, classModel, title);
break;
Expand Down
20 changes: 2 additions & 18 deletions src/1edtech/templates/classTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
renderIssue,
renderNote,
renderPrivacyImplicationDoc,
renderType
} from "./templateUtils.js";
import { html } from "../../core/import-maps.js";

Expand Down Expand Up @@ -65,7 +66,7 @@ function renderExtensibility(config, classData) {
function renderProperty(config, property) {
return html` <tr>
<td style="min-width: 150px; word-break: break-all;">${property.name}</td>
<td>${renderType(property)}</td>
<td>${renderType(property.type)}</td>
<td>
${property.documentation.description}
${property.documentation.issues.map(renderIssue)}
Expand Down Expand Up @@ -122,20 +123,3 @@ function renderPrivacyImplicationCell(property) {
function renderPrivacyImplication(property) {
return html`${property.privacyImplications.label}`;
}

/**
* Return a clickable link to the property type definition.
* @param {*} property The MPS Property object.
* @returns {HTMLAnchorElement} Returns an anchor element that links to the property type definition.
*/
function renderType(property) {
let name = property.type.name;
if (
property.type.stereoType === "Enumeration" ||
property.type.stereoType === "EnumExt"
) {
name += " Enumeration";
}
name = html`<a href="#${property.type.id}"><samp>${name}</samp></a>`;
return name;
}
47 changes: 47 additions & 0 deletions src/1edtech/templates/embeddedSelectionTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// @ts-check
import { renderIssue, renderNote, renderType } from "./templateUtils.js";
import { html } from "../../core/import-maps.js";

/**
* Render an EmbeddedSelection class.
* @param {*} classData The MPS Class object.
* @param {string?} title The preferred title.
* @returns {HTMLElement[]} The entire section contents.
*/
export default (classData, title) => {
if (classData && classData.generalizations) {
title = title ?? `${classData.name}`;
return html`<h3>${title}</h3>
<p>${classData.documentation.description}</p>
${classData.documentation.issues.map(renderIssue)}
${classData.documentation.notes.map(renderNote)}
<p>This class is a choice of exactly one in the following set:</p>
<table class="simple">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
${classData.generalizations.map(renderSuperClass)}
</tbody>
</table>`;
}
};

/**
* Render superclass information.
* @param {*} cls The MPS ModelClass object.
* @returns {HTMLTableRowElement?} A table row with property information.
*/
function renderSuperClass(cls) {
return html` <tr>
<td style="min-width: 150px; word-break: break-all;">${renderType(cls)}</td>
<td>
${cls.documentation.description}
${cls.documentation.issues.map(renderIssue)}
${cls.documentation.notes.map(renderNote)}
</td>
</tr>`;
}
17 changes: 17 additions & 0 deletions src/1edtech/templates/templateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,20 @@ export function renderTerm(term) {
</td>
</tr>`;
}

/**
* Return a clickable link to the type definition.
* @param {*} type The MPS ModelClass object.
* @returns {HTMLAnchorElement} Returns an anchor element that links to the property type definition.
*/
export function renderType(type) {
let name = type.name;
if (
type.stereoType === "Enumeration" ||
type.stereoType === "EnumExt"
) {
name += " Enumeration";
}
name = html`<a href="#${type.id}"><samp>${name}</samp></a>`;
return name;
}
Loading