diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-04-11 10:51:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-11 10:51:44 +0800 |
commit | bec69f702ba8ecdc9a77db34ff94b7e55879be59 (patch) | |
tree | f6791e83ddbab715dc2fc9c8e3d004faddc92f6d /public/js/index.js | |
parent | 1946ce2954d49474b750938a1a6bb541f081485f (diff) | |
download | gitea-bec69f702ba8ecdc9a77db34ff94b7e55879be59.tar.gz gitea-bec69f702ba8ecdc9a77db34ff94b7e55879be59.zip |
Add topic support (#3711)
* add topic models and unit tests
* fix comments
* fix comment
* add the UI to show or add topics for a repo
* show topics on repositories list
* fix test
* don't show manage topics link when no permission
* use green basic as topic label
* fix topic label color
* remove trace content
* remove debug function
Diffstat (limited to 'public/js/index.js')
-rw-r--r-- | public/js/index.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/public/js/index.js b/public/js/index.js index 8b3d7c3d7d..c1ea85fc7d 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1591,6 +1591,7 @@ $(document).ready(function () { initTeamSettings(); initCtrlEnterSubmit(); initNavbarContentToggle(); + initTopicbar(); // Repo clone url. if ($('#repo-clone-url').length > 0) { @@ -2122,3 +2123,74 @@ function initNavbarContentToggle() { } }); } + +function initTopicbar() { + var mgrBtn = $("#manage_topic") + var editDiv = $("#topic_edit") + var viewDiv = $("#repo-topic") + var saveBtn = $("#save_topic") + + mgrBtn.click(function() { + viewDiv.hide(); + editDiv.show(); + }) + + saveBtn.click(function() { + var topics = $("input[name=topics]").val(); + + $.post($(this).data('link'), { + "_csrf": csrf, + "topics": topics + }).success(function(res){ + if (res["status"] != "ok") { + alert(res.message); + } else { + viewDiv.children(".topic").remove(); + var topicArray = topics.split(","); + var last = viewDiv.children("a").last(); + for (var i=0;i < topicArray.length; i++) { + $('<div class="ui green basic label topic" style="cursor:pointer;">'+topicArray[i]+'</div>').insertBefore(last) + } + } + }).done(function() { + editDiv.hide(); + viewDiv.show(); + }) + }) + + $('#topic_edit .dropdown').dropdown({ + allowAdditions: true, + fields: { name: "description", value: "data-value" }, + saveRemoteData: false, + label: { + transition : 'horizontal flip', + duration : 200, + variation : false, + blue : true, + basic: true, + }, + className: { + label: 'ui green basic label' + }, + apiSettings: { + url: suburl + '/api/v1/topics/search?q={query}', + throttle: 500, + cache: false, + onResponse: function(res) { + var formattedResponse = { + success: false, + results: new Array(), + }; + + if (res.topics) { + formattedResponse.success = true; + for (var i=0;i < res.topics.length;i++) { + formattedResponse.results.push({"description": res.topics[i].Name, "data-value":res.topics[i].Name}) + } + } + + return formattedResponse; + }, + }, + }); +}
\ No newline at end of file |