Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions cms-api/src/main/java/com/condation/cms/api/db/NodeStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.condation.cms.api.db;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 - 2026 CondationCMS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import com.condation.cms.api.Constants;
import com.condation.cms.api.utils.DateRange;
import java.time.Instant;
import java.util.Date;
import java.util.Map;

/**
*
* @author thmar
*/
public class NodeStatus {

public static Status get (Map<String, Object> meta) {
var published = (boolean) meta.getOrDefault(Constants.MetaFields.PUBLISHED, false);
var publish_date = (Date) meta.getOrDefault(Constants.MetaFields.PUBLISH_DATE, Date.from(Instant.now()));

var unpublish_date = (Date) meta.getOrDefault(Constants.MetaFields.UNPUBLISH_DATE, null);

return new Status(published, DateRange.isNowWithin(publish_date, unpublish_date));
}

public static record Status (boolean published, boolean withinSchedule){};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.condation.cms.api.Constants;
import com.condation.cms.api.auth.Permissions;
import com.condation.cms.api.db.DB;
import com.condation.cms.api.db.NodeStatus;
import com.condation.cms.api.db.cms.ReadOnlyFile;
import com.condation.cms.api.eventbus.events.InvalidateContentCacheEvent;
import com.condation.cms.api.eventbus.events.ReIndexContentMetaDataEvent;
Expand Down Expand Up @@ -77,6 +78,7 @@ public Object getContent(Map<String, Object> parameters) {
ContentFileParser parser = new ContentFileParser(contentFile);
result.put("content", parser.getContent());
result.put("meta", parser.getHeader());
result.put("status", NodeStatus.get(parser.getHeader()));
} catch (IOException ex) {
log.error("", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export async function runAction(params) {
point.style.display = "block";
focal.x = parseFloat(relX);
focal.y = parseFloat(relY);
// Ausgabe
console.log(`Focal Point: x: ${relX}, y: ${relY}`);
});
}
});
Expand Down
49 changes: 49 additions & 0 deletions modules/ui-module/src/main/resources/manager/css/manager.css
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,53 @@ body.resizing-sidebar {
.cherry-editor-container .cm-editor {
height: 100%;
overflow: auto;
}

.cms-node-status-published{
--bs-btn-color:#fff;
--bs-btn-bg:#5cb85c;
--bs-btn-border-color:#5cb85c;
--bs-btn-hover-color:#fff;
--bs-btn-hover-bg:#4e9c4e;
--bs-btn-hover-border-color:#4a934a;
--bs-btn-focus-shadow-rgb:116,195,116;
--bs-btn-active-color:#fff;
--bs-btn-active-bg:#4a934a;
--bs-btn-active-border-color:#458a45;
--bs-btn-active-shadow:inset 0 3px 5px rgba(0, 0, 0, 0.125);
--bs-btn-disabled-color:#fff;
--bs-btn-disabled-bg:#5cb85c;
--bs-btn-disabled-border-color:#5cb85c
}
.cms-node-status-published-not-visible{
--bs-btn-color:#fff;
--bs-btn-bg:#5bc0de;
--bs-btn-border-color:#5bc0de;
--bs-btn-hover-color:#fff;
--bs-btn-hover-bg:#4da3bd;
--bs-btn-hover-border-color:#499ab2;
--bs-btn-focus-shadow-rgb:116,201,227;
--bs-btn-active-color:#fff;
--bs-btn-active-bg:#499ab2;
--bs-btn-active-border-color:#4490a7;
--bs-btn-active-shadow:inset 0 3px 5px rgba(0, 0, 0, 0.125);
--bs-btn-disabled-color:#fff;
--bs-btn-disabled-bg:#5bc0de;
--bs-btn-disabled-border-color:#5bc0de
}
.cms-node-status-unpublished{
--bs-btn-color:#fff;
--bs-btn-bg:#ffc107;
--bs-btn-border-color:#ffc107;
--bs-btn-hover-color:#fff;
--bs-btn-hover-bg:#d9a406;
--bs-btn-hover-border-color:#cc9a06;
--bs-btn-focus-shadow-rgb:255,202,44;
--bs-btn-active-color:#fff;
--bs-btn-active-bg:#cc9a06;
--bs-btn-active-border-color:#bf9105;
--bs-btn-active-shadow:inset 0 3px 5px rgba(0, 0, 0, 0.125);
--bs-btn-disabled-color:#fff;
--bs-btn-disabled-bg:#ffc107;
--bs-btn-disabled-border-color:#ffc107
}
3 changes: 2 additions & 1 deletion modules/ui-module/src/main/resources/manager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
baseUrl: '{{ managerBaseURL }}',
contextPath: '{{ contextPath }}',
siteId: '{{ siteId }}',
previewUrl: "{{ links.createUrl('/?preview=manager&preview-token22=' + previewToken) | raw }}"
}
</script>
<link rel="stylesheet" href="{{ links.createUrl('/manager/css/manager.css') }}" />
Expand Down Expand Up @@ -211,7 +212,7 @@
<div id="content" class="flex-grow-1 d-flex flex-column overflow-hidden">
<div id="previewWrapper" class="flex-grow-1 position-relative">
<iframe id="contentPreview" class="position-absolute top-0 start-0 w-100 h-100 border-0"
src="{{ links.createUrl('/?preview=manager&preview-token22=' + previewToken) | raw }}"></iframe>
srcalt="{{ links.createUrl('/?preview=manager&preview-token22=' + previewToken) | raw }}"></iframe>

<!-- Overlay -->
<div id="previewOverlay"
Expand Down
48 changes: 27 additions & 21 deletions modules/ui-module/src/main/resources/manager/js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ document.addEventListener("DOMContentLoaded", function () {
});
}, 5 * 60 * 1000);
const iframe = document.getElementById('contentPreview');
iframe.addEventListener("load", previewLoadedHandler);
const urlParams = new URLSearchParams(window.location.search);
const pageUrl = urlParams.get('page');
/*
page param is use for deeplinks when changing translation
*/
if (pageUrl) {
loadPreview(pageUrl);
// Clean the URL
Expand All @@ -50,29 +54,31 @@ document.addEventListener("DOMContentLoaded", function () {
}
else {
const preview = UIStateManager.getTabState("preview", null);
if (preview) {
if (preview.siteId === window.manager.siteId) {
loadPreview(preview.url);
}
if (preview && preview.siteId === window.manager.siteId) {
loadPreview(preview.url);
}
}
iframe.addEventListener("load", () => {
EventBus.emit("preview:loaded", {});
try {
const currentUrl = iframe.contentWindow.location.href;
const url = new URL(currentUrl);
const preview_url = url.pathname + url.search;
const preview_update = {
url: preview_url,
siteId: window.manager.siteId
};
UIStateManager.setTabState("preview", preview_update);
updateStateButton();
}
catch (e) {
console.log(e);
else {
loadPreview(window.manager.previewUrl);
}
});
}
initMessageHandlers();
});
const previewLoadedHandler = () => {
EventBus.emit("preview:loaded", {});
try {
const iframe = document.getElementById('contentPreview');
const currentUrl = iframe.contentWindow.location.href;
const url = new URL(currentUrl);
const preview_url = url.pathname + url.search;
const preview_update = {
url: preview_url,
siteId: window.manager.siteId
};
UIStateManager.setTabState("preview", preview_update);
updateStateButton();
}
catch (e) {
console.log(e);
}
};
// DOMContentLoaded end
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ const getData = (context) => {
};
}
});
console.log("send: " + data);
return data;
};
const init = (context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ const cmsImageSelection = window.Cherry.createMenuHook("Image", {
mediaFormats.forEach((format) => {
formatOptions[format.name] = format.name;
});
console.log("Media Formats", mediaFormats, formatOptions);
var selectedFormat = await alertSelect({
title: i18n.t("form.media.format.title", "Select Media Format"),
values: formatOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
* #L%
*/
export function updateStateButton(): void;
export function isPagePublishedExpired(contentResponse: any): boolean;
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import { getContentNode, setMeta, getContent } from '@cms/modules/rpc/rpc-content.js';
import { getPreviewUrl } from '@cms/modules/preview.utils.js';
import { getContent, getContentNode } from '@cms/modules/rpc/rpc-content.js';
export function updateStateButton() {
var previewUrl = getPreviewUrl();
;
Expand All @@ -36,37 +36,31 @@ export function updateStateButton() {
getContent({
uri: contentNode.result.uri
}).then((getContentResponse) => {
var published = getContentResponse?.result?.meta?.published;
if (published) {
if (isPagePublishedExpired(getContentResponse)) {
document.querySelector('#cms-btn-status').classList.remove('btn-warning');
document.querySelector('#cms-btn-status').classList.remove('btn-success');
document.querySelector('#cms-btn-status').classList.add('btn-info');
}
else {
document.querySelector('#cms-btn-status').classList.remove('btn-warning');
document.querySelector('#cms-btn-status').classList.remove('btn-info');
document.querySelector('#cms-btn-status').classList.add('btn-success');
}
}
else {
document.querySelector('#cms-btn-status').classList.remove('btn-success');
document.querySelector('#cms-btn-status').classList.remove('btn-info');
document.querySelector('#cms-btn-status').classList.add('btn-warning');
}
updateNodeStatus(getContentResponse);
});
});
}
export function isPagePublishedExpired(contentResponse) {
const publishDateStr = contentResponse?.result?.meta?.publish_date;
const unpublishDateStr = contentResponse?.result?.meta?.unpublish_date;
const now = new Date();
const publishDate = publishDateStr ? new Date(publishDateStr) : null;
const unpublishDate = unpublishDateStr ? new Date(unpublishDateStr) : null;
// page is published if:
// - publishDate empty or in the past
// - und unpublishDate empty or in the future
const isPublished = (!publishDate || publishDate <= now) &&
(!unpublishDate || unpublishDate > now);
return !isPublished;
function updateNodeStatus(getContentResponse) {
const statusBtn = document.querySelector('#cms-btn-status');
if (!statusBtn)
return;
// Alle cms-node-status-* Klassen entfernen
Array.from(statusBtn.classList).forEach(className => {
if (className.startsWith('cms-node-status-')) {
statusBtn.classList.remove(className);
}
});
var published = getContentResponse?.result?.status?.published;
// Status bestimmen (Provider-fähig)
let status;
if (!published) {
status = 'unpublished';
}
else if (!getContentResponse?.result?.status?.withinSchedule) {
status = 'published-not-visible';
}
else {
status = 'published';
}
statusBtn.classList.add(`cms-node-status-${status}`);
}
6 changes: 6 additions & 0 deletions modules/ui-module/src/main/ts/README
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

```shell
tsc
```

## publish

```shell
npm publish
```
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export async function runAction(params) {
point.style.display = "block";
focal.x = parseFloat(relX);
focal.y = parseFloat(relY);
// Ausgabe
console.log(`Focal Point: x: ${relX}, y: ${relY}`);
});
}
});
Expand Down
48 changes: 27 additions & 21 deletions modules/ui-module/src/main/ts/dist/js/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ document.addEventListener("DOMContentLoaded", function () {
});
}, 5 * 60 * 1000);
const iframe = document.getElementById('contentPreview');
iframe.addEventListener("load", previewLoadedHandler);
const urlParams = new URLSearchParams(window.location.search);
const pageUrl = urlParams.get('page');
/*
page param is use for deeplinks when changing translation
*/
if (pageUrl) {
loadPreview(pageUrl);
// Clean the URL
Expand All @@ -50,29 +54,31 @@ document.addEventListener("DOMContentLoaded", function () {
}
else {
const preview = UIStateManager.getTabState("preview", null);
if (preview) {
if (preview.siteId === window.manager.siteId) {
loadPreview(preview.url);
}
if (preview && preview.siteId === window.manager.siteId) {
loadPreview(preview.url);
}
}
iframe.addEventListener("load", () => {
EventBus.emit("preview:loaded", {});
try {
const currentUrl = iframe.contentWindow.location.href;
const url = new URL(currentUrl);
const preview_url = url.pathname + url.search;
const preview_update = {
url: preview_url,
siteId: window.manager.siteId
};
UIStateManager.setTabState("preview", preview_update);
updateStateButton();
}
catch (e) {
console.log(e);
else {
loadPreview(window.manager.previewUrl);
}
});
}
initMessageHandlers();
});
const previewLoadedHandler = () => {
EventBus.emit("preview:loaded", {});
try {
const iframe = document.getElementById('contentPreview');
const currentUrl = iframe.contentWindow.location.href;
const url = new URL(currentUrl);
const preview_url = url.pathname + url.search;
const preview_update = {
url: preview_url,
siteId: window.manager.siteId
};
UIStateManager.setTabState("preview", preview_update);
updateStateButton();
}
catch (e) {
console.log(e);
}
};
// DOMContentLoaded end
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ const getData = (context) => {
};
}
});
console.log("send: " + data);
return data;
};
const init = (context) => {
Expand Down
Loading