提交 7fd4a286 编写于 作者: J Joao Moreno

show license link only if extension sets one

fixes #10464
上级 1a544350
......@@ -29,6 +29,7 @@ export interface IGalleryVersion {
readmeUrl: string;
downloadUrl: string;
iconUrl: string;
licenseUrl: string;
downloadHeaders: { [key: string]: string; };
}
......
......@@ -68,7 +68,8 @@ const AssetType = {
Icon: 'Microsoft.VisualStudio.Services.Icons.Default',
Details: 'Microsoft.VisualStudio.Services.Content.Details',
Manifest: 'Microsoft.VisualStudio.Code.Manifest',
VSIX: 'Microsoft.VisualStudio.Services.VSIXPackage'
VSIX: 'Microsoft.VisualStudio.Services.VSIXPackage',
License: 'Microsoft.VisualStudio.Services.Content.License'
};
interface ICriterium {
......@@ -152,21 +153,22 @@ function getStatistic(statistics: IRawGalleryExtensionStatistics[], name: string
return result ? result.value : 0;
}
function getAssetSource(files: IRawGalleryExtensionFile[], type: string): string {
const result = files.filter(f => f.assetType === type)[0];
return result && result.source;
}
function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUrl: string, downloadHeaders: any): IGalleryExtension {
const versions = galleryExtension.versions.map<IGalleryVersion>(v => {
const iconFile = v.files.filter(f => f.assetType === AssetType.Icon)[0];
const iconUrl = iconFile ? iconFile.source : require.toUrl('./media/defaultIcon.png');
return {
version: v.version,
date: v.lastUpdated,
downloadHeaders,
downloadUrl: `${ v.assetUri }/${ AssetType.VSIX }?install=true`,
manifestUrl: `${ v.assetUri }/${ AssetType.Manifest }`,
readmeUrl: `${ v.assetUri }/${ AssetType.Details }`,
iconUrl
};
});
const versions = galleryExtension.versions.map<IGalleryVersion>(v => ({
version: v.version,
date: v.lastUpdated,
downloadHeaders,
downloadUrl: `${ v.assetUri }/${ AssetType.VSIX }?install=true`,
manifestUrl: `${ v.assetUri }/${ AssetType.Manifest }`,
readmeUrl: `${ v.assetUri }/${ AssetType.Details }`,
iconUrl: getAssetSource(v.files, AssetType.Icon) || require.toUrl('./media/defaultIcon.png'),
licenseUrl: getAssetSource(v.files, AssetType.License)
}));
return {
id: galleryExtension.extensionId,
......@@ -222,7 +224,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
.withFlags(Flags.IncludeVersions, Flags.IncludeCategoryAndTags, Flags.IncludeAssetUri, Flags.IncludeStatistics, Flags.IncludeFiles)
.withPage(1, pageSize)
.withFilter(FilterType.Target, 'Microsoft.VisualStudio.Code')
.withAssetTypes(AssetType.Icon);
.withAssetTypes(AssetType.Icon, AssetType.License);
if (text) {
query = query.withFilter(FilterType.SearchText, text).withSortBy(SortBy.NoneOrRelevance);
......
......@@ -109,6 +109,7 @@ export class ExtensionEditor extends BaseEditor {
this.license = append(subtitle, $<HTMLAnchorElement>('a.license'));
this.license.href = '#';
this.license.textContent = localize('license', 'License');
this.license.style.display = 'none';
this.description = append(details, $('.description'));
......@@ -131,16 +132,22 @@ export class ExtensionEditor extends BaseEditor {
if (product.extensionsGallery) {
const extensionUrl = `${ product.extensionsGallery.itemUrl }?itemName=${ extension.publisher }.${ extension.name }`;
const licenseUrl = `${ product.extensionsGallery.itemUrl }/${ extension.publisher }.${ extension.name }/license`;
this.name.onclick = finalHandler(() => shell.openExternal(extensionUrl));
this.license.onclick = finalHandler(() => shell.openExternal(licenseUrl));
this.rating.onclick = finalHandler(() => shell.openExternal(`${ extensionUrl }#review-details`));
this.publisher.onclick = finalHandler(() => {
this.viewletService.openViewlet(VIEWLET_ID, true)
.then(viewlet => viewlet as IExtensionsViewlet)
.done(viewlet => viewlet.search(`publisher:"${ extension.publisherDisplayName }"`, true));
});
if (extension.licenseUrl) {
this.license.onclick = finalHandler(() => shell.openExternal(extension.licenseUrl));
this.license.style.display = 'initial';
} else {
this.license.onclick = null;
this.license.style.display = 'none';
}
}
const install = this.instantiationService.createInstance(InstallWidget, this.installCount, { extension });
......
......@@ -34,6 +34,7 @@ export interface IExtension {
description: string;
readmeUrl: string;
iconUrl: string;
licenseUrl: string;
installCount: number;
rating: number;
ratingCount: number;
......
......@@ -98,6 +98,14 @@ class Extension implements IExtension {
return require.toUrl('./media/defaultIcon.png');
}
get licenseUrl(): string {
if (this.gallery) {
return this.gallery.versions[0].licenseUrl;
}
return null;
}
get state(): ExtensionState {
return this.stateProvider(this);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册