提交 8f032f9e 编写于 作者: J Joao Moreno

Merge branch 'wadeanderson-install-count'

......@@ -23,6 +23,7 @@ export interface IGalleryInformation {
downloadUrl: string;
publisherId: string;
publisherDisplayName: string;
installCount: number;
date: string;
}
......
......@@ -8,6 +8,7 @@ import 'vs/css!./media/extensions';
import nls = require('vs/nls');
import { IDisposable, disposeAll } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { isNumber } from 'vs/base/common/types';
import * as dom from 'vs/base/browser/dom';
import Severity from 'vs/base/common/severity';
import { onUnexpectedError } from 'vs/base/common/errors';
......@@ -56,7 +57,7 @@ interface ITemplateData {
root: HTMLElement;
displayName: HighlightedLabel;
version: HTMLElement;
since: HTMLElement;
installCount: HTMLElement;
author: HTMLElement;
actionbar: ActionBar;
description: HighlightedLabel;
......@@ -80,9 +81,15 @@ function extensionEquals(one: IExtension, other: IExtension): boolean {
}
function extensionEntryCompare(one: IExtensionEntry, other: IExtensionEntry): number {
const oneName = one.extension.displayName || one.extension.name;
const otherName = other.extension.displayName || other.extension.name;
return oneName.localeCompare(otherName);
const oneInstallCount = one.extension.galleryInformation ? one.extension.galleryInformation.installCount : 0;
const otherInstallCount = other.extension.galleryInformation ? other.extension.galleryInformation.installCount : 0;
const diff = otherInstallCount - oneInstallCount;
if (diff !== 0) {
return diff;
}
return one.extension.displayName.localeCompare(other.extension.displayName);
}
class OpenInGalleryAction extends Action {
......@@ -171,19 +178,22 @@ class Renderer implements IRenderer<IExtensionEntry> {
}
renderTemplate(templateId: string, container: HTMLElement): ITemplateData {
// Important to preserve order here.
const root = dom.append(container, $('.extension'));
const firstRow = dom.append(root, $('.row'));
const secondRow = dom.append(root, $('.row'));
const published = dom.append(firstRow, $('.published'));
const since = dom.append(published, $('span.since'));
const displayName = new HighlightedLabel(dom.append(firstRow, $('span.name')));
const installCount = dom.append(firstRow, $('span.installCount'));
const version = dom.append(published, $('span.version'));
const author = dom.append(published, $('span.author'));
return {
root,
author,
since,
displayName: new HighlightedLabel(dom.append(firstRow, $('span.name'))),
version: dom.append(firstRow, $('span.version')),
displayName,
version,
installCount,
actionbar: new ActionBar(dom.append(secondRow, $('.actions'))),
description: new HighlightedLabel(dom.append(secondRow, $('span.description'))),
disposables: []
......@@ -194,6 +204,7 @@ class Renderer implements IRenderer<IExtensionEntry> {
const extension = entry.extension;
const date = extension.galleryInformation ? extension.galleryInformation.date : null;
const publisher = extension.galleryInformation ? extension.galleryInformation.publisherDisplayName : extension.publisher;
const installCount = extension.galleryInformation ? extension.galleryInformation.installCount : null;
const actionOptions = { icon: true, label: false };
const updateActions = () => {
......@@ -236,7 +247,25 @@ class Renderer implements IRenderer<IExtensionEntry> {
data.displayName.set(extension.displayName, entry.highlights.displayName);
data.displayName.element.title = extension.name;
data.version.textContent = extension.version;
data.since.textContent = date ? since(new Date(date)) : '';
if (isNumber(installCount)) {
data.installCount.textContent = String(installCount);
dom.addClass(data.installCount, 'octicon');
dom.addClass(data.installCount, 'octicon-cloud-download');
if (!installCount) {
data.installCount.title = nls.localize('installCountZero', "{0} wasn't downloaded yet.", extension.displayName);
} else if (installCount === 1) {
data.installCount.title = nls.localize('installCountOne', "{0} was downloaded once.", extension.displayName);
} else {
data.installCount.title = nls.localize('installCountMultiple', "{0} was downloaded {1} times.", extension.displayName, installCount);
}
} else {
data.installCount.textContent = '';
dom.removeClass(data.installCount, 'octicon');
dom.removeClass(data.installCount, 'octicon-cloud-download');
}
data.author.textContent = publisher;
data.description.set(extension.description, entry.highlights.description);
data.description.element.title = extension.description;
......
......@@ -28,14 +28,17 @@
opacity: 0.6;
}
.quick-open-widget .extension .version {
font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
.quick-open-widget .extension .installCount:not(:empty) {
margin-left: 6px;
padding: 1px 3px;
border-radius: 3px;
background-color: rgba(132, 132, 132, 0.3);
font-size: smaller;
opacity: 0.7;
}
.quick-open-widget .extension .version {
padding-left: 6px;
opacity: 0.7;
.quick-open-widget .extension .installCount:not(:empty):before {
margin-right: 2px;
}
.quick-open-widget .extension .published {
......@@ -44,7 +47,7 @@
font-size: smaller;
}
.quick-open-widget .extension .published > .since {
.quick-open-widget .extension .published > .version {
opacity: 0.6;
margin-right: 0.5em;
}
......
......@@ -33,6 +33,21 @@ export interface IGalleryExtension {
publisher: { displayName: string, publisherId: string, publisherName: string; };
versions: IGalleryExtensionVersion[];
galleryApiUrl: string;
statistics: IGalleryExtensionStatistics[];
}
export interface IGalleryExtensionStatistics {
statisticName: string;
value: number;
}
function getInstallCount(statistics: IGalleryExtensionStatistics[]): number {
if (!statistics) {
return 0;
}
const result = statistics.filter(s => s.statisticName === 'install')[0];
return result ? result.value : 0;
}
export class GalleryService implements IGalleryService {
......@@ -69,7 +84,7 @@ export class GalleryService implements IGalleryService {
value: 'vscode'
}]
}],
flags: 0x1 | 0x4 | 0x80
flags: 0x1 | 0x4 | 0x80 | 0x100
});
const request = {
......@@ -98,7 +113,8 @@ export class GalleryService implements IGalleryService {
downloadUrl: `${ extension.versions[0].assetUri }/Microsoft.VisualStudio.Services.VSIXPackage?install=true`,
publisherId: extension.publisher.publisherId,
publisherDisplayName: extension.publisher.displayName,
date: extension.versions[0].lastUpdated
installCount: getInstallCount(extension.statistics),
date: extension.versions[0].lastUpdated,
}
}));
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册