mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-02 01:19:14 +00:00
Base functionality working
This commit is contained in:
parent
8c3e03399e
commit
65b10fe994
@ -0,0 +1,14 @@
|
||||
export const IssueSeverity = {
|
||||
FATAL: {
|
||||
code: 'Fatal'
|
||||
},
|
||||
ERROR: {
|
||||
code: 'Error'
|
||||
},
|
||||
WARNING: {
|
||||
code: 'Warning'
|
||||
},
|
||||
INFORMATION: {
|
||||
code: 'Information'
|
||||
}
|
||||
}
|
@ -1,11 +1,37 @@
|
||||
import {CliContext} from './model/CliContext.js';
|
||||
import {ValidationRequest} from './model/ValidationRequest.js';
|
||||
import {FileInfo} from './model/FileInfo.js';
|
||||
import {FhirFormat} from './enums/FhirFormat.js';
|
||||
import {IssueSeverity} from './enums/IssueSeverity.js';
|
||||
|
||||
// Constants
|
||||
/*
|
||||
<Constants>
|
||||
*/
|
||||
|
||||
// Icon Constants
|
||||
const jsonIcon = './assets/json-svgrepo-com.svg';
|
||||
const xmlIcon = './assets/xml-svgrepo-com.svg';
|
||||
|
||||
// HTML classes
|
||||
const CLASS_LIST_ITEM_PLAIN = "list-group-item";
|
||||
const CLASS_LIST_ITEM_FATAL = "list-group-item list-group-item-dark";
|
||||
const CLASS_LIST_ITEM_ERROR = "list-group-item list-group-item-danger";
|
||||
const CLASS_LIST_ITEM_WARNING = "list-group-item list-group-item-warning";
|
||||
const CLASS_LIST_ITEM_INFORMATION = "list-group-item list-group-item-info";
|
||||
|
||||
// HTML IDs
|
||||
const ID_FILE_ENTRY_TEMPLATE = '#file_entry_template';
|
||||
const ID_FILE_ENTRY_NAME = 'file_entry_name_field';
|
||||
const ID_FILE_ENTRY_ICON = 'file_entry_type_icon';
|
||||
const ID_FILE_ENTRY_DELETE_BUTTON = 'file_entry_delete_button';
|
||||
const ID_FILE_ENTRY_FILE_LIST = 'file_entry_file_list';
|
||||
const ID_FILE_ENTRY_OUTCOME_LIST = 'file_entry_outcome_list';
|
||||
const ID_FILE_ENTRY_COLLAPSE_SECTION = 'file_entry_collapse_section';
|
||||
|
||||
/*
|
||||
</Constants>
|
||||
*/
|
||||
|
||||
// Data Fields
|
||||
const cli = new CliContext();
|
||||
const filesToValidate = [];
|
||||
@ -29,33 +55,69 @@ function generateFileEntry(file) {
|
||||
fr.onload = function(e) {
|
||||
// TODO there may be timing issues here
|
||||
filesToValidate.push(new FileInfo(file.name, e.target.result, file.type));
|
||||
document.getElementById('loaded_file_list').appendChild(generateNewFileListItemFromTemplate(file));
|
||||
document.getElementById(ID_FILE_ENTRY_FILE_LIST).appendChild(generateNewFileListItemFromTemplate(file, filesToValidate.length - 1));
|
||||
};
|
||||
fr.readAsText(file);
|
||||
}
|
||||
|
||||
// File List Template Generation
|
||||
|
||||
function generateNewFileListItemFromTemplate(file) {
|
||||
var template = document.querySelector('#loaded_file_entry');
|
||||
function generateNewFileListItemFromTemplate(file, index) {
|
||||
var template = document.querySelector(ID_FILE_ENTRY_TEMPLATE);
|
||||
var clone = template.content.cloneNode(true);
|
||||
|
||||
// Add file name
|
||||
clone.getElementById('file_name_field').textContent = file.name;
|
||||
clone.getElementById(ID_FILE_ENTRY_NAME).textContent = file.name;
|
||||
|
||||
// Add appropriate icon for filetype
|
||||
if (file.type.includes("json")) {
|
||||
clone.getElementById('file_type_icon').src = jsonIcon;
|
||||
} else if (file.type.includes("xml")) {
|
||||
clone.getElementById('file_type_icon').src = xmlIcon;
|
||||
if (file.type.includes(FhirFormat.JSON.extension)) {
|
||||
clone.getElementById(ID_FILE_ENTRY_ICON).src = jsonIcon;
|
||||
} else if (file.type.includes(FhirFormat.XML.extension)) {
|
||||
clone.getElementById(ID_FILE_ENTRY_ICON).src = xmlIcon;
|
||||
}
|
||||
|
||||
clone.getElementById(ID_FILE_ENTRY_COLLAPSE_SECTION).setAttribute("id", (ID_FILE_ENTRY_COLLAPSE_SECTION + index));
|
||||
clone.getElementById(ID_FILE_ENTRY_NAME).setAttribute("aria-controls", (ID_FILE_ENTRY_COLLAPSE_SECTION + index));
|
||||
clone.getElementById(ID_FILE_ENTRY_NAME).setAttribute("data-target", ('#' + ID_FILE_ENTRY_COLLAPSE_SECTION + index));
|
||||
|
||||
// Add delete listener
|
||||
clone.getElementById("delete_button").addEventListener("click", handleDeleteOnFileList);
|
||||
clone.getElementById(ID_FILE_ENTRY_DELETE_BUTTON).addEventListener("click", handleDeleteOnFileList);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
function addIssueToFileEntryList(index, severity, details) {
|
||||
var ul = document.getElementById(ID_FILE_ENTRY_FILE_LIST);
|
||||
var listItems = ul.children;
|
||||
var fileEntry = listItems[index];
|
||||
console.log(fileEntry);
|
||||
var listOfIssues = fileEntry.querySelector('#' + ID_FILE_ENTRY_OUTCOME_LIST);
|
||||
var issueItem = createIssueListItem(severity, details);
|
||||
listOfIssues.appendChild(issueItem);
|
||||
}
|
||||
|
||||
function createIssueListItem(severity, details) {
|
||||
var newIssue = document.createElement('li');
|
||||
switch(severity) {
|
||||
case IssueSeverity.FATAL.code:
|
||||
newIssue.setAttribute("class", CLASS_LIST_ITEM_FATAL);
|
||||
break;
|
||||
case IssueSeverity.ERROR.code:
|
||||
newIssue.setAttribute("class", CLASS_LIST_ITEM_ERROR);
|
||||
break;
|
||||
case IssueSeverity.WARNING.code:
|
||||
newIssue.setAttribute("class", CLASS_LIST_ITEM_WARNING);
|
||||
break;
|
||||
case IssueSeverity.INFORMATION.code:
|
||||
newIssue.setAttribute("class", CLASS_LIST_ITEM_INFORMATION);
|
||||
break;
|
||||
default:
|
||||
console.error('Passed in bad severity: ' + severity);
|
||||
}
|
||||
newIssue.innerHTML = details;
|
||||
return newIssue;
|
||||
}
|
||||
|
||||
function handleDeleteOnFileList(e) {
|
||||
var li = e.target.closest('li');
|
||||
var nodes = Array.from( li.closest('ul').children );
|
||||
@ -88,10 +150,21 @@ function sendFilesToValidate(arrayOfFileInfo) {
|
||||
}
|
||||
|
||||
function processValidationResponse(validationResponse) {
|
||||
console.log(validationResponse.outcomes[0]);
|
||||
console.log(validationResponse.outcomes[1]);
|
||||
//console.log(validationResponse);
|
||||
//Do something
|
||||
console.log(validationResponse);
|
||||
console.log(validationResponse.length);
|
||||
console.log(validationResponse.outcomes);
|
||||
console.log(validationResponse.outcomes.length);
|
||||
|
||||
for (var i = 0; i < validationResponse.outcomes.length; i++) {
|
||||
console.log(validationResponse.outcomes[i]);
|
||||
var fileInfo = validationResponse.outcomes[i].fileInfo;
|
||||
var issues = validationResponse.outcomes[i].issues;
|
||||
issues.forEach(issue => {
|
||||
console.log(issue);
|
||||
addIssueToFileEntryList(i, issue.severity, issue.details);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,22 +50,10 @@
|
||||
<button id="validate_button" class="btn btn-secondary mb-1">Validate</button>
|
||||
</div>
|
||||
|
||||
<ul id="loaded_file_list">
|
||||
<template id="loaded_file_entry">
|
||||
<li class="media text-muted pt-3">
|
||||
<img id="file_type_icon" class="bd-placeholder-img mr-2 rounded" src="./assets/json-svgrepo-com.svg" width="32" height="32" preserveAspectRatio="xMidYMid slice">
|
||||
<div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
|
||||
<div class="d-flex justify-content-between align-items-center w-100">
|
||||
<strong class="text-gray-dark" id="file_name_field"></strong>
|
||||
<svg id="delete_button" class="delete_button" height="24" viewBox="0 0 24 24" width="24">
|
||||
<path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zm2.46-7.12l1.41-1.41L12 12.59l2.12-2.12 1.41 1.41L13.41 14l2.12 2.12-1.41 1.41L12 15.41l-2.12 2.12-1.41-1.41L10.59 14l-2.13-2.12zM15.5 4l-1-1h-5l-1 1H5v2h14V4z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<span class="d-block"></span>
|
||||
</div>
|
||||
</li>
|
||||
</template>
|
||||
</ul>
|
||||
<div class="accordion" id="accordionExample">
|
||||
<ul id="file_entry_file_list" class="list-group border">
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="bd-callout bd-callout-info">
|
||||
<small class="d-block text-right mt-3">
|
||||
@ -74,74 +62,34 @@
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<template id="file_entry_template">
|
||||
<li class="list-unstyled">
|
||||
<div class="card">
|
||||
<div class="card-header" id="headingOne">
|
||||
<div class="d-flex">
|
||||
<div class="d-flex align-items-center">
|
||||
<img id="file_entry_type_icon" class="bd-placeholder-img mr-2 rounded" src="./assets/json-svgrepo-com.svg" width="32" height="32" preserveAspectRatio="xMidYMid slice">
|
||||
<button id="file_entry_name_field" class="btn btn-link" type="button" data-toggle="collapse" data-target="#file_entry_collapse_section" aria-expanded="true" aria-controls="file_entry_collapse_section">
|
||||
Collapsible Group Item #1
|
||||
</button>
|
||||
</div>
|
||||
<div class="ml-auto d-flex">
|
||||
<svg id="file_entry_delete_button" class="delete_button align-self-center" height="24" viewBox="0 0 24 24" width="24">
|
||||
<path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zm2.46-7.12l1.41-1.41L12 12.59l2.12-2.12 1.41 1.41L13.41 14l2.12 2.12-1.41 1.41L12 15.41l-2.12 2.12-1.41-1.41L10.59 14l-2.13-2.12zM15.5 4l-1-1h-5l-1 1H5v2h14V4z"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="accordion" id="accordionExample">
|
||||
<div class="card z-depth-0 bordered">
|
||||
<div class="card-header" id="headingOne">
|
||||
<h5 class="mb-0">
|
||||
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne"
|
||||
aria-expanded="true" aria-controls="collapseOne">
|
||||
Collapsible Group Item #1
|
||||
</button>
|
||||
</h5>
|
||||
</div>
|
||||
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne"
|
||||
data-parent="#accordionExample">
|
||||
<div class="card-body">
|
||||
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3
|
||||
wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum
|
||||
eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla
|
||||
assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred
|
||||
nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer
|
||||
farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus
|
||||
labore sustainable.
|
||||
<div id="file_entry_collapse_section" class="collapse" aria-labelledby="headingOne" data-parent="#accordionExample">
|
||||
<div class="card-body">
|
||||
<ul id="file_entry_outcome_list" class="list-group">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card z-depth-0 bordered">
|
||||
<div class="card-header" id="headingTwo">
|
||||
<h5 class="mb-0">
|
||||
<button class="btn btn-link collapsed" type="button" data-toggle="collapse"
|
||||
data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
|
||||
Collapsible Group Item #2
|
||||
</button>
|
||||
</h5>
|
||||
</div>
|
||||
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
|
||||
<div class="card-body">
|
||||
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3
|
||||
wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum
|
||||
eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla
|
||||
assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred
|
||||
nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer
|
||||
farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus
|
||||
labore sustainable.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card z-depth-0 bordered">
|
||||
<div class="card-header" id="headingThree">
|
||||
<h5 class="mb-0">
|
||||
<button class="btn btn-link collapsed" type="button" data-toggle="collapse"
|
||||
data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
|
||||
Collapsible Group Item #3
|
||||
</button>
|
||||
</h5>
|
||||
</div>
|
||||
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionExample">
|
||||
<div class="card-body">
|
||||
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3
|
||||
wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum
|
||||
eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla
|
||||
assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred
|
||||
nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer
|
||||
farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus
|
||||
labore sustainable.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
</template>
|
||||
|
||||
</main>
|
||||
<script type="module" src="./main.js"></script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user