mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-12-21 06:51:19 +08:00
fixed mostly view stuff (#55)
Co-authored-by: MiniDigger <admin@minidigger.me>
This commit is contained in:
parent
1ed562d952
commit
e56ec0ec27
@ -3,7 +3,7 @@
|
||||
[#-- @ftlvariable name="@helper" type="freemarker.template.TemplateHashModel" --]
|
||||
[#-- @ftlvariable name="alerts" type="java.util.Map" --]
|
||||
[#-- @ftlvariable name="routes" type="me.minidigger.hangar.util.RouteHelper" --]
|
||||
[#-- @ftlvariable name="templateHelper" type="me.minidigger.hangar.util.TemplateHelper" --]
|
||||
[#-- @ftlvariable name="rand" type="java.util.Random" --]
|
||||
[#-- @ftlvariable name="headerData" type="me.minidigger.hangar.model.viewhelpers.HeaderData" --]
|
||||
[#-- @ftlvariable name="rc" type="org.springframework.web.servlet.support.RequestContext" --]
|
||||
[#-- @ftlvariable name="config" type="me.minidigger.hangar.config.HangarConfig" --]
|
||||
|
@ -13,12 +13,17 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "hangar")
|
||||
@ComponentScan("me.minidigger.hangar")
|
||||
public class HangarConfig {
|
||||
|
||||
private String logo = "https://paper.readthedocs.io/en/latest/_images/papermc_logomark_500.png";
|
||||
private String service = "Hangar";
|
||||
private List<Sponsor> sponsors;
|
||||
|
||||
private boolean debug = false;
|
||||
private int debugLevel = 3;
|
||||
private boolean staging = true;
|
||||
@ -41,6 +46,37 @@ public class HangarConfig {
|
||||
@NestedConfigurationProperty
|
||||
public HangarApiConfig api;
|
||||
|
||||
@Component
|
||||
public static class Sponsor {
|
||||
private String name;
|
||||
private String image;
|
||||
private String link;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public HangarConfig(FakeUserConfig fakeUser, HangarHomepageConfig homepage, HangarChannelsConfig channels, HangarPagesConfig pages, HangarProjectsConfig projects, HangarUserConfig user, HangarOrgConfig org, HangarApiConfig api) {
|
||||
this.fakeUser = fakeUser;
|
||||
@ -53,6 +89,30 @@ public class HangarConfig {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
|
||||
public String getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(String service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public List<Sponsor> getSponsors() {
|
||||
return sponsors;
|
||||
}
|
||||
|
||||
public void setSponsors(List<Sponsor> sponsors) {
|
||||
this.sponsors = sponsors;
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
@ -8,12 +8,12 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import me.minidigger.hangar.config.HangarConfig;
|
||||
import me.minidigger.hangar.service.MarkdownService;
|
||||
import me.minidigger.hangar.service.UserService;
|
||||
import me.minidigger.hangar.util.RouteHelper;
|
||||
import me.minidigger.hangar.util.TemplateHelper;
|
||||
|
||||
public abstract class HangarController {
|
||||
|
||||
@ -22,8 +22,6 @@ public abstract class HangarController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private TemplateHelper templateHelper;
|
||||
@Autowired
|
||||
private HangarConfig hangarConfig;
|
||||
@Autowired
|
||||
private MarkdownService markdownService;
|
||||
@ -31,13 +29,13 @@ public abstract class HangarController {
|
||||
protected ModelAndView fillModel(ModelAndView mav) {
|
||||
// helpers
|
||||
mav.addObject("routes", routeHelper);
|
||||
mav.addObject("templateHelper", templateHelper);
|
||||
BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_30);
|
||||
builder.setExposeFields(true);
|
||||
builder.setUseModelCache(true);
|
||||
mav.addObject("@helper", builder.build().getStaticModels());
|
||||
mav.addObject("config", hangarConfig);
|
||||
mav.addObject("markdownService", markdownService);
|
||||
mav.addObject("rand", ThreadLocalRandom.current());
|
||||
|
||||
// alerts
|
||||
if (mav.getModelMap().getAttribute("alerts") == null) {
|
||||
|
@ -16,7 +16,7 @@ public class RolesTable {
|
||||
private long permission;
|
||||
|
||||
public static RolesTable fromRole(Role role) {
|
||||
return new RolesTable(role.getRoleId(), role.getValue(), role.getCategory(), role.getTitle(), role.getColor().getHex(), role.isAssignable(), null, role.getPermissions().getValue());
|
||||
return new RolesTable(role.getRoleId(), role.getValue(), role.getCategory(), role.getTitle(), role.getColor().getHex(), role.isAssignable(), role.getRank(), role.getPermissions().getValue());
|
||||
}
|
||||
|
||||
public RolesTable() {
|
||||
|
@ -26,11 +26,11 @@ public enum Role {
|
||||
CONTRIBUTOR("Contributor", 12, GLOBAL, None, "Contributor", GREEN),
|
||||
ADVISOR("Advisor", 13, GLOBAL, None, "Advisor", AQUA),
|
||||
|
||||
STONE_DONOR("Stone_Donor", 14, GLOBAL, None, "Stone Donor", GRAY),
|
||||
QUARTZ_DONOR("Quartz_Donor",15, GLOBAL, None, "Quartz Donor", QUARTZ),
|
||||
IRON_DONOR("Iron_Donor",16, GLOBAL, None, "Iron Donor", SILVER),
|
||||
GOLD_DONOR("Gold_Donor",17, GLOBAL, None, "Gold Donor", GOLD),
|
||||
DIAMOND_DONOR("Diamond_Donor",18, GLOBAL, None, "Diamond Donor", LIGHTBLUE),
|
||||
STONE_DONOR("Stone_Donor", 14, GLOBAL, None, "Stone Donor", GRAY, 5L),
|
||||
QUARTZ_DONOR("Quartz_Donor",15, GLOBAL, None, "Quartz Donor", QUARTZ, 4L),
|
||||
IRON_DONOR("Iron_Donor",16, GLOBAL, None, "Iron Donor", SILVER, 3L),
|
||||
GOLD_DONOR("Gold_Donor",17, GLOBAL, None, "Gold Donor", GOLD, 2L),
|
||||
DIAMOND_DONOR("Diamond_Donor",18, GLOBAL, None, "Diamond Donor", LIGHTBLUE, 1L),
|
||||
|
||||
PROJECT_SUPPORT("Project_Support", 22, PROJECT, IsProjectMember, "Support", TRANSPARENT),
|
||||
PROJECT_EDITOR("Project_Editor", 21, PROJECT, EditPage.add(PROJECT_SUPPORT.getPermissions()), "Editor", TRANSPARENT),
|
||||
@ -51,11 +51,17 @@ public enum Role {
|
||||
private String title;
|
||||
private Color color;
|
||||
private boolean isAssignable;
|
||||
private Long rank = null;
|
||||
|
||||
Role(String value, int roleId, RoleCategory category, Permission permissions, String title, Color color) {
|
||||
this(value, roleId, category, permissions, title, color, true);
|
||||
}
|
||||
|
||||
Role(String value, int roleId, RoleCategory category, Permission permissions, String title, Color color, Long rank) {
|
||||
this(value, roleId, category, permissions, title, color);
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
Role(String value, int roleId, RoleCategory category, Permission permissions, String title, Color color, boolean isAssignable) {
|
||||
this.value = value;
|
||||
this.roleId = roleId;
|
||||
@ -94,6 +100,10 @@ public enum Role {
|
||||
return isAssignable;
|
||||
}
|
||||
|
||||
public Long getRank() {
|
||||
return rank;
|
||||
}
|
||||
|
||||
public static Role fromTitle(String title) {
|
||||
for (Role r : values()) {
|
||||
if (r.title.equals(title)) {
|
||||
|
@ -73,4 +73,8 @@ public class Author {
|
||||
public void setCount(long count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getAvatarUrl() {
|
||||
return "https://paper.readthedocs.io/en/latest/_images/papermc_logomark_500.png"; // TODO figure out what to do with avatar url
|
||||
}
|
||||
}
|
||||
|
@ -53,4 +53,8 @@ public class Staff {
|
||||
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public String getAvatarUrl() {
|
||||
return "https://paper.readthedocs.io/en/latest/_images/papermc_logomark_500.png"; // TODO figure out what to do with avatar url
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package me.minidigger.hangar.util;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class TemplateHelper {
|
||||
|
||||
public Map<String, String> randomSponsor() {
|
||||
// TODO implement random sponsor stuff
|
||||
return Map.of("link", "https://minidigger.me", "image", "https://avatars2.githubusercontent.com/u/2185527?s=400&v=4");
|
||||
}
|
||||
}
|
@ -35,6 +35,14 @@ hangar:
|
||||
staging: true
|
||||
log-timings: false
|
||||
|
||||
sponsors:
|
||||
- name: Theranos
|
||||
image: https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Theranos_Logo.svg/1200px-Theranos_Logo.svg.png
|
||||
link: https://en.wikipedia.org/wiki/Theranos
|
||||
- name: MiniDigger
|
||||
image: https://avatars2.githubusercontent.com/u/2185527?s=400&v=4
|
||||
link: https://minidigger.me
|
||||
|
||||
homepage:
|
||||
update-interval: 10m
|
||||
|
||||
|
@ -23,6 +23,11 @@ sorted according to different criteria.
|
||||
<meta property="og:description" content="<@spring.message "general.description" />" />
|
||||
</#macro>
|
||||
|
||||
<#function randomSponsor>
|
||||
<#local index = rand.nextInt(config.getSponsors()?size) />
|
||||
<#return config.sponsors[index] />
|
||||
</#function>
|
||||
|
||||
<#assign message><@spring.message "general.title" /></#assign>
|
||||
<#assign scriptsVar><@scripts /></#assign>
|
||||
<#assign stylesheetsVar><@stylesheets /></#assign>
|
||||
@ -46,9 +51,10 @@ sorted according to different criteria.
|
||||
<div class="panel sponsor-panel">
|
||||
<span>Sponsored by</span>
|
||||
<div class="panel-body">
|
||||
<#assign sponsor=templateHelper.randomSponsor() />
|
||||
<#-- @ftlvariable name="sponsor" type="me.minidigger.hangar.config.HangarConfig.Sponsor" -->
|
||||
<#assign sponsor=randomSponsor() />
|
||||
<a href="${sponsor.link}">
|
||||
<img class="logo" src="${sponsor.image}" alt="Sponsor" />
|
||||
<img class="logo" src="${sponsor.image}" alt="${sponsor.name}" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
@pageSize = @{ config.ore.users.authorPageSize }
|
||||
-->
|
||||
<#assign pageSize=config.user.authorPageSize />
|
||||
|
||||
<#function direction>
|
||||
<#if ordering?startsWith("-")>
|
||||
@ -40,6 +41,7 @@
|
||||
<script <#--@CSPNonce.attr-->>CURRENT_PAGE = ${page};</script>
|
||||
</#assign>
|
||||
|
||||
<#-- @ftlvariable name="page" type="java.lang.Integer" -->
|
||||
<@base.base title="Authors - Hangar" additionalScripts=scriptsVar>
|
||||
<#assign UserOrdering = @helper["me.minidigger.hangar.model.UserOrdering"]>
|
||||
<#-- @ftlvariable name="UserOrdering" type="me.minidigger.hangar.model.UserOrdering" -->
|
||||
@ -70,13 +72,13 @@
|
||||
<#list authors as author>
|
||||
<tr>
|
||||
<#import "*/utils/userAvatar.ftlh" as userAvatar>
|
||||
<td><@userAvatar.userAvatar userName=author.name avatarUrl=User.avatarUrl(author.name) clazz="user-avatar-xs"></@userAvatar.userAvatar></td>
|
||||
<td><@userAvatar.userAvatar userName=author.name avatarUrl=author.avatarUrl clazz="user-avatar-xs"></@userAvatar.userAvatar></td>
|
||||
<td>
|
||||
<a href="${routes.getRouteUrl("users.showProjects", author.name)}">${author.name}</a>
|
||||
</td>
|
||||
<td>
|
||||
<#if author.donatorRole??>
|
||||
<span class="channel channel-sm" style="background-color: ${role.color.hex}">
|
||||
<span class="channel channel-sm" style="background-color: ${author.donatorRole.color.hex}">
|
||||
${author.donatorRole}
|
||||
</span>
|
||||
</#if>
|
||||
|
@ -2,10 +2,6 @@
|
||||
<#import "*/utils/hangar.ftlh" as hangar />
|
||||
<#import "*/layout/base.ftlh" as base>
|
||||
|
||||
<#--
|
||||
@(staff: Seq[(String, Role, Option[OffsetDateTime], OffsetDateTime)], ordering: String, page: Int)(implicit messages: Messages, request: OreRequest[_], config: OreConfig, flash: Flash, assetsFinder: AssetsFinder)
|
||||
-->
|
||||
|
||||
<#function direction>
|
||||
<#if ordering?startsWith("-")>
|
||||
<#return "chevron-down">
|
||||
@ -50,22 +46,23 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<#list staff as user>
|
||||
<#list staff as staffUser>
|
||||
<tr>
|
||||
<#import "*/utils/userAvatar.ftlh" as userAvatar>
|
||||
<td><@userAvatar.userAvatar userName=user.name avatarUrl=User.avatarUrl(user.name) clazz="user-avatar-xs"></@userAvatar.userAvatar></td>
|
||||
<td><@userAvatar.userAvatar userName=staffUser.name avatarUrl=staffUser.avatarUrl clazz="user-avatar-xs"></@userAvatar.userAvatar></td>
|
||||
<td>
|
||||
<a href="${routes.getRouteUrl("showActivities", user.name)}">${user.name}</a>
|
||||
<a href="${routes.getRouteUrl("showActivities", staffUser.name)}">${staffUser.name}</a>
|
||||
</td>
|
||||
<td>
|
||||
<span class="user-role channel" style="background-color: ${user.role.color.hex}">
|
||||
${user.role.title}
|
||||
<span class="user-role channel" style="background-color: ${staffUser.role.color.hex}">
|
||||
${staffUser.role.title}
|
||||
</span>
|
||||
</td>
|
||||
<td>${(user.joinDate!user.createdAt).format("yyyy-MM-dd")}</td>
|
||||
<td>${(staffUser.joinDate!staffUser.createdAt).format("yyyy-MM-dd")}</td>
|
||||
</tr>
|
||||
</#list>
|
||||
|
||||
<#-- @ftlvariable name="page" type="java.lang.Integer" -->
|
||||
<#-- @ftlvariable name="pageSize" type="java.lang.Integer" -->
|
||||
<#if page gt 1 || staff?size gte pageSize>
|
||||
<tr class="authors-footer">
|
||||
<td></td>
|
||||
|
Loading…
Reference in New Issue
Block a user