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

Add support for URL interpolation when setting up panels #156

Merged
merged 6 commits into from
Jan 9, 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
28 changes: 24 additions & 4 deletions platform/src/ActivityManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,35 @@ class ActivityManager {
return null;
}

/**
* Interpolate someString using information from session storage.
*
* @param {*} someString the string to be changed
*/
interpolate(someString) {
let result = someString;

for (let i = 0; i < sessionStorage.length; i++) {
let currentKey = sessionStorage.key(i);

if (currentKey !== "isAuthenticated") {
// TODO: This *assumes* this can only be a panel ID, but that may change over time,
// so this code may need to be improved to only allow access to panel IDs explicitly
result = result.replace("{{ID-" + currentKey + "}}", sessionStorage.getItem(currentKey));
}
}

return result;
}

/* resolve panel refs recursively because of CompositePanels */
resolveRef(panelList) {
for ( let apanel of panelList ){

if (apanel.file != null) {
apanel.url = new URL( apanel.file, this.activitiesUrl).href;
let file = this.fetchFile(apanel.file);
if (apanel.file != null) {
let panelURLString = this.interpolate(apanel.file);
apanel.url = new URL(panelURLString, this.activitiesUrl).href;
let file = this.fetchFile(panelURLString);
apanel.file = file.content;
apanel.sha = file.sha;
};
Expand Down Expand Up @@ -523,4 +543,4 @@ class ActivityManager {



export {ActivityManager};
export {ActivityManager};
55 changes: 28 additions & 27 deletions platform/src/FileHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,39 @@ class FileHandler {

fetchFile(url, isPrivate){

if(isPrivate){

if (isPrivate){
// Private so request via token server
const requestUrl = this.getPrivateFileRequestUrl(url);

var xhr = new XMLHttpRequest();
xhr.open("GET", requestUrl, false);
xhr.withCredentials = true;
xhr.send();

if (xhr.status === 200) {
if (requestUrl != null) {
var xhr = new XMLHttpRequest();
xhr.open("GET", requestUrl, false);
xhr.withCredentials = true;
xhr.send();

let response = JSON.parse(xhr.responseText);

return { content: window.atob(response.data.content), sha: response.data.sha };

} else {
return null;
}
if (xhr.status === 200) {

let response = JSON.parse(xhr.responseText);

return { content: window.atob(response.data.content), sha: response.data.sha };

} else {
return null;
}
}
}

// At this point, this is either a public repository, or it's a private repository but an unknown type of URL.
// In either case, we assume that we can simply access the URL directly.
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.send();

if (xhr.status === 200) {
return { content: xhr.responseText, sha: null }; //TODO need to retrieve the sha for the file IF it's from a public repository

} else {
// Public so request directly
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.send();

if (xhr.status === 200) {
return { content: xhr.responseText, sha: null }; //TODO need to retrieve the sha for the file

} else {
return null;
}
return null;
}
}

Expand Down Expand Up @@ -189,4 +190,4 @@ class FileHandler {
}
}

export { FileHandler };
export { FileHandler };
2 changes: 1 addition & 1 deletion platform/src/ProgramPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ProgramPanel extends Panel {

canSave() {
// Only save if there are any actual changes to save -- this avoids empty commits.
return !(this.editor.session.getUndoManager().isClean());
return (this.getValueSha()) && (!(this.editor.session.getUndoManager().isClean()));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion platform/src/XtextEditorPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class XtextEditorPanel extends Panel {

canSave() {
// Only save if there are any actual changes to save -- this avoids empty commits.
return !(this.editor.session.getUndoManager().isClean());
return (this.getValueSha()) && (!(this.editor.session.getUndoManager().isClean()));
}

/**
Expand Down