nitdoc: Adding a way to switch of branch
authorStefan Lage <lagestfan@gmail.com>
Fri, 24 May 2013 01:22:31 +0000 (21:22 -0400)
committerStefan Lage <lagestfan@gmail.com>
Fri, 24 May 2013 02:26:50 +0000 (22:26 -0400)
Adding dropdown in the loggin form, visible only when we are
logged, which list all branches of the
repository on github, it allow to switch between all branch and load all
comment of the branch selected

signed-off by: Stefan Lage <lagestfan@gmail.com>

share/nitdoc/scripts/js-facilities.js
share/nitdoc/styles/main.css
src/nitdoc.nit

index 84aab54..a946d9b 100644 (file)
@@ -1,5 +1,7 @@
 // User\r
 var userB64 = null;\r
+var userName = "";\r
+var password = "";\r
 var sessionStarted = false;\r
 var editComment = 0;\r
 var currentfileContent = '';\r
@@ -431,6 +433,7 @@ $(document).ready(function() {
                                setCookie("logginNitdoc", base64.encode(userName+':'+password+':'+repoName+':'+branchName), 1);\r
                                $('#loginGit').val("");\r
                                $('#passwordGit').val("");\r
+                               reloadComment();\r
                        }\r
                }       \r
                else\r
@@ -467,7 +470,7 @@ $(document).ready(function() {
                        // Show commit button\r
                        $(this).next().next().next().show();\r
                        // Add text in edit box\r
-                       if($(this).next().val() == ""){ $(this).next().val(adapt); }\r
+                       if($(this).next().val() == "" || $(this).next().val() != adapt){ $(this).next().val(adapt); }\r
                        // Resize edit box \r
                        $(this).next().height($(this).next().prop("scrollHeight"));\r
                        // Select it\r
@@ -612,6 +615,16 @@ $(document).ready(function() {
                preElement = $(this);  \r
         });\r
 \r
+       $("#dropBranches").change(function () {         \r
+               $("#dropBranches option:selected").each(function () {\r
+                       if(branchName != $(this).text()){\r
+                               branchName = $(this).text();\r
+                       }\r
+               });\r
+               $.when(updateCookie(userName, password, repoName, branchName)).done(function(){\r
+                       reloadComment();\r
+               });\r
+       });\r
 });\r
 \r
 /* Parse current URL and return anchor name */\r
@@ -676,7 +689,10 @@ function startCommitProcess()
 }\r
 \r
 function displayLogginModal(){\r
-       if ($('.popover').is(':hidden')) { $('.popover').show(); }\r
+       if ($('.popover').is(':hidden')) { \r
+               if(sessionStarted){ getListBranches(); }\r
+               $('.popover').show(); \r
+       }\r
        else { $('.popover').hide(); }  \r
        updateDisplaying();\r
 }\r
@@ -693,13 +709,14 @@ function updateDisplaying(){
                $('#lbrepositoryGit').hide();\r
                $('#lbbranchGit').hide();  \r
                $('#branchGit').hide();\r
+               $('#listBranches').show();\r
                $("#liGitHub").attr("class", "current");\r
                $("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");\r
                $('#nickName').text(userName);          \r
                $('#githubAccount').attr("href", "https://github.com/"+userName);\r
                $('#logginMessage').css({'display' : 'block'});\r
                $('#logginMessage').css({'text-align' : 'center'});\r
-               $('.popover').css({'height' : '80px'}); \r
+               $('.popover').css({'height' : '120px'});\r
                $('#signIn').text("Sign out");  \r
                sessionStarted = true;\r
                reloadComment();\r
@@ -726,6 +743,7 @@ function updateDisplaying(){
                $('#lbrepositoryGit').show();\r
                $('#lbbranchGit').show();  \r
                $('#branchGit').show();  \r
+               $('#listBranches').hide();\r
        }\r
 }\r
 \r
@@ -742,6 +760,13 @@ function del_cookie(c_name)
     document.cookie = c_name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';\r
 }\r
 \r
+function updateCookie(user, pwd, repo, branch){\r
+       if(checkCookie()){\r
+               branchName = branch;\r
+               setCookie("logginNitdoc", base64.encode(user+':'+pwd+':'+repo+':'+branch), 1);\r
+       }\r
+}\r
+\r
 function getCookie(c_name)\r
 {\r
        var c_value = document.cookie;\r
@@ -770,6 +795,7 @@ function checkCookie()
        {\r
                cookie = base64.decode(cookie);\r
                userName = cookie.split(':')[0];\r
+               password = cookie.split(':')[1];\r
                repoName = cookie.split(':')[2];                \r
                branchName = cookie.split(':')[3];\r
                return true;\r
@@ -1230,3 +1256,33 @@ function getCommentOfFunction(element){
            if (textC != ""){ element.text(textC); }\r
        }\r
 }\r
+\r
+// Get list of branches\r
+function getListBranches()\r
+{\r
+       cleanListBranches();\r
+    $.ajax({\r
+        beforeSend: function (xhr) { \r
+            if ($("#login").val() != ""){ xhr.setRequestHeader ("Authorization", userB64); }\r
+        },\r
+        type: "GET", \r
+        url: "https://api.github.com/repos/"+userName+"/"+githubRepo+"/branches", \r
+        async:false,\r
+        dataType:'json',\r
+        success: function(success)\r
+        {   \r
+            for(var branch in success) { \r
+               var selected = '';\r
+               if(branchName == success[branch].name){\r
+                       selected = 'selected';\r
+               }\r
+               $('#dropBranches').append('<option value="" '+ selected +'>' + success[branch].name + '</option>');\r
+            }\r
+        }\r
+    });\r
+}\r
+\r
+// Delete all option in the list\r
+function cleanListBranches(){\r
+       $('#dropBranches').children("option").remove();\r
+}
index 5bc8880..b5358be 100644 (file)
@@ -775,7 +775,7 @@ fieldset {
        margin-left: 10px;\r
        margin-top: 10px;       \r
 }\r
-#logginMessage {\r
+#logginMessage , #lbBranches{\r
        color: black;\r
        font-style: normal;\r
        text-align: center;\r
@@ -824,3 +824,15 @@ fieldset {
 #imgGitHub{\r
        width:20px;\r
 }\r
+\r
+#dropBranches{\r
+       font-size: 12px;\r
+       height:20px; \r
+}\r
+\r
+#listBranches{\r
+       display:block;\r
+       text-align:center;\r
+       margin-top: 15px;\r
+       margin-bottom: 15px;    \r
+}
index fc233bf..472ac76 100644 (file)
@@ -170,7 +170,7 @@ class DocContext
                var custom_items = ""
                if self._opt_custom_menu_items.value != null then custom_items = self._opt_custom_menu_items.value.as(not null)
 
-               var action_bar = "<header><nav class='main'><ul>{custom_items}<li class=\"current\">Overview</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li><li id=\"liGitHub\" class=\"\"><a id=\"logGitHub\" class=\"btn\" ><img id=\"imgGitHub\" src=\"resources/icons/github-icon.png\" /></a><div class=\"popover bottom\"><div class=\"arrow\"></div><div><label id=\"lbloginGit\" for=\"login\">Username</label><input id=\"loginGit\" type=\"text\" name=\"login\"><label id=\"logginMessage\" >Hello <a id=\"githubAccount\" ><strong id=\"nickName\"></strong></a></label></div><div><label id=\"lbpasswordGit\" for=\"password\">Password</label><input id=\"passwordGit\" type=\"password\" name=\"password\"><div><label id=\"lbrepositoryGit\" for=\"repository\">Repository</label><input id=\"repositoryGit\" type=\"text\" name=\"repository\"></div><div><label id=\"lbbranchGit\" for=\"branch\">Branch</label><input id=\"branchGit\" type=\"text\" name=\"branch\"></div></div><div id=\"divlogIn\"><a id=\"signIn\" >Sign In</a></div></div></li></ul></nav></header>\n"
+               var action_bar = "<header><nav class='main'><ul>{custom_items}<li class=\"current\">Overview</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li><li id=\"liGitHub\" class=\"\"><a id=\"logGitHub\" class=\"btn\" ><img id=\"imgGitHub\" src=\"resources/icons/github-icon.png\" /></a><div class=\"popover bottom\"><div class=\"arrow\"></div><div><label id=\"lbloginGit\" for=\"login\">Username</label><input id=\"loginGit\" type=\"text\" name=\"login\"><label id=\"logginMessage\" >Hello <a id=\"githubAccount\" ><strong id=\"nickName\"></strong></a></label></div><div><label id=\"lbpasswordGit\" for=\"password\">Password</label><input id=\"passwordGit\" type=\"password\" name=\"password\"><div id=\"listBranches\"><label id=\"lbBranches\">Branch </label><select id=\"dropBranches\" name=\"dropBranches\" tabindex=\"1\" class=\"dropdown\"></select></div></div><div><label id=\"lbrepositoryGit\" for=\"repository\">Repository</label><input id=\"repositoryGit\" type=\"text\" name=\"repository\"></div><div><label id=\"lbbranchGit\" for=\"branch\">Branch</label><input id=\"branchGit\" type=\"text\" name=\"branch\"></div></div><div id=\"divlogIn\"><a id=\"signIn\" >Sign In</a></div></div></li></ul></nav></header>\n"
                var custom_title = "Nitdoc"
                if self._opt_custom_title.value != null then custom_title = self._opt_custom_title.value.as(not null)
                
@@ -227,7 +227,7 @@ class DocContext
                        assert mod isa MMSrcModule
                        if not mod.require_doc(self) then continue
                        self.filename = mod.html_name
-                       action_bar = "<header><nav class='main'><ul>{custom_items}<li><a href='./index.html'>Overview</a></li><li class=\"current\">{mod.name}</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li><li id=\"liGitHub\" class=\"\"><a id=\"logGitHub\" class=\"btn\" ><img id=\"imgGitHub\" src=\"resources/icons/github-icon.png\" /></a><div class=\"popover bottom\"><div class=\"arrow\"></div><div><label id=\"lbloginGit\" for=\"login\">Username</label><input id=\"loginGit\" type=\"text\" name=\"login\"><label id=\"logginMessage\" >Hello <a id=\"githubAccount\" ><strong id=\"nickName\"></strong></a></label></div><div><label id=\"lbpasswordGit\" for=\"password\">Password</label><input id=\"passwordGit\" type=\"password\" name=\"password\"></div><div><label id=\"lbrepositoryGit\" for=\"repository\">Repository</label><input id=\"repositoryGit\" type=\"text\" name=\"repository\"></div><div><label id=\"lbbranchGit\" for=\"branch\">Branch</label><input id=\"branchGit\" type=\"text\" name=\"branch\"></div><div id=\"divlogIn\"><a id=\"signIn\" >Sign In</a></div></div></li></ul></nav></header>\n"
+                       action_bar = "<header><nav class='main'><ul>{custom_items}<li><a href='./index.html'>Overview</a></li><li class=\"current\">{mod.name}</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li><li id=\"liGitHub\" class=\"\"><a id=\"logGitHub\" class=\"btn\" ><img id=\"imgGitHub\" src=\"resources/icons/github-icon.png\" /></a><div class=\"popover bottom\"><div class=\"arrow\"></div><div><label id=\"lbloginGit\" for=\"login\">Username</label><input id=\"loginGit\" type=\"text\" name=\"login\"><label id=\"logginMessage\" >Hello <a id=\"githubAccount\" ><strong id=\"nickName\"></strong></a></label></div><div><label id=\"lbpasswordGit\" for=\"password\">Password</label><input id=\"passwordGit\" type=\"password\" name=\"password\"><div id=\"listBranches\"><label id=\"lbBranches\">Branch </label><select id=\"dropBranches\" name=\"dropBranches\" tabindex=\"1\" class=\"dropdown\"></select></div>/div><div><label id=\"lbrepositoryGit\" for=\"repository\">Repository</label><input id=\"repositoryGit\" type=\"text\" name=\"repository\"></div><div><label id=\"lbbranchGit\" for=\"branch\">Branch</label><input id=\"branchGit\" type=\"text\" name=\"branch\"></div><div id=\"divlogIn\"><a id=\"signIn\" >Sign In</a></div></div></li></ul></nav></header>\n"
                        clear
                        addGithubInformation
                        addCommitForm
@@ -246,7 +246,7 @@ class DocContext
                for c in mainmod.local_classes do
                        if not c.require_doc(self) then continue
                        self.filename = c.html_name
-                       action_bar = "<header><nav class='main'><ul>{custom_items}<li><a href='./index.html'>Overview</a></li><li>{c.global.intro.mmmodule.toplevel_owner.html_link(self)}</li><li class=\"current\">{c.name}</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li><li id=\"liGitHub\" class=\"\"><a id=\"logGitHub\" class=\"btn\" ><img id=\"imgGitHub\" src=\"resources/icons/github-icon.png\" /></a><div class=\"popover bottom\"><div class=\"arrow\"></div><div><label id=\"lbloginGit\" for=\"login\">Username</label><input id=\"loginGit\" type=\"text\" name=\"login\"><label id=\"logginMessage\" >Hello <a id=\"githubAccount\" ><strong id=\"nickName\"></strong></a></label></div><div><label id=\"lbpasswordGit\" for=\"password\">Password</label><input id=\"passwordGit\" type=\"password\" name=\"password\"></div><div><label id=\"lbrepositoryGit\" for=\"repository\">Repository</label><input id=\"repositoryGit\" type=\"text\" name=\"repository\"></div><div><label id=\"lbbranchGit\" for=\"branch\">Branch</label><input id=\"branchGit\" type=\"text\" name=\"branch\"></div><div id=\"divlogIn\"><a id=\"signIn\" >Sign In</a></div></div></li></ul></nav></header>\n"
+                       action_bar = "<header><nav class='main'><ul>{custom_items}<li><a href='./index.html'>Overview</a></li><li>{c.global.intro.mmmodule.toplevel_owner.html_link(self)}</li><li class=\"current\">{c.name}</li><li><a href='full-index.html'>Full Index</a></li><li><a href=\"help.html\">Help</a></li><li id=\"liGitHub\" class=\"\"><a id=\"logGitHub\" class=\"btn\" ><img id=\"imgGitHub\" src=\"resources/icons/github-icon.png\" /></a><div class=\"popover bottom\"><div class=\"arrow\"></div><div><label id=\"lbloginGit\" for=\"login\">Username</label><input id=\"loginGit\" type=\"text\" name=\"login\"><label id=\"logginMessage\" >Hello <a id=\"githubAccount\" ><strong id=\"nickName\"></strong></a></label></div><div><label id=\"lbpasswordGit\" for=\"password\">Password</label><input id=\"passwordGit\" type=\"password\" name=\"password\"><div id=\"listBranches\"><label id=\"lbBranches\">Branch </label><select id=\"dropBranches\" name=\"dropBranches\" tabindex=\"1\" class=\"dropdown\"></select></div></div><div><label id=\"lbrepositoryGit\" for=\"repository\">Repository</label><input id=\"repositoryGit\" type=\"text\" name=\"repository\"></div><div><label id=\"lbbranchGit\" for=\"branch\">Branch</label><input id=\"branchGit\" type=\"text\" name=\"branch\"></div><div id=\"divlogIn\"><a id=\"signIn\" >Sign In</a></div></div></li></ul></nav></header>\n"
                        clear
                        addGithubInformation
                        addCommitForm
@@ -262,7 +262,7 @@ class DocContext
                end
 
                self.filename = "fullindex"
-               action_bar = "<header><nav class='main'><ul>{custom_items}<li><a href='./index.html'>Overview</a></li><li class=\"current\">Full Index</li><li><a href=\"help.html\">Help</a></li><li id=\"liGitHub\" class=\"\"><a id=\"logGitHub\" class=\"btn\" ><img id=\"imgGitHub\" src=\"resources/icons/github-icon.png\" /></a><div class=\"popover bottom\"><div class=\"arrow\"></div><div><label id=\"lbloginGit\" for=\"login\">Username</label><input id=\"loginGit\" type=\"text\" name=\"login\"><label id=\"logginMessage\" >Hello <a id=\"githubAccount\" ><strong id=\"nickName\"></strong></a></label></div><div><label id=\"lbpasswordGit\" for=\"password\">Password</label><input id=\"passwordGit\" type=\"password\" name=\"password\"></div><div><label id=\"lbrepositoryGit\" for=\"repository\">Repository</label><input id=\"repositoryGit\" type=\"text\" name=\"repository\"></div><div><label id=\"lbbranchGit\" for=\"branch\">Branch</label><input id=\"branchGit\" type=\"text\" name=\"branch\"></div><div id=\"divlogIn\"><a id=\"signIn\" >Sign In</a></div></div></li></ul></nav></header>\n"
+               action_bar = "<header><nav class='main'><ul>{custom_items}<li><a href='./index.html'>Overview</a></li><li class=\"current\">Full Index</li><li><a href=\"help.html\">Help</a></li><li id=\"liGitHub\" class=\"\"><a id=\"logGitHub\" class=\"btn\" ><img id=\"imgGitHub\" src=\"resources/icons/github-icon.png\" /></a><div class=\"popover bottom\"><div class=\"arrow\"></div><div><label id=\"lbloginGit\" for=\"login\">Username</label><input id=\"loginGit\" type=\"text\" name=\"login\"><label id=\"logginMessage\" >Hello <a id=\"githubAccount\" ><strong id=\"nickName\"></strong></a></label></div><div><label id=\"lbpasswordGit\" for=\"password\">Password</label><input id=\"passwordGit\" type=\"password\" name=\"password\"><div id=\"listBranches\"><label id=\"lbBranches\">Branch </label><select id=\"dropBranches\" name=\"dropBranches\" tabindex=\"1\" class=\"dropdown\"></select></div></div><div><label id=\"lbrepositoryGit\" for=\"repository\">Repository</label><input id=\"repositoryGit\" type=\"text\" name=\"repository\"></div><div><label id=\"lbbranchGit\" for=\"branch\">Branch</label><input id=\"branchGit\" type=\"text\" name=\"branch\"></div><div id=\"divlogIn\"><a id=\"signIn\" >Sign In</a></div></div></li></ul></nav></header>\n"
                clear
                addGithubInformation
                addCommitForm