如何解决当有多个站点的单个内容目录时,SmartEdit 无法加载正确的站点
在我当前的项目中,我们有多个站点和单个内容目录。 例如。 目录:abcContentCatalog 站点:usSite、europeSite、africaSite。 所有网站都有不同的登录页面。
所有这些站点都连接到一个目录,即 abcContentCatalog。
现在,当我打开 SmartEdit 并选择任何站点时,SmartEdit 会选择它从列表中获得的最后一个站点。
在浏览器控制台中收到此警告消息:“为内容目录找到了许多默认站点”。
经过 SmartEdit 源代码后,我发现 CatalogService.ts 文件具有 getDefaultSiteForContentCatalog 方法。
getDefaultSiteForContentCatalog(contentCatalogId: string): Promise<ISite> {
return ((this.siteService.getSites() as unkNown) as Promise<ISite[]>).then((sites) => {
const defaultSitesForCatalog = sites.filter((site) => {
// ContentCatalogs in the site object are sorted. The last one is considered
// the default one for a given site.
const siteDefaultContentCatalog = lodash.last(site.contentCatalogs);
return siteDefaultContentCatalog && siteDefaultContentCatalog === contentCatalogId;
});
if (defaultSitesForCatalog.length === 0) {
this.logService.warn(
`[catalogService] - No default site found for content catalog ${contentCatalogId}`
);
} else if (defaultSitesForCatalog.length > 1) {
this.logService.warn(
`[catalogService] - Many default sites found for content catalog ${contentCatalogId}`
);
}
return defaultSitesForCatalog[0];
});
}
我在自定义 smartEdit 扩展中覆盖了 Service 方法,但我需要知道如何覆盖调用此服务的 OOTB Angular 组件 LandingPageComponent。
我使用了 https://launchpad.support.sap.com/#/notes/2805883 提供的解决方案 但是在覆盖 LandaingPageComponent 之后,它并没有被调用,而是一直在调用 OOTB。
PfizerLandingPageComponent
/*
* copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
*/
import * as angular from 'angular';
import { PfizerCatalogService } from 'pfizerprimesmarteditcontainer/PfizerCatalogService';
import { PfizerSiteService } from 'pfizerprimesmarteditcontainer/PfizerSiteService';
import {
GenericEditorField,IBaseCatalog,ISeComponent,ISeDropdownSelectedOption,ISeDropdownSelectedOptionEventData,IStorageService,SeComponent,SystemEventService,TypedMap
} from 'smarteditcommons';
interface ISelectedSite extends ISeDropdownSelectedOption {
uid: string;
contentCatalogs: string[];
name: TypedMap<string>;
previewUrl: string;
}
/**
* @ngdoc overview
* @name PfizerLandingPageComponent
* @description
*
* Component responsible of displaying the SmartEdit landing page.
*
*/
@SeComponent({
templateUrl: 'PfizerLandingPageTemplate.html'
})
export class PfizerLandingPageComponent implements ISeComponent {
public sitesId: string = 'sites-id';
public catalogs: IBaseCatalog[];
public qualifier: string;
public field: Partial<GenericEditorField>;
public model: { site: string };
private unregisterSitesDropdownEventHandler: () => void;
private SELECTED_SITE_COOKIE_NAME = 'seselectedsite';
constructor(
private siteService: PfizerSiteService,private catalogService: PfizerCatalogService,private systemEventService: SystemEventService,private storageService: IStorageService,private SITES_RESOURCE_URI: string,private LINKED_DROPDOWN: string
) {}
$onInit() {
this.catalogs = [];
this.qualifier = 'site';
this.field = {
uri: this.SITES_RESOURCE_URI,idAttribute: 'uid',labelAttributes: ['name'],editable: true,paged: false
};
this.siteService.getSelectedSiteUid().then((siteId: string) => (this.model = { site: siteId }));
this.removeStorefrontCssClass();
this.unregisterSitesDropdownEventHandler = this.systemEventService.subscribe(
this.sitesId + this.LINKED_DROPDOWN,this.selectedSiteDropdownEventHandler.bind(this)
);
}
$onDestroy() {
this.unregisterSitesDropdownEventHandler();
}
private removeStorefrontCssClass(): void {
const bodyTag = angular.element(document.querySelector('body'));
if (bodyTag.hasClass('is-storefront')) {
bodyTag.removeClass('is-storefront');
}
}
private selectedSiteDropdownEventHandler(
eventId: string,data: ISeDropdownSelectedOptionEventData<ISelectedSite>
): void {
if (data.optionObject) {
const siteId = data.optionObject.id;
this.setSelectedSite(siteId);
this.loadCatalogsBySite(siteId);
} else {
this.catalogs = [];
}
}
private setSelectedSite(siteId: string): void {
this.storageService.setValueInLocalStorage(this.SELECTED_SITE_COOKIE_NAME,siteId,false);
}
private loadCatalogsBySite(siteId: string): void {
this.catalogService
.getContentCatalogsForSite(siteId)
.then((catalogs: IBaseCatalog[]) => (this.catalogs = catalogs));
}
}
覆盖 SeRouteService 路由以使用我的组件
legacypfizerprimesmarteditcontainer.ts
/*
* copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
*/
import { doImport } from './forcedImports';
doImport();
import {IFeatureService,SeModule,SeRouteService } from 'smarteditcommons';
import { PfizerLandingPageComponent } from './pfizerLandingPage/PfizerLandingPageComponent';
/**
* @ngdoc overview
* @name pfizerprimesmarteditContainer
* @description
* Placeholder for documentation
*/
@SeModule({
declarations: [PfizerLandingPageComponent],imports: ['smarteditServicesModule','abAnalyticsToolbarItemmodule'],initialize: (featureService: IFeatureService) => {
'ngInject';
////////////////////////////////////////////////////
// Create Toolbar Item
////////////////////////////////////////////////////
// Create the toolbar item as a feature.
featureService.addToolbarItem({
toolbarId: 'smartEditPerspectivetoolbar',key: 'abAnalyticsToolbarItem',type: 'HYBRID_ACTION',nameI18nKey: 'ab.analytics.toolbar.item.name',priority: 2,section: 'left',iconClassName: 'icon-message-information se-toolbar-menu-ddlb--button__icon',include: 'abAnalyticsToolbarItemWrapperTemplate.html'
});
},config: (
$provide: angular.auto.IProvideService,LANDING_PAGE_PATH: string,$routeProvider: angular.route.IRouteProvider
) => {
'ngInject';
SeRouteService.init($routeProvider);
SeRouteService.provideLegacyRoute({
path: '/',route: {
template: '<landing-page></landing-page>'
}
});
/*SeRouteService.provideLegacyRoute({
path: LANDING_PAGE_PATH + 'sites/:siteId',route: {
template: '<landing-page></landing-page>'
}
});*/
}
})
export class PfizerprimesmarteditContainer {}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。