Add more info text to version creation

This commit is contained in:
Nassim Jahnke 2022-07-29 19:49:42 +02:00 committed by MiniDigger | Martin
parent 4474a191ea
commit 861c827643
7 changed files with 39 additions and 29 deletions

View File

@ -415,10 +415,13 @@
},
"platforms": "Platforms",
"platformVersions": "Platform Versions",
"platformVersionsDescription": "Please select at least one version per platform that your resource is compatible with. You can still change platform versions and dependencies after the initial version creation.",
"versionDescription": "Enter the name of the version as well as its channel.",
"tags": "Version Tags",
"dependencies": "Dependencies",
"changelogTitle": "What's new?",
"artifactTitle": "You can either upload a jar file or link to an external site.",
"artifactTitle": "You can either upload a file or set an external download url. Each file/url needs at least one platform selected.",
"artifactNumber": "Download #{0}",
"externalLinkAlert": "An external link needs to be a direct download link!",
"addedArtifacts": "Provided Artifacts"
},

View File

@ -265,12 +265,11 @@ useHead(
<template>
<Steps v-model="selectedStep" :steps="steps" button-lang-key="version.new.steps.">
<template #artifact>
<p class="mb-2">{{ t("version.new.form.artifactTitle") }}</p>
<p class="mb-4">{{ t("version.new.form.artifactTitle") }}</p>
<!-- todo: make prettier, translations -->
<div v-for="(platformFile, idx) in platformFiles" :key="idx" class="mb-8">
<span class="text-xl">File #{{ idx + 1 }}</span>
<div class="flex flex-row items-center">
<div v-for="(platformFile, idx) in platformFiles" :key="idx" class="mb-6">
<span class="text-xl">{{ t("version.new.form.artifactNumber", [idx + 1]) }}</span>
<div class="md:(flex flex-row) items-center">
<Tabs v-model="platformFile.selectedTab" :tabs="selectedUploadTabs" :vertical="false" class="max-w-150">
<template #file>
<InputFile v-model="platformFile.file" accept=".jar,.zip" />
@ -279,7 +278,7 @@ useHead(
<InputText v-model="platformFile.url" :label="t('version.new.form.externalUrl')" :rules="artifactURLRules" />
</template>
</Tabs>
<div class="mt-4 ml-8">
<div class="mt-4 md:ml-8">
<div v-for="platform in platforms" :key="platform.name">
<InputCheckbox
:model-value="platformFile.platforms.includes(platform.enumName)"
@ -290,7 +289,7 @@ useHead(
</InputCheckbox>
</div>
</div>
<Button v-if="platformFiles.length !== 1" class="ml-4 mt-4" @click="removePlatformFile(idx)"><IconMdiDelete /></Button>
<Button v-if="platformFiles.length !== 1" class="md:ml-4 mt-4" @click="removePlatformFile(idx)"><IconMdiDelete /></Button>
</div>
<div></div>
</div>
@ -299,6 +298,7 @@ useHead(
</Button>
</template>
<template #basic>
<p class="mb-4">{{ i18n.t("version.new.form.versionDescription") }}</p>
<div class="flex flex-wrap mt-2 md:-space-x-2 <md:space-y-2">
<!-- TODO validate version string against existing versions - now super easy! -->
<div class="basis-full md:basis-4/12 items-center">
@ -344,6 +344,7 @@ useHead(
</div>
</template>
<template #dependencies>
<p class="mb-4">{{ i18n.t("version.new.form.platformVersionsDescription") }}</p>
<h2 class="text-xl mt-2 mb-2">{{ t("version.new.form.platformVersions") }}</h2>
<div class="flex flex-wrap gap-y-3 mb-5">
<div v-for="platform in selectedPlatformsData" :key="platform.enumName" class="basis-full">

View File

@ -154,7 +154,7 @@ public class ProjectFactory extends HangarComponent {
@Transactional
public void hardDelete(final ProjectTable projectTable, final String comment) {
this.actionLogger.project(LogAction.PROJECT_VISIBILITY_CHANGED.create(ProjectContext.of(projectTable.getId()), "Deleted: " + comment, projectTable.getVisibility().getTitle()));
FileUtils.deleteDirectory(this.projectFiles.getProjectDir(projectTable.getOwnerName(), projectTable.getName()));
FileUtils.deleteDirectory(this.projectFiles.getProjectDir(projectTable.getOwnerName(), projectTable.getSlug()));
this.jobService.save(new DeleteDiscourseTopicJob(projectTable.getId()));
this.projectsDAO.delete(projectTable);
this.projectService.refreshHomeProjects();

View File

@ -6,6 +6,7 @@ import io.papermc.hangar.util.FileUtils;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.function.Predicate;
import java.util.stream.Stream;
import org.slf4j.Logger;
@ -49,20 +50,20 @@ public class ProjectFiles {
}
public void transferProject(String owner, String newOwner, String slug) {
Path newProjectDir = getProjectDir(owner, slug);
Path oldProjectDir = getProjectDir(newOwner, slug);
final Path oldProjectDir = getProjectDir(newOwner, slug);
final Path newProjectDir = getProjectDir(owner, slug);
try {
Files.move(oldProjectDir, newProjectDir);
Files.move(oldProjectDir, newProjectDir, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
public void renameProject(String owner, String slug, String newSlug) {
final Path newProjectDir = getProjectDir(owner, newSlug);
final Path oldProjectDir = getProjectDir(owner, slug);
final Path newProjectDir = getProjectDir(owner, newSlug);
try {
Files.move(oldProjectDir, newProjectDir);
Files.move(oldProjectDir, newProjectDir, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
@ -72,8 +73,8 @@ public class ProjectFiles {
final Path oldVersionDir = getVersionDir(owner, slug, version);
final Path newVersionDir = getVersionDir(owner, slug, newVersionName);
try {
Files.move(oldVersionDir, newVersionDir);
} catch (IOException e) {
Files.move(oldVersionDir, newVersionDir, StandardCopyOption.REPLACE_EXISTING);
} catch (final IOException e) {
e.printStackTrace();
}
}

View File

@ -96,13 +96,13 @@ public class DownloadService extends HangarComponent {
final ProjectVersionPlatformDownloadTable platformDownload = downloadsDAO.getPlatformDownload(pvt.getVersionId(), platform);
final ProjectVersionDownloadTable download = downloadsDAO.getDownload(platformDownload.getVersionId(), platformDownload.getDownloadId());
if (download.getFileName() == null) {
throw new HangarApiException("Couldn't find a file for that version");
throw new HangarApiException("Couldn't find a file for version " + versionString);
}
ProjectTable project = projectsDAO.getById(pvt.getProjectId());
Path path = projectFiles.getVersionDir(project.getOwnerName(), project.getName(), versionString, platform).resolve(download.getFileName());
Path path = projectFiles.getVersionDir(project.getOwnerName(), project.getSlug(), versionString, platform).resolve(download.getFileName());
if (Files.notExists(path)) {
throw new HangarApiException("Couldn't find a file for that version");
throw new HangarApiException("Couldn't find a file for version " + versionString);
}
if (requiresConfirmation(pvt, download)) {

View File

@ -251,7 +251,7 @@ public class VersionFactory extends HangarComponent {
}
ProjectVersionTable projectVersionTable = null;
final Path versionDir = projectFiles.getVersionDir(projectTable.getOwnerName(), projectTable.getName(), pendingVersion.getVersionString());
final Path versionDir = projectFiles.getVersionDir(projectTable.getOwnerName(), projectTable.getSlug(), pendingVersion.getVersionString());
try {
ProjectChannelTable projectChannelTable = channelService.getProjectChannel(projectId, pendingVersion.getChannelName(), pendingVersion.getChannelColor());
if (projectChannelTable == null) {

View File

@ -3,6 +3,7 @@ package io.papermc.hangar.service.internal.versions;
import io.papermc.hangar.HangarComponent;
import io.papermc.hangar.controller.extras.pagination.filters.versions.VersionChannelFilter;
import io.papermc.hangar.controller.extras.pagination.filters.versions.VersionPlatformFilter;
import io.papermc.hangar.db.dao.internal.table.projects.ProjectsDAO;
import io.papermc.hangar.db.dao.internal.table.versions.ProjectVersionsDAO;
import io.papermc.hangar.db.dao.internal.versions.HangarVersionsDAO;
import io.papermc.hangar.db.dao.v1.VersionsApiDAO;
@ -23,17 +24,16 @@ import io.papermc.hangar.service.internal.visibility.ProjectVersionVisibilitySer
import io.papermc.hangar.service.internal.visibility.ProjectVisibilityService;
import io.papermc.hangar.util.FileUtils;
import io.papermc.hangar.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
@Service
public class VersionService extends HangarComponent {
@ -44,9 +44,10 @@ public class VersionService extends HangarComponent {
private final ProjectVersionVisibilityService projectVersionVisibilityService;
private final VersionDependencyService versionDependencyService;
private final ProjectFiles projectFiles;
private final ProjectsDAO projectsDAO;
@Autowired
public VersionService(ProjectVersionsDAO projectVersionDAO, VersionsApiDAO versionsApiDAO, HangarVersionsDAO hangarProjectsDAO, ProjectVisibilityService projectVisibilityService, ProjectVersionVisibilityService projectVersionVisibilityService, VersionDependencyService versionDependencyService, ProjectFiles projectFiles) {
public VersionService(ProjectVersionsDAO projectVersionDAO, VersionsApiDAO versionsApiDAO, HangarVersionsDAO hangarProjectsDAO, ProjectVisibilityService projectVisibilityService, ProjectVersionVisibilityService projectVersionVisibilityService, VersionDependencyService versionDependencyService, ProjectFiles projectFiles, final ProjectsDAO projectsDAO) {
this.projectVersionsDAO = projectVersionDAO;
this.versionsApiDAO = versionsApiDAO;
this.hangarVersionsDAO = hangarProjectsDAO;
@ -54,6 +55,7 @@ public class VersionService extends HangarComponent {
this.projectVersionVisibilityService = projectVersionVisibilityService;
this.versionDependencyService = versionDependencyService;
this.projectFiles = projectFiles;
this.projectsDAO = projectsDAO;
}
@Nullable
@ -131,16 +133,19 @@ public class VersionService extends HangarComponent {
}
Visibility oldVisibility = pvt.getVisibility();
renameVersion(pvt, pvt.getVersionString() + ProjectFactory.SOFT_DELETION_SUFFIX + deletedId);
projectVersionVisibilityService.changeVisibility(pvt, Visibility.SOFTDELETE, comment);
actionLogger.version(LogAction.VERSION_DELETED.create(VersionContext.of(projectId, pvt.getId()), "Soft Delete: " + comment, oldVisibility.getTitle()));
renameVersion(pvt, pvt.getVersionString() + ProjectFactory.SOFT_DELETION_SUFFIX + deletedId);
}
private void renameVersion(final ProjectVersionTable projectVersionTable, final String newName) {
final String compactNewName = StringUtils.compact(newName);
projectVersionTable.setVersionString(compactNewName);
this.projectVersionsDAO.update(projectVersionTable);
//projectFiles.renameVersion(); //TODO rename version files
final ProjectTable project = projectsDAO.getById(projectVersionTable.getProjectId());
//TODO bork?
projectFiles.renameVersion(project.getOwnerName(), project.getSlug(), projectVersionTable.getVersionString(), compactNewName);
}
@Transactional
@ -153,7 +158,7 @@ public class VersionService extends HangarComponent {
actionLogger.version(LogAction.VERSION_DELETED.create(VersionContext.of(pt.getId(), pvt.getId()), "Deleted: " + comment, pvt.getVisibility().getTitle()));
projectVersionsDAO.delete(pvt);
FileUtils.deleteDirectory(projectFiles.getVersionDir(pt.getOwnerName(), pt.getName(), pvt.getVersionString()));
FileUtils.deleteDirectory(projectFiles.getVersionDir(pt.getOwnerName(), pt.getSlug(), pvt.getVersionString()));
}
@Transactional