From 68546c312da49bcb65d8fe09822afaf7557200f6 Mon Sep 17 00:00:00 2001
From: Lone Iversen <108085781+loivsen@users.noreply.github.com>
Date: Thu, 6 Oct 2022 11:02:00 +0200
Subject: [PATCH 1/4] buttonstates, api calls, popups
---
src/Umbraco.Web.UI.Client/schemas/api/api.yml | 29 ++++
.../schemas/generated-schema.ts | 35 +++++
.../dashboard-published-status.element.ts | 127 ++++++++++++++++--
.../shared/section-dashboards.element.ts | 9 +-
.../src/core/api/fetcher.ts | 2 +
.../domains/published-status.handlers.ts | 19 +++
.../temp-schema-generator/publishedstatus.ts | 27 ++++
7 files changed, 234 insertions(+), 14 deletions(-)
diff --git a/src/Umbraco.Web.UI.Client/schemas/api/api.yml b/src/Umbraco.Web.UI.Client/schemas/api/api.yml
index cf8864266f..f8df04d366 100644
--- a/src/Umbraco.Web.UI.Client/schemas/api/api.yml
+++ b/src/Umbraco.Web.UI.Client/schemas/api/api.yml
@@ -134,6 +134,35 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetails'
+ /published-cache/rebuild:
+ post:
+ operationId: PublishedCacheRebuild
+ parameters: []
+ responses:
+ '201':
+ description: 201 response
+ '400':
+ description: 400 response
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ProblemDetails'
+ /published-cache/collect:
+ get:
+ operationId: PublishedCacheCollect
+ responses:
+ '200':
+ description: 200 response
+ content:
+ application/json:
+ schema:
+ type: string
+ default:
+ description: default response
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ProblemDetails'
/server/status:
get:
operationId: GetStatus
diff --git a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts
index 2c4423664d..2352052cc2 100644
--- a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts
+++ b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts
@@ -28,6 +28,12 @@ export interface paths {
"/published-cache/reload": {
post: operations["PublishedCacheReload"];
};
+ "/published-cache/rebuild": {
+ post: operations["PublishedCacheRebuild"];
+ };
+ "/published-cache/collect": {
+ get: operations["PublishedCacheCollect"];
+ };
"/server/status": {
get: operations["GetStatus"];
};
@@ -453,6 +459,35 @@ export interface operations {
};
};
};
+ PublishedCacheRebuild: {
+ parameters: {};
+ responses: {
+ /** 201 response */
+ 201: unknown;
+ /** 400 response */
+ 400: {
+ content: {
+ "application/json": components["schemas"]["ProblemDetails"];
+ };
+ };
+ };
+ };
+ PublishedCacheCollect: {
+ responses: {
+ /** 200 response */
+ 200: {
+ content: {
+ "application/json": string;
+ };
+ };
+ /** default response */
+ default: {
+ content: {
+ "application/json": components["schemas"]["ProblemDetails"];
+ };
+ };
+ };
+ };
GetStatus: {
responses: {
/** 200 response */
diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
index 5b437546db..4d3eb4a8ed 100644
--- a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
+++ b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
@@ -3,8 +3,14 @@ import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
import { css, html, LitElement } from 'lit';
import { customElement, state } from 'lit/decorators.js';
-import { getPublishedCacheStatus, postPublishedCacheReload } from '../../../core/api/fetcher';
+import {
+ getPublishedCacheStatus,
+ postPublishedCacheReload,
+ postPublishedCacheRebuild,
+ getPublishedCacheCollect,
+} from '../../../core/api/fetcher';
import { UmbContextConsumerMixin } from '../../../core/context';
+import { UmbModalService } from '../../../core/services/modal';
import { UmbNotificationService } from '../../../core/services/notification';
import { UmbNotificationDefaultData } from '../../../core/services/notification/layouts/default';
@@ -28,7 +34,17 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
@state()
private _buttonState: UUIButtonState = undefined;
+ @state()
+ private _buttonStateReload: UUIButtonState = undefined;
+
+ @state()
+ private _buttonStateRebuild: UUIButtonState = undefined;
+
+ @state()
+ private _buttonStateCollect: UUIButtonState = undefined;
+
private _notificationService?: UmbNotificationService;
+ private _modalService?: UmbModalService;
constructor() {
super();
@@ -36,14 +52,18 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
this.consumeContext('umbNotificationService', (notificationService: UmbNotificationService) => {
this._notificationService = notificationService;
});
+ this.consumeContext('umbModalService', (modalService: UmbModalService) => {
+ this._modalService = modalService;
+ });
}
connectedCallback() {
super.connectedCallback();
-
this._getPublishedStatus();
}
+ // Refresh
+
private async _getPublishedStatus() {
try {
const { data } = await getPublishedCacheStatus({});
@@ -56,11 +76,9 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
}
}
}
-
private async _onRefreshCacheHandler() {
this._buttonState = 'waiting';
try {
- await postPublishedCacheReload({});
this._getPublishedStatus();
this._buttonState = 'success';
} catch (e) {
@@ -73,16 +91,90 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
}
}
+ //Reload
+
+ private async _reloadMemoryCache() {
+ this._buttonStateReload = 'waiting';
+ try {
+ await postPublishedCacheReload({});
+ this._buttonStateReload = 'success';
+ } catch (e) {
+ this._buttonStateReload = 'failed';
+ if (e instanceof postPublishedCacheReload.Error) {
+ const error = e.getActualType();
+ const data: UmbNotificationDefaultData = { message: error.data.detail ?? 'Something went wrong' };
+ this._notificationService?.peek('danger', { data });
+ }
+ }
+ }
private async _onReloadCacheHandler() {
- await undefined;
+ const modalHandler = this._modalService?.confirm({
+ headline: 'Reload',
+ content: html` Trigger a in-memory and local file cache reload on all servers. `,
+ color: 'danger',
+ confirmLabel: 'Continue',
+ });
+ modalHandler?.onClose.then(({ confirmed }) => {
+ if (confirmed) this._reloadMemoryCache();
+ });
}
+ // Rebuild
+
+ private async _rebuildDatabaseCache() {
+ this._buttonStateRebuild = 'waiting';
+ try {
+ await postPublishedCacheRebuild({});
+ this._buttonStateRebuild = 'success';
+ } catch (e) {
+ this._buttonStateRebuild = 'failed';
+ if (e instanceof postPublishedCacheRebuild.Error) {
+ const error = e.getActualType();
+ const data: UmbNotificationDefaultData = { message: error.data.detail ?? 'Something went wrong' };
+ this._notificationService?.peek('danger', { data });
+ }
+ }
+ }
private async _onRebuildCacheHandler() {
- await undefined;
+ const modalHandler = this._modalService?.confirm({
+ headline: 'Rebuild',
+ content: html` Rebuild content in cmsContentNu database table. Expensive.`,
+ color: 'danger',
+ confirmLabel: 'Continue',
+ });
+ modalHandler?.onClose.then(({ confirmed }) => {
+ if (confirmed) this._rebuildDatabaseCache();
+ });
+ }
+
+ //Collect
+
+ private async _CacheCollect() {
+ try {
+ const { data } = await getPublishedCacheCollect({});
+ console.log(data);
+ } catch (e) {
+ if (e instanceof postPublishedCacheRebuild.Error) {
+ const error = e.getActualType();
+ const data: UmbNotificationDefaultData = { message: error.data.detail ?? 'Something went wrong' };
+ this._notificationService?.peek('danger', { data });
+ }
+ }
}
private async _onSnapshotCacheHandler() {
- await undefined;
+ this._buttonStateCollect = 'waiting';
+ try {
+ this._CacheCollect();
+ this._buttonStateCollect = 'success';
+ } catch (e) {
+ this._buttonStateCollect = 'failed';
+ if (e instanceof postPublishedCacheRebuild.Error) {
+ const error = e.getActualType();
+ const data: UmbNotificationDefaultData = { message: error.data.detail ?? 'Something went wrong' };
+ this._notificationService?.peek('danger', { data });
+ }
+ }
}
render() {
@@ -106,7 +198,12 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
been properly refreshed, after some events triggered—which would indicate a minor Umbraco issue. (note:
triggers the reload on all servers in an LB environment).
- Reload Memory Cache
@@ -117,7 +214,12 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
expensive. Use it when reloading is not enough, and you think that the database cache has not been properly
generated—which would indicate some critical Umbraco issue.
- Rebuild Database Cache
@@ -127,7 +229,12 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
This button lets you trigger a NuCache snapshots collection (after running a fullCLR GC). Unless you know what
that means, you probably do not need to use it.
- Snapshot Internal Cache
diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-dashboards.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-dashboards.element.ts
index 3f2ec93220..69f06da640 100644
--- a/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-dashboards.element.ts
+++ b/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-dashboards.element.ts
@@ -25,16 +25,17 @@ export class UmbSectionDashboards extends UmbContextConsumerMixin(LitElement) {
height: 70px;
}
+ #scroll-container {
+ height: calc(100vh - 70px - 60px); // TODO: This is a temporary fix to get scrolling to work
+ // changed it so the height is correct but the fix is still not ideal. the 70px and 60px are the height of the blue top bar and the dashboard menu. Need a better solution still.
+ }
+
#router-slot {
width: 100%;
box-sizing: border-box;
padding: var(--uui-size-space-5);
display: block;
}
-
- #scroll-container {
- height: 500px; // TODO: This is a temporary fix to get scrolling to work
- }
`,
];
diff --git a/src/Umbraco.Web.UI.Client/src/core/api/fetcher.ts b/src/Umbraco.Web.UI.Client/src/core/api/fetcher.ts
index 4d8899883f..7a687f2826 100644
--- a/src/Umbraco.Web.UI.Client/src/core/api/fetcher.ts
+++ b/src/Umbraco.Web.UI.Client/src/core/api/fetcher.ts
@@ -23,3 +23,5 @@ export const getManifests = fetcher.path('/manifests').method('get').create();
export const getPackagesInstalled = fetcher.path('/manifests/packages/installed').method('get').create();
export const getPublishedCacheStatus = fetcher.path('/published-cache/status').method('get').create();
export const postPublishedCacheReload = fetcher.path('/published-cache/reload').method('post').create();
+export const postPublishedCacheRebuild = fetcher.path('/published-cache/rebuild').method('post').create();
+export const getPublishedCacheCollect = fetcher.path('/published-cache/collect').method('get').create();
diff --git a/src/Umbraco.Web.UI.Client/src/mocks/domains/published-status.handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/domains/published-status.handlers.ts
index 1cef7b9433..f1404e6771 100644
--- a/src/Umbraco.Web.UI.Client/src/mocks/domains/published-status.handlers.ts
+++ b/src/Umbraco.Web.UI.Client/src/mocks/domains/published-status.handlers.ts
@@ -21,4 +21,23 @@ export const handlers = [
ctx.status(201)
);
}),
+
+ rest.post(umbracoPath('/published-cache/rebuild'), async (_req, res, ctx) => {
+ await new Promise((resolve) => setTimeout(resolve, (Math.random() + 1) * 1000)); // simulate a delay of 1-2 seconds
+
+ return res(
+ // Respond with a 200 status code
+ ctx.status(201)
+ );
+ }),
+
+ rest.get(umbracoPath('/published-cache/collect'), (_req, res, ctx) => {
+ return res(
+ // Respond with a 200 status code
+ ctx.status(200),
+ ctx.json(
+ 'Database cache is ok. ContentStore contains 1 item and has 1 generation and 0 snapshot. MediaStore contains 5 items and has 1 generation and 0 snapshot.'
+ )
+ );
+ }),
];
diff --git a/src/Umbraco.Web.UI.Client/temp-schema-generator/publishedstatus.ts b/src/Umbraco.Web.UI.Client/temp-schema-generator/publishedstatus.ts
index 7079625166..35e8dc52c4 100644
--- a/src/Umbraco.Web.UI.Client/temp-schema-generator/publishedstatus.ts
+++ b/src/Umbraco.Web.UI.Client/temp-schema-generator/publishedstatus.ts
@@ -28,3 +28,30 @@ export class PublishedCacheReload {
@response({ status: 400 })
badRequest(@body body: ProblemDetails) {}
}
+
+@endpoint({
+ method: 'POST',
+ path: '/published-cache/rebuild',
+})
+export class PublishedCacheRebuild {
+ @request
+ request() {}
+
+ @response({ status: 201 })
+ success() {}
+
+ @response({ status: 400 })
+ badRequest(@body body: ProblemDetails) {}
+}
+
+@endpoint({
+ method: 'GET',
+ path: '/published-cache/collect',
+})
+export class PublishedCacheCollect {
+ @response({ status: 200 })
+ success(@body body: string) {}
+
+ @defaultResponse
+ default(@body body: ProblemDetails) {}
+}
From 1ac4fee398f00425968013a0a053434938c599a5 Mon Sep 17 00:00:00 2001
From: Lone Iversen <108085781+loivsen@users.noreply.github.com>
Date: Fri, 7 Oct 2022 10:01:18 +0200
Subject: [PATCH 2/4] cleanup, collect call doesnt return string
---
.../dashboard-published-status.element.ts | 42 ++++++-------------
.../domains/published-status.handlers.ts | 9 ++--
2 files changed, 15 insertions(+), 36 deletions(-)
diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
index 4d3eb4a8ed..499d103696 100644
--- a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
+++ b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
@@ -78,28 +78,22 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
}
private async _onRefreshCacheHandler() {
this._buttonState = 'waiting';
- try {
- this._getPublishedStatus();
- this._buttonState = 'success';
- } catch (e) {
- this._buttonState = 'failed';
- if (e instanceof postPublishedCacheReload.Error) {
- const error = e.getActualType();
- const data: UmbNotificationDefaultData = { message: error.data.detail ?? 'Something went wrong' };
- this._notificationService?.peek('danger', { data });
- }
- }
+ await this._getPublishedStatus();
+ this._buttonState = 'success';
}
//Reload
-
private async _reloadMemoryCache() {
this._buttonStateReload = 'waiting';
+ this._buttonState = 'waiting';
try {
await postPublishedCacheReload({});
this._buttonStateReload = 'success';
+ this._getPublishedStatus();
+ this._buttonState = 'success';
} catch (e) {
this._buttonStateReload = 'failed';
+ this._buttonState = 'failed';
if (e instanceof postPublishedCacheReload.Error) {
const error = e.getActualType();
const data: UmbNotificationDefaultData = { message: error.data.detail ?? 'Something went wrong' };
@@ -120,7 +114,6 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
}
// Rebuild
-
private async _rebuildDatabaseCache() {
this._buttonStateRebuild = 'waiting';
try {
@@ -148,33 +141,22 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
}
//Collect
-
- private async _CacheCollect() {
+ private async _cacheCollect() {
try {
- const { data } = await getPublishedCacheCollect({});
- console.log(data);
+ await getPublishedCacheCollect({});
+ this._buttonStateCollect = 'success';
} catch (e) {
- if (e instanceof postPublishedCacheRebuild.Error) {
+ this._buttonStateCollect = 'failed';
+ if (e instanceof getPublishedCacheCollect.Error) {
const error = e.getActualType();
const data: UmbNotificationDefaultData = { message: error.data.detail ?? 'Something went wrong' };
this._notificationService?.peek('danger', { data });
}
}
}
-
private async _onSnapshotCacheHandler() {
this._buttonStateCollect = 'waiting';
- try {
- this._CacheCollect();
- this._buttonStateCollect = 'success';
- } catch (e) {
- this._buttonStateCollect = 'failed';
- if (e instanceof postPublishedCacheRebuild.Error) {
- const error = e.getActualType();
- const data: UmbNotificationDefaultData = { message: error.data.detail ?? 'Something went wrong' };
- this._notificationService?.peek('danger', { data });
- }
- }
+ await this._cacheCollect();
}
render() {
diff --git a/src/Umbraco.Web.UI.Client/src/mocks/domains/published-status.handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/domains/published-status.handlers.ts
index f1404e6771..63c9207ddc 100644
--- a/src/Umbraco.Web.UI.Client/src/mocks/domains/published-status.handlers.ts
+++ b/src/Umbraco.Web.UI.Client/src/mocks/domains/published-status.handlers.ts
@@ -18,7 +18,7 @@ export const handlers = [
return res(
// Respond with a 200 status code
- ctx.status(201)
+ ctx.status(200)
);
}),
@@ -27,17 +27,14 @@ export const handlers = [
return res(
// Respond with a 200 status code
- ctx.status(201)
+ ctx.status(200)
);
}),
rest.get(umbracoPath('/published-cache/collect'), (_req, res, ctx) => {
return res(
// Respond with a 200 status code
- ctx.status(200),
- ctx.json(
- 'Database cache is ok. ContentStore contains 1 item and has 1 generation and 0 snapshot. MediaStore contains 5 items and has 1 generation and 0 snapshot.'
- )
+ ctx.status(200)
);
}),
];
From b71087cbeb0825429d5df27629b3e6fb8967ccf7 Mon Sep 17 00:00:00 2001
From: Lone Iversen <108085781+loivsen@users.noreply.github.com>
Date: Fri, 7 Oct 2022 11:05:43 +0200
Subject: [PATCH 3/4] onclose promise
---
.../published-status/dashboard-published-status.element.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
index 499d103696..8fa3ba2bd4 100644
--- a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
+++ b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
@@ -108,7 +108,7 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
color: 'danger',
confirmLabel: 'Continue',
});
- modalHandler?.onClose.then(({ confirmed }) => {
+ modalHandler?.onClose.then(({ confirmed }: any) => {
if (confirmed) this._reloadMemoryCache();
});
}
@@ -135,7 +135,7 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
color: 'danger',
confirmLabel: 'Continue',
});
- modalHandler?.onClose.then(({ confirmed }) => {
+ modalHandler?.onClose.then(({ confirmed }: any) => {
if (confirmed) this._rebuildDatabaseCache();
});
}
From b5f342b51b5c3ea3b04b66042fbcaee2210b17cc Mon Sep 17 00:00:00 2001
From: Lone Iversen <108085781+loivsen@users.noreply.github.com>
Date: Fri, 7 Oct 2022 11:09:49 +0200
Subject: [PATCH 4/4] onclose fix
---
.../published-status/dashboard-published-status.element.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
index 8fa3ba2bd4..4080314d5c 100644
--- a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
+++ b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/published-status/dashboard-published-status.element.ts
@@ -108,7 +108,7 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
color: 'danger',
confirmLabel: 'Continue',
});
- modalHandler?.onClose.then(({ confirmed }: any) => {
+ modalHandler?.onClose().then(({ confirmed }: any) => {
if (confirmed) this._reloadMemoryCache();
});
}
@@ -135,7 +135,7 @@ export class UmbDashboardPublishedStatusElement extends UmbContextConsumerMixin(
color: 'danger',
confirmLabel: 'Continue',
});
- modalHandler?.onClose.then(({ confirmed }: any) => {
+ modalHandler?.onClose().then(({ confirmed }: any) => {
if (confirmed) this._rebuildDatabaseCache();
});
}