Skip to content

Commit

Permalink
Fixed missing styling for readonly content + refactoring (#7243)
Browse files Browse the repository at this point in the history
  • Loading branch information
alansemenov committed Mar 1, 2024
1 parent 4a01df5 commit 972062a
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,17 @@ export class ContentTreeGrid
private processContentQueryResponse(node: TreeNode<ContentSummaryAndCompareStatus>,
data: ContentQueryResult<ContentSummary, ContentSummaryJson>,
from: number): Q.Promise<ContentSummaryAndCompareStatus[]> {
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());
}
node.setMaxChildren(meta.getTotalHits());
return contents;
});

});
}

private doFetchChildren(parentNode: TreeNode<ContentSummaryAndCompareStatus>): Q.Promise<ContentSummaryAndCompareStatus[]> {
Expand Down Expand Up @@ -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[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -490,6 +501,8 @@ export class ContentSummaryBuilder {

variantOf: string;

readOnly: boolean;

constructor(source?: ContentSummary) {
if (source) {
this.id = source.getId();
Expand Down Expand Up @@ -525,6 +538,7 @@ export class ContentSummaryBuilder {
this.originalParentPath = source.getOriginalParentPath();
this.originalName = source.getOriginalName();
this.variantOf = source.getVariantOf();
this.readOnly = source.isReadOnly();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -336,7 +334,6 @@ export class ContentSummaryAndCompareStatus implements ViewItem, Cloneable {
this.compareStatus,
this.publishStatus
);
clone.setReadOnly(this.readOnly);
clone.setRenderable(this.renderable);
return clone;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)[] = [];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,74 +51,39 @@ export class ContentSummaryAndCompareStatusFetcher {
.setOrder(childOrder)
.setContentRootPath(this.contentRootPath)
.sendAndParse()
.then((response: ContentResponse<ContentSummary>) => {
return CompareContentRequest.fromContentSummaries(response.getContents(), null, this.contentRootPath).sendAndParse().then(
(compareResults: CompareContentResults) => {
const contents: ContentSummaryAndCompareStatus[] = this.updateCompareStatus(response.getContents(), compareResults);

const promises: Q.Promise<boolean>[] = [];
promises.push(this.updateReadOnly(contents));

return Q.all([promises]).then(() => {
return new ContentResponse<ContentSummaryAndCompareStatus>(
contents,
response.getMetadata()
);
});
});
});
.then((response: ContentResponse<ContentSummary>) =>
this.updateReadonlyAndCompareStatus(response.getContents())
.then((contents: ContentSummaryAndCompareStatus[]) =>
new ContentResponse<ContentSummaryAndCompareStatus>(contents, response.getMetadata())
)
);
}

fetch(contentId: ContentId, projectName?: string): Q.Promise<ContentSummaryAndCompareStatus> {
return new GetContentByIdRequest(contentId)
.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<boolean>[] = [];
promises.push(this.updateReadOnly([result], projectName));

return Q.all(promises).then(() => {
return result;
});
});
});

.then((content: Content) => this.fetchByContent(content));
}

fetchByContent(content: Content): Q.Promise<ContentSummaryAndCompareStatus> {
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<ContentSummaryAndCompareStatus[]> {
if (ids.length === 0) {
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<boolean>[] = [];
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<ContentSummaryAndCompareStatus[]> {
Expand All @@ -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[] {
Expand All @@ -151,13 +114,13 @@ export class ContentSummaryAndCompareStatusFetcher {
return list;
}

updateReadOnly(contents: ContentSummaryAndCompareStatus[], projectName?: string): Q.Promise<boolean> {
return new IsContentReadOnlyRequest(contents.map(content => content.getContentId()))
updateReadOnly(contentSummaries: ContentSummary[], projectName?: string): Q.Promise<boolean> {
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;
Expand Down Expand Up @@ -187,4 +150,14 @@ export class ContentSummaryAndCompareStatusFetcher {
return Q(null);
});
}

updateReadonlyAndCompareStatus(contentSummaries: ContentSummary[], projectName?: string): Q.Promise<ContentSummaryAndCompareStatus[]> {
return this.updateReadOnly(contentSummaries, projectName)
.then(() => {
return CompareContentRequest
.fromContentSummaries(contentSummaries, projectName, this.contentRootPath)
.sendAndParse()
.then((compareResults: CompareContentResults) => Q(this.updateCompareStatus(contentSummaries, compareResults)));
});
}
}
Loading

0 comments on commit 972062a

Please sign in to comment.