tag store and repo
This commit is contained in:
@@ -13,18 +13,12 @@ export class UmbTagRepository {
|
|||||||
#dataSource: UmbTagServerDataSource;
|
#dataSource: UmbTagServerDataSource;
|
||||||
#tagStore?: UmbTagStore;
|
#tagStore?: UmbTagStore;
|
||||||
|
|
||||||
#notificationContext?: UmbNotificationContext;
|
|
||||||
|
|
||||||
constructor(host: UmbControllerHostElement) {
|
constructor(host: UmbControllerHostElement) {
|
||||||
this.#host = host;
|
this.#host = host;
|
||||||
|
|
||||||
this.#dataSource = new UmbTagServerDataSource(this.#host);
|
this.#dataSource = new UmbTagServerDataSource(this.#host);
|
||||||
|
|
||||||
this.#init = Promise.all([
|
this.#init = Promise.all([
|
||||||
new UmbContextConsumerController(this.#host, UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
|
||||||
this.#notificationContext = instance;
|
|
||||||
}),
|
|
||||||
|
|
||||||
new UmbContextConsumerController(this.#host, UMB_TAG_STORE_CONTEXT_TOKEN, (instance) => {
|
new UmbContextConsumerController(this.#host, UMB_TAG_STORE_CONTEXT_TOKEN, (instance) => {
|
||||||
this.#tagStore = instance;
|
this.#tagStore = instance;
|
||||||
}).asPromise(),
|
}).asPromise(),
|
||||||
@@ -39,7 +33,6 @@ export class UmbTagRepository {
|
|||||||
const { data, error } = await this.#dataSource.getCollection({ query, skip, take, tagGroup, culture });
|
const { data, error } = await this.#dataSource.getCollection({ query, skip, take, tagGroup, culture });
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
// TODO: allow to append an array of items to the store
|
|
||||||
data.items.forEach((x) => this.#tagStore?.append(x));
|
data.items.forEach((x) => this.#tagStore?.append(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { PagedTagResponseModel, TagResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
import type { TagResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||||
import { ArrayState } from '@umbraco-cms/backoffice/observable-api';
|
import { ArrayState } from '@umbraco-cms/backoffice/observable-api';
|
||||||
import { UmbStoreBase } from '@umbraco-cms/backoffice/store';
|
import { UmbStoreBase } from '@umbraco-cms/backoffice/store';
|
||||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller';
|
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller';
|
||||||
|
|
||||||
export const UMB_TAG_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbTagStore>('UmbTAGStore');
|
export const UMB_TAG_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbTagStore>('UmbTagStore');
|
||||||
/**
|
/**
|
||||||
* @export
|
* @export
|
||||||
* @class UmbTagStore
|
* @class UmbTagStore
|
||||||
@@ -13,6 +13,7 @@ export const UMB_TAG_STORE_CONTEXT_TOKEN = new UmbContextToken<UmbTagStore>('Umb
|
|||||||
*/
|
*/
|
||||||
export class UmbTagStore extends UmbStoreBase {
|
export class UmbTagStore extends UmbStoreBase {
|
||||||
#data = new ArrayState<TagResponseModel>([], (x) => x.id);
|
#data = new ArrayState<TagResponseModel>([], (x) => x.id);
|
||||||
|
data = this.#data.asObservable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of UmbTagStore.
|
* Creates an instance of UmbTagStore.
|
||||||
@@ -28,19 +29,31 @@ export class UmbTagStore extends UmbStoreBase {
|
|||||||
* @param {TagResponseModel} TAG
|
* @param {TagResponseModel} TAG
|
||||||
* @memberof UmbTagStore
|
* @memberof UmbTagStore
|
||||||
*/
|
*/
|
||||||
append(TAG: TagResponseModel) {
|
append(tag: TagResponseModel) {
|
||||||
this.#data.append([TAG]);
|
this.#data.append([tag]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a tag to the store
|
* Append a tag to the store
|
||||||
* @param {id} TAGResponseModel id.
|
* @param {id} TagResponseModel id.
|
||||||
* @memberof UmbTagStore
|
* @memberof UmbTagStore
|
||||||
*/
|
*/
|
||||||
byId(id: TagResponseModel['id']) {
|
byId(id: TagResponseModel['id']) {
|
||||||
return this.#data.getObservablePart((x) => x.find((y) => y.id === id));
|
return this.#data.getObservablePart((x) => x.find((y) => y.id === id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
byGroup(group: TagResponseModel['group']) {
|
||||||
|
return this.#data.getObservablePart((x) => x.filter((y) => y.group === group));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
byText(text: string) {
|
||||||
|
return this.#data.getObservablePart((items) =>
|
||||||
|
items.filter((item) => item.text?.toLocaleLowerCase().includes(text.toLocaleLowerCase()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes tag in the store with the given uniques
|
* Removes tag in the store with the given uniques
|
||||||
* @param {string[]} uniques
|
* @param {string[]} uniques
|
||||||
|
|||||||
Reference in New Issue
Block a user