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

To merge #52

Merged
merged 36 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4fc31f7
add savetocloud button
vulongphan Feb 18, 2023
73b4f52
add google api script
vulongphan Feb 18, 2023
98e4f1f
retrieve uploaded files from Drive
vulongphan Mar 1, 2023
c529549
implement MyDrive file browser using Google Picker API
vulongphan Mar 3, 2023
c4de93c
merge changes from master
vulongphan Mar 3, 2023
426dd8a
persist logged in state with sessionStorage
vulongphan Mar 9, 2023
558cf08
implement update existing file in Drive
vulongphan Mar 9, 2023
8ac4406
implement logout button
vulongphan Mar 22, 2023
0861d7e
only show text/plain files in the file picker
vulongphan Mar 22, 2023
686c3aa
fix download tree functionality
vulongphan Mar 22, 2023
a51fab7
use list view for file picker
vulongphan Mar 22, 2023
6eb874d
add save as feature
vulongphan Mar 24, 2023
656a679
retrieve default config files from github
vulongphan Apr 3, 2023
e9a5e7c
fix listing feature
vulongphan Apr 3, 2023
c1c8ca4
implement nodejs server that delivers GCP credentials upon request
vulongphan Apr 25, 2023
0ffb33b
add example .env file
vulongphan Apr 25, 2023
5071aa8
update clientOrigin
vulongphan Apr 25, 2023
6e362e9
obtain GCP credentials with GET to server
vulongphan Apr 25, 2023
fb29915
change saveas to rename
vulongphan May 1, 2023
873b545
use axios for sending API requests
vulongphan May 1, 2023
309f822
set name of local file
vulongphan May 1, 2023
d855bf2
refactor
vulongphan May 10, 2023
3754b10
resolve conflict from master
vulongphan May 10, 2023
ba46636
update authenticator filename
vulongphan May 10, 2023
8dfea93
resolve conflict from master
vulongphan May 13, 2023
406d407
show dropdown after conll file upload
vulongphan May 18, 2023
6d946f1
change button styling
vulongphan May 18, 2023
254a734
update auth button style
vulongphan May 18, 2023
b15405c
update button styling
vulongphan May 18, 2023
37c2705
added nodemon
muhammed-abuodeh Jun 2, 2023
081e008
fix config file creation
vulongphan Jun 3, 2023
78e7b76
add parser html and modal
muhammed-abuodeh Oct 4, 2023
d6e76be
add parser fn to submit data and display modal
muhammed-abuodeh Oct 4, 2023
f1e76b8
made fixes to frontend authentication
muhammed-abuodeh Feb 14, 2024
51f1aae
removed lines
muhammed-abuodeh Feb 15, 2024
813c67c
Merge branch 'master' into to_merge
muhammed-abuodeh Feb 15, 2024
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ node_modules/
.parcel-cache/
dist/
package-lock.json

.env
68 changes: 68 additions & 0 deletions authenticator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
let isAuthenticated = false;

function logout() {
// remove access token from session storage
sessionStorage.removeItem("GCP_access_token");
// remove access token from gapi client
gapi.client.setToken(null);
// disable browse button
$("#browse_btn").hide();
// if logged out successfully, hide logout button && show authentication button
$(".toolbar [id='logout_btn']").hide();
$(".toolbar [id='auth_btn']").show();
}

function onAuthenticated() {
// set access token in gapi client for future requests
gapi.client.setToken({ access_token: getTokenFromSessionStorage() });
const accessToken = getTokenFromSessionStorage();
if (accessToken) {
isAuthenticated = true;
// alert("Authenticated with Google Drive successfully!");
// enable browse button
enableBrowseButton(accessToken);
// if authenticated successfully, hide authentication button && show logout button
$(".toolbar [id='auth_btn']").hide();
$(".toolbar [id='logout_btn']").show();
}
}

function authenticate() {
window.open("https://mra9407.pythonanywhere.com/authorize", "_self", "popup");
// // callbackafter access token is retrieved
// tokenClient.callback = async (resp) => {
// if (resp.error !== undefined) {
// throw resp;
// }
// setTokenInSessionStorage(gapi.client.getToken().access_token);
// onAuthenticated();
// };
// // need to add a check for when the token expires
// if (gapi.client.getToken() === null) {
// // Prompt the user to select a Google Account and ask for consent to share their data
// // when establishing a new session.
// tokenClient.requestAccessToken({ prompt: "consent" });
// }
}

function setTokenInSessionStorage(token) {
sessionStorage.setItem("GCP_access_token", token);
}

function getTokenFromSessionStorage() {
return sessionStorage.getItem("GCP_access_token");
}

// retrieve access token from session storage when page is loaded
window.onload = function () {
const urlParams = new URLSearchParams(window.location.search);

const sessionToken = urlParams.get('token');
if (sessionToken) {
setTokenInSessionStorage(sessionToken);
}

if (getTokenFromSessionStorage()) {
onAuthenticated();
}
};
17 changes: 8 additions & 9 deletions configFileHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ function retrieveConfigFiles() {
return new Promise((resolve, reject) => {
let fileObjects = [];
let rsp;
sendRequest(
"GET",
"https://api.github.com/repos/CAMeL-Lab/palmyra/contents/palmyraSampleFiles/config"
)
axios
.get(
"https://api.github.com/repos/CAMeL-Lab/palmyra/contents/palmyraSampleFiles/config"
)
.then(async (rsp) => {
let files = JSON.parse(rsp);
let files = rsp.data;
for (let file of files) {
rsp = await sendRequest("GET", file.download_url);
let fileObject = new File([rsp], file.name, { type: "text/plain" });
rsp = await axios.get(file.download_url);
let fileObject = new File([JSON.stringify(rsp.data)], file.name, { type: "text/plain" });
fileObjects.push(fileObject);
}
resolve(fileObjects);
Expand Down Expand Up @@ -227,7 +227,6 @@ var parseConfig = function (content) {

lexicalFeats.append(titleParagraph);
lexicalFeats.appendChild(lexDiv);
console.log();
}
}

Expand Down Expand Up @@ -319,4 +318,4 @@ var readConfigFile = async function () {
};

window.populateConfigFileSelector = populateConfigFileSelector;
window.readConfigFile = readConfigFile;
window.readConfigFile = readConfigFile;
149 changes: 149 additions & 0 deletions gapiLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
let gapiClientInited = false;
let gapiPickerInited = false;
let gisInited = false;
// set this to the right server origin when pushed to Github
const SERVER_ORIGIN = "https://mra9407.pythonanywhere.com";
let tokenClient;
let pickedFile;
let fileId;

/**
* Callback after api script is loaded.
*/
function gapiLoaded(libraryName, callback) {
gapi.load(libraryName, callback);
}

/**
* Callback after Google Identity Services are loaded.
*/
// function gisLoaded() {
// axios
// .get(`${SERVER_ORIGIN}/gis_credentials`)
// .then((rsp) => {
// let credentials = rsp.data;
// tokenClient = google.accounts.oauth2.initTokenClient({
// client_id: credentials.client_id,
// scope: credentials.scope,
// callback: "", // defined later
// });
// gisInited = true;
// maybeEnableAuthButton();
// })
// .catch((err) => {
// console.log(err);
// });
// }

/**
* Callback after the API client is loaded.
*/
// function initializeGapiClient() {
// axios
// .get(`${SERVER_ORIGIN}/gapi_credentials`)
// .then((rsp) => {
// let credentials = rsp.data;
// gapi.client
// .init({
// apiKey: credentials.apiKey,
// discoveryDocs: credentials.discoveryDocs,
// })
// .then(() => {
// gapiClientInited = true;
// maybeEnableAuthButton();
// })
// .catch((err) => {
// console.log(err);
// });
// })
// .catch((err) => {
// console.log(err);
// });
// }

function initializeGapiPicker() {
gapiPickerInited = true;
}

function showPicker(accessToken, callback) {
// axios
// .get(`${SERVER_ORIGIN}/gapi_credentials`)
// .then((rsp) => {
// let credentials = rsp.data;
let view = new google.picker.DocsView(google.picker.ViewId.DOCS);
view.setMimeTypes("text/plain");
view.setMode(google.picker.DocsViewMode.LIST);
let picker = new google.picker.PickerBuilder()
.addView(view)
.setOAuthToken(accessToken)
// .setDeveloperKey(credentials.apiKey)
.setCallback(callback)
.build();
picker.setVisible(true);
// })
// .catch((err) => {
// console.log(err);
// });
}

function pickerCallback(data) {
// if the user picked a file
// need to check if the file is a conllu file
if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
let doc = data[google.picker.Response.DOCUMENTS][0];
let fileNameParts = doc.name.split(".");
if (
fileNameParts[fileNameParts.length - 1] !== "conllu" &&
fileNameParts[fileNameParts.length - 1] !== "conllx"
) {
alert(
"File does not end with the .conllu/conllx extension, please upload a ConllU/X file."
);
return;
}
// need to add extension for conllx files as well
let url =
"https://www.googleapis.com/drive/v3/files/" + doc.id + "?alt=media";
axios
.get(url, {
headers: {
Authorization: "Bearer " + getTokenFromSessionStorage(),
},
})
.then((rsp) => {
// show name of picked file
// set global pickedFile variable
document.getElementById("picked_filename").innerHTML = doc.name;
pickedFile = new File([rsp.data], doc.name, { type: doc.mimeType });
fileId = doc.id;
})
.catch((err) => {
console.log(err);
alert("Failed to retrieve file!");
});
}
}

function enableBrowseButton(accessToken) {
let browseBtn = document.getElementById("browse_btn");
browseBtn.style.display = "inline-block";
browseBtn.onclick = () => {
showPicker(accessToken, pickerCallback);
// showPicker(gapi.client.getToken().access_token, pickerCallback);
};
}

/**
* Enables user interaction after all libraries are loaded.
*/
function maybeEnableAuthButton() {
if (gapiClientInited && gapiPickerInited && gisInited && !isAuthenticated) {
$(".toolbar [id='auth_btn']").show();
}
}

function maybeEnableSaveRemoteButton() {
if (gapiClientInited && gisInited) {
$("#save_remote").show();
}
}
Loading