Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #500 from beakerbrowser/lib-and-viewsource-updates
Browse files Browse the repository at this point in the history
Library and view-source updates
  • Loading branch information
pfrazee authored Jun 3, 2017
2 parents 98e610e + e23ee77 commit 0cecd3c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 37 deletions.
37 changes: 27 additions & 10 deletions app/builtin-pages/com/files-list.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import yo from 'yo-yo'
import prettyBytes from 'pretty-bytes'
import * as toast from './toast'
import {niceDate} from '../../lib/time'
import {writeToClipboard} from '../../lib/fg/event-handlers'

// exported api
// =

export default function render (archiveInfo) {
var lastPublishedURL = yo`
<a href="${archiveInfo.url}+${archiveInfo.version}">${archiveInfo.version}</a>`

return yo`
<div>
<p>Latest revision: ${lastPublishedURL}</p>
${rFolder(archiveInfo)}
${rFilesList(archiveInfo)}
</div>
Expand Down Expand Up @@ -49,11 +47,19 @@ function rFolder (archiveInfo) {
if (!archiveInfo.userSettings) return ''
return yo`
<div class="dat-local-path">
${archiveInfo.userSettings.localPath}
<a onclick=${e => onOpenFolder(e, archiveInfo)} href="#">
Open folder
<i class="fa fa-folder-open-o"></i>
</a>
<span>
${archiveInfo.userSettings.localPath}
</span>
<span>
<a onclick=${e => onCopyFolder(e, archiveInfo)} href="#">
<i class="fa fa-clipboard"></i>
Copy path
</a>
<a onclick=${e => onOpenFolder(e, archiveInfo)} href="#">
<i class="fa fa-folder-open-o"></i>
Open folder
</a>
</span>
</div>
`
}
Expand Down Expand Up @@ -143,12 +149,23 @@ async function onClickDirectory (e, archiveInfo, node) {
redraw(archiveInfo)
}

function onCopyFolder (e, archiveInfo) {
e.preventDefault()
if (archiveInfo.userSettings.localPath) {
var path = archiveInfo.userSettings.localPath
if (path.indexOf(' ') !== -1) {
path = `"${path}"`
}
writeToClipboard(path)
toast.create(`Folder path copied to clipboard.`)
}
}

function onOpenFolder (e, archiveInfo) {
e.preventDefault()
if (archiveInfo.userSettings.localPath) {
beakerBrowser.openFolder(archiveInfo.userSettings.localPath)
}
// update()
}

// helpers
Expand Down
47 changes: 21 additions & 26 deletions app/builtin-pages/views/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,14 @@ function rArchive (archiveInfo) {
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-btn-list">
${archiveInfo.userSettings.localPath
? yo`<a class="dropdown-item" onclick=${onOpenFolder}>
<i class="fa fa-folder-open-o"></i>
Open folder
</a>`
: yo`<a class="dropdown-item disabled">
<i class="fa fa-folder-open-o"></i>
Open folder
</a>`}
<div class="dropdown-item" onclick=${onFork}>
<i class="fa fa-code-fork"></i>
Fork this site
</div>
<div class="dropdown-item" onclick=${onViewSource}>
<i class="fa fa-code"></i>
View source
</div>
<div class="dropdown-item" onclick=${onChooseNewLocation}>
<i class="fa fa-folder-o"></i>
Change folder
Expand All @@ -350,14 +349,6 @@ function rArchive (archiveInfo) {
Edit site info
</div>`
: ''}
<div class="dropdown-item" onclick=${onFork}>
<i class="fa fa-code-fork"></i>
Fork this site
</div>
<div class="dropdown-item" onclick=${onViewSource}>
<i class="fa fa-code"></i>
View source
</div>
<div class="dropdown-item" onclick=${onViewSwarmDebugger}>
<i class="fa fa-bug"></i>
Swarm debugger
Expand Down Expand Up @@ -388,7 +379,7 @@ function rArchive (archiveInfo) {
{id: 'metadata', label: 'Metadata', onclick: onClickTab('metadata')}
].filter(Boolean))}
${({
files: () => renderFiles(archiveInfo),
files: () => rFiles(archiveInfo),
log: () => rHistory(archiveInfo),
metadata: () => rMetadata(archiveInfo),
})[currentSection]()}
Expand Down Expand Up @@ -469,6 +460,18 @@ function rStagingArea (archiveInfo) {
`
}

function rFiles (archiveInfo) {
return yo`<div>
<p>
Latest revision:
<a href="${archiveInfo.url}+${archiveInfo.version}">
${archiveInfo.version}
</a>
</p>
${renderFiles(archiveInfo)}
</div>`
}

function rHistory (archiveInfo) {
var rows = archiveInfo.history.map(function (item, i) {
var rev = item.version
Expand Down Expand Up @@ -582,14 +585,6 @@ function onShare (e) {
sharePopup.create(selectedArchive.url)
}

function onOpenFolder (e) {
e.preventDefault()
if (selectedArchive.userSettings.localPath) {
beakerBrowser.openFolder(selectedArchive.userSettings.localPath)
}
update()
}

async function onEditSettings (e) {
e.preventDefault()
update()
Expand Down
6 changes: 5 additions & 1 deletion app/builtin-pages/views/view-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ function renderFile () {

function onClickFilesList (e) {
e.preventDefault()
var href = e.target.getAttribute('href')
var node = e.target
if (node.tagName !== 'A') {
node = node.querySelector('a')
}
var href = node && node.getAttribute('href')
if (href && href.startsWith('dat://')) {
window.history.pushState(null, '', 'beaker://view-source/' + href.slice('dat://'.length))
}
Expand Down

0 comments on commit 0cecd3c

Please sign in to comment.