Skip to content

Commit

Permalink
feat: js copy share link directly
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfly committed Oct 27, 2018
1 parent 36653db commit 8a3a45f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 33 deletions.
29 changes: 8 additions & 21 deletions Makefile
Expand Up @@ -74,7 +74,7 @@ proto:

## --- these stages are copied from gotty for asset building --- ##
.PHONY: asset
asset: clear static/js/gotty-bundle.js static/index.html static/favicon.png static/css/index.css static/css/xterm.css static/css/xterm_customize.css
asset: clear static/js static/css static/html
go-bindata -nometadata -prefix static -pkg route -ignore=\\.gitkeep -o route/asset.go static/...
gofmt -w route/asset.go

Expand All @@ -84,38 +84,25 @@ clear:
static:
mkdir -p static

static/index.html: static resources/index.html resources/list.html
cp resources/index.html static/index.html
cp resources/list.html static/list.html

static/favicon.png: static resources/favicon.png
static/html: static
cp resources/*.html static/
cp resources/favicon.png static/favicon.png

static/js: static
static/js: static js/dist/gotty-bundle.js
mkdir -p static/js

static/js/gotty-bundle.js: static/js js/dist/gotty-bundle.js
cp resources/*.js static/js/
cp js/dist/gotty-bundle.js static/js/gotty-bundle.js
cp resources/control.js static/js/control.js

static/css: static
static/css: static js/node_modules/xterm/dist/xterm.css
mkdir -p static/css

static/css/index.css: static/css resources/index.css resources/list.css
cp resources/index.css static/css/index.css
cp resources/list.css static/css/list.css

static/css/xterm_customize.css: static/css resources/xterm_customize.css
cp resources/xterm_customize.css static/css/xterm_customize.css

static/css/xterm.css: static/css js/node_modules/xterm/dist/xterm.css
cp resources/*.css static/css
cp js/node_modules/xterm/dist/xterm.css static/css/xterm.css

js/node_modules/xterm/dist/xterm.css:
cd js && \
npm install

js/dist/gotty-bundle.js: js/src/* js/node_modules/webpack
js/dist/gotty-bundle.js: js/node_modules/webpack
cd js && \
`npm bin`/webpack

Expand Down
7 changes: 7 additions & 0 deletions resources/clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 25 additions & 9 deletions resources/list.html
Expand Up @@ -6,6 +6,7 @@
<title>{{ .title }}</title>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" href="/css/list.css" />
<script src="/js/clipboard.min.js"></script>
</head>

<body>
Expand Down Expand Up @@ -40,17 +41,17 @@
<a href="/exec/{{ printf "%.12s" .ID }}" target="_blank">{{ printf "%.12s" .ID }}</a>
</td>
{{- if $share -}}
<td class="cell100 column2" title="{{ .Image }} | share tty">
<a href="/share/{{ printf "%.12s" .ID }}" target="_blank">{{ printf .Image }}</a>
</td>
{{- else -}}
<td class="cell100 column2" title="{{ .Image }}">
{{ printf .Image }}
</td>
{{- end -}}
<td class="cell100 column2" title="{{ .Image }} | share tty">
<a href="#" class="copy" data-clipboard-text="/share/{{ printf "%.12s" .ID }}">{{ printf .Image }}</a>
</td>
{{- else -}}
<td class="cell100 column2" title="{{ .Image }}">
{{ printf .Image }}
</td>
{{- end -}}
<td class="cell100 column3" title="{{ .Command }}">{{ printf .Command }}</td>
<td class="cell100 column4" title="{{ .Name }}">
<a href="/logs/{{ printf "%.12s" .ID }}?follow=1&tail=10" target="_blank" title="get logs">{{ printf .Name }}</a>
<a href="/logs/{{ printf "%.12s" .ID }}?follow=1&tail=10" target="_blank" title="get logs">{{ printf .Name }}</a>
</td>
<td class="cell100 column5" title="{{ .IPs }}">{{ index .IPs 0 }}</td>
{{- if $showLocation -}}
Expand All @@ -73,6 +74,21 @@
</div>

<script src="/js/control.js"></script>
<script>
var clipboard = new ClipboardJS('.copy', {
text: function (trigger) {
return trigger.baseURI.replace('/#','') + trigger.getAttribute('data-clipboard-text');
}
});
clipboard.on('success', function (e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);

e.clearSelection();
alert("share link ("+e.text+") copied!");
});
</script>
</body>

</html>

0 comments on commit 8a3a45f

Please sign in to comment.