-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
80 changed files
with
6,308 additions
and
6,013 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
font-size: 20px; | ||
font-weight: 400; | ||
border-bottom: 1px solid #e0e0e0; | ||
position: relative; | ||
} | ||
|
||
&__main { | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.switch { | ||
position: absolute; | ||
top: 6px; | ||
right: 10px; | ||
|
||
&__link { | ||
display: block; | ||
border: 1px solid #e0e0e0; | ||
border-right: none; | ||
padding: 2px 12px; | ||
text-decoration: none; | ||
font-size: 14px; | ||
color: #757575; | ||
|
||
&:hover, | ||
&:active { | ||
background-color: #fafafa; | ||
} | ||
|
||
&--active { | ||
background-color: #eee; | ||
box-shadow: inset 0 1px 3px 1px rgba(0,0,0,.08); | ||
cursor: default; | ||
|
||
&:hover, | ||
&:active { | ||
background-color: #eee; | ||
} | ||
} | ||
|
||
} | ||
|
||
&__item { | ||
display: inline-block; | ||
|
||
&:first-child { | ||
.switch__link { | ||
border-radius: 2px 0 0 2px; | ||
} | ||
} | ||
|
||
&:last-child { | ||
.switch__link { | ||
border-radius: 0 2px 2px 0; | ||
border-right: 1px solid #e0e0e0; | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* eslint-disable no-console */ | ||
'use-strict'; | ||
|
||
(function() { | ||
var projectIdElem = document.getElementById('project'), | ||
projectId = projectIdElem.value, | ||
blueprintForm = document.getElementById('blueprintForm'); | ||
|
||
// Takes passed content models object and transforms it into select options | ||
var fillBlueprintSelector = function (data) { | ||
var selector = document.getElementById('contentmodel'), | ||
option = ''; | ||
|
||
// It there are not any data | ||
if (data.length === 0) { | ||
// Set the selector to the disabled state | ||
selector.innerHTML = '<option value="">Fill in a valid Project ID</option>'; | ||
selector.setAttribute('disabled', 'disabled'); | ||
} else { | ||
// Fill the selector with content model names and codenames | ||
selector.innerHTML = ''; | ||
selector.removeAttribute('disabled'); | ||
|
||
for (var i = 0; i < data.length; i++) { | ||
option = '<option value="' + data[i].system.codename + '">' + data[i].system.name + '</option>'; | ||
selector.appendChild(helper.createNodeFromString(option)[0]); | ||
} | ||
} | ||
|
||
}; | ||
|
||
// Request the Delivery API to get all content models | ||
var initBlueprintSelector = function (projectId) { | ||
var request = new XMLHttpRequest(), | ||
response; | ||
|
||
// Assemble endpoint url | ||
request.open('GET', 'https://deliver.kenticocloud.com/' + projectId + '/types', true); | ||
request.setRequestHeader('Content-Type', 'application/json'); | ||
|
||
// When a response is obtained | ||
request.onload = function() { | ||
response = request.responseText; | ||
|
||
// If the response is successful | ||
if (request.status >= 200 && request.status < 400) { | ||
// Initialize the blueprint selector with data | ||
fillBlueprintSelector(JSON.parse(response).types); | ||
} | ||
}; | ||
|
||
request.onerror = function() { | ||
// There was a connection error | ||
console.error('Connection error'); | ||
helper.addLog('Connection error', false); | ||
}; | ||
|
||
// Make the request | ||
request.send(); | ||
}; | ||
|
||
// Request the Blueprint endpoint to get a blueprint of the selected content model | ||
var generateBlueprint = function (projectId, format, model) { | ||
var request = new XMLHttpRequest(), | ||
response, | ||
mimeType; | ||
|
||
// Assemble endpoint url | ||
request.open('GET', '/' + projectId + '/blueprint/' + format + '/' + model, true); | ||
request.setRequestHeader('Content-Type', helper.getMimeType(format)); | ||
|
||
// When a response is obtained | ||
request.onload = function() { | ||
helper.removeLoading(); | ||
response = request.responseText; | ||
|
||
// If the response is successful | ||
if (request.status >= 200 && request.status < 400) { | ||
// Set the response body to the code editor | ||
if (format === 'json') { | ||
editorWrapper.setValue(js_beautify(response, {indent_size: 4})); | ||
helper.addLog('JSON blueprint for the "' + model + '" content model successfully generated.', true); | ||
} else if (format === 'csv') { | ||
editorWrapper.setValue(response); | ||
helper.addLog('CSV header blueprint for the "' + model + '" content model successfully generated.', true); | ||
} | ||
} else { | ||
// If the response is failed | ||
//Log errors | ||
helper.addLog(helper.encodedStr(JSON.parse(response).message), false); | ||
} | ||
}; | ||
|
||
request.onerror = function() { | ||
// There was a connection error | ||
console.error('Connection error'); | ||
helper.addLog('Connection error', false); | ||
}; | ||
|
||
// Make the request | ||
request.send(); | ||
}; | ||
|
||
// Get mode set in the code editor as a string to be passed in the blueprint endpoint | ||
function getFormat () { | ||
// editorWrapper is a global variable set in the ./code-editor.js file | ||
var format = editorWrapper.getOption('mode'); | ||
|
||
switch (format) { | ||
case 'application/json': | ||
format = 'json'; | ||
break; | ||
case 'text/csv': | ||
format = 'csv'; | ||
break; | ||
} | ||
|
||
return format; | ||
} | ||
|
||
// On page load | ||
|
||
if (projectId !== '') { | ||
// Fill content models selector with data | ||
initBlueprintSelector(projectId); | ||
} | ||
|
||
// When Project ID input loses focus | ||
projectIdElem.addEventListener('blur', function () { | ||
projectId = projectIdElem.value; | ||
|
||
if (projectId !== '') { | ||
// Fill content models selector with data | ||
initBlueprintSelector(projectId); | ||
} | ||
}); | ||
|
||
// On the blueprint form submit | ||
blueprintForm.addEventListener('submit', function (event) { | ||
var format = getFormat(); | ||
selector = document.getElementById('contentmodel'); | ||
model = selector.options[selector.selectedIndex].value; | ||
|
||
projectId = projectIdElem.value; | ||
helper.addLog('=== New blueprint at ' + helper.getNow() + '==='); | ||
helper.addLoading('blueprint'); | ||
|
||
if (model !== '' && format !== '' && selector !== null) { | ||
// Generate blueprint and show it in the code editor | ||
generateBlueprint(projectId, format, model); | ||
} else { | ||
helper.addLog('A content model must be selected to be able to generate a blueprint.' , false); | ||
} | ||
|
||
event.preventDefault(); | ||
|
||
}, true); | ||
|
||
})(); |
Oops, something went wrong.