publish corrections
This commit is contained in:
@@ -39,6 +39,14 @@ export class UmbVariantId {
|
||||
return this.segment || '';
|
||||
}
|
||||
|
||||
public isCultureInvariant(): boolean {
|
||||
return this.culture === null;
|
||||
}
|
||||
|
||||
public isSegmentInvariant(): boolean {
|
||||
return this.segment === null;
|
||||
}
|
||||
|
||||
public isInvariant(): boolean {
|
||||
return this.culture === null && this.segment === null;
|
||||
}
|
||||
|
||||
@@ -219,25 +219,6 @@ export class UmbDocumentRepository
|
||||
return { error };
|
||||
}
|
||||
|
||||
async saveAndPublish(id: string, item: UpdateDocumentRequestModel, variantIds: Array<UmbVariantId>) {
|
||||
if (!id) throw new Error('id is missing');
|
||||
if (!variantIds) throw new Error('variant IDs are missing');
|
||||
//await this.#init;
|
||||
|
||||
await this.save(id, item);
|
||||
|
||||
const { error } = await this.#detailDataSource.publish(id, variantIds);
|
||||
|
||||
if (!error) {
|
||||
// TODO: Update other stores based on above effect.
|
||||
|
||||
const notification = { data: { message: `Document saved and published` } };
|
||||
this.#notificationContext?.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
|
||||
async publish(id: string, variantIds: Array<UmbVariantId>) {
|
||||
if (!id) throw new Error('id is missing');
|
||||
if (!variantIds) throw new Error('variant IDs are missing');
|
||||
|
||||
@@ -129,7 +129,9 @@ export class UmbDocumentServerDataSource
|
||||
|
||||
// TODO: THIS DOES NOT TAKE SEGMENTS INTO ACCOUNT!!!!!!
|
||||
const requestBody: PublishDocumentRequestModel = {
|
||||
cultures: variantIds.map((variant) => variant.toCultureString()),
|
||||
cultures: variantIds
|
||||
.map((variant) => (variant.isCultureInvariant() ? null : variant.toCultureString()))
|
||||
.filter((x) => x !== null) as Array<string>,
|
||||
};
|
||||
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.putDocumentByIdPublish({ id, requestBody }));
|
||||
|
||||
@@ -187,9 +187,8 @@ export class UmbDocumentWorkspaceContext
|
||||
}
|
||||
}
|
||||
|
||||
async save() {
|
||||
if (!this.#currentData.value) return;
|
||||
if (!this.#currentData.value.id) return;
|
||||
async #createOrSave() {
|
||||
if (!this.#currentData.value?.id) throw new Error('Id is missing');
|
||||
|
||||
if (this.getIsNew()) {
|
||||
// TODO: typescript hack until we get the create type
|
||||
@@ -200,6 +199,10 @@ export class UmbDocumentWorkspaceContext
|
||||
} else {
|
||||
await this.repository.save(this.#currentData.value.id, this.#currentData.value);
|
||||
}
|
||||
}
|
||||
|
||||
async save() {
|
||||
await this.#createOrSave();
|
||||
|
||||
this.saveComplete(this.getData());
|
||||
}
|
||||
@@ -211,6 +214,19 @@ export class UmbDocumentWorkspaceContext
|
||||
}
|
||||
}
|
||||
|
||||
public async saveAndPublish() {
|
||||
await this.#createOrSave();
|
||||
// TODO: This might be right to publish all, but we need a method that just saves and publishes a declared range of variants.
|
||||
const currentData = this.#currentData.value;
|
||||
if (currentData) {
|
||||
const variantIds = currentData.variants?.map((x) => UmbVariantId.Create(x));
|
||||
const id = currentData.id;
|
||||
if (variantIds && id) {
|
||||
await this.repository.publish(id, variantIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async publish() {
|
||||
// TODO: This might be right to publish all, but we need a method that just publishes a declared range of variants.
|
||||
const currentData = this.#currentData.value;
|
||||
@@ -223,18 +239,6 @@ export class UmbDocumentWorkspaceContext
|
||||
}
|
||||
}
|
||||
|
||||
public async saveAndPublish() {
|
||||
// TODO: This might be right to publish all, but we need a method that just saves and publishes a declared range of variants.
|
||||
const currentData = this.#currentData.value;
|
||||
if (currentData) {
|
||||
const variantIds = currentData.variants?.map((x) => UmbVariantId.Create(x));
|
||||
const id = currentData.id;
|
||||
if (variantIds && id) {
|
||||
await this.repository.saveAndPublish(id, currentData, variantIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async unpublish() {
|
||||
// TODO: This might be right to unpublish all, but we need a method that just publishes a declared range of variants.
|
||||
const currentData = this.#currentData.value;
|
||||
|
||||
Reference in New Issue
Block a user