mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-30 19:08:37 +00:00 
			
		
		
		
	Refactor project templates (#26448)
This PR refactors a bunch of projects-related code, mostly the
templates.
The following things were done:
  - rename boards to columns in frontend code
  - use the new `ctx.Locale.Tr` method
  - cleanup template, remove useless newlines, classes, comments
  - merge org-/user and repo level project template together
    - move "new column" button into project toolbar
- move issue card (shared by projects and pinned issues) to shared
template, remove useless duplicated styles
- add search function to projects (to make the layout more similar to
milestones list where it is inherited from 😆)
  - maybe more changes I forgot I've done 😆 
Closes #24893
After:



---------
Co-authored-by: silverwind <me@silverwind.io>
			
			
This commit is contained in:
		| @@ -140,7 +140,7 @@ function initRepoIssueListAuthorDropdown() { | ||||
| } | ||||
|  | ||||
| function initPinRemoveButton() { | ||||
|   for (const button of document.getElementsByClassName('pinned-issue-unpin')) { | ||||
|   for (const button of document.getElementsByClassName('issue-card-unpin')) { | ||||
|     button.addEventListener('click', async (event) => { | ||||
|       const el = event.currentTarget; | ||||
|       const id = Number(el.getAttribute('data-issue-id')); | ||||
| @@ -157,7 +157,7 @@ function initPinRemoveButton() { | ||||
|         // Delete the tooltip | ||||
|         el._tippy.destroy(); | ||||
|         // Remove the Card | ||||
|         el.closest(`div.pinned-issue-card[data-issue-id="${id}"]`).remove(); | ||||
|         el.closest(`div.issue-card[data-issue-id="${id}"]`).remove(); | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
|   | ||||
| @@ -7,27 +7,27 @@ const {csrfToken} = window.config; | ||||
|  | ||||
| function updateIssueCount(cards) { | ||||
|   const parent = cards.parentElement; | ||||
|   const cnt = parent.getElementsByClassName('board-card').length; | ||||
|   parent.getElementsByClassName('board-card-cnt')[0].textContent = cnt; | ||||
|   const cnt = parent.getElementsByClassName('issue-card').length; | ||||
|   parent.getElementsByClassName('project-column-issue-count')[0].textContent = cnt; | ||||
| } | ||||
|  | ||||
| function createNewBoard(url, boardTitle, projectColorInput) { | ||||
| function createNewColumn(url, columnTitle, projectColorInput) { | ||||
|   $.ajax({ | ||||
|     url, | ||||
|     data: JSON.stringify({title: boardTitle.val(), color: projectColorInput.val()}), | ||||
|     data: JSON.stringify({title: columnTitle.val(), color: projectColorInput.val()}), | ||||
|     headers: { | ||||
|       'X-Csrf-Token': csrfToken, | ||||
|     }, | ||||
|     contentType: 'application/json', | ||||
|     method: 'POST', | ||||
|   }).done(() => { | ||||
|     boardTitle.closest('form').removeClass('dirty'); | ||||
|     columnTitle.closest('form').removeClass('dirty'); | ||||
|     window.location.reload(); | ||||
|   }); | ||||
| } | ||||
|  | ||||
| function moveIssue({item, from, to, oldIndex}) { | ||||
|   const columnCards = to.getElementsByClassName('board-card'); | ||||
|   const columnCards = to.getElementsByClassName('issue-card'); | ||||
|   updateIssueCount(from); | ||||
|   updateIssueCount(to); | ||||
|  | ||||
| @@ -56,19 +56,19 @@ async function initRepoProjectSortable() { | ||||
|   const els = document.querySelectorAll('#project-board > .board.sortable'); | ||||
|   if (!els.length) return; | ||||
|  | ||||
|   // the HTML layout is: #project-board > .board > .board-column .board.cards > .board-card.card .content | ||||
|   // the HTML layout is: #project-board > .board > .project-column .cards > .issue-card | ||||
|   const mainBoard = els[0]; | ||||
|   let boardColumns = mainBoard.getElementsByClassName('board-column'); | ||||
|   let boardColumns = mainBoard.getElementsByClassName('project-column'); | ||||
|   createSortable(mainBoard, { | ||||
|     group: 'board-column', | ||||
|     draggable: '.board-column', | ||||
|     group: 'project-column', | ||||
|     draggable: '.project-column', | ||||
|     filter: '[data-id="0"]', | ||||
|     animation: 150, | ||||
|     ghostClass: 'card-ghost', | ||||
|     delayOnTouchOnly: true, | ||||
|     delay: 500, | ||||
|     onSort: () => { | ||||
|       boardColumns = mainBoard.getElementsByClassName('board-column'); | ||||
|       boardColumns = mainBoard.getElementsByClassName('project-column'); | ||||
|       for (let i = 0; i < boardColumns.length; i++) { | ||||
|         const column = boardColumns[i]; | ||||
|         if (parseInt($(column).data('sorting')) !== i) { | ||||
| @@ -87,7 +87,7 @@ async function initRepoProjectSortable() { | ||||
|   }); | ||||
|  | ||||
|   for (const boardColumn of boardColumns) { | ||||
|     const boardCardList = boardColumn.getElementsByClassName('board')[0]; | ||||
|     const boardCardList = boardColumn.getElementsByClassName('cards')[0]; | ||||
|     createSortable(boardCardList, { | ||||
|       group: 'shared', | ||||
|       animation: 150, | ||||
| @@ -107,18 +107,18 @@ export function initRepoProject() { | ||||
|  | ||||
|   const _promise = initRepoProjectSortable(); | ||||
|  | ||||
|   $('.edit-project-board').each(function () { | ||||
|     const projectHeader = $(this).closest('.board-column-header'); | ||||
|     const projectTitleLabel = projectHeader.find('.board-label'); | ||||
|     const projectTitleInput = $(this).find('.project-board-title'); | ||||
|     const projectColorInput = $(this).find('#new_board_color'); | ||||
|     const boardColumn = $(this).closest('.board-column'); | ||||
|   $('.edit-project-column-modal').each(function () { | ||||
|     const projectHeader = $(this).closest('.project-column-header'); | ||||
|     const projectTitleLabel = projectHeader.find('.project-column-title'); | ||||
|     const projectTitleInput = $(this).find('.project-column-title-input'); | ||||
|     const projectColorInput = $(this).find('#new_project_column_color'); | ||||
|     const boardColumn = $(this).closest('.project-column'); | ||||
|  | ||||
|     if (boardColumn.css('backgroundColor')) { | ||||
|       setLabelColor(projectHeader, rgbToHex(boardColumn.css('backgroundColor'))); | ||||
|     } | ||||
|  | ||||
|     $(this).find('.edit-column-button').on('click', function (e) { | ||||
|     $(this).find('.edit-project-column-button').on('click', function (e) { | ||||
|       e.preventDefault(); | ||||
|  | ||||
|       $.ajax({ | ||||
| @@ -141,9 +141,9 @@ export function initRepoProject() { | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   $('.default-project-board-modal').each(function () { | ||||
|     const boardColumn = $(this).closest('.board-column'); | ||||
|     const showButton = $(boardColumn).find('.default-project-board-show'); | ||||
|   $('.default-project-column-modal').each(function () { | ||||
|     const boardColumn = $(this).closest('.project-column'); | ||||
|     const showButton = $(boardColumn).find('.default-project-column-show'); | ||||
|     const commitButton = $(this).find('.actions > .ok.button'); | ||||
|  | ||||
|     $(commitButton).on('click', (e) => { | ||||
| @@ -162,7 +162,7 @@ export function initRepoProject() { | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   $('.show-delete-column-modal').each(function () { | ||||
|   $('.show-delete-project-column-modal').each(function () { | ||||
|     const deleteColumnModal = $(`${$(this).attr('data-modal')}`); | ||||
|     const deleteColumnButton = deleteColumnModal.find('.actions > .ok.button'); | ||||
|     const deleteUrl = $(this).attr('data-url'); | ||||
| @@ -183,28 +183,28 @@ export function initRepoProject() { | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   $('#new_board_submit').on('click', (e) => { | ||||
|   $('#new_project_column_submit').on('click', (e) => { | ||||
|     e.preventDefault(); | ||||
|     const boardTitle = $('#new_board'); | ||||
|     const projectColorInput = $('#new_board_color_picker'); | ||||
|     if (!boardTitle.val()) { | ||||
|     const columnTitle = $('#new_project_column'); | ||||
|     const projectColorInput = $('#new_project_column_color_picker'); | ||||
|     if (!columnTitle.val()) { | ||||
|       return; | ||||
|     } | ||||
|     const url = $(this).data('url'); | ||||
|     createNewBoard(url, boardTitle, projectColorInput); | ||||
|     createNewColumn(url, columnTitle, projectColorInput); | ||||
|   }); | ||||
|  | ||||
|   $('.new-board').on('input keyup', (e) => { | ||||
|     const boardTitle = $('#new_board'); | ||||
|     const projectColorInput = $('#new_board_color_picker'); | ||||
|     if (!boardTitle.val()) { | ||||
|       $('#new_board_submit').addClass('disabled'); | ||||
|   $('.new-project-column').on('input keyup', (e) => { | ||||
|     const columnTitle = $('#new_project_column'); | ||||
|     const projectColorInput = $('#new_project_column_color_picker'); | ||||
|     if (!columnTitle.val()) { | ||||
|       $('#new_project_column_submit').addClass('disabled'); | ||||
|       return; | ||||
|     } | ||||
|     $('#new_board_submit').removeClass('disabled'); | ||||
|     $('#new_project_column_submit').removeClass('disabled'); | ||||
|     if (e.key === 'Enter') { | ||||
|       const url = $(this).data('url'); | ||||
|       createNewBoard(url, boardTitle, projectColorInput); | ||||
|       createNewColumn(url, columnTitle, projectColorInput); | ||||
|     } | ||||
|   }); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user