users Bundle
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import { UmbStore } from './store.interface.js';
|
||||
import { UmbContextProviderController } from '@umbraco-cms/backoffice/context-api';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
|
||||
|
||||
// TODO: Make a Store interface?
|
||||
export class UmbStoreBase<StoreItemType = any> implements UmbStore<StoreItemType> {
|
||||
protected _host: UmbControllerHostElement;
|
||||
protected _host: UmbControllerHost;
|
||||
protected _data: UmbArrayState<StoreItemType>;
|
||||
|
||||
public readonly storeAlias: string;
|
||||
|
||||
constructor(_host: UmbControllerHostElement, storeAlias: string, data: UmbArrayState<StoreItemType>) {
|
||||
constructor(_host: UmbControllerHost, storeAlias: string, data: UmbArrayState<StoreItemType>) {
|
||||
this._host = _host;
|
||||
this.storeAlias = storeAlias;
|
||||
this._data = data;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import { UmbDeepState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { UmbStoreBase } from '@umbraco-cms/backoffice/store';
|
||||
|
||||
export type UmbModelType = 'dialog' | 'sidebar';
|
||||
|
||||
@@ -9,13 +11,16 @@ export type UmbCurrentUserHistoryItem = {
|
||||
icon?: string;
|
||||
};
|
||||
|
||||
export class UmbCurrentUserHistoryStore {
|
||||
#history = new UmbDeepState(<Array<UmbCurrentUserHistoryItem>>[]);
|
||||
export class UmbCurrentUserHistoryStore extends UmbStoreBase<UmbCurrentUserHistoryItem> {
|
||||
public readonly history = this._data.asObservable();
|
||||
public readonly latestHistory = this._data.getObservablePart((historyItems) => historyItems.slice(-10));
|
||||
|
||||
public readonly history = this.#history.asObservable();
|
||||
public readonly latestHistory = this.#history.getObservablePart((historyItems) => historyItems.slice(-10));
|
||||
|
||||
constructor() {
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(
|
||||
host,
|
||||
UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_TOKEN.toString(),
|
||||
new UmbArrayState<UmbCurrentUserHistoryItem>([])
|
||||
);
|
||||
if (!('navigation' in window)) return;
|
||||
(window as any).navigation.addEventListener('navigate', (event: any) => {
|
||||
const url = new URL(event.destination.url);
|
||||
@@ -31,12 +36,12 @@ export class UmbCurrentUserHistoryStore {
|
||||
* @memberof UmbHistoryService
|
||||
*/
|
||||
public push(historyItem: UmbCurrentUserHistoryItem): void {
|
||||
const history = this.#history.getValue();
|
||||
const history = this._data.getValue();
|
||||
const lastItem = history[history.length - 1];
|
||||
|
||||
// This prevents duplicate entries in the history array.
|
||||
if (!lastItem || lastItem.path !== historyItem.path) {
|
||||
this.#history.next([...this.#history.getValue(), historyItem]);
|
||||
this._data.next([...this._data.getValue(), historyItem]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +51,13 @@ export class UmbCurrentUserHistoryStore {
|
||||
* @memberof UmbHistoryService
|
||||
*/
|
||||
public clear() {
|
||||
this.#history.next([]);
|
||||
this._data.next([]);
|
||||
}
|
||||
}
|
||||
|
||||
export const UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbCurrentUserHistoryStore>(
|
||||
'UmbCurrentUserHistoryStore'
|
||||
);
|
||||
|
||||
// Default export for the globalContext manifest:
|
||||
export default UmbCurrentUserHistoryStore;
|
||||
|
||||
@@ -3,6 +3,12 @@ import { manifests as userProfileAppsManifests } from './user-profile-apps/manif
|
||||
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const headerApps: Array<ManifestTypes> = [
|
||||
{
|
||||
type: 'store',
|
||||
alias: 'Umb.Store.CurrentUser',
|
||||
name: 'Current User Store',
|
||||
loader: () => import('./current-user-history.store.js'),
|
||||
},
|
||||
{
|
||||
type: 'headerApp',
|
||||
alias: 'Umb.HeaderApp.CurrentUser',
|
||||
|
||||
@@ -1,30 +1,2 @@
|
||||
import { manifests as userGroupManifests } from './user-groups/manifests.js';
|
||||
import { manifests as userManifests } from './users/manifests.js';
|
||||
import { manifests as userSectionManifests } from './user-section/manifests.js';
|
||||
import { manifests as currentUserManifests } from './current-user/manifests.js';
|
||||
|
||||
import {
|
||||
UmbCurrentUserHistoryStore,
|
||||
UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_TOKEN,
|
||||
} from './current-user/current-user-history.store.js';
|
||||
import { UmbUserItemStore } from './users/repository/user-item.store.js';
|
||||
import { UmbUserGroupItemStore } from './user-groups/repository/user-group-item.store.js';
|
||||
import { UmbContextProviderController } from '@umbraco-cms/backoffice/context-api';
|
||||
import { UmbEntryPointOnInit } from '@umbraco-cms/backoffice/extension-api';
|
||||
|
||||
import './users/components/index.js';
|
||||
import './user-groups/components/index.js';
|
||||
|
||||
export const manifests = [...userGroupManifests, ...userManifests, ...userSectionManifests, ...currentUserManifests];
|
||||
|
||||
export const onInit: UmbEntryPointOnInit = (host, extensionRegistry) => {
|
||||
extensionRegistry.registerMany(manifests);
|
||||
|
||||
new UmbUserItemStore(host);
|
||||
new UmbUserGroupItemStore(host);
|
||||
new UmbContextProviderController(
|
||||
host,
|
||||
UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_TOKEN,
|
||||
new UmbCurrentUserHistoryStore()
|
||||
);
|
||||
};
|
||||
export * from './users/components/index.js';
|
||||
export * from './user-groups/components/index.js';
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { manifests as userGroupManifests } from './user-groups/manifests.js';
|
||||
import { manifests as userManifests } from './users/manifests.js';
|
||||
import { manifests as userSectionManifests } from './user-section/manifests.js';
|
||||
import { manifests as currentUserManifests } from './current-user/manifests.js';
|
||||
|
||||
export const manifests = [...userGroupManifests, ...userManifests, ...userSectionManifests, ...currentUserManifests];
|
||||
@@ -2,9 +2,9 @@ export const name = 'Umbraco.Core.UserManagement';
|
||||
export const version = '0.0.1';
|
||||
export const extensions = [
|
||||
{
|
||||
name: 'User Management Entry Point',
|
||||
alias: 'Umb.EntryPoint.UserManagement',
|
||||
type: 'entryPoint',
|
||||
loader: () => import('./index.js'),
|
||||
name: 'User Management Bundle',
|
||||
alias: 'Umb.Bundle.UserManagement',
|
||||
type: 'bundle',
|
||||
loader: () => import('./manifests.js'),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
import { UmbUserGroupRepository } from '../repository/user-group.repository.js';
|
||||
import { UmbUserGroupItemStore } from './user-group-item.store.js';
|
||||
import { UmbUserGroupStore } from './user-group.store.js';
|
||||
import type { ManifestStore, ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export const USER_GROUP_REPOSITORY_ALIAS = 'Umb.Repository.UserGroup';
|
||||
import type { ManifestStore, ManifestRepository, ManifestItemStore } from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
const repository: ManifestRepository = {
|
||||
type: 'repository',
|
||||
alias: USER_GROUP_REPOSITORY_ALIAS,
|
||||
alias: 'Umb.Repository.UserGroup',
|
||||
name: 'User Group Repository',
|
||||
class: UmbUserGroupRepository,
|
||||
};
|
||||
|
||||
export const USER_GROUP_STORE_ALIAS = 'Umb.Store.UserGroup';
|
||||
|
||||
const store: ManifestStore = {
|
||||
type: 'store',
|
||||
alias: USER_GROUP_STORE_ALIAS,
|
||||
alias: 'Umb.Store.UserGroup',
|
||||
name: 'User Group Store',
|
||||
class: UmbUserGroupStore,
|
||||
};
|
||||
|
||||
export const manifests = [repository, store];
|
||||
const itemStore: ManifestItemStore = {
|
||||
type: 'itemStore',
|
||||
alias: 'Umb.ItemStore.UserGroup',
|
||||
name: 'User Group Item Store',
|
||||
class: UmbUserGroupItemStore,
|
||||
};
|
||||
|
||||
export const manifests = [repository, store, itemStore];
|
||||
|
||||
Reference in New Issue
Block a user