-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
206 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,23 @@ | ||
import {ArchiveItemPreviewToolbar} from './ArchiveItemPreviewToolbar'; | ||
import {IsRenderableRequest} from 'lib-contentstudio/app/resource/IsRenderableRequest'; | ||
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler'; | ||
import {ContentPath} from 'lib-contentstudio/app/content/ContentPath'; | ||
import {ArchiveContentViewItem} from './ArchiveContentViewItem'; | ||
import {ContentItemPreviewPanel} from 'lib-contentstudio/app/view/ContentItemPreviewPanel'; | ||
import {ContentSummaryAndCompareStatus} from 'lib-contentstudio/app/content/ContentSummaryAndCompareStatus'; | ||
import {StatusCode} from '@enonic/lib-admin-ui/rest/StatusCode'; | ||
import {PreviewActionHelper} from 'lib-contentstudio/app/action/PreviewActionHelper'; | ||
|
||
export class ArchiveItemPreviewPanel | ||
extends ContentItemPreviewPanel { | ||
|
||
protected item: ArchiveContentViewItem; | ||
|
||
private renderableItems: Map<string, boolean> = new Map<string, boolean>(); | ||
|
||
constructor() { | ||
super(ContentPath.ARCHIVE_ROOT); | ||
} | ||
|
||
createToolbar(): ArchiveItemPreviewToolbar { | ||
return new ArchiveItemPreviewToolbar(); | ||
} | ||
|
||
setItem(item: ArchiveContentViewItem): void { | ||
if (this.renderableItems.has(item.getId())) { | ||
this.debouncedSetItem(item); | ||
} else { | ||
new IsRenderableRequest(item.getContentSummary()) | ||
.sendAndParse() | ||
.then((statusCode: number) => { | ||
const isRenderable = statusCode === StatusCode.OK; | ||
item.setRenderable(isRenderable); | ||
this.renderableItems.set(item.getId(), isRenderable); | ||
this.debouncedSetItem(item); | ||
}).catch(DefaultErrorHandler.handle); | ||
} | ||
this.addClass('archive-item-preview-panel'); | ||
} | ||
|
||
doRender(): Q.Promise<boolean> { | ||
return super.doRender().then((rendered: boolean) => { | ||
this.addClass('archive-item-preview-panel'); | ||
|
||
return rendered; | ||
}); | ||
} | ||
|
||
protected viewItemToContent(item: ArchiveContentViewItem): ContentSummaryAndCompareStatus { | ||
return item; | ||
} | ||
|
||
protected isNonBinaryItemRenderable(item: ContentSummaryAndCompareStatus): boolean { | ||
return false; | ||
createToolbar(): ArchiveItemPreviewToolbar { | ||
return new ArchiveItemPreviewToolbar(new PreviewActionHelper({ | ||
archive: "true" | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,18 @@ | ||
import * as Q from 'q'; | ||
import {SpanEl} from '@enonic/lib-admin-ui/dom/SpanEl'; | ||
import {i18n} from '@enonic/lib-admin-ui/util/Messages'; | ||
import {DivEl} from '@enonic/lib-admin-ui/dom/DivEl'; | ||
import {ContentSummary} from 'lib-contentstudio/app/content/ContentSummary'; | ||
import {ItemPreviewToolbar} from '@enonic/lib-admin-ui/app/view/ItemPreviewToolbar'; | ||
import {ArchiveContentViewItem} from './ArchiveContentViewItem'; | ||
import {PrincipalKey} from '@enonic/lib-admin-ui/security/PrincipalKey'; | ||
import {Principal} from '@enonic/lib-admin-ui/security/Principal'; | ||
import {GetPrincipalByKeyRequest} from 'lib-contentstudio/app/resource/GetPrincipalByKeyRequest'; | ||
import {GetContentVersionsRequest} from 'lib-contentstudio/app/resource/GetContentVersionsRequest'; | ||
import {ContentVersions} from 'lib-contentstudio/app/ContentVersions'; | ||
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler'; | ||
import {DateTimeFormatter} from '@enonic/lib-admin-ui/ui/treegrid/DateTimeFormatter'; | ||
import {ContentItemPreviewToolbar} from 'lib-contentstudio/app/view/ContentItemPreviewToolbar'; | ||
import {ContentSummaryAndCompareStatus} from 'lib-contentstudio/app/content/ContentSummaryAndCompareStatus'; | ||
import {PreviewActionHelper} from 'lib-contentstudio/app/action/PreviewActionHelper'; | ||
|
||
export class ArchiveItemPreviewToolbar | ||
extends ItemPreviewToolbar<ArchiveContentViewItem> { | ||
extends ContentItemPreviewToolbar { | ||
|
||
private readonly archivedEl: DivEl; | ||
constructor(previewHelper: PreviewActionHelper) { | ||
super(previewHelper); | ||
|
||
private readonly originalPathEl: SpanEl; | ||
|
||
constructor() { | ||
super({className: 'archive-status-toolbar'}); | ||
|
||
this.archivedEl = new DivEl('archived'); | ||
|
||
const originalPathWrapper = new DivEl('original-path'); | ||
this.originalPathEl = new SpanEl('original-path-value'); | ||
originalPathWrapper.appendChildren(new SpanEl().setHtml(i18n('preview.originalPath')), this.originalPathEl); | ||
|
||
this.appendChild(originalPathWrapper); | ||
} | ||
|
||
setItem(item: ArchiveContentViewItem): void { | ||
super.setItem(item); | ||
|
||
if (item) { | ||
const summary: ContentSummary = item.getContentSummary(); | ||
this.updatedArchivedBlock(summary); | ||
this.updateOriginalPathBlock(item); | ||
} | ||
} | ||
|
||
clearItem(): void { | ||
this.setItem(null); | ||
|
||
this.archivedEl.setHtml(''); | ||
} | ||
|
||
doRender(): Q.Promise<boolean> { | ||
return super.doRender().then((rendered: boolean) => { | ||
this.insertChild(this.archivedEl, 1); | ||
|
||
return rendered; | ||
}); | ||
} | ||
|
||
protected foldOrExpand(): void { | ||
return; | ||
} | ||
|
||
private updatedArchivedBlock(summary: ContentSummary): void { | ||
const status: string = i18n('status.archived'); | ||
const archivedBy: PrincipalKey = summary.getArchivedBy(); | ||
|
||
const versionsPromise: Q.Promise<ContentVersions> = new GetContentVersionsRequest(summary.getContentId()).sendAndParse(); | ||
const principalPromise: Q.Promise<Principal> = archivedBy != null ? new GetPrincipalByKeyRequest(archivedBy).sendAndParse() : Q( | ||
null); | ||
|
||
Q.all([versionsPromise, principalPromise]).spread((versions: ContentVersions, principal: Principal) => { | ||
const when: string = DateTimeFormatter.createHtml(summary.getArchivedTime()); | ||
const displayName: string = i18n('field.preview.toolbar.status', | ||
principal ? principal.getDisplayName() : PrincipalKey.ofAnonymous().getId()); | ||
this.archivedEl.setHtml(`${status} ${when} ${displayName}`); | ||
}).catch(DefaultErrorHandler.handle); | ||
this.addClass('archive-item-preview-toolbar'); | ||
} | ||
|
||
private updateOriginalPathBlock(item: ArchiveContentViewItem): void { | ||
this.originalPathEl.setHtml(item.getOriginalFullPath()); | ||
protected updateStatus(content: ContentSummaryAndCompareStatus): void { | ||
this.status.setHtml(i18n('status.archived')); // for now just archived | ||
} | ||
} |
30 changes: 3 additions & 27 deletions
30
src/main/resources/assets/styles/browse/archive-item-preview-panel.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.