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

Merge release with main branch for rebasing #272

Merged
merged 16 commits into from
Oct 16, 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
101 changes: 55 additions & 46 deletions web/src/components/AppBar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
v-if="!navItem.if || navItem.if()"
:key="navItem.text"
:to="navItem.external ? undefined : {name: navItem.to}"
:href="navItem.external ? navItem.to : undefined"
:target="navItem.external ? '_blank' : undefined"
:rel="navItem.external ? 'noopener' : undefined"
@click.stop.prevent="navItem.onClick ? navItem.onClick() : null"
:href="navItem.external && navItem.text !== 'WebKNOSSOS' ? navItem.to : undefined"
:target="navItem.external && navItem.text !== 'WebKNOSSOS' ? '_blank' : undefined"
:rel="navItem.external && navItem.text !== 'WebKNOSSOS' ? 'noopener' : undefined"
exact
text
>
Expand Down Expand Up @@ -48,6 +47,24 @@
</v-icon>
</v-list-item>
</template>
<v-list-item
@click.stop.prevent="handleWebKNOSSOSClick()"
exact
text
>
<v-list-item-content
text
class="text-md"
>
WebKNOSSOS
</v-list-item-content>
<v-icon
class="ml-1"
small
>
mdi-open-in-new
</v-icon>
</v-list-item>
</v-list-item-group>
</v-list>
</v-menu>
Expand Down Expand Up @@ -88,6 +105,31 @@
</v-icon>
</v-btn>
</template>
<v-btn
exact
text
@click.stop.prevent="handleWebKNOSSOSClick"
class="justify-start"
style="padding-left: 0;"
>
<v-list-item
exact
text
>
<v-list-item-content
text
class="text-md"
>
WebKNOSSOS
</v-list-item-content>
<v-icon
class="ml-1"
small
>
mdi-open-in-new
</v-icon>
</v-list-item>
</v-btn>
</v-toolbar-items>

<v-spacer />
Expand Down Expand Up @@ -145,7 +187,7 @@
user,
} from '@/rest';
import {
dandiAboutUrl, lincDocumentationUrl, lincHelpUrl, lincHubUrl, lincBrainUrl, lincWebKNOSSOSUrl

Check warning on line 190 in web/src/components/AppBar/AppBar.vue

View workflow job for this annotation

GitHub Actions / lint-type-check

'dandiAboutUrl' is defined but never used
} from '@/utils/constants';
import UserMenu from '@/components/AppBar/UserMenu.vue';
import logo from '@/assets/linc-logo.svg';
Expand Down Expand Up @@ -194,15 +236,7 @@
text: 'JupyterHub',
to: lincHubUrl,
external: true,
},
{
text: 'WebKNOSSOS',
to: lincWebKNOSSOSUrl,
external: true,
onClick: () => {
handleWebKNOSSOSClick();
},
},
}
];

function login() {
Expand All @@ -213,41 +247,16 @@
return new Promise(resolve => setTimeout(resolve, ms));
}

async function waitForCookie(cookieName: string, timeout = 5000, interval = 100) {
const startTime = Date.now();

while (Date.now() - startTime < timeout) {
// Log current document.cookie state for debugging
console.log('Checking for cookie:', document.cookie);

if (document.cookie.includes(`${cookieName}=`)) {
console.log('Cookie found:', cookieName);
return true; // Cookie found
}
await sleep(interval); // Wait and check again
}

console.log('Timeout: Cookie not found:', cookieName);
return false; // Timeout occurred, cookie not found
}

async function handleWebKNOSSOSClick() {
try {
console.log('Attempting login to WebKNOSSOS...');
const loginResponse = await dandiRest.loginWebKnossos();

// Log login response to ensure it's complete
console.log('Login response received:', loginResponse);

// Poll for the cookie named 'id' with a 5-second timeout and 100ms intervals
const cookieSet = await waitForCookie('id', 10000); // Extend timeout to 10 seconds for robustness

if (cookieSet) {
console.log('Opening WebKNOSSOS...');
window.open(lincWebKNOSSOSUrl, '_blank');
} else {
console.error('Login to WebKNOSSOS did not populate the cookie within the timeout.');
}
const response = await fetch('https://api.lincbrain.org/api/external-api/login/webknossos/', {
method: 'GET', // or 'POST' if that's what the API requires
credentials: 'include' // to ensure cookies are sent and received
});
const data = await response.json();
console.log(data);
await sleep(2000);
window.open(lincWebKNOSSOSUrl, '_blank');
} catch (error) {
console.error('Login to WebKNOSSOS failed:', error);
}
Expand Down
41 changes: 8 additions & 33 deletions web/src/views/FileBrowserView/FileBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
</v-subheader>
<v-list-item
v-for="el in item.asset.webknossos_info"
:key="item.asset.s3_uri"

Check failure on line 323 in web/src/views/FileBrowserView/FileBrowser.vue

View workflow job for this annotation

GitHub Actions / lint-type-check

Expected 'v-bind:key' directive to use the variables which are defined by the 'v-for' directive
@click.stop.prevent="el ? handleWebKnossosClick(el.webknossos_url) : null"
:href="el.webknossos_url ? el.webknossos_url : null"
target="_blank"
Expand Down Expand Up @@ -720,7 +720,7 @@
itemToDelete.value = null;
}

function getCookie(name: string): string | null {

Check warning on line 723 in web/src/views/FileBrowserView/FileBrowser.vue

View workflow job for this annotation

GitHub Actions / lint-type-check

'getCookie' is defined but never used
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);

Expand All @@ -737,41 +737,16 @@
return new Promise(resolve => setTimeout(resolve, ms));
}

async function waitForCookie(cookieName: string, timeout = 5000, interval = 100) {
const startTime = Date.now();

while (Date.now() - startTime < timeout) {
if (document.cookie.includes(`${cookieName}=`)) {
return true; // Cookie found
}
await sleep(interval); // Wait and check again
}

return false; // Timeout occurred, cookie not found
}

async function handleWebKnossosClick(url: string) {
// Check if the 'id' cookie is present
const idCookie = getCookie('id');
const response = await fetch('https://api.lincbrain.org/api/external-api/login/webknossos/', {
method: 'GET', // or 'POST' if that's what the API requires
credentials: 'include' // to ensure cookies are sent and received
});
const data = await response.json();
console.log(data);
await sleep(1000);
window.open(url, '_blank');

if (idCookie) {
window.open(url, '_blank');
} else {
// If no cookie, call webKnossosLogin
try {
await dandiRest.loginWebKnossos(); // Call the login function

const cookieSet = await waitForCookie('id');

if (cookieSet) {
window.open(url, '_blank');
} else {
console.error('Login to WebKNOSSOS did not populate the cookie within the timeout.');
} // After successful login, proceed to the URL
} catch (error) {
console.error('Login to WebKNOSSOS failed:', error);
}
}
}

// Update URL if location changes
Expand Down
Loading