Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4c8637c
current library attribute added
iloveskittles82 Jun 9, 2025
9c4c803
WIP method to grab all bibentries
iloveskittles82 Jun 9, 2025
826a50a
update branch
iloveskittles82 Jun 17, 2025
7c3c4b1
cleanup and renaming
iloveskittles82 Jun 17, 2025
7f13610
add buttons for Bibentry nodes
iloveskittles82 Jun 17, 2025
1f3f83f
added function to get the entry preview for a BibEntry in the current…
iloveskittles82 Jun 17, 2025
1ebae5d
Minor logging and comments' fixes in HTTPClient
Robert35-dll Jun 20, 2025
362f6cc
Optimized GET response type checking
Robert35-dll Jun 20, 2025
c8b933e
Replaced AddBibEntries' dropdown with separated buttons in selection …
Robert35-dll Jun 20, 2025
fae6e7b
Distinguished between application/json and text/plain response cases …
Robert35-dll Jun 20, 2025
52634cd
Refactored HTTPClient's urls' definition to allow access to cayw endp…
Robert35-dll Jun 21, 2025
f9fb89c
Returned previous dropdown for adding BibEntries and added some dynam…
Robert35-dll Jun 21, 2025
caf88c6
Added creation of BibEntry nodes using JabRef's cayw endpoint
Robert35-dll Jun 21, 2025
063a577
Added assignNodeType() for nodes' extension and implemented type icon…
Robert35-dll Jun 21, 2025
e4f4691
Minor fix of constructing mind map's URL upon saving
Robert35-dll Jun 21, 2025
96918da
Fixed a bug with undo()/redo() when previously opened map was shown
Robert35-dll Jun 21, 2025
6daf4c5
Prevent loading maps if no option was selected
Robert35-dll Jun 21, 2025
2197bb4
Merge branch 'dev' into get-bibentries-data
Robert35-dll Jun 21, 2025
2868c22
save map state for undo/redo after new BibEntry nodes are created
iloveskittles82 Jun 21, 2025
d052def
fixed methods for getting entry preview from server
iloveskittles82 Jun 21, 2025
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
Binary file removed Japmap icons/alignement.png
Binary file not shown.
Binary file removed Japmap icons/cycle.png
Binary file not shown.
Binary file removed Japmap icons/link.png
Binary file not shown.
Binary file removed Japmap icons/orange eye.png
Binary file not shown.
Binary file removed Japmap icons/star.png
Binary file not shown.
129 changes: 92 additions & 37 deletions http/HTTPClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ export class HTTPClient {
#host = "http://localhost:6050/";

constructor() {
// The default return value for PUT and POST requests
/**
* The default return value for PUT requests.
*/
this.NULL_MAP = { map: {} };
this.currentLibrary = "demo";
}

/**
* Sends a HTTP-request to the JabRef's server.
* Sends a HTTP-request to JabRef's server.
* @param { string } url - The server's URL to make a request to.
* @param { object } options - Optional request's options.
* @returns
* - An **object** in case of a `GET request` or
* - An **object** { map: {} } in case of a `PUT / POST request`
* or if any request failed.
*/
async #performFetch(url, options = null) {
let fetchResult = this.NULL_MAP;
async #performRequest(url, options = null) {
let result = this.NULL_MAP;
let logMessage = "";

const requestUrl = this.#host.concat(url);
Expand All @@ -40,18 +43,26 @@ export class HTTPClient {

// If some output is awaited, save it
if (options.method !== "PUT") {
fetchResult = await response.json();
if (options.headers["Content-Type"] === 'application/json') {
result = await response.json();
}
if (options.headers["Accept"] === 'text/plain') {
result = await response.text();
}
if (options.headers["Accept"] === 'text/html') {
result = await response.text();
}
}

// Providing infos about the request
logMessage =
`${options.method} ${url} Request succeeded (~ UwU)~(${response.status}).\n` +
`${options.method} ${requestUrl} Request succeeded (~ UwU)~(${response.status}).\n` +
`Output:\n` +
`${JSON.stringify(fetchResult, null, 2)}`;
`${JSON.stringify(result, null, 2)}`;
} catch (e) {
// Logging basic information about the error
console.error(e);
logMessage = `${options.method} ${url} Request failed (.'T_T)`;
logMessage = `${options.method} ${requestUrl} Request failed (.'T_T)`;

// If connection was present, provide more details
if (typeof (response) !== "undefined") {
Expand All @@ -65,71 +76,115 @@ export class HTTPClient {
// Finally showing the resulting log
console.log(logMessage);

return fetchResult;
return result;
}

/**
* Requests a mind map (.jmp file) from JabRef's server.
* @param { string } path - The path to the requested mind map.
* @param { string } library - The library of the requested mind map.
* @returns The requested mind map object.
*/
async loadMap(path = "libraries/demo/map") {
const url = path;
*/
async loadMap(library = "demo") {
const url = `libraries/${library}/map`;
const options = {
method: "GET",
headers: { "Content-Type": "application/json" }
}

return this.#performFetch(url, options);
// Changing current library
this.currentLibrary = library;
console.log(`Current library is now: ${this.currentLibrary}`);

return this.#performRequest(url, options);
}

/**
* Sends a mind map to JabRef's server to save.
* Sends a mind map to JabRef's server to save next to currently active library.
* @param { object } mindMap - The mind map to save.
* @param { string } path - The path to save the mind map to.
* @returns An empty map object (NULL_MAP).
*/
async saveMap(mindMap, path = "libraries/demo/map") {
// The url will probably be modified according to mindMap's properties (coming in sprint 2)
const url = path;
*/
async saveMap(mindMap) {
const url = `libraries/${this.currentLibrary}/map`;
const options = {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ map: mindMap })
}

return this.#performFetch(url, options)
return this.#performRequest(url, options)
}

/**
* Sends a mind map to JabRef's server to save for the first time.
* @param { object } mindMap - The mind map to save.
* @param { string } path - The path to save the mind map to.
* @returns An empty map object (NULL_MAP).
* Requests a list of stored mind maps saved on the server.
* @returns A list of available mind maps stored on the server.
*/
async saveNewMap(mindMap, path = "libraries/demo/map") {
// The url will probably be modified according to mindMap's properties (coming in sprint 2)
const url = path;
async listMaps() {
const url = 'libraries'
const options = {
method: "PUT",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({map: mindMap})
method: "GET",
headers: { "Content-Type": "application/json" }
}

return this.#performFetch(url, options)
return this.#performRequest(url, options)
}

/**
* Requests a list of stored mind maps saved on the server.
* @returns A list of available mind maps stored on the server.
* Requests a list of all entries in the current library.
* @returns A list of all entries in the current library in json format.
*/
async listMaps() {
const url = "libraries";
async listEntries() {
const options = {
method: "GET",
headers: { "Content-Type": "application/json" }
}
// TODO - format the list to contain the keys, titles, authors and releases of the entries and return it
return this.#performRequest(this.currentLibrary, options)
}

/**
* Sends a request to open a cite-as-you-write window
* to select saved citation keys.
* @returns A list of selected citation keys.
*/
async getCiteKeysWithCAYW() {
const url = 'better-bibtex/cayw';
const options = {
method: "GET",
headers: { "Content-Type": "application/json" }
}

return this.#performFetch(url, options)
return this.#performRequest(url, options)
}

/**
* Requests the preview for a certain BibEntry from the current library.
* @param { string } citationKey - The citation key (identifier) of the entry.
* @returns A string containing the preview with relevant information
* about the entry (e.g. author, title, release date, etc.).
*/
async getPreviewString(citationKey) {
const url = `libraries/${this.currentLibrary}/entries/${citationKey}`;
const options = {
method: "GET",
headers: { "Accept": "text/plain" }
}

return this.#performRequest(url, options);
}

/**
* Requests the preview for a certain BibEntry from the current library.
* @param { string } citationKey - The citation key (identifier) of the entry.
* @returns A string containing the preview with relevant information
* about the entry (e.g. author, title, release date, etc.).
*/
async getPreviewHTML(citationKey) {
const url = `libraries/${this.currentLibrary}/entries/${citationKey}`;
const options = {
method: "GET",
headers: { "Accept": "text/html" }
}

return this.#performRequest(url, options);
}
}
Loading