Example #1
0
  @Authenticated(value = {LoggedIn.class, HasRole.class})
  @Authorized(value = "admin")
  @Transactional
  @RequireCSRFCheck
  public Result postCreateArchive() {
    Form<ArchiveUpsertForm> archiveUpsertForm =
        Form.form(ArchiveUpsertForm.class).bindFromRequest();

    if (formHasErrors(archiveUpsertForm)) {
      return showCreateArchive(0, archiveUpsertForm);
    }

    ArchiveUpsertForm archiveUpsertData = archiveUpsertForm.get();
    if (!archiveUpsertData.parentJid.isEmpty()
        && !archiveService.archiveExistsByJid(archiveUpsertData.parentJid)) {
      archiveUpsertForm.reject(Messages.get("error.archive.notExist"));

      return showCreateArchive(0, archiveUpsertForm);
    }

    long archiveId =
        archiveService.createArchive(
            archiveUpsertData.parentJid,
            archiveUpsertData.name,
            archiveUpsertData.description,
            IdentityUtils.getUserJid(),
            IdentityUtils.getIpAddress());

    return redirect(routes.ArchiveController.viewArchives(archiveId));
  }
Example #2
0
  @Authenticated(value = {LoggedIn.class, HasRole.class})
  @Authorized(value = "admin")
  @Transactional
  @RequireCSRFCheck
  public Result postEditArchive(long archiveId) throws ArchiveNotFoundException {
    Archive archive = archiveService.findArchiveById(archiveId);
    Form<ArchiveUpsertForm> archiveUpsertForm =
        Form.form(ArchiveUpsertForm.class).bindFromRequest();

    if (formHasErrors(archiveUpsertForm)) {
      return showEditArchive(archiveUpsertForm, archive);
    }

    ArchiveUpsertForm archiveUpsertData = archiveUpsertForm.get();
    archiveService.updateArchive(
        archive.getJid(),
        archiveUpsertData.parentJid,
        archiveUpsertData.name,
        archiveUpsertData.description,
        IdentityUtils.getUserJid(),
        IdentityUtils.getIpAddress());

    return redirect(routes.ArchiveController.viewArchives(archive.getId()));
  }
Example #3
0
  private Result showListArchivesProblemSets(
      long archiveId, long pageIndex, String orderBy, String orderDir, String filterString)
      throws ArchiveNotFoundException {
    Archive archive = archiveService.findArchiveById(archiveId);
    Archive parentArchive = archive.getParentArchive();

    LazyHtml content;
    if (!JerahmeelUtils.isGuest()) {
      List<ArchiveWithScore> childArchivesWithScore =
          archiveService.getChildArchivesWithScore(archive.getJid(), IdentityUtils.getUserJid());
      Page<ProblemSetWithScore> pageOfProblemSetsWithScore =
          problemSetService.getPageOfProblemSetsWithScore(
              archive,
              IdentityUtils.getUserJid(),
              pageIndex,
              PAGE_SIZE,
              orderBy,
              orderDir,
              filterString);

      content =
          new LazyHtml(
              listArchivesAndProblemSetsWithScoreView.render(
                  archive,
                  childArchivesWithScore,
                  pageOfProblemSetsWithScore,
                  orderBy,
                  orderDir,
                  filterString));
    } else {
      List<Archive> childArchives = archiveService.getChildArchives(archive.getJid());
      Page<ProblemSet> pageOfProblemSets =
          problemSetService.getPageOfProblemSets(
              archive, pageIndex, PAGE_SIZE, orderBy, orderDir, filterString);

      content =
          new LazyHtml(
              listArchivesAndProblemSetsView.render(
                  archive, childArchives, pageOfProblemSets, orderBy, orderDir, filterString));
    }

    if (!archive.getDescription().isEmpty()) {
      content.appendLayout(c -> descriptionHtmlLayout.render(archive.getDescription(), c));
    }

    final String parentArchiveName;
    final Call backCall;
    if (parentArchive == null) {
      parentArchiveName = Messages.get("training.home");
      backCall = org.iatoki.judgels.jerahmeel.training.routes.TrainingController.index();
    } else {
      parentArchiveName = parentArchive.getName();
      backCall = routes.ArchiveController.viewArchives(parentArchive.getId());
    }

    if (JerahmeelUtils.hasRole("admin")) {
      ImmutableList.Builder<InternalLink> actionsBuilder = ImmutableList.builder();
      actionsBuilder.add(
          new InternalLink(
              Messages.get("commons.button.edit"),
              routes.ArchiveController.editArchive(archiveId)));
      actionsBuilder.add(
          new InternalLink(
              Messages.get("archive.create"), routes.ArchiveController.createArchive(archiveId)));
      actionsBuilder.add(
          new InternalLink(
              Messages.get("archive.problemSet.create"),
              org.iatoki.judgels.jerahmeel.problemset.routes.ProblemSetController.createProblemSet(
                  archive.getId())));

      content.appendLayout(
          c ->
              headingWithActionsAndBackLayout.render(
                  Messages.get("archive.archive") + " " + archive.getName(),
                  actionsBuilder.build(),
                  new InternalLink(
                      Messages.get("archive.backTo") + " " + parentArchiveName, backCall),
                  c));
    } else {
      content.appendLayout(
          c ->
              headingWithBackLayout.render(
                  archive.getName(),
                  new InternalLink(
                      Messages.get("archive.backTo") + " " + parentArchiveName, backCall),
                  c));
    }

    JerahmeelControllerUtils.getInstance().appendSidebarLayout(content);

    ImmutableList.Builder<InternalLink> breadcrumbsBuilder = ImmutableList.builder();
    ArchiveControllerUtils.fillBreadcrumbsBuilder(breadcrumbsBuilder, archive);
    ArchiveControllerUtils.appendBreadcrumbsLayout(content, breadcrumbsBuilder.build());
    JerahmeelControllerUtils.getInstance().appendTemplateLayout(content, "Archives");

    return JerahmeelControllerUtils.getInstance().lazyOk(content);
  }