Skip to content

Commit 38e8f63

Browse files
iloveskittles82Robert35-dllkoppor
authored
Finishing sprint 3 (#34) with cleanup
* Disabled debug button * Renamed nodes' types * Added type updating upon loading mind maps * Swapped Open / Save buttons. Closes #26 * Renamed popups with BibEntry to BibTex Closes #28 * Replaced disabling dropdown buttons Instead their options will be disabled so that the menus can be hidden upon clicking elsewhere. Closes #23 * Update README.md added newer screenshot and expanded "try it out" section with gg.cmd tool instructions * add shortcut cheat sheet * add link to shortcuts cheat sheet * Add ctrl + S for saving and added gg.cmd to gitignore * Add CTRL + S * Reworked disabling dropdowns' buttons Their menus will be closed upon toggling anytime so that you can disable dropdowns in a tidy way. Closes #23 (for real) * Implemented ModalDesigner This allows to switch bootstrap modals' layouts more generalized * Extracted default mind maps and options * Fixed minor bugs with extracted options * Refactored HTTPClient default return value The return struct contains now the code and the value of related request * Cleaned HTTPClient Fixed comments and added edge case handling if no citation keys were selected * Moved rest of buttons into "General Manipulation" region Undo / Redo / Debug buttons' click handlers are now defined in "General Element Manipulation" region * Cleaned main.js Fixed comments and added edge case handling if no lists of things were retrieved. Also some console logging (~ UwU)~ * Added more shortcuts There're now shortcuts for saving and adding BibEntry / PDF nodes as children. These shortcuts work, if jsMind is active. Closes #27 * Added cutting long nodes' topics If there's too much text, it will be simply cut at the max length with '...' Relates to #32 * Created a "Connection Failed" page This shows a couple of hints about how to start the server and has a retry button. However, it's still not working with electron. Refers to #33 * Applied suggestions to README.md Co-authored-by: Oliver Kopp <kopp.dev@gmail.com> * Added shortcuts documentation Refers to #27 * fixed comments --------- Co-authored-by: Robert Koch <Robert.Koch@Student.HTW-Berlin.de> Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
1 parent f37d2b6 commit 38e8f63

File tree

15 files changed

+881
-358
lines changed

15 files changed

+881
-358
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,6 @@ electron-dist/
151151
/.idea/modules.xml
152152
/.idea/vcs.xml
153153
/JabMap/.idea/
154+
155+
# wrapper tool for trying out jabmap
156+
/gg.cmd

README.md

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,81 @@
11
# JabMap
2+
23
Next-Generation scientific mind mapping.
34

5+
46
## 📸 Screenshots
5-
<img width="1548" alt="JabMap mainview example" src="https://github.com/user-attachments/assets/69f5de97-3b2d-4ed7-b8f8-050a1559f93b" />
6-
<img width="1549" alt="JabMap opening a mindmap example" src="https://github.com/user-attachments/assets/23aa56d0-4432-4e5f-957b-8797d36a22fd" />
7+
8+
<img width="1429" alt="JabMap-Example" src="https://github.com/user-attachments/assets/4a175c10-a0eb-438f-b5f6-1dcfb4e2520c" />
9+
10+
11+
## ⌨️ Shortcuts
12+
13+
You can find a list of shortcuts at [shortcuts.md](shortcuts.md).
714

815
## 🌟 Try It Out!
9-
The current state of the application is hosted on [github pages](https://jabref.github.io/jabmap/) for you to try out. Note that saving and loading mind maps does not work when running the app like this because the communication with the [JabRef's HTTP server](#getting-the-server) is restricted by your browser for security reasons. Unfortunately this applies to any interaction with the server.
1016

11-
## 💾 Installation
17+
There are a couple of ways to try out JabMap. The fastest way to just get a grasp of it is on [github pages](https://jabref.github.io/jabmap/). Note that this will merely allow you to create some nodes, edit and tag them. Saving, Loading and JabRef-related features like BibTeX-Nodes and importing attached PDF-files as nodes won't work unless you are running our version of JabRef's HTTP-Server (see [below](##-🤖-getting-the-server-running) for setup) since the mentioned features rely on it.
18+
19+
>Note: It's still possible your browser blocks access to the server due to HTTP/HTTPS issues, for the best experience follow the steps below on how to try JabMap running it locally.
20+
21+
### Running it locally
22+
23+
The following commands get the code in place and start JabRef and JabMap with the help of a handy wrapper tool called [gg.cmd](https://github.com/eirikb/gg).
24+
A little terminal magic is required, but don't worry, we have the commands all laid out for you!
25+
26+
#### JabRef:
27+
28+
1. Go to your git-repositories folder and start a new terminal session
29+
2. `git clone --recurse-submodules https://github.com/JabRef/jabref.git`
30+
3. `cd jabref`
31+
4. `git checkout jabmap`
32+
5. Enable nice wrapper: `curl -L ggcmd.io > gg.cmd`
33+
6. `sh ./gg.cmd just run-pr 13519`
34+
7. Wait for JabRef to come up
35+
8. File > Preferences > Check "HTTP Server"
36+
37+
#### JabMap:
38+
39+
1. Go to your git-repositories folder and start a new terminal session
40+
2. Clone it: `git clone git@github.com:JabRef/jabmap.git`
41+
3. `cd jabmap`
42+
4. Fix branch: `git checkout jabmap`
43+
5. Enable nice wrapper: `curl -L ggcmd.io > gg.cmd`
44+
6. Install dependencies: `sh gg.cmd npm install`
45+
7. Build: `sh ./gg.cmd npm run build`
46+
8. Run: `sh ./gg.cmd npm run preview`
47+
9. Now one can open http://localhost:4173/ and open a library with the corresponding map.
48+
49+
50+
## 🤖 Getting the server running
51+
52+
As mentioned above, several features are handled by JabRef's HTTP server. Currently you have to start it manually. Luckily, there are multiple ways to do that:
53+
54+
### using gg.cmd
55+
56+
If you followed the steps (**running-it-locally**) above, instead of steps 6. - 9. you can simply do the following to start the server without JabRef's GUI:
57+
58+
```
59+
sh ./gg.cmd jbang .jbang/JabSrvLauncher.java
60+
```
61+
62+
### Starting it from an IDE
63+
64+
1. If you haven't already, clone our [JabRef's fork repository](https://github.com/iloveskittles82/jabref) (_Note: It is recommended to complete this step of_ [_JabRef's setup guide_](https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-12-build.html)).
65+
2. Afterwards, open it in editor of your choice (_IDEA works well for this_) and locate the `jabsrv/src/test/rest-api.http` file.
66+
3. Follow the steps described at the top of the file to start the server.
67+
68+
_Alternatively_ you can do the following:
69+
1. Open `ServerCLI` file located at `./jabsrv-cli/src/main/java/org.jabref.http.server.cli`
70+
2. Execute its `main()` method
71+
72+
More about starting the server in [JabRef's server documentation](https://devdocs.jabref.org/code-howtos/http-server.html)
73+
74+
75+
## 💾 Install by building the application
76+
77+
Now that you've tried it, here is how to build and install it. We hope to provide a downloadable installer in the future, but for now you have to build the app yourself.
78+
This section is more targeted towards
1279
Currently, there is no production build available for download so you have to build it yourself :3
1380

1481
### Basic Setup
@@ -39,24 +106,9 @@ If bundling fails with `ERROR: Cannot create symbolic link`, you have to do the
39106

40107
_More about this workaround in [this issue](https://github.com/electron-userland/electron-builder/issues/8149)_.
41108

42-
On Linux, there is a bug with npm and optional dependencies (See [this issue](https://github.com/npm/cli/issues/4828). Should you encounter this bug after running `npm install`, remove the `package-lock.json` file and `node-modules` directory and run `npm i`. Then, simply continue with step 2.
109+
On Linux and Mac, there is a bug with npm and optional dependencies (See [this issue](https://github.com/npm/cli/issues/4828). Should you encounter this bug after running `npm install`, remove the `package-lock.json` file and `node-modules` directory and run `npm i`. Then, simply continue with step 2.
43110

44111
### Starting
45112
After a successful build you can finally start the app located at `./electron-dist/win-unpacked/JabMap.exe`.
46113

47114
_Optionally you can install it by opening_ `./electron-dist/JabMap Setup 1.0.0.exe`
48-
49-
## 🤖 Getting the server running
50-
As mentioned above, several features are handled by JabRef's HTTP server. Currently you have to start it manually:
51-
52-
First clone our [JabRef's fork repository](https://github.com/iloveskittles82/jabref) (_Note: It is recommended to complete this step of_ [_JabRef's setup guide_](https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-12-build.html)).
53-
54-
After you cloned the repository, open it in editor of your choice (_IDEA works well for this_) and locate the `jabsrv/src/test/rest-api.http` file.
55-
56-
Follow the steps described at the top of the file to start the server.
57-
58-
_Alternatively_ you can do the following:
59-
1. Open `ServerCLI` file located at `./jabsrv-cli/src/main/java/org.jabref.http.server.cli`
60-
2. Execute its `main()` method
61-
62-
More about starting the server in [JabRef's server documentation](https://devdocs.jabref.org/code-howtos/http-server.html)

http/HTTPClient.js

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
/**
22
* Provides HTTP-connection functionality.
33
*/
4-
export class HTTPClient {
4+
class HTTPClient {
55
#host = "http://localhost:23119/";
66

77
constructor() {
8-
/**
9-
* The default return value for PUT requests.
10-
*/
11-
this.NULL_MAP = { map: {} };
128
this.currentLibrary = "demo";
139
}
1410

1511
/**
16-
* Sends a HTTP-request to JabRef's server.
12+
* Sends an HTTP-request to JabRef's server.
1713
* @param { string } url - The server's URL to make a request to.
1814
* @param { object } options - Optional request's options.
19-
* @returns
20-
* - An **object** in case of a `GET request` or
21-
* - An **object** { map: {} } in case of a `PUT / POST request`
22-
* or if any request failed.
15+
* @returns A result object of following structure:
16+
* - code: the status of the request defined by REQUEST_RESULT enum.
17+
* - value: **null** in case of `PUT` or `POST` requests
18+
* or **object** requested by `GET`.
2319
*/
2420
async #performRequest(url, options = null) {
25-
let result = this.NULL_MAP;
21+
let result = {
22+
code: REQUEST_RESULT.Refused,
23+
value: null
24+
};
2625
let logMessage = "";
2726

2827
const requestUrl = this.#host.concat(url);
@@ -41,19 +40,25 @@ export class HTTPClient {
4140
throw new Error("Request's result is not ok ( -.-)");
4241
}
4342

43+
// If connection succeeded, try parsing the result (failed by default)
44+
result.code = REQUEST_RESULT.Failed;
45+
4446
// If some output is awaited, save it
4547
if (options.method !== "PUT") {
4648
if (options.headers["Accept"] === 'application/json') {
47-
result = await response.json();
49+
result.value = await response.json();
4850
}
4951
if (options.headers["Accept"] === 'text/plain') {
50-
result = await response.text();
52+
result.value = await response.text();
5153
}
5254
if (options.headers["Accept"] === 'text/html') {
53-
result = await response.text();
55+
result.value = await response.text();
5456
}
5557
}
5658

59+
// If parsing's successful, set the best result code \(OwO)/
60+
result.code = REQUEST_RESULT.Success;
61+
5762
// Providing infos about the request
5863
logMessage =
5964
`${options.method} ${requestUrl} Request succeeded (~ UwU)~(${response.status}).\n` +
@@ -85,7 +90,7 @@ export class HTTPClient {
8590
*/
8691
async isConnected() {
8792
try {
88-
const response = await fetch(this.#host);
93+
await fetch(this.#host);
8994
return true;
9095
} catch (e) {
9196
return false;
@@ -95,7 +100,10 @@ export class HTTPClient {
95100
/**
96101
* Requests a mind map (.jmp file) from JabRef's server.
97102
* @param { string } library - The library of the requested mind map.
98-
* @returns The requested mind map object.
103+
* @returns A result object of following structure:
104+
* - code: the status of the request defined by REQUEST_RESULT enum.
105+
* - value: null in case the request failed
106+
* or requested mind map.
99107
*/
100108
async loadMap(library = "demo") {
101109
const url = `libraries/${library}/map`;
@@ -104,17 +112,23 @@ export class HTTPClient {
104112
headers: { "Accept": "application/json" }
105113
}
106114

107-
// Changing current library
108-
this.currentLibrary = library;
109-
console.log(`Current library is now: ${this.currentLibrary}`);
115+
const loadRequest = await this.#performRequest(url, options);
110116

111-
return this.#performRequest(url, options);
117+
// Changing current library if succeeded
118+
if (loadRequest.code === REQUEST_RESULT.Success) {
119+
this.currentLibrary = library;
120+
console.log(`Current library is now: ${this.currentLibrary}`);
121+
}
122+
123+
return loadRequest
112124
}
113125

114126
/**
115127
* Sends a mind map to JabRef's server to save next to currently active library.
116128
* @param { object } mindMap - The mind map to save.
117-
* @returns An empty map object (NULL_MAP).
129+
* @returns A result object of following structure:
130+
* - code: the status of the request defined by REQUEST_RESULT enum.
131+
* - value: null.
118132
*/
119133
async saveMap(mindMap) {
120134
const url = `libraries/${this.currentLibrary}/map`;
@@ -129,7 +143,10 @@ export class HTTPClient {
129143

130144
/**
131145
* Requests a list of stored mind maps saved on the server.
132-
* @returns A list of available mind maps stored on the server.
146+
* @returns A result object of following structure:
147+
* - code: the status of the request defined by REQUEST_RESULT enum.
148+
* - value: null in case the request failed
149+
* or a list of available mind maps.
133150
*/
134151
async listMaps() {
135152
const url = 'libraries'
@@ -143,7 +160,10 @@ export class HTTPClient {
143160

144161
/**
145162
* Requests a list of all entries in the current library.
146-
* @returns A list of all entries in the current library in json format.
163+
* @returns A result object of following structure:
164+
* - code: the status of the request defined by REQUEST_RESULT enum.
165+
* - value: null in case the request failed
166+
* or a list of available entries of current mind map.
147167
*/
148168
async listEntries() {
149169
const options = {
@@ -156,7 +176,10 @@ export class HTTPClient {
156176
/**
157177
* Sends a request to open a cite-as-you-write window
158178
* to select any number of BibEntries from the current library.
159-
* @returns A list of selected citation keys.
179+
* @returns A result object of following structure:
180+
* - code: the status of the request defined by REQUEST_RESULT enum.
181+
* - value: null in case the request failed
182+
* or list of requested citation keys.
160183
*/
161184
async getCiteKeysWithCAYW() {
162185
let url = 'better-bibtex/cayw';
@@ -166,19 +189,30 @@ export class HTTPClient {
166189
method: "GET",
167190
headers: { "Accept": "application/json" }
168191
}
169-
let selectedEntries = await this.#performRequest(url, options);
170-
let selectedCiteKeys = [];
171-
for (let entry of selectedEntries) {
172-
selectedCiteKeys.push(entry.citationKey);
192+
193+
let entriesRequest = await this.#performRequest(url, options);
194+
let selectedEntries = entriesRequest.value;
195+
196+
if (entriesRequest.code !== REQUEST_RESULT.Success) {
197+
return null;
173198
}
199+
200+
let selectedCiteKeys = [];
201+
for (let entry of selectedEntries) {
202+
selectedCiteKeys.push(entry.citationKey);
203+
}
204+
174205
return selectedCiteKeys;
175206
}
176207

177208
/**
178209
* Requests the preview for a certain BibEntry from the current library.
179210
* @param { string } citationKey - The citation key (identifier) of the entry.
180-
* @returns A string containing the preview with relevant information
181-
* about the entry (e.g. author, title, release date, etc.).
211+
* @returns A result object of following structure:
212+
* - code: the status of the request defined by REQUEST_RESULT enum.
213+
* - value: null in case the request failed
214+
* or a string containing the preview with relevant information
215+
* about the entry (e.g. author, title, release date, etc.).
182216
*/
183217
async getPreviewString(citationKey) {
184218
const url = `libraries/${this.currentLibrary}/entries/${citationKey}`;
@@ -193,8 +227,11 @@ export class HTTPClient {
193227
/**
194228
* Requests the preview for a certain BibEntry from the current library.
195229
* @param { string } citationKey - The citation key (identifier) of the entry.
196-
* @returns A string containing the preview with relevant information
197-
* about the entry (e.g. author, title, release date, etc.).
230+
* @returns A result object of following structure:
231+
* - code: the status of the request defined by REQUEST_RESULT enum.
232+
* - value: null in case the request failed
233+
* or an HTML string containing the preview with relevant information
234+
* about the entry (e.g. author, title, release date, etc.).
198235
*/
199236
async getPreviewHTML(citationKey) {
200237
const url = `libraries/${this.currentLibrary}/entries/${citationKey}`;
@@ -208,7 +245,10 @@ export class HTTPClient {
208245

209246
/**
210247
* Requests a list of all local pdf files from the current library.
211-
* @returns A list of objects of the following structure
248+
* @returns A result object of following structure:
249+
* - code: the status of the request defined by REQUEST_RESULT enum.
250+
* - value: null in case the request failed
251+
* or a list of objects of the following structure
212252
* ```
213253
* [
214254
* {
@@ -229,7 +269,14 @@ export class HTTPClient {
229269
headers: { "Accept": "application/json" }
230270
}
231271

232-
let response = await this.#performRequest(url, options);
233-
return response;
272+
return this.#performRequest(url, options);
234273
}
235-
}
274+
}
275+
276+
const REQUEST_RESULT = Object.freeze({
277+
Refused: -1,
278+
Failed: 0,
279+
Success: 1
280+
});
281+
282+
export { HTTPClient, REQUEST_RESULT };

0 commit comments

Comments
 (0)