Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a button to copy api token to clipboard #1345 #1346

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions BrainPortal/app/views/users/new_token.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# CBRAIN Project
#
# Copyright (C) 2008-2020
# Copyright (C) 2008-2024
# The Royal Institution for the Advancement of Learning
# McGill University
#
Expand All @@ -24,12 +24,27 @@

<% title 'New API Token' %>

<% content_for :scripts do %>
<%= javascript_include_tag 'cbrain/users/clipboard' %>
<% end %>


<h2>New API Token</h2>

We have just generated a new API token for you.
<p>
<pre><%= @new_token %></pre>
<div>
<code id="api_token" ><%= @new_token %></code>
<button class="button" title="Click this button to copy the API token to the clipboard" onclick="copy_text_to_clipboard()">
<!-- SVG copy icon (akin to unicode's copy symbol but clean) -->
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" >
<rect x="4" y="4" width="14" height="14" rx="2" ry="2" fill="#d1d5da" stroke="#6a737d" stroke-width="1.25" />
<rect x="7" y="7" width="14" height="14" rx="2" ry="2" fill="#d1d5da" stroke="#6a737d" stroke-width="1.25" />
</svg> copy to clipboard
</button>
</div>
<p>

If you are a developer and want to automate working
with CBRAIN or NeuroHub, this token will be needed
to access the APIs.
Expand Down
27 changes: 27 additions & 0 deletions BrainPortal/public/javascripts/cbrain/users/clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

/*
#
# CBRAIN Project
#
# Copyright (C) 2024
# The Royal Institution for the Advancement of Learning
# McGill University
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
*/

function copy_text_to_clipboard() {
navigator.clipboard.writeText($("#api_token").text().trim());
}
Loading