Skip to content

Commit

Permalink
BDE-226 better handling of the popup displaying
Browse files Browse the repository at this point in the history
  - get connect location from the nuxeo server
  - allow to override the connect location for the nuxeo server connected
  - hide the popup page building, display it when the load ends up
  • Loading branch information
nxmatic committed Mar 26, 2024
1 parent 8c38f66 commit 995758e
Show file tree
Hide file tree
Showing 8 changed files with 708 additions and 666 deletions.
70 changes: 41 additions & 29 deletions src/main/connect-locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,51 @@ class ConnectLocator extends ServiceWorkerComponent {
const hash = CryptoJS
.SHA512(location.toString())
.toString();
return `connect-locator.${hash}`;
return `connect-locator.credentials.${hash}`;
};

this.nuxeoKeyOf = (location) => {
const hash = CryptoJS
.SHA512(location.toString())
.toString();
return `connect-locator.nuxeo.${hash}`;
};
}

asRegistration(url) {
if (url) {
const { location, credentials } = this.extractCredentialsAndCleanUrl(url);
return this.worker.browserStore
.set({ 'connect-locator.url': location, [this.credentialsKeyOf(location)]: credentials })
.then((store) => {
this.worker.developmentMode
.asConsole()
.then((console) => console
.log(`ConnectLocator.asRegistration(${url})`, store));
return store;
})
.then(() => this.asRegistration());
}
return this.worker.browserStore
.get({ 'connect-locator.url': 'https://connect.nuxeo.com/' })
.then((store) => {
const location = new URL(store['connect-locator.url']);
location.pathname = location.pathname.replace(/\/?$/, '/');
return location;
})
.then((location) => ({ location, key: this.credentialsKeyOf(location) }))
.then(({ location, key }) => this.worker.browserStore.get({ [key]: undefined })
.then((credentialsStore) => {
if (!(credentialsStore && credentialsStore[key])) {
return { location, credentials: null };
}
return { location, credentials: credentialsStore[key] };
}));
return this.worker.serverConnector
.asRuntimeInfo()
.then(({ serverUrl: nuxeoUrl, connectUrl }) => {
const nuxeoKey = this.nuxeoKeyOf(new URL(nuxeoUrl));
if (url) {
const { location, credentials } = this.extractCredentialsAndCleanUrl(url);
return this.worker.browserStore
.set({ [nuxeoKey]: location, [this.credentialsKeyOf(location)]: credentials })
.then((store) => {
this.worker.developmentMode
.asConsole()
.then((console) => console
.log(`ConnectLocator.asRegistration(${url})`, store));
return store;
})
.then(() => this.asRegistration());
}
return this.worker.browserStore
.get({ [nuxeoKey]: connectUrl })
.then((store) => {
const location = new URL(store[nuxeoKey]);
location.pathname = location.pathname.replace(/\/?$/, '/');
return location;
})
.then((location) => ({ location, key: this.credentialsKeyOf(location) }))
.then(({ location, key }) => this.worker.browserStore.get({ [key]: undefined })
.then((credentialsStore) => {
if (!(credentialsStore && credentialsStore[key])) {
return { location, credentials: null };
}
return { location, credentials: credentialsStore[key] };
}));
});
}

// eslint-disable-next-line class-methods-use-this
Expand Down
2 changes: 1 addition & 1 deletion src/main/designer-live-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class DesignerLivePreview extends ServiceWorkerComponent {
return this.worker.connectLocator
.asRegistration()
.then(({ location, credentials }) => {
const url = new URL(`/nuxeo/site/studio/v2/project/${projectName}/workspace/ws.resources`, location);
const url = new URL(`studio/v2/project/${projectName}/workspace/ws.resources`, location);
return { url, credentials };
})
.then(({ url: workspaceUrl, credentials }) => fetch(workspaceUrl, {
Expand Down
10 changes: 10 additions & 0 deletions src/main/groovy/connect-location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function connectLocation() {
return `
import groovy.json.JsonOutput
import org.nuxeo.connect.connector.http.ConnectUrlConfig
def output = new URL(ConnectUrlConfig.getBaseUrl())
println JsonOutput.toJson(output)
`;
}
2 changes: 2 additions & 0 deletions src/main/groovy/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import connectLocation from './connect-location';
import developedStudioProjects from './developed-studio-projects';
import installedAddons from './installed-addons';
import registedStudioProject from './registered-studio-project';
import registerDevelopedStudioProject from './register-developed-studio-project';

export default {
'connect-location': connectLocation,
'developed-studio-projects': developedStudioProjects,
'installed-addons': installedAddons,
'registered-studio-project': registedStudioProject,
Expand Down
13 changes: 10 additions & 3 deletions src/main/server-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,23 @@ class ServerConnector extends ServiceWorkerComponent {

asRuntimeInfo() {
return Promise.all([
this.asConnectLocation(),
this.asInstalledAddons(),
this.asDevelopedStudioProjects()])
.then(([installedAddons, developedStudioProjects]) => ({
this.asRegisteredStudioProject()
])
.then(([connectLocation, installedAddons, registredStudioProject]) => ({
nuxeo: this.nuxeo,
serverUrl: this.serverUrl,
connectUrl: connectLocation,
installedAddons,
developedStudioProjects,
registredStudioProject,
}));
}

asConnectLocation() {
return this.executeScript('connect-location');
}

asRegisteredStudioProject() {
return this.executeScript('registered-studio-project');
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/tab-navigation-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class TabNavigationHandler extends ServiceWorkerComponent {
message: 'You are not authenticated. Please log in and try again.',
iconUrl: '../images/access_denied.png',
});
return this.reloadServerTab({ rootUrl: nuxeoUrl, tabInfo }, 0);
return this.reloadServerTab({ rootUrl: nuxeoUrl, tabInfo });
})
.then((response) => {
if (response.ok) return response;
Expand Down
15 changes: 5 additions & 10 deletions src/popup/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Rest of the code -->
</head>
<body>
<!-- Rest of the code -->
</body>
</html>
<html lang="en">
<head>
<!--
Expand All @@ -28,6 +18,11 @@
-->
<title>Nuxeo Dev Tools</title>
<link rel=stylesheet href=/styles/main.css>
<style>
body {
display: none;
}
</style>
<script type="module" src="index.js"></script>
</head>
<body>
Expand Down
Loading

0 comments on commit 995758e

Please sign in to comment.