neocgit

a more 'modern' version of cgit
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/neocgit

commit b11fde70a236802ba4bb27507dab82870e3129c8
parent fc70487b9b61462f6ec6d88f849d1a36219ca0e7
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon,  2 Jul 2018 18:50:19 +0200

NEW: Proper repo-url selector

Signed-off-by: Ne02ptzero <louis@ne02ptzero.me>

Diffstat:
Mcgit.css | 71++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mui-shared.c | 57+++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 109 insertions(+), 19 deletions(-)

diff --git a/cgit.css b/cgit.css @@ -28,6 +28,16 @@ div#cgit table { border-collapse: collapse; } +.input-copy { + font-family: "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", + "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; + font-size: 14px; +} + +.hidden { + display: none; +} + #header { width: 100%; background: #2C3E50; @@ -153,7 +163,7 @@ div#cgit table { } .repo-logo { - width: 3.5%; + width: 2%; padding-right: 5px; } @@ -224,11 +234,66 @@ div#cgit table { } .summary-header input { - height: 28px; - width: 220px; + width: 250px; + text-align: center; + border: 1px solid #e5e5e5; + padding: 6px 15px; + font-size: 14px; + margin-left: -5px; +} + +.summary-header .repo-url { + display: inline-block; + list-style: none; + padding: 0; + margin: 0; + position: relative; +} + +.summary-header .repo-url li { + display: inline-block; + margin: 0; +} + +.summary-header .repo-url li select { + background: #FFFFFF; + border: 1px solid #e5e5e5; + width: 100%; + padding: 5px 14px 5px 10px; + border-radius: 3px; + border-bottom-right-radius: 0; + border-top-right-radius: 0; + -moz-appearance: none; /* Firefox */ + -webkit-appearance: none; /* Safari and Chrome */ + appearance: none; + text-align: left; + font-size: 14px; +} + +.summary-header .repo-url .select-arrow { + padding-top: 7px; + position: absolute; + margin-left: -20px; +} + +.summary-header .repo-url li .copy { text-align: center; border: 1px solid #e5e5e5; border-radius: 3px; + padding: 5px 15px; + border-bottom-left-radius: 0; + border-top-left-radius: 0; + color: #7e7c7c !important; + height: 100%; + margin: 0; + margin-left: -5px; + transition-duration: 0.3s; + transition-property: all; +} + +.summary-header .repo-url li .copy:hover { + background: #e6e3e3; + cursor: pointer; } .summary-menu { diff --git a/ui-shared.c b/ui-shared.c @@ -773,8 +773,6 @@ void cgit_print_docstart(void) strbuf_release(&sb); free(fileurl); } - if (ctx.repo) - cgit_add_clone_urls(print_rel_vcs_link); if (ctx.cfg.head_include) html_include(ctx.cfg.head_include); html("<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.1.0/css/all.css' integrity='sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt' crossorigin='anonymous'>"); @@ -831,6 +829,18 @@ void cgit_print_layout_end(void) cgit_print_docend(); } +static const char *get_clone_type(char *url) +{ + if (strncmp("git://", url, sizeof("git://") - 1) == 0) + return "GIT"; + if (strncmp("http://", url, sizeof("http://") - 1) == 0) + return "HTTP"; + if (strncmp("https://", url, sizeof("https://") - 1) == 0) + return "HTTPS"; + else + return "SSH"; +} + static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) { struct strbuf **url_list = strbuf_split_str(txt, ' ', 0); @@ -842,9 +852,35 @@ static void add_clone_urls(void (*fn)(const char *), char *txt, char *suffix) continue; if (suffix && *suffix) strbuf_addf(url_list[i], "/%s", suffix); - fn(url_list[i]->buf); } + _html("<ul class='repo-url'>") { + _html("<li>") { + _html("<select>") { + for (i = 0; url_list[i] != NULL; i++) + htmlf("<option " + "onclick=\"document.getElementById('clone-url-value')" + ".value='%s'\">%s</option>", + url_list[i]->buf, get_clone_type(url_list[i]->buf)); + } _html("</select>"); + } _html("</li>"); + html("<li class='select-arrow'><i class='fa fa-caret-down'></i></li>"); + + _html("<li>") { + htmlf("<input onclick='this.select()', type='text' " + "class='input-copy' id='clone-url-value' value='%s' readonly />", + url_list[0]->buf); + } _html("</li>"); + + _html("<li>") { + html("<span class='copy' " + "onclick=\"document.getElementById('clone-url-value').select();" + "document.execCommand('copy')\">" + "<i class='fa fa-copy'></i></span>"); + } _html("</li>"); + + } _html("</ul>"); + strbuf_list_free(url_list); } @@ -1003,17 +1039,6 @@ static void print_header(void) /*html("</td></tr></table>\n");*/ } -static void print_url(const char *url) -{ - static bool print = true; - - if (print) - { - htmlf("<input type='text' value='%s' readonly />", url); - print = false; - } -} - void cgit_print_pageheader(void) { html("<div id='cgit'>"); @@ -1023,14 +1048,14 @@ void cgit_print_pageheader(void) if (ctx.env.authenticated && ctx.repo) { _html("<div class='summary-header'>") { if (ctx.repo->logo != NULL) - htmlf("<img src='%s' />", ctx.repo->logo); + htmlf("<img src='/%s' />", ctx.repo->logo); else htmlf("<img src='%s' />", ctx.cfg.logo); html("<br />"); htmlf("<h3>%s</h3>", ctx.repo->name); htmlf("<span>%s</span>", ctx.repo->desc); htmlf("<h5>%s</h5>", ctx.repo->owner == NULL ? "" : ctx.repo->owner); - cgit_add_clone_urls(print_url); + cgit_add_clone_urls(NULL); } _html("</div>"); _html("<div class='summary-menu'>") {