Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status filtration #209

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface TypoRepository extends JpaRepository<Typo, Long> {

Page<Typo> findPageTypoByWorkspaceName(Pageable pageable, String name);

Page<Typo> findPageTypoByWorkspaceNameAndTypoStatus(Pageable pageable, String name, TypoStatus status);

Integer deleteTypoById(Long id);

@Query("""
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/io/hexlet/typoreporter/service/TypoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public Page<TypoInfo> getTypoPage(final Pageable pageable, final String wksName)
.map(typoMapper::toTypoInfo);
}

@Transactional(readOnly = true)
public Page<TypoInfo> getTypoPageFiltered(final Pageable pageable, final String wksName, final String typoStatus) {
if (!workspaceService.existsWorkspaceByName(wksName)) {
throw new WorkspaceNotFoundException(wksName);
}

TypoStatus typoStatusEnum;
try {
typoStatusEnum = TypoStatus.valueOf(typoStatus);
} catch (IllegalArgumentException e) {
typoStatusEnum = null;
}

return repository.findPageTypoByWorkspaceNameAndTypoStatus(pageable, wksName, typoStatusEnum)
.map(typoMapper::toTypoInfo);
}

@Transactional(readOnly = true)
public List<Pair<TypoStatus, Long>> getCountTypoByStatusForWorkspaceName(final String wksName) {
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/io/hexlet/typoreporter/web/WorkspaceController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.hexlet.typoreporter.web;

import io.hexlet.typoreporter.domain.account.Account;
import io.hexlet.typoreporter.domain.typo.TypoStatus;
import io.hexlet.typoreporter.domain.workspace.Workspace;
import io.hexlet.typoreporter.domain.workspace.WorkspaceRole;
import io.hexlet.typoreporter.service.AccountService;
Expand Down Expand Up @@ -40,6 +41,7 @@
import org.springframework.web.bind.annotation.RequestParam;

import java.security.Principal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -65,6 +67,11 @@ public class WorkspaceController {

private final TreeSet<Integer> availableSizes = new TreeSet<>(List.of(2, 5, 10, 15, 25));

private final List<TypoStatus> availableStatuses = Arrays.asList(TypoStatus.values());
// .stream()
// .map(status -> status.name().replace("_"," "))
// .collect(Collectors.toList());

private final TypoService typoService;

private final WorkspaceService workspaceService;
Expand Down Expand Up @@ -121,21 +128,30 @@ public String getWorkspaceInfoPage(Model model, @PathVariable String wksName) {
@PreAuthorize(IS_USER_RELATED_TO_WKS)
public String getWorkspaceTyposPage(Model model,
@PathVariable String wksName,
@RequestParam(required = false) String typoStatus,
@SortDefault("createdDate") Pageable pageable) {
var wksOptional = workspaceService.getWorkspaceInfoByName(wksName);
if (wksOptional.isEmpty()) {
//TODO send error page
log.error("Workspace with name {} not found", wksName);
return "redirect:/workspaces";
}

model.addAttribute("wksName", wksName);
model.addAttribute("wksInfo", wksOptional.get());
getStatisticDataToModel(model, wksName);
getLastTypoDataToModel(model, wksName);

var size = Optional.ofNullable(availableSizes.floor(pageable.getPageSize())).orElseGet(availableSizes::first);
var size = Optional.ofNullable(availableSizes.floor(pageable.getPageSize())).orElseGet(availableSizes::first);
var pageRequest = PageRequest.of(pageable.getPageNumber(), size, pageable.getSort());
var typoPage = typoService.getTypoPage(pageRequest, wksName);
Page<TypoInfo> typoPage;
if (typoStatus == null) {
typoPage = typoService.getTypoPage(pageRequest, wksName);
} else {
typoPage = typoService.getTypoPageFiltered(pageRequest, wksName, typoStatus);
model.addAttribute("typoStatus", typoStatus);
model.addAttribute("typoStatusStyle", TypoStatus.valueOf(typoStatus).getStyle());
}

var sort = typoPage.getSort()
.stream()
Expand All @@ -144,6 +160,7 @@ public String getWorkspaceTyposPage(Model model,

model.addAttribute("typoPage", typoPage);
model.addAttribute("availableSizes", availableSizes);
model.addAttribute("availableStatuses", availableStatuses);
model.addAttribute("sortProp", sort.getProperty());
model.addAttribute("sortDir", sort.getDirection());
model.addAttribute("DESC", DESC);
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ RESOLVED=RESOLVED
CANCELED=CANCELED
TOTAL=TOTAL

# TYPO EVENTS
OPEN=OPEN
RESOLVE=RESOLVE
REOPEN=REOPEN
CANCEL=CANCEL

btn.create-account=Create Account
btn.save=Save
btn.close=Close
Expand Down Expand Up @@ -64,6 +70,7 @@ alert.report-success=Error message sent successfully. Thank you!
btn.send=Send
btn.regenerate-token=Regenerate Token
btn.page-size=Page size
btn.page-empty-filter=All statuses

text.leave-comment=Leave additional comment:
text.last-typo-added=Last typo added {0} at {1}
Expand All @@ -75,6 +82,9 @@ text.script-descr=Install this script on your website:

text.modified-info=Modified by {0} {1} at {2}
text.created-info=Created by {0} {1} at {2}
text.created-at=Created at
text.modified-at=Modified at
text.reported-by=Reported by
text.add-user-to-wks=Adding a user to a workspace
text.confirm-delete-user-wks=Are you sure you want to delete user from this workspace?
text.hint-choose-a-user=Choose a user from the list
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/messages_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ RESOLVED=РЕШЕНО
CANCELED=ОТМЕНЕНО
TOTAL=ВСЕГО

# TYPO EVENTS
OPEN=ОТКРЫТЬ
RESOLVE=ВЫПОЛНИТЬ
REOPEN=ОТКРЫТЬ ЗАНОВО
CANCEL=ОТМЕНИТЬ

btn.edit=Изменить
btn.send=Отправить
btn.save=Сохранить
btn.close=Закрыть
btn.create=Создать
btn.page-size=Размер страницы
btn.page-empty-filter=Все статусы
btn.add-to-wks=Добавить в пространство
btn.delete-from-wks=Удалить из пространства
btn.create-account=Создать Аккаунт
Expand Down Expand Up @@ -73,6 +80,9 @@ text.use-header=Используйте заголовок
text.script-descr=Установите этот скрипт на ваш сайт:
text.modified-info=Изменен пользователем {0} {1} в {2}
text.created-info=Создан пользователем {0} {1} в {2}
text.created-at=Создан
text.modified-at=Изменен
text.reported-by=Отправитель
text.add-user-to-wks=Добавить пользователя в пространство
text.confirm-delete-user-wks=Вы действительно хотите удалить пользователя из рабочего пространства?
text.hint-choose-a-user=Выберите пользователя из списка
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/fragments/panels.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<a class="list-group-item list-group-item-action"
th:aria-current="${itemActive} == 'typos'"
th:classappend="${itemActive} == 'typos' ? 'active' : ''"
th:href="@{'/workspace/' + ${wksName} + '/typos'}"
th:href="@{'/workspace/' + ${wksName} + '/typos'(typoStatus=REPORTED)}"
th:text="#{wks.typos}"></a>
<a class="list-group-item list-group-item-action"
th:aria-current="${itemActive} == 'settings'"
Expand Down
Loading
Loading