From 972062a87b5c752368f11c8626ebe45981264b36 Mon Sep 17 00:00:00 2001 From: alansemenov Date: Thu, 8 Feb 2024 17:40:20 +0100 Subject: [PATCH] Fixed missing styling for readonly content + refactoring (#7243) --- .../js/app/browse/ContentBrowsePanel.ts | 9 -- .../assets/js/app/browse/ContentTreeGrid.ts | 22 ++--- .../assets/js/app/content/ContentSummary.ts | 14 +++ .../content/ContentSummaryAndCompareStatus.ts | 9 +- .../ContentSummaryAndCompareStatusViewer.ts | 5 +- .../app/event/ContentServerEventsHandler.ts | 43 --------- .../ContentSummaryAndCompareStatusFetcher.ts | 89 +++++++------------ .../styles/browse/content-tree-grid.less | 11 ++- 8 files changed, 69 insertions(+), 133 deletions(-) diff --git a/modules/lib/src/main/resources/assets/js/app/browse/ContentBrowsePanel.ts b/modules/lib/src/main/resources/assets/js/app/browse/ContentBrowsePanel.ts index e5ce0424bb..acb2e170d5 100644 --- a/modules/lib/src/main/resources/assets/js/app/browse/ContentBrowsePanel.ts +++ b/modules/lib/src/main/resources/assets/js/app/browse/ContentBrowsePanel.ts @@ -289,8 +289,6 @@ export class ContentBrowsePanel data.map((item: ContentServerChangeItem) => new DeletedContentItem(item.getContentId(), item.getPath()))); }); - handler.onContentPending((data: ContentSummaryAndCompareStatus[]) => this.handleContentPending(data)); - handler.onContentPublished((data: ContentSummaryAndCompareStatus[]) => this.handleContentPublished(data)); handler.onContentUnpublished((data: ContentSummaryAndCompareStatus[]) => this.handleContentUnpublished(data)); @@ -390,13 +388,6 @@ export class ContentBrowsePanel } } - private handleContentPending(data: ContentSummaryAndCompareStatus[]) { - if (ContentBrowsePanel.debug) { - console.debug('ContentBrowsePanel: pending', data); - } - this.doHandleContentUpdate(data); - } - private handleContentPublished(data: ContentSummaryAndCompareStatus[]) { if (ContentBrowsePanel.debug) { console.debug('ContentBrowsePanel: published', data); diff --git a/modules/lib/src/main/resources/assets/js/app/browse/ContentTreeGrid.ts b/modules/lib/src/main/resources/assets/js/app/browse/ContentTreeGrid.ts index cd5088dca0..bbd75b4ed8 100644 --- a/modules/lib/src/main/resources/assets/js/app/browse/ContentTreeGrid.ts +++ b/modules/lib/src/main/resources/assets/js/app/browse/ContentTreeGrid.ts @@ -292,16 +292,10 @@ export class ContentTreeGrid private processContentQueryResponse(node: TreeNode, data: ContentQueryResult, from: number): Q.Promise { - const contentSummaries: ContentSummary[] = data.getContents(); - const compareRequest: CompareContentRequest = CompareContentRequest.fromContentSummaries(contentSummaries); - return compareRequest.sendAndParse().then((compareResults: CompareContentResults) => { - const contents: ContentSummaryAndCompareStatus[] = node.getChildren().map((el) => { - return el.getData(); - }).slice(0, from).concat(this.contentFetcher.updateCompareStatus(contentSummaries, - compareResults)); - - return this.contentFetcher.updateReadOnly(contents).then(() => { + return this.contentFetcher + .updateReadonlyAndCompareStatus(data.getContents()) + .then((contents: ContentSummaryAndCompareStatus[]) => { const meta: ResultMetadata = data.getMetadata(); if (this.isEmptyNodeNeeded(meta, from)) { contents.push(new ContentSummaryAndCompareStatus()); @@ -309,8 +303,6 @@ export class ContentTreeGrid node.setMaxChildren(meta.getTotalHits()); return contents; }); - - }); } private doFetchChildren(parentNode: TreeNode): Q.Promise { @@ -561,19 +553,19 @@ export class ContentTreeGrid let cssClasses: string = ''; - if (!!node.getData().getContentSummary() && node.getData().getContentSummary().isDataInherited()) { + if (node.getData().getContentSummary()?.isDataInherited()) { cssClasses += 'data-inherited'; } - if (!!node.getData().getContentSummary() && node.getData().getContentSummary().isSortInherited()) { + if (node.getData().getContentSummary()?.isSortInherited()) { cssClasses += ' sort-inherited'; } if (node.getData().isReadOnly()) { - cssClasses += `readonly' title='${i18n('field.readOnly')}'`; + cssClasses += ' readonly'; } - return {cssClasses: cssClasses}; + return {cssClasses: cssClasses.trim()}; } getSelectedOrHighlightedItems(): ContentSummaryAndCompareStatus[] { diff --git a/modules/lib/src/main/resources/assets/js/app/content/ContentSummary.ts b/modules/lib/src/main/resources/assets/js/app/content/ContentSummary.ts index 5572301d75..ff2c0fc9fd 100644 --- a/modules/lib/src/main/resources/assets/js/app/content/ContentSummary.ts +++ b/modules/lib/src/main/resources/assets/js/app/content/ContentSummary.ts @@ -83,6 +83,8 @@ export class ContentSummary { private readonly variantOf: string; + private readOnly: boolean; + constructor(builder: ContentSummaryBuilder) { this.name = builder.name; this.displayName = builder.displayName; @@ -118,6 +120,7 @@ export class ContentSummary { this.originalParentPath = builder.originalParentPath; this.originalName = builder.originalName; this.variantOf = builder.variantOf; + this.readOnly = builder.readOnly; } static fromJson(json: ContentSummaryJson): ContentSummary { @@ -312,6 +315,14 @@ export class ContentSummary { return !!this.variantOf; } + setReadOnly(value: boolean) { + this.readOnly = value; + } + + isReadOnly(): boolean { + return !!this.readOnly; + } + private isInheritedByType(type: ContentInheritType): boolean { return this.isInherited() && this.inherit.some((inheritType: ContentInheritType) => inheritType === type); } @@ -490,6 +501,8 @@ export class ContentSummaryBuilder { variantOf: string; + readOnly: boolean; + constructor(source?: ContentSummary) { if (source) { this.id = source.getId(); @@ -525,6 +538,7 @@ export class ContentSummaryBuilder { this.originalParentPath = source.getOriginalParentPath(); this.originalName = source.getOriginalName(); this.variantOf = source.getVariantOf(); + this.readOnly = source.isReadOnly(); } } diff --git a/modules/lib/src/main/resources/assets/js/app/content/ContentSummaryAndCompareStatus.ts b/modules/lib/src/main/resources/assets/js/app/content/ContentSummaryAndCompareStatus.ts index 7c743da7ac..91012076fb 100644 --- a/modules/lib/src/main/resources/assets/js/app/content/ContentSummaryAndCompareStatus.ts +++ b/modules/lib/src/main/resources/assets/js/app/content/ContentSummaryAndCompareStatus.ts @@ -23,8 +23,6 @@ export class ContentSummaryAndCompareStatus implements ViewItem, Cloneable { private publishStatus: PublishStatus; - private readOnly: boolean; - private renderable: boolean = false; public static fromContentSummary(contentSummary: ContentSummary) { @@ -276,11 +274,11 @@ export class ContentSummaryAndCompareStatus implements ViewItem, Cloneable { } setReadOnly(value: boolean) { - this.readOnly = value; + this.contentSummary?.setReadOnly(value); } isReadOnly(): boolean { - return !!this.readOnly; + return !!this.contentSummary ? this.contentSummary.isReadOnly() : false; } isPendingDelete(): boolean { @@ -326,7 +324,7 @@ export class ContentSummaryAndCompareStatus implements ViewItem, Cloneable { canBeMarkedAsReady(): boolean { const contentSummary = this.getContentSummary(); - return !this.isOnline() && !this.isPendingDelete() && contentSummary.isValid() && !contentSummary.isReady(); + return !this.isOnline() && contentSummary.isValid() && !contentSummary.isReady(); } clone(): ContentSummaryAndCompareStatus { @@ -336,7 +334,6 @@ export class ContentSummaryAndCompareStatus implements ViewItem, Cloneable { this.compareStatus, this.publishStatus ); - clone.setReadOnly(this.readOnly); clone.setRenderable(this.renderable); return clone; } diff --git a/modules/lib/src/main/resources/assets/js/app/content/ContentSummaryAndCompareStatusViewer.ts b/modules/lib/src/main/resources/assets/js/app/content/ContentSummaryAndCompareStatusViewer.ts index 89b4835c76..ecacf2e92c 100644 --- a/modules/lib/src/main/resources/assets/js/app/content/ContentSummaryAndCompareStatusViewer.ts +++ b/modules/lib/src/main/resources/assets/js/app/content/ContentSummaryAndCompareStatusViewer.ts @@ -73,12 +73,15 @@ export class ContentSummaryAndCompareStatusViewer const invalid: boolean = !contentSummary.isValid() || !contentSummary.getDisplayName() || contentSummary.getName().isUnnamed(); const isPendingDelete: boolean = contentSummary.getContentState().isPendingDelete(); this.toggleClass('invalid', invalid); - this.toggleClass('pending-delete', isPendingDelete); this.toggleClass('readonly', object.isReadOnly()); this.toggleClass('has-origin-project', object.hasOriginProject()); this.toggleClass('data-inherited', object.isDataInherited()); this.toggleClass('icon-variant', object.isVariant()); + if (object.isReadOnly()) { + this.setTitle(i18n('field.readOnly')); + } + if (!invalid && !object.isOnline() && !object.isPendingDelete()) { const workflowState = this.resolveWorkflowState(object); this.getNamesAndIconView().setIconToolTip(workflowState); diff --git a/modules/lib/src/main/resources/assets/js/app/event/ContentServerEventsHandler.ts b/modules/lib/src/main/resources/assets/js/app/event/ContentServerEventsHandler.ts index 1b09ac8118..3a4409873c 100644 --- a/modules/lib/src/main/resources/assets/js/app/event/ContentServerEventsHandler.ts +++ b/modules/lib/src/main/resources/assets/js/app/event/ContentServerEventsHandler.ts @@ -46,8 +46,6 @@ export class ContentServerEventsHandler { private contentUnpublishListeners: ((data: ContentSummaryAndCompareStatus[]) => void)[] = []; - private contentPendingListeners: ((data: ContentSummaryAndCompareStatus[]) => void)[] = []; - private contentDuplicateListeners: ((data: ContentSummaryAndCompareStatus[]) => void)[] = []; private contentSortListeners: ((data: ContentSummaryAndCompareStatus[]) => void)[] = []; @@ -156,27 +154,6 @@ export class ContentServerEventsHandler { this.notifyContentDeleted(changeItems); } - private handleContentPending(data: ContentSummaryAndCompareStatus[]) { - if (ContentServerEventsHandler.debug) { - console.debug('ContentServerEventsHandler: pending', data); - } - let contentDeletedEvent = new ContentDeletedEvent(); - - data.filter((el) => { - return !!el; // not sure if this check is necessary - }).forEach((el) => { - - if (CompareStatusChecker.isPendingDelete(el.getCompareStatus())) { - contentDeletedEvent.addPendingItem(el); - } else { - contentDeletedEvent.addUndeletedItem(el); - } - }); - contentDeletedEvent.fire(); - - this.notifyContentPending(data); - } - private handleContentDuplicated(data: ContentSummaryAndCompareStatus[]) { if (ContentServerEventsHandler.debug) { console.debug('ContentServerEventsHandler: duplicated', data); @@ -392,23 +369,6 @@ export class ContentServerEventsHandler { }); } - onContentPending(listener: (data: ContentSummaryAndCompareStatus[]) => void) { - this.contentPendingListeners.push(listener); - } - - unContentPending(listener: (data: ContentSummaryAndCompareStatus[]) => void) { - this.contentPendingListeners = - this.contentPendingListeners.filter((currentListener: (data: ContentSummaryAndCompareStatus[]) => void) => { - return currentListener !== listener; - }); - } - - private notifyContentPending(data: ContentSummaryAndCompareStatus[]) { - this.contentPendingListeners.forEach((listener: (data: ContentSummaryAndCompareStatus[]) => void) => { - listener(data); - }); - } - onContentSorted(listener: (data: ContentSummaryAndCompareStatus[]) => void) { this.contentSortListeners.push(listener); } @@ -544,9 +504,6 @@ export class ContentServerEventsHandler { // deleting from master is unpublish this.handleContentUnpublished(summaries); break; - case NodeServerChangeType.PENDING: - this.handleContentPending(summaries); - break; case NodeServerChangeType.DUPLICATE: this.handleContentDuplicated(summaries); break; diff --git a/modules/lib/src/main/resources/assets/js/app/resource/ContentSummaryAndCompareStatusFetcher.ts b/modules/lib/src/main/resources/assets/js/app/resource/ContentSummaryAndCompareStatusFetcher.ts index 2c3df75045..37163aa3c0 100644 --- a/modules/lib/src/main/resources/assets/js/app/resource/ContentSummaryAndCompareStatusFetcher.ts +++ b/modules/lib/src/main/resources/assets/js/app/resource/ContentSummaryAndCompareStatusFetcher.ts @@ -51,22 +51,12 @@ export class ContentSummaryAndCompareStatusFetcher { .setOrder(childOrder) .setContentRootPath(this.contentRootPath) .sendAndParse() - .then((response: ContentResponse) => { - return CompareContentRequest.fromContentSummaries(response.getContents(), null, this.contentRootPath).sendAndParse().then( - (compareResults: CompareContentResults) => { - const contents: ContentSummaryAndCompareStatus[] = this.updateCompareStatus(response.getContents(), compareResults); - - const promises: Q.Promise[] = []; - promises.push(this.updateReadOnly(contents)); - - return Q.all([promises]).then(() => { - return new ContentResponse( - contents, - response.getMetadata() - ); - }); - }); - }); + .then((response: ContentResponse) => + this.updateReadonlyAndCompareStatus(response.getContents()) + .then((contents: ContentSummaryAndCompareStatus[]) => + new ContentResponse(contents, response.getMetadata()) + ) + ); } fetch(contentId: ContentId, projectName?: string): Q.Promise { @@ -74,30 +64,12 @@ export class ContentSummaryAndCompareStatusFetcher { .setRequestProjectName(projectName) .setContentRootPath(this.contentRootPath) .sendAndParse() - .then((content: Content) => { - return CompareContentRequest.fromContentSummaries([content], projectName, this.contentRootPath).sendAndParse() - .then((compareResults: CompareContentResults) => { - const result: ContentSummaryAndCompareStatus = this.updateCompareStatus([content], - compareResults)[0]; - - const promises: Q.Promise[] = []; - promises.push(this.updateReadOnly([result], projectName)); - - return Q.all(promises).then(() => { - return result; - }); - }); - }); - + .then((content: Content) => this.fetchByContent(content)); } fetchByContent(content: Content): Q.Promise { - return CompareContentRequest.fromContentSummaries([content], null, this.contentRootPath).sendAndParse().then( - (compareResults: CompareContentResults) => { - const result: ContentSummaryAndCompareStatus = this.updateCompareStatus([content], compareResults)[0]; - - return this.updateReadOnly([result]).then(() => result); - }); + return this.updateReadonlyAndCompareStatus([content]) + .then((contents: ContentSummaryAndCompareStatus[]) => contents[0]); } fetchByIds(ids: ContentId[]): Q.Promise { @@ -105,20 +77,13 @@ export class ContentSummaryAndCompareStatusFetcher { return Q([]); } - return new GetContentSummaryByIds(ids).setContentRootPath(this.contentRootPath).sendAndParse().then( - (contentSummaries: ContentSummary[]) => { - - return CompareContentRequest.fromContentSummaries(contentSummaries, null, this.contentRootPath).sendAndParse().then( - (compareResults: CompareContentResults) => { - const contents: ContentSummaryAndCompareStatus[] = this.updateCompareStatus(contentSummaries, compareResults); - const promises: Q.Promise[] = []; - promises.push(this.updateReadOnly(contents)); - - return Q.all(promises).then(() => { - return contents; - }); - }); - }); + return new GetContentSummaryByIds(ids) + .setContentRootPath(this.contentRootPath) + .sendAndParse() + .then((contentSummaries: ContentSummary[]) => + this.updateReadonlyAndCompareStatus(contentSummaries) + .then((contents: ContentSummaryAndCompareStatus[]) => contents) + ); } fetchStatus(contentSummaries: ContentSummary[]): Q.Promise { @@ -133,10 +98,8 @@ export class ContentSummaryAndCompareStatusFetcher { .setContentRootPath(this.contentRootPath) .setParentId(parentContentId) .setOrder(order) - .sendAndParse().then( - (response: ContentId[]) => { - return response; - }); + .sendAndParse() + .then((response: ContentId[]) => response); } updateCompareStatus(contentSummaries: ContentSummary[], compareResults: CompareContentResults): ContentSummaryAndCompareStatus[] { @@ -151,13 +114,13 @@ export class ContentSummaryAndCompareStatusFetcher { return list; } - updateReadOnly(contents: ContentSummaryAndCompareStatus[], projectName?: string): Q.Promise { - return new IsContentReadOnlyRequest(contents.map(content => content.getContentId())) + updateReadOnly(contentSummaries: ContentSummary[], projectName?: string): Q.Promise { + return new IsContentReadOnlyRequest(contentSummaries.map(content => content.getContentId())) .setRequestProjectName(projectName) .setContentRootPath(this.contentRootPath) .sendAndParse().then((readOnlyContentIds: string[]) => { readOnlyContentIds.forEach((id: string) => { - contents.some(content => { + contentSummaries.some(content => { if (content.getId() === id) { content.setReadOnly(true); return true; @@ -187,4 +150,14 @@ export class ContentSummaryAndCompareStatusFetcher { return Q(null); }); } + + updateReadonlyAndCompareStatus(contentSummaries: ContentSummary[], projectName?: string): Q.Promise { + return this.updateReadOnly(contentSummaries, projectName) + .then(() => { + return CompareContentRequest + .fromContentSummaries(contentSummaries, projectName, this.contentRootPath) + .sendAndParse() + .then((compareResults: CompareContentResults) => Q(this.updateCompareStatus(contentSummaries, compareResults))); + }); + } } diff --git a/modules/lib/src/main/resources/assets/styles/browse/content-tree-grid.less b/modules/lib/src/main/resources/assets/styles/browse/content-tree-grid.less index b50ea94f63..cab6f1bdb9 100644 --- a/modules/lib/src/main/resources/assets/styles/browse/content-tree-grid.less +++ b/modules/lib/src/main/resources/assets/styles/browse/content-tree-grid.less @@ -50,7 +50,16 @@ z-index: 1; } - .names-and-icon-viewer.data-inherited { + &.readonly { + > * { + opacity: 0.25; + } + .display-name { + font-style: italic; + } + } + + &:not(.readonly) .names-and-icon-viewer.data-inherited { opacity: 0.5; }