total contributions in the last 12 months
'
+ });
+
+ new Vue({
+ delimiters: vueDelimeters,
+ el: el,
+
+ data: {
+ suburl: document.querySelector('meta[name=_suburl]').content,
+ heatmapUser: heatmapUser,
+ locale: locale
+ },
+ });
+}
+
+function initFilterBranchTagDropdown(selector) {
+ $(selector).each(function() {
+ const $dropdown = $(this);
+ const $data = $dropdown.find('.data');
+ const data = {
+ items: [],
+ mode: $data.data('mode'),
+ searchTerm: '',
+ noResults: '',
+ canCreateBranch: false,
+ menuVisible: false,
+ active: 0
+ };
+ $data.find('.item').each(function() {
+ data.items.push({
+ name: $(this).text(),
+ url: $(this).data('url'),
+ branch: $(this).hasClass('branch'),
+ tag: $(this).hasClass('tag'),
+ selected: $(this).hasClass('selected')
+ });
+ });
+ $data.remove();
+ new Vue({
+ delimiters: ['${', '}'],
+ el: this,
+ data: data,
+
+ beforeMount: function () {
+ const vm = this;
+
+ this.noResults = vm.$el.getAttribute('data-no-results');
+ this.canCreateBranch = vm.$el.getAttribute('data-can-create-branch') === 'true';
+
+ document.body.addEventListener('click', function(event) {
+ if (vm.$el.contains(event.target)) {
+ return;
+ }
+ if (vm.menuVisible) {
+ Vue.set(vm, 'menuVisible', false);
+ }
+ });
+ },
+
+ watch: {
+ menuVisible: function(visible) {
+ if (visible) {
+ this.focusSearchField();
+ }
+ }
+ },
+
+ computed: {
+ filteredItems: function() {
+ const vm = this;
+
+ const items = vm.items.filter(function (item) {
+ return ((vm.mode === 'branches' && item.branch)
+ || (vm.mode === 'tags' && item.tag))
+ && (!vm.searchTerm
+ || item.name.toLowerCase().indexOf(vm.searchTerm.toLowerCase()) >= 0);
+ });
+
+ vm.active = (items.length === 0 && vm.showCreateNewBranch ? 0 : -1);
+
+ return items;
+ },
+ showNoResults: function() {
+ return this.filteredItems.length === 0
+ && !this.showCreateNewBranch;
+ },
+ showCreateNewBranch: function() {
+ const vm = this;
+ if (!this.canCreateBranch || !vm.searchTerm || vm.mode === 'tags') {
+ return false;
+ }
+
+ return vm.items.filter(function (item) {
+ return item.name.toLowerCase() === vm.searchTerm.toLowerCase()
+ }).length === 0;
+ }
+ },
+
+ methods: {
+ selectItem: function(item) {
+ const prev = this.getSelected();
+ if (prev !== null) {
+ prev.selected = false;
+ }
+ item.selected = true;
+ window.location.href = item.url;
+ },
+ createNewBranch: function() {
+ if (!this.showCreateNewBranch) {
+ return;
+ }
+ this.$refs.newBranchForm.submit();
+ },
+ focusSearchField: function() {
+ const vm = this;
+ Vue.nextTick(function() {
+ vm.$refs.searchField.focus();
+ });
+ },
+ getSelected: function() {
+ for (let i = 0, j = this.items.length; i < j; ++i) {
+ if (this.items[i].selected)
+ return this.items[i];
+ }
+ return null;
+ },
+ getSelectedIndexInFiltered: function() {
+ for (let i = 0, j = this.filteredItems.length; i < j; ++i) {
+ if (this.filteredItems[i].selected)
+ return i;
+ }
+ return -1;
+ },
+ scrollToActive: function() {
+ let el = this.$refs['listItem' + this.active];
+ if (!el || el.length === 0) {
+ return;
+ }
+ if (Array.isArray(el)) {
+ el = el[0];
+ }
+
+ const cont = this.$refs.scrollContainer;
+
+ if (el.offsetTop < cont.scrollTop) {
+ cont.scrollTop = el.offsetTop;
+ }
+ else if (el.offsetTop + el.clientHeight > cont.scrollTop + cont.clientHeight) {
+ cont.scrollTop = el.offsetTop + el.clientHeight - cont.clientHeight;
+ }
+ },
+ keydown: function(event) {
+ const vm = this;
+ if (event.keyCode === 40) {
+ // arrow down
+ event.preventDefault();
+
+ if (vm.active === -1) {
+ vm.active = vm.getSelectedIndexInFiltered();
+ }
+
+ if (vm.active + (vm.showCreateNewBranch ? 0 : 1) >= vm.filteredItems.length) {
+ return;
+ }
+ vm.active++;
+ vm.scrollToActive();
+ }
+ if (event.keyCode === 38) {
+ // arrow up
+ event.preventDefault();
+
+ if (vm.active === -1) {
+ vm.active = vm.getSelectedIndexInFiltered();
+ }
+
+ if (vm.active <= 0) {
+ return;
+ }
+ vm.active--;
+ vm.scrollToActive();
+ }
+ if (event.keyCode == 13) {
+ // enter
+ event.preventDefault();
+
+ if (vm.active >= vm.filteredItems.length) {
+ vm.createNewBranch();
+ } else if (vm.active >= 0) {
+ vm.selectItem(vm.filteredItems[vm.active]);
+ }
+ }
+ if (event.keyCode == 27) {
+ // escape
+ event.preventDefault();
+ vm.menuVisible = false;
+ }
+ }
+ }
+ });
+ });
+}
+
+$(".commit-button").click(function(e) {
+ e.preventDefault();
+ $(this).parent().find('.commit-body').toggle();
+});
+
+function initNavbarContentToggle() {
+ const content = $('#navbar');
+ const toggle = $('#navbar-expand-toggle');
+ let isExpanded = false;
+ toggle.click(function() {
+ isExpanded = !isExpanded;
+ if (isExpanded) {
+ content.addClass('shown');
+ toggle.addClass('active');
+ }
+ else {
+ content.removeClass('shown');
+ toggle.removeClass('active');
+ }
+ });
+}
+
+function initTopicbar() {
+ const mgrBtn = $("#manage_topic");
+ const editDiv = $("#topic_edit");
+ const viewDiv = $("#repo-topics");
+ const saveBtn = $("#save_topic");
+ const topicDropdown = $('#topic_edit .dropdown');
+ const topicForm = $('#topic_edit.ui.form');
+ const topicPrompts = getPrompts();
+
+ mgrBtn.click(function() {
+ viewDiv.hide();
+ editDiv.css('display', ''); // show Semantic UI Grid
+ });
+
+ function getPrompts() {
+ const hidePrompt = $("div.hide#validate_prompt"),
+ prompts = {
+ countPrompt: hidePrompt.children('#count_prompt').text(),
+ formatPrompt: hidePrompt.children('#format_prompt').text()
+ };
+ hidePrompt.remove();
+ return prompts;
+ }
+
+ saveBtn.click(function() {
+ const topics = $("input[name=topics]").val();
+
+ $.post(saveBtn.data('link'), {
+ "_csrf": csrf,
+ "topics": topics
+ }, function(_data, _textStatus, xhr){
+ if (xhr.responseJSON.status === 'ok') {
+ viewDiv.children(".topic").remove();
+ if (topics.length) {
+ const topicArray = topics.split(",");
+
+ const last = viewDiv.children("a").last();
+ for (let i=0; i < topicArray.length; i++) {
+ $('
'+topicArray[i]+'
').insertBefore(last)
+ }
+ }
+ editDiv.css('display', 'none');
+ viewDiv.show();
+ }
+ }).fail(function(xhr){
+ if (xhr.status === 422) {
+ if (xhr.responseJSON.invalidTopics.length > 0) {
+ topicPrompts.formatPrompt = xhr.responseJSON.message;
+
+ const invalidTopics = xhr.responseJSON.invalidTopics,
+ topicLables = topicDropdown.children('a.ui.label');
+
+ topics.split(',').forEach(function(value, index) {
+ for (let i=0; i < invalidTopics.length; i++) {
+ if (invalidTopics[i] === value) {
+ topicLables.eq(index).removeClass("green").addClass("red");
+ }
+ }
+ });
+ } else {
+ topicPrompts.countPrompt = xhr.responseJSON.message;
+ }
+ }
+ }).always(function() {
+ topicForm.form('validate form');
+ });
+ });
+
+ topicDropdown.dropdown({
+ allowAdditions: true,
+ forceSelection: false,
+ fields: { name: "description", value: "data-value" },
+ saveRemoteData: false,
+ label: {
+ transition : 'horizontal flip',
+ duration : 200,
+ variation : false,
+ blue : true,
+ basic: true,
+ },
+ className: {
+ label: 'ui small label'
+ },
+ apiSettings: {
+ url: suburl + '/api/v1/topics/search?q={query}',
+ throttle: 500,
+ cache: false,
+ onResponse: function(res) {
+ const formattedResponse = {
+ success: false,
+ results: [],
+ };
+ const stripTags = function (text) {
+ return text.replace(/<[^>]*>?/gm, "");
+ };
+
+ const query = stripTags(this.urlData.query.trim());
+ let found_query = false;
+ const current_topics = [];
+ topicDropdown.find('div.label.visible.topic,a.label.visible').each(function(_,e){ current_topics.push(e.dataset.value); });
+
+ if (res.topics) {
+ let found = false;
+ for (let i=0;i < res.topics.length;i++) {
+ // skip currently added tags
+ if (current_topics.indexOf(res.topics[i].topic_name) != -1){
+ continue;
+ }
+
+ if (res.topics[i].topic_name.toLowerCase() === query.toLowerCase()){
+ found_query = true;
+ }
+ formattedResponse.results.push({"description": res.topics[i].topic_name, "data-value": res.topics[i].topic_name});
+ found = true;
+ }
+ formattedResponse.success = found;
+ }
+
+ if (query.length > 0 && !found_query){
+ formattedResponse.success = true;
+ formattedResponse.results.unshift({"description": query, "data-value": query});
+ } else if (query.length > 0 && found_query) {
+ formattedResponse.results.sort(function(a, b){
+ if (a.description.toLowerCase() === query.toLowerCase()) return -1;
+ if (b.description.toLowerCase() === query.toLowerCase()) return 1;
+ if (a.description > b.description) return -1;
+ if (a.description < b.description) return 1;
+ return 0;
+ });
+ }
+
+
+ return formattedResponse;
+ },
+ },
+ onLabelCreate: function(value) {
+ value = value.toLowerCase().trim();
+ this.attr("data-value", value).contents().first().replaceWith(value);
+ return $(this);
+ },
+ onAdd: function(addedValue, _addedText, $addedChoice) {
+ addedValue = addedValue.toLowerCase().trim();
+ $($addedChoice).attr('data-value', addedValue);
+ $($addedChoice).attr('data-text', addedValue);
+ }
+ });
+
+ $.fn.form.settings.rules.validateTopic = function(_values, regExp) {
+ const topics = topicDropdown.children('a.ui.label'),
+ status = topics.length === 0 || topics.last().attr("data-value").match(regExp);
+ if (!status) {
+ topics.last().removeClass("green").addClass("red");
+ }
+ return status && topicDropdown.children('a.ui.label.red').length === 0;
+ };
+
+ topicForm.form({
+ on: 'change',
+ inline : true,
+ fields: {
+ topics: {
+ identifier: 'topics',
+ rules: [
+ {
+ type: 'validateTopic',
+ value: /^[a-z0-9][a-z0-9-]{1,35}$/,
+ prompt: topicPrompts.formatPrompt
+ },
+ {
+ type: 'maxCount[25]',
+ prompt: topicPrompts.countPrompt
+ }
+ ]
+ },
+ }
+ });
+}
+function toggleDeadlineForm() {
+ $('#deadlineForm').fadeToggle(150);
+}
+
+function setDeadline() {
+ const deadline = $('#deadlineDate').val();
+ updateDeadline(deadline);
+}
+
+function updateDeadline(deadlineString) {
+ $('#deadline-err-invalid-date').hide();
+ $('#deadline-loader').addClass('loading');
+
+ let realDeadline = null;
+ if (deadlineString !== '') {
+
+ const newDate = Date.parse(deadlineString)
+
+ if (isNaN(newDate)) {
+ $('#deadline-loader').removeClass('loading');
+ $('#deadline-err-invalid-date').show();
+ return false;
+ }
+ realDeadline = new Date(newDate);
+ }
+
+ $.ajax($('#update-issue-deadline-form').attr('action') + '/deadline', {
+ data: JSON.stringify({
+ 'due_date': realDeadline,
+ }),
+ headers: {
+ 'X-Csrf-Token': csrf,
+ 'X-Remote': true,
+ },
+ contentType: 'application/json',
+ type: 'POST',
+ success: function () {
+ reload();
+ },
+ error: function () {
+ $('#deadline-loader').removeClass('loading');
+ $('#deadline-err-invalid-date').show();
+ }
+ });
+}
+
+function deleteDependencyModal(id, type) {
+ $('.remove-dependency')
+ .modal({
+ closable: false,
+ duration: 200,
+ onApprove: function () {
+ $('#removeDependencyID').val(id);
+ $('#dependencyType').val(type);
+ $('#removeDependencyForm').submit();
+ }
+ }).modal('show')
+ ;
+}
+
+function initIssueList() {
+ const repolink = $('#repolink').val();
+ $('#new-dependency-drop-list')
+ .dropdown({
+ apiSettings: {
+ url: suburl + '/api/v1/repos/' + repolink + '/issues?q={query}',
+ onResponse: function(response) {
+ const filteredResponse = {'success': true, 'results': []};
+ const currIssueId = $('#new-dependency-drop-list').data('issue-id');
+ // Parse the response from the api to work with our dropdown
+ $.each(response, function(_i, issue) {
+ // Don't list current issue in the dependency list.
+ if(issue.id === currIssueId) {
+ return;
+ }
+ filteredResponse.results.push({
+ 'name' : '#' + issue.number + ' ' + htmlEncode(issue.title),
+ 'value' : issue.id
+ });
+ });
+ return filteredResponse;
+ },
+ cache: false,
+ },
+
+ fullTextSearch: true
+ })
+ ;
+}
+function cancelCodeComment(btn) {
+ const form = $(btn).closest("form");
+ if(form.length > 0 && form.hasClass('comment-form')) {
+ form.addClass('hide');
+ form.parent().find('button.comment-form-reply').show();
+ } else {
+ form.closest('.comment-code-cloud').remove()
+ }
+}
+function onOAuthLoginClick() {
+ const oauthLoader = $('#oauth2-login-loader');
+ const oauthNav = $('#oauth2-login-navigator');
+
+ oauthNav.hide();
+ oauthLoader.removeClass('disabled');
+
+ setTimeout(function(){
+ // recover previous content to let user try again
+ // usually redirection will be performed before this action
+ oauthLoader.addClass('disabled');
+ oauthNav.show();
+ },5000);
+}
From a65f16b430f4aab0a3868f4982b579b1550330a2 Mon Sep 17 00:00:00 2001
From: caicai8 <1149225589@qq.com>
Date: Thu, 26 Dec 2019 14:30:50 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=9D=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
public/react/src/forge/New/Index.js | 97 ++++++++++++++++++++++-------
1 file changed, 75 insertions(+), 22 deletions(-)
diff --git a/public/react/src/forge/New/Index.js b/public/react/src/forge/New/Index.js
index 72f63e8cd..48c07e397 100644
--- a/public/react/src/forge/New/Index.js
+++ b/public/react/src/forge/New/Index.js
@@ -13,13 +13,15 @@ class Index extends Component{
this.state={
// authorValue:"0",
preType:"0",
- subType:"0",
+ // subType:"0",
languageValue:"0",
gitignoreType:"0",
- openSourceType:"0",
+ LicensesType:"0",
CategoryList:undefined,
- LanguageList:undefined
+ LanguageList:undefined,
+ GitignoreList:undefined,
+ LicensesList:undefined,
}
}
componentDidMount=()=>{
@@ -27,32 +29,79 @@ class Index extends Component{
this.getCategory();
// 获取项目语言
this.getLanguage();
+ // 获取Gitignore
+ this.getGitignore();
+ // 获取开源许可证
+ this.getLicenses();
}
getCategory=()=>{
- const url = `/project_categories`
+ const url = `/project_categories.json`
axios.get(url).then((result)=>{
if(result){
-
+ let CategoryList = this.setOptionsList(result.data.project_categories)
+ this.setState({
+ CategoryList
+ })
}
}).catch((error)=>{})
}
getLanguage=()=>{
- const url = `/project_languages`
+ const url = `/project_languages.json`
+ axios.get(url).then((result)=>{
+ if(result){
+ let LanguageList = this.setOptionsList(result.data.project_languages)
+ this.setState({
+ LanguageList
+ })
+ }
+ }).catch((error)=>{})
+ }
+
+ getGitignore=()=>{
+ const url = `/ignores.json`
axios.get(url).then((result)=>{
if(result){
+ let GitignoreList = this.setOptionsList(result.data.ignores)
+ this.setState({
+ GitignoreList
+ })
+ }
+ }).catch((error)=>{})
+ }
+ getLicenses=()=>{
+ const url = `/licenses.json`
+ axios.get(url).then((result)=>{
+ if(result){
+ let LicensesList = this.setOptionsList(result.data.licenses)
+ this.setState({
+ LicensesList
+ })
}
}).catch((error)=>{})
}
+ setOptionsList = (data) =>{
+ let list = undefined;
+ if(data && data.length > 0){
+ list = data.map((item,key)=>{
+ return(
+
+ )
+ })
+ }
+ return list;
+ }
+
subMitFrom = () =>{
this.props.form.validateFieldsAndScroll((err, values) => {
if(!err){
- const url = `/projects`;
+ console.log(values)
+ const url = `/projects.json`;
axios.post(url,{
- values,
- user_id:'50207'
+ ...values,
+ user_id:50207
}).then((result)=>{
if(result){
@@ -70,10 +119,15 @@ class Index extends Component{
const {
// authorValue,
preType,
- subType,
+ // subType,
languageValue,
gitignoreType,
- openSourceType
+ LicensesType,
+
+ CategoryList,
+ LanguageList,
+ GitignoreList,
+ LicensesList
}=this.state;
return(
@@ -129,7 +183,7 @@ class Index extends Component{
)}
好的存储库名称使用简单、深刻和独特的关键字
-
+ {/*
*/}
@@ -138,13 +192,12 @@ class Index extends Component{
required: true, message: '请选择大类别'
}],
})(
-
-
+ {/*
{getFieldDecorator('project_language_id', {
rules: [{
required: true, message: '请选择子类别'
@@ -155,8 +208,8 @@ class Index extends Component{
)}
-
-
+ */}
+ {/*
*/}
@@ -166,7 +219,7 @@ class Index extends Component{
}],
})(
-
+ {LanguageList}
)}
@@ -177,7 +230,7 @@ class Index extends Component{
>
{getFieldDecorator('ignore_id')(
-
+ {GitignoreList}
)}
@@ -185,8 +238,8 @@ class Index extends Component{
label="开源许可证"
>
{getFieldDecorator('license_id')(
-
-
+
+ {LicensesList}
)}