mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Add initial available packages view
This commit is contained in:
@@ -81,6 +81,12 @@ _.extend atom,
|
||||
else
|
||||
throw new Error("Could not resolve '#{id}' to a package path")
|
||||
|
||||
packageExists: (id) ->
|
||||
if fsUtils.isDirectory(id)
|
||||
true
|
||||
else
|
||||
fsUtils.isDirectory(fsUtils.resolve(config.packageDirPaths..., id))
|
||||
|
||||
resolvePackagePath: _.memoize (id) ->
|
||||
return id if fsUtils.isDirectory(id)
|
||||
path = fsUtils.resolve(config.packageDirPaths..., id)
|
||||
|
||||
40
src/app/available-packages-config-panel.coffee
Normal file
40
src/app/available-packages-config-panel.coffee
Normal file
@@ -0,0 +1,40 @@
|
||||
ConfigPanel = require 'config-panel'
|
||||
PackageConfigView = require 'package-config-view'
|
||||
{$$} = require 'space-pen'
|
||||
$ = require 'jquery'
|
||||
{spawn} = require 'child_process'
|
||||
roaster = require 'roaster'
|
||||
async = require 'async'
|
||||
|
||||
###
|
||||
# Internal #
|
||||
###
|
||||
|
||||
module.exports =
|
||||
class AvailablePackagesConfigPanel extends ConfigPanel
|
||||
@content: ->
|
||||
@div =>
|
||||
@legend 'Available Packages'
|
||||
|
||||
initialize: ->
|
||||
apm = require.resolve '.bin/apm'
|
||||
apmProcess = spawn(apm, ['available', '--json'])
|
||||
chunks = []
|
||||
apmProcess.stdout.on 'data', (chunk) -> chunks.push(chunk)
|
||||
apmProcess.on 'close', (code) =>
|
||||
if code is 0
|
||||
try
|
||||
packages = JSON.parse(Buffer.concat(chunks).toString()) ? []
|
||||
catch error
|
||||
packages = []
|
||||
console.error(error.stack ? error)
|
||||
|
||||
if packages.length > 0
|
||||
queue = async.queue (pack, callback) ->
|
||||
roaster pack.description, {}, (error, html) ->
|
||||
pack.descriptionHtml = html
|
||||
callback()
|
||||
queue.push(pack) for pack in packages
|
||||
queue.drain = =>
|
||||
for pack in packages
|
||||
@append(new PackageConfigView(pack, @operationQueue))
|
||||
@@ -5,6 +5,7 @@ GeneralConfigPanel = require 'general-config-panel'
|
||||
EditorConfigPanel = require 'editor-config-panel'
|
||||
ThemeConfigPanel = require 'theme-config-panel'
|
||||
PackageConfigPanel = require 'package-config-panel'
|
||||
AvailablePackagesConfigPanel = require 'available-packages-config-panel'
|
||||
|
||||
###
|
||||
# Internal #
|
||||
@@ -39,6 +40,7 @@ class ConfigView extends View
|
||||
@addPanel('Editor', new EditorConfigPanel)
|
||||
@addPanel('Themes', new ThemeConfigPanel)
|
||||
@addPanel('Installed Packages', new PackageConfigPanel)
|
||||
@addPanel('Available Packages', new AvailablePackagesConfigPanel)
|
||||
|
||||
addPanel: (name, panel) ->
|
||||
panelItem = $$ -> @li name: name, => @a name
|
||||
|
||||
30
src/app/package-config-view.coffee
Normal file
30
src/app/package-config-view.coffee
Normal file
@@ -0,0 +1,30 @@
|
||||
{View} = require 'space-pen'
|
||||
|
||||
module.exports =
|
||||
class PackageConfigView extends View
|
||||
@content: ->
|
||||
@div class: 'panel', =>
|
||||
@div outlet: 'heading', class: 'panel-heading', =>
|
||||
@span outlet: 'name'
|
||||
@button outlet: 'action', class: 'btn btn-small btn-primary pull-right'
|
||||
@div outlet: 'description'
|
||||
@div outlet: 'versions', class: 'panel-footer'
|
||||
|
||||
initialize: (@pack, @queue) ->
|
||||
@versions.text("Version: #{@pack.version}")
|
||||
@name.text(@pack.name)
|
||||
if @pack.descriptionHtml
|
||||
@description.html(pack.descriptionHtml)
|
||||
else if @pack.description
|
||||
@description.text(@pack.description)
|
||||
else
|
||||
@description.text('No further description available.')
|
||||
|
||||
@updateInstallState()
|
||||
|
||||
updateInstallState: ->
|
||||
@installed = atom.packageExists(@pack.name)
|
||||
if @installed
|
||||
@action.text('Uninstall')
|
||||
else
|
||||
@action.text('Install')
|
||||
Reference in New Issue
Block a user