-
Notifications
You must be signed in to change notification settings - Fork 45
Dashboard as pane #134
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
Closed
Closed
Dashboard as pane #134
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
10b2737
Introduces dashboard that switches content dep on authentication state
megoth 2469d3c
Managed to insert the dashboard, albeit it is presented wrongly
megoth f33259a
Managed to insert dashboard as pane
megoth 031509a
Only showing dashboard for root
megoth 01f08d7
It's now tightly coupled with the changes in mashlib
megoth 2a1ea69
Allows to select a specific tab in the global dashboard
megoth 8545dda
Generating a homepage as fallback for guests
megoth ff46ef6
Do not think we need cancel button anymore
megoth 1b68ad6
Some smaller changes based on feedback from Tim
megoth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { PaneDefinition, SolidSession } from "../types" | ||
| import solidUi, { SolidUi } from "solid-ui" | ||
| import paneRegistry from "pane-registry" | ||
| import { NamedNode, sym } from "rdflib" | ||
| import { generateHomepage } from "./homepage" | ||
|
|
||
| let panes: any | ||
| let UI: SolidUi | ||
|
|
||
| const nodeMode = (typeof module !== "undefined") | ||
|
|
||
| if (nodeMode) { | ||
| UI = solidUi | ||
| panes = paneRegistry | ||
| } else { // Add to existing mashlib | ||
| panes = (window as any).panes | ||
| UI = panes.UI | ||
| } | ||
|
|
||
| export const dashboardPane: PaneDefinition = { | ||
| icon: UI.icons.iconBase + "noun_547570.svg", | ||
| name: "dashboard", | ||
| label: (subject) => { | ||
| if (subject.uri === subject.site().uri) { | ||
| return "Dashboard" | ||
| } | ||
| return null | ||
| }, | ||
| render: (subject, dom) => { | ||
| const container = dom.createElement("div") | ||
| const webId = UI.authn.currentUser() | ||
| buildPage(container, webId, dom, subject) | ||
| UI.authn.solidAuthClient.trackSession(async (session: SolidSession) => { | ||
| container.innerHTML = "" | ||
| buildPage(container, session ? sym(session.webId) : null, dom, subject) | ||
| }) | ||
|
|
||
| return container | ||
| } | ||
| } | ||
|
|
||
| function buildPage (container: HTMLElement, webId: NamedNode | null, dom: HTMLDocument, subject: NamedNode) { | ||
| if (!webId) { | ||
| return buildHomePage(container, subject) | ||
| } | ||
| if (webId.site().uri === subject.site().uri) { | ||
| return buildDashboard(container, dom) | ||
| } | ||
| return buildHomePage(container, subject) | ||
| } | ||
|
|
||
| function buildDashboard (container: HTMLElement, dom: HTMLDocument) { | ||
| const outliner = panes.getOutliner(dom) | ||
| outliner.showDashboard(container) | ||
| } | ||
|
|
||
| function buildHomePage (container: HTMLElement, subject: NamedNode) { | ||
| const wrapper = document.createElement('div') | ||
| container.appendChild(wrapper) | ||
| const shadow = wrapper.attachShadow({ mode: 'open' }) | ||
| const link = document.createElement('link') | ||
| link.rel = 'stylesheet' | ||
| link.href = '/common/css/bootstrap.min.css' | ||
| shadow.appendChild(link) | ||
| generateHomepage(subject, UI.store, UI.store.fetcher).then(homepage => shadow.appendChild(homepage)) | ||
| } | ||
|
|
||
|
|
||
| export default dashboardPane | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import $rdf, { Fetcher, IndexedFormula, NamedNode } from "rdflib" | ||
| import UI from "solid-ui" | ||
|
|
||
| const ns = UI.ns | ||
|
|
||
| export async function generateHomepage(subject: NamedNode, store: IndexedFormula, fetcher: Fetcher): Promise<HTMLElement> { | ||
| const pod = subject.site().uri | ||
| const ownersProfile = await loadProfile(`${pod}/profile/card#me`, fetcher) | ||
| const name = getName(store, ownersProfile) | ||
|
|
||
| const wrapper = document.createElement('div') | ||
| wrapper.classList.add('container') | ||
| wrapper.appendChild(createTitle(ownersProfile.uri, name)) | ||
| wrapper.appendChild(createDataSection(name)) | ||
|
|
||
| return wrapper | ||
| } | ||
|
|
||
| function createDataSection(name: string): HTMLElement { | ||
| const dataSection = document.createElement('section') | ||
|
|
||
| const title = document.createElement('h2') | ||
| title.innerText = 'Data' | ||
| dataSection.appendChild(title) | ||
|
|
||
| const listGroup = document.createElement('div') | ||
| listGroup.classList.add('list-group') | ||
| dataSection.appendChild(listGroup) | ||
|
|
||
| const publicDataLink = document.createElement('a') | ||
| publicDataLink.classList.add('list-group-item') | ||
| publicDataLink.href = '/public/' | ||
| publicDataLink.innerText = `View ${name}'s files` | ||
| listGroup.appendChild(publicDataLink) | ||
|
|
||
| return dataSection | ||
| } | ||
|
|
||
| function createTitle(uri: string, name: string): HTMLElement { | ||
| const profileLink = document.createElement('a') | ||
| profileLink.href = uri | ||
| profileLink.innerText = name | ||
|
|
||
| const profileLinkPost = document.createElement('span') | ||
| profileLinkPost.innerText = `'s Pod` | ||
|
|
||
| const title = document.createElement('h1') | ||
| title.appendChild(profileLink) | ||
| title.appendChild(profileLinkPost) | ||
|
|
||
| return title | ||
| } | ||
|
|
||
|
|
||
| async function loadProfile(profileUrl: string, fetcher: Fetcher): Promise<NamedNode> { | ||
| const webId = $rdf.sym(profileUrl) | ||
| await fetcher.load(webId) | ||
| return webId | ||
| } | ||
|
|
||
|
|
||
|
|
||
| function getName (store: IndexedFormula, ownersProfile: NamedNode): string { | ||
| return (store.anyValue as any)(ownersProfile, ns.vcard("fn"), null, ownersProfile.doc()) | ||
| || (store.anyValue as any)(ownersProfile, ns.foaf("name"), null, ownersProfile.doc()) | ||
| || new URL(ownersProfile.uri).host.split('.')[0] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,3 +54,34 @@ interface NewPaneOptions { | |
| pane: PaneDefinition; | ||
| refreshTarget: HTMLTableElement; | ||
| } | ||
|
|
||
| export interface SolidSession { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Time for another PR to DefinitelyTyped, I guess? :) |
||
| authorization: SolidAuthorization; | ||
| credentialType: string; | ||
| idClaims: SolidClaim; | ||
| idp: string; | ||
| issuer: string; | ||
| sessionKey: string; | ||
| webId: string; | ||
| } | ||
|
|
||
| interface SolidAuthorization { | ||
| access_token: string; | ||
| client_id: string; | ||
| id_token: string; | ||
| } | ||
|
|
||
| interface SolidClaim { | ||
| at_hash: string; | ||
| aud: string; | ||
| azp: string; | ||
| cnf: { | ||
| jwk: string; | ||
| }; | ||
| exp: number; | ||
| iat: number; | ||
| iss: string; | ||
| jti: string; | ||
| nonce: string; | ||
| sub: string; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the homepage is shown inside the data browser in the area reserved for the Pane, is that correct? I also just realised that Shadow DOM isn't supported in IE11, is that something we're OK with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data browser is currently not working with IE at all - so in my mind, it is not something we can prioritize at the moment.
But we should be mindful of this in the future, so glad that you mentioned this.