add object type input and repo
This commit is contained in:
@@ -42,6 +42,7 @@ export * from './variant/index.js';
|
||||
export * from './workspace/index.js';
|
||||
export * from './culture/index.js';
|
||||
export * from './temporary-file/index.js';
|
||||
export * from './object-type/index.js';
|
||||
|
||||
const manifests: Array<ManifestTypes | UmbBackofficeManifestKind> = [
|
||||
...conditionManifests,
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './object-type.repository.js';
|
||||
export * from './input-object-type.element.js';
|
||||
@@ -0,0 +1,57 @@
|
||||
import { html, customElement, property, query, state, nothing } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { FormControlMixin, UUISelectElement, UUISelectEvent } from '@umbraco-cms/backoffice/external/uui';
|
||||
import { UmbLitElement } from '@umbraco-cms/internal/lit-element';
|
||||
import { UmbObjectTypeRepository } from './object-type.repository';
|
||||
|
||||
@customElement('umb-input-object-type')
|
||||
export class UmbInputObjectTypeElement extends FormControlMixin(UmbLitElement) {
|
||||
@query('uui-select')
|
||||
private select!: UUISelectElement;
|
||||
|
||||
@property()
|
||||
public set value(value: UUISelectElement['value']) {
|
||||
this.select.value = value;
|
||||
}
|
||||
public get value(): UUISelectElement['value'] {
|
||||
return this.select.value;
|
||||
}
|
||||
|
||||
@state()
|
||||
private _options: UUISelectElement['options'] = [];
|
||||
|
||||
#repository: UmbObjectTypeRepository;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.#repository = new UmbObjectTypeRepository(this);
|
||||
|
||||
this.#repository.read().then(({ data, error }) => {
|
||||
if (!data) return;
|
||||
|
||||
this._options = data.items.map((item) => ({ value: item.id, name: item.name ?? '' }));
|
||||
});
|
||||
}
|
||||
|
||||
protected getFormElement() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
#onChange() {
|
||||
this.dispatchEvent(new CustomEvent('change'));
|
||||
}
|
||||
|
||||
render() {
|
||||
return html`<uui-select .options=${this._options} @change=${this.#onChange}></uui-select> `;
|
||||
}
|
||||
|
||||
static styles = [];
|
||||
}
|
||||
|
||||
export default UmbInputObjectTypeElement;
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
'umb-input-object-type': UmbInputObjectTypeElement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ObjectTypesResource } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
|
||||
import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbApi } from '@umbraco-cms/backoffice/extension-api';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
|
||||
export class UmbObjectTypeRepository extends UmbBaseController implements UmbApi {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
async #read() {
|
||||
return tryExecuteAndNotify(this.#host, ObjectTypesResource.getObjectTypes({}));
|
||||
}
|
||||
|
||||
async read() {
|
||||
const { data, error } = await this.#read();
|
||||
|
||||
return { data, error };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user