mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-01-18 14:14:50 +08:00
rebased
This commit is contained in:
parent
04af2b164f
commit
195ec2196b
133
src/main/frontend/src/components/BBCodeConverter.vue
Normal file
133
src/main/frontend/src/components/BBCodeConverter.vue
Normal file
@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<HangarModal target-id="convert-modal" modal-class="modal-xl">
|
||||
<template v-slot:activator>
|
||||
<button type="button" class="btn btn-secondary btn-block" data-toggle="modal" data-target="#convert-modal">
|
||||
Convert project description from Spigot
|
||||
</button>
|
||||
</template>
|
||||
<template v-slot:modal-content>
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="convert-modal-label">Convert project description</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" id="convert-tab" data-toggle="tab" href="#convert" role="tab" aria-controls="convert" aria-selected="true"
|
||||
>Convert</a
|
||||
>
|
||||
</li>
|
||||
<li class="nav-item" @click="showMDPreview">
|
||||
<a class="nav-link" id="preview-tab" data-toggle="tab" href="#preview" role="tab" aria-controls="preview" aria-selected="false"
|
||||
>Preview</a
|
||||
>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" id="howto-tab" data-toggle="tab" href="#getbbcode" role="tab" aria-controls="getbbcode" aria-selected="false"
|
||||
>How to get the BBCode</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content" id="convert-content">
|
||||
<div class="tab-pane fade show active" id="convert" role="tabpanel" aria-labelledby="convert-tab">
|
||||
<div class="container-fluid" id="converter-windows">
|
||||
<textarea
|
||||
v-model="input"
|
||||
class="form-control"
|
||||
id="input-window"
|
||||
rows="12"
|
||||
cols="50"
|
||||
aria-label="Input"
|
||||
placeholder="Paste your BBCode here:"
|
||||
></textarea>
|
||||
<div class="py-3 text-center">
|
||||
<button type="button" class="btn btn-primary" @click="convert">
|
||||
Convert
|
||||
<i class="ml-1 fas fa-arrows-alt-v"></i>
|
||||
</button>
|
||||
</div>
|
||||
<textarea
|
||||
v-model="output"
|
||||
class="form-control"
|
||||
id="output-window"
|
||||
rows="12"
|
||||
cols="50"
|
||||
aria-label="Output"
|
||||
placeholder="Output:"
|
||||
></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="preview" role="tabpanel" aria-labelledby="preview-tab" v-html="outputHtml"></div>
|
||||
<div class="tab-pane fade" id="getbbcode" role="tabpanel" aria-labelledby="howto-tab">
|
||||
To get the BBCode of your Spigot project, do the following:
|
||||
<br />1. Go to your project and click on "Edit Resource".
|
||||
<img src="https://i.imgur.com/8CyLMf3.png" alt="Edit Project" />
|
||||
<br /><br />Click on the wrench symbol in the description editor.
|
||||
<img src="https://i.imgur.com/FLVIuQK.png" width="425" height="198" alt="Show BBCode" />
|
||||
<br /><br />Copy paste the new contents into the upper converter texbox, do changes to the output if you like, and hit save!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal" :disabled="!output" @click="saveOutput">Save and Close</button>
|
||||
<button type="button" class="btn btn-warning" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</HangarModal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from 'axios';
|
||||
|
||||
import HangarModal from '@/components/HangarModal';
|
||||
export default {
|
||||
name: 'BBCodeConverter',
|
||||
emits: ['update:proj-page-content'],
|
||||
components: { HangarModal },
|
||||
props: {
|
||||
projPageContent: String,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
input: '',
|
||||
output: '',
|
||||
outputHtml: '',
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
convert() {
|
||||
axios
|
||||
.post(
|
||||
window.ROUTES.parse('PAGES_BB_CONVERT'),
|
||||
{
|
||||
raw: this.input,
|
||||
},
|
||||
window.ajaxSettings
|
||||
)
|
||||
.then((res) => {
|
||||
this.output = res.data;
|
||||
});
|
||||
},
|
||||
showMDPreview() {
|
||||
axios
|
||||
.post(
|
||||
window.ROUTES.parse('PAGES_SHOW_PREVIEW'),
|
||||
{
|
||||
raw: this.output,
|
||||
},
|
||||
window.ajaxSettings
|
||||
)
|
||||
.then((res) => {
|
||||
this.outputHtml = res.data;
|
||||
});
|
||||
},
|
||||
saveOutput() {
|
||||
this.$emit('update:proj-page-content', this.output);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
@ -126,6 +126,11 @@
|
||||
<input id="keywords-input" name="keywords" type="text" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 text-center"><span class="input-divider">BBCode</span></div>
|
||||
<div class="col-12">
|
||||
<input type="hidden" name="pageContent" v-model="form.pageContent" />
|
||||
<BBCodeConverter v-model:proj-page-content="form.pageContent"></BBCodeConverter>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@ -151,10 +156,12 @@
|
||||
import axios from 'axios';
|
||||
import HangarForm from '@/components/HangarForm';
|
||||
import { Category } from '@/enums';
|
||||
import BBCodeConverter from '@/components/BBCodeConverter';
|
||||
|
||||
export default {
|
||||
name: 'CreateProject',
|
||||
components: {
|
||||
BBCodeConverter,
|
||||
HangarForm,
|
||||
},
|
||||
data() {
|
||||
@ -171,6 +178,7 @@ export default {
|
||||
description: '',
|
||||
licenseType: '',
|
||||
customName: '',
|
||||
pageContent: '',
|
||||
},
|
||||
categories: Category.values,
|
||||
};
|
||||
|
@ -3,6 +3,7 @@ import '@fortawesome/fontawesome-svg-core/styles.css';
|
||||
import {
|
||||
faArrowLeft,
|
||||
faArrowRight,
|
||||
faArrowsAltV,
|
||||
faAsterisk,
|
||||
faBell,
|
||||
faBirthdayCake,
|
||||
@ -178,7 +179,8 @@ library.add(
|
||||
faQuestion,
|
||||
faTag,
|
||||
faGavel,
|
||||
faBirthdayCake
|
||||
faBirthdayCake,
|
||||
faArrowsAltV
|
||||
);
|
||||
|
||||
dom.watch();
|
||||
|
@ -1,41 +0,0 @@
|
||||
import $ from 'jquery';
|
||||
|
||||
function showMDPreview() {
|
||||
let preview = document.getElementById('preview');
|
||||
let text = document.getElementById('output-window').value;
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '/pages/preview',
|
||||
data: JSON.stringify({ raw: text }),
|
||||
contentType: 'application/json',
|
||||
dataType: 'html',
|
||||
success: function (result) {
|
||||
preview.innerHTML = result;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// https://github.com/JonDum/BBCode-To-Markdown-Converter/blob/gh-pages/index.js
|
||||
function convert() {
|
||||
let input = document.getElementById('input-window');
|
||||
let output = document.getElementById('output-window');
|
||||
|
||||
let inputValue = input.value;
|
||||
//TODO request to controller
|
||||
output.value = inputValue;
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$.ajaxSetup(window.ajaxSettings);
|
||||
document.getElementById('preview-tab').onclick = function () {
|
||||
showMDPreview();
|
||||
};
|
||||
|
||||
let input = document.getElementById('input-window');
|
||||
input.onchange = function () {
|
||||
convert();
|
||||
};
|
||||
input.onkeyup = function () {
|
||||
convert();
|
||||
};
|
||||
});
|
@ -1,6 +1,7 @@
|
||||
package io.papermc.hangar.controller;
|
||||
|
||||
import io.papermc.hangar.controller.forms.PagePreview;
|
||||
import io.papermc.hangar.controller.forms.RawPage;
|
||||
import io.papermc.hangar.controller.util.BBCodeConverter;
|
||||
import io.papermc.hangar.db.customtypes.LoggedActionType;
|
||||
import io.papermc.hangar.db.customtypes.LoggedActionType.ProjectPageContext;
|
||||
import io.papermc.hangar.db.dao.HangarDao;
|
||||
@ -67,10 +68,16 @@ public class PagesController extends HangarController {
|
||||
}
|
||||
|
||||
@PostMapping(value = "/pages/preview", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<String> showPreview(@RequestBody PagePreview rawObj) {
|
||||
public ResponseEntity<String> showPreview(@RequestBody RawPage rawObj) {
|
||||
return ResponseEntity.ok(markdownService.render(rawObj.getRaw()));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/pages/bb-convert", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<String> bbConverter(@RequestBody RawPage rawObj) {
|
||||
BBCodeConverter bbCodeConverter = new BBCodeConverter();
|
||||
return ResponseEntity.ok(bbCodeConverter.convertToMarkdown(rawObj.getRaw()));
|
||||
}
|
||||
|
||||
@GetMapping({"/{author}/{slug}/pages/{page}", "/{author}/{slug}/pages/{page}/{subPage}"})
|
||||
public ModelAndView show(@PathVariable String author, @PathVariable String slug, @PathVariable String page, @PathVariable(required = false) String subPage) {
|
||||
ProjectData projData = projectData.get();
|
||||
|
@ -183,6 +183,7 @@ public class ProjectsController extends HangarController {
|
||||
generalDao.get().refreshHomeProjects();
|
||||
|
||||
return Routes.PROJECTS_SHOW.getRedirect(project.getOwnerName(), project.getSlug());
|
||||
// return Routes.PROJECTS_SHOW_CREATOR.getRedirect();
|
||||
}
|
||||
|
||||
private ProjectOwner getProjectOwner(long owner) {
|
||||
|
@ -16,6 +16,8 @@ public class NewProjectForm {
|
||||
private String licenseName;
|
||||
private String licenseUrl;
|
||||
|
||||
private String pageContent;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -111,4 +113,31 @@ public class NewProjectForm {
|
||||
public void setLicenseUrl(String licenseUrl) {
|
||||
this.licenseUrl = licenseUrl;
|
||||
}
|
||||
|
||||
public String getPageContent() {
|
||||
return pageContent;
|
||||
}
|
||||
|
||||
public void setPageContent(String pageContent) {
|
||||
this.pageContent = pageContent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NewProjectForm{" +
|
||||
"name='" + name + '\'' +
|
||||
", category='" + category + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", owner=" + owner +
|
||||
", homepageUrl='" + homepageUrl + '\'' +
|
||||
", issueTrackerUrl='" + issueTrackerUrl + '\'' +
|
||||
", sourceUrl='" + sourceUrl + '\'' +
|
||||
", externalSupportUrl='" + externalSupportUrl + '\'' +
|
||||
", keywords='" + keywords + '\'' +
|
||||
", licenseType='" + licenseType + '\'' +
|
||||
", licenseName='" + licenseName + '\'' +
|
||||
", licenseUrl='" + licenseUrl + '\'' +
|
||||
", pageContent='" + pageContent + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PagePreview {
|
||||
public class RawPage {
|
||||
|
||||
@NotNull
|
||||
private final String raw;
|
||||
|
||||
@JsonCreator
|
||||
public PagePreview(@JsonProperty(value = "raw", required = true) @NotNull String raw) {
|
||||
public RawPage(@JsonProperty(value = "raw", required = true) @NotNull String raw) {
|
||||
this.raw = raw;
|
||||
}
|
||||
|
@ -93,8 +93,11 @@ public class ProjectFactory {
|
||||
|
||||
ProjectChannelsTable channelsTable = new ProjectChannelsTable(hangarConfig.channels.getNameDefault(), hangarConfig.channels.getColorDefault(), -1, false);
|
||||
|
||||
String content = "# " + projectsTable.getName() + "\n\n" + hangarConfig.pages.home.getMessage();
|
||||
ProjectPagesTable pagesTable = new ProjectPage(-1, hangarConfig.pages.home.getName(), StringUtils.slugify(hangarConfig.pages.home.getName()), content, false, null);
|
||||
String newPageContent = StringUtils.stringOrNull(newProjectForm.getPageContent());
|
||||
if (newPageContent == null) {
|
||||
newPageContent = "# " + projectsTable.getName() + "\n\n" + hangarConfig.pages.home.getMessage();
|
||||
}
|
||||
ProjectPagesTable pagesTable = new ProjectPage(-1, hangarConfig.pages.home.getName(), StringUtils.slugify(hangarConfig.pages.home.getName()), newPageContent, false, null);
|
||||
|
||||
checkProjectAvailability(ownerUser, projectsTable.getName());
|
||||
|
||||
|
@ -88,6 +88,7 @@ public enum Routes {
|
||||
VERSIONS_SHOW_CREATOR_WITH_META("versions.showCreatorWithMeta", Paths.VERSIONS_SHOW_CREATOR_WITH_META, of("author", "slug", "version"), of()),
|
||||
VERSIONS_CONFIRM_DOWNLOAD("versions.confirmDownload", Paths.VERSIONS_CONFIRM_DOWNLOAD, of("author", "slug", "version"), of("downloadType", "token", "dummy")),
|
||||
PAGES_SHOW_PREVIEW("pages.showPreview", Paths.PAGES_SHOW_PREVIEW, of(), of()),
|
||||
PAGES_BB_CONVERT("pages.bbConvert", Paths.PAGES_BB_CONVERT, of(), of()),
|
||||
PAGES_SAVE("pages.save", Paths.PAGES_SAVE, of("author", "slug", "page"), of()),
|
||||
PAGES_SHOW_EDITOR("pages.showEditor", Paths.PAGES_SHOW_EDITOR, of("author", "slug", "page"), of()),
|
||||
PAGES_SHOW("pages.show", Paths.PAGES_SHOW, of("author", "slug", "page"), of()),
|
||||
@ -306,6 +307,7 @@ public enum Routes {
|
||||
public static final String VERSIONS_CONFIRM_DOWNLOAD = "/{author}/{slug}/versions/{version}/confirm";
|
||||
|
||||
public static final String PAGES_SHOW_PREVIEW = "/pages/preview";
|
||||
public static final String PAGES_BB_CONVERT = "/pages/bb-convert";
|
||||
public static final String PAGES_SAVE = "/{author}/{slug}/pages/{page}/edit";
|
||||
public static final String PAGES_SHOW_EDITOR = "/{author}/{slug}/pages/{page}/edit";
|
||||
public static final String PAGES_SHOW = "/{author}/{slug}/pages/{page}";
|
||||
|
Loading…
Reference in New Issue
Block a user