brackets-npm-registry
Version:
Install your extensions into Brackets using npm
224 lines (207 loc) • 7.07 kB
JavaScript
define(function (require, exports, module) {
'use strict';
var _ = brackets.getModule('thirdparty/lodash');
var NativeApp = brackets.getModule('utils/NativeApp');
var React = brackets.getModule('thirdparty/react');
var Strings = require('strings');
var registryUtils = require('../registry-utils');
var formatDate = function formatDate(val) {
return val.substring(0, 10);
};
module.exports = React.createClass({
displayName: 'exports',
getInitialState: function getInitialState() {
return {
dependeciesShown: false
};
},
render: function render() {
var _this = this;
var registryInfo = this.props.registryInfo;
var latestVersion = registryInfo.version;
var latestVersionDate = formatDate(registryInfo.time[registryInfo.version]);
var buttons = [];
if (!registryInfo._currentlyInstalled) {
buttons.push(React.createElement(
'button',
{ className: 'btn btn-mini btn-install', onClick: this.handleInstall },
Strings.INSTALL
));
} else if (registryInfo._updateAvailable) {
buttons.push(React.createElement(
'button',
{ className: 'btn btn-mini btn-update', onClick: this.handleInstall },
Strings.UPDATE
), React.createElement(
'button',
{ className: 'btn btn-mini btn-remove', onClick: this.handleRemove },
Strings.REMOVE
));
} else {
buttons.push(React.createElement(
'button',
{ className: 'btn btn-mini btn-reinstall', onClick: this.handleInstall },
Strings.REINSTALL
), React.createElement(
'button',
{ className: 'btn btn-mini btn-remove', onClick: this.handleRemove },
Strings.REMOVE
));
}
return React.createElement(
'div',
{ className: 'row-fluid registry-item' },
React.createElement(
'div',
{ className: 'span10 text-left' },
React.createElement(
'h1',
null,
React.createElement(
'a',
{ className: 'defaultColor', onClick: this.handleShowNpm.bind(this, this.props.registryInfo.name), href: '#' },
registryInfo.displayName
)
),
React.createElement(
'h2',
null,
registryInfo.description
),
React.createElement(
'div',
null,
Strings.AUTHOR,
': ',
React.createElement(
'a',
{ onClick: this.handleShowAuthor, href: '#' },
registryInfo.author.name
)
),
React.createElement(
'div',
null,
Strings.LATEST,
': ',
latestVersion,
' - ',
latestVersionDate,
registryInfo.github ? React.createElement(
'span',
null,
React.createElement(
'span',
null,
'; '
),
React.createElement(
'a',
{ className: 'defaultColor', href: '', onClick: this.handleShowIssues },
registryInfo.github.issueCount,
' ',
Strings._OPEN_ISSUES
),
React.createElement(
'span',
null,
', '
),
React.createElement(
'a',
{ className: 'defaultColor', href: '', onClick: this.handleShowPulls },
registryInfo.github.pullCount,
' ',
Strings._OPEN_PULLS
),
' ' + Strings._ON_GITHUB
) : ''
),
React.createElement(
'div',
null,
this.props.registryInfo.downloadsLastWeek,
' ',
Strings._DOWNLOADS,
' ',
Strings._LAST_WEEK + ', ',
this.props.registryInfo.downloadsTotal,
' ',
Strings._DOWNLOADS,
' ',
Strings._TOTAL
),
React.createElement(
'div',
null,
this.getDependencies().length,
' ',
Strings._DEPENDENCIES,
!this.state.dependeciesShown ? React.createElement(
'span',
null,
' ',
React.createElement(
'a',
{ className: 'defaultColor', href: '', onClick: this.handleShowDependencies },
Strings._SHOW_LINK
)
) : React.createElement(
'ul',
null,
this.getDependencies().map(function (obj, i) {
return React.createElement(
'li',
{ key: i },
React.createElement(
'a',
{ className: 'defaultColor', href: '', onClick: _this.handleShowNpm.bind(_this, obj.name) },
obj.name,
'@',
obj.version
)
);
})
)
)
),
React.createElement(
'div',
{ className: 'span2' },
buttons
)
);
},
getDependencies: function getDependencies() {
var mapper = function mapper(version, name) {
return { name: name, version: version };
};
var dependencies = [].concat(_.map(this.props.registryInfo.dependencies, mapper)
// , _.map(this.props.registryInfo.devDependencies, mapper)
);
return _.sortBy(dependencies, 'name');
},
handleShowDependencies: function handleShowDependencies() {
this.setState({ dependeciesShown: true });
},
handleInstall: function handleInstall() {
registryUtils.install(this.props.registryInfo.name);
},
handleRemove: function handleRemove() {
registryUtils.remove(this.props.registryInfo.name);
},
handleShowNpm: function handleShowNpm(pkg) {
NativeApp.openURLInDefaultBrowser('https://www.npmjs.com/package/' + pkg);
},
handleShowAuthor: function handleShowAuthor() {
NativeApp.openURLInDefaultBrowser(this.props.registryInfo.author.url);
},
handleShowIssues: function handleShowIssues() {
NativeApp.openURLInDefaultBrowser('https://github.com/' + this.props.registryInfo.github.username + '/' + this.props.registryInfo.github.repository + '/issues');
},
handleShowPulls: function handleShowPulls() {
NativeApp.openURLInDefaultBrowser('https://github.com/' + this.props.registryInfo.github.username + '/' + this.props.registryInfo.github.repository + '/pulls');
}
});
});
//# sourceMappingURL=C:\Users\Zaggi\AppData\Roaming\Brackets-Electron\extensions\user\brackets-npm-registry\dist//../ui/react-components/registry-item.js.map