93 lines
2.4 KiB
TypeScript
93 lines
2.4 KiB
TypeScript
import * as appstate from '../appstate.js';
|
|
import * as shared from './shared/index.js';
|
|
import { appRouter } from '../router.js';
|
|
import {
|
|
css,
|
|
cssManager,
|
|
customElement,
|
|
DeesElement,
|
|
html,
|
|
state,
|
|
type TemplateResult,
|
|
} from '@design.estate/dees-element';
|
|
|
|
@customElement('sg-view-dashboard')
|
|
export class SgViewDashboard extends DeesElement {
|
|
@state()
|
|
accessor organizationsState: appstate.IOrganizationsState = {
|
|
organizations: [],
|
|
currentOrg: null,
|
|
repositories: [],
|
|
members: [],
|
|
};
|
|
|
|
@state()
|
|
accessor packagesState: appstate.IPackagesState = {
|
|
packages: [],
|
|
currentPackage: null,
|
|
versions: [],
|
|
total: 0,
|
|
query: '',
|
|
protocolFilter: '',
|
|
};
|
|
|
|
constructor() {
|
|
super();
|
|
const orgSub = appstate.organizationsStatePart
|
|
.select((s) => s)
|
|
.subscribe((s) => {
|
|
this.organizationsState = s;
|
|
});
|
|
this.rxSubscriptions.push(orgSub);
|
|
|
|
const pkgSub = appstate.packagesStatePart
|
|
.select((s) => s)
|
|
.subscribe((s) => {
|
|
this.packagesState = s;
|
|
});
|
|
this.rxSubscriptions.push(pkgSub);
|
|
}
|
|
|
|
public static styles = [
|
|
cssManager.defaultStyles,
|
|
shared.viewHostCss,
|
|
];
|
|
|
|
async connectedCallback() {
|
|
super.connectedCallback();
|
|
await appstate.organizationsStatePart.dispatchAction(appstate.fetchOrganizationsAction, null);
|
|
await appstate.packagesStatePart.dispatchAction(appstate.searchPackagesAction, { offset: 0 });
|
|
}
|
|
|
|
public render(): TemplateResult {
|
|
return html`
|
|
<sg-dashboard-view
|
|
.stats="${{
|
|
organizationCount: this.organizationsState.organizations.length,
|
|
packageCount: this.packagesState.total,
|
|
totalDownloads: 0,
|
|
tokenCount: 0,
|
|
}}"
|
|
.recentPackages="${this.packagesState.packages.slice(0, 5)}"
|
|
.organizations="${this.organizationsState.organizations}"
|
|
@navigate="${(e: CustomEvent) => this.handleNavigate(e)}"
|
|
></sg-dashboard-view>
|
|
`;
|
|
}
|
|
|
|
private handleNavigate(e: CustomEvent) {
|
|
const { type, id } = e.detail;
|
|
if (type === 'org' && id) {
|
|
appRouter.navigateToEntity('organizations', id);
|
|
} else if (type === 'org') {
|
|
appRouter.navigateToView('organizations');
|
|
} else if (type === 'package' && id) {
|
|
appRouter.navigateToEntity('packages', id);
|
|
} else if (type === 'packages') {
|
|
appRouter.navigateToView('packages');
|
|
} else if (type === 'tokens') {
|
|
appRouter.navigateToView('tokens');
|
|
}
|
|
}
|
|
}
|