1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-31 02:22:27 +00:00

#79: Change background and logo image

This commit is contained in:
jendib
2016-05-08 17:25:21 +02:00
parent f5394534f7
commit 4d79dd7076
13 changed files with 153 additions and 32 deletions

View File

@@ -107,7 +107,7 @@ public class FileResource extends BaseResource {
String mimeType;
try {
mimeType = MimeTypeUtil.guessMimeType(fileInputStream);
} catch (Exception e) {
} catch (IOException e) {
throw new ServerException("ErrorGuessMime", "Error guessing mime type", e);
}
if (mimeType == null) {

View File

@@ -1,22 +1,31 @@
package com.sismics.docs.rest.resource;
import javax.json.*;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import com.google.common.base.Strings;
import com.google.common.io.ByteStreams;
import com.sismics.docs.core.constant.ConfigType;
import com.sismics.docs.core.dao.jpa.ConfigDao;
import com.sismics.docs.core.model.jpa.Config;
import com.sismics.docs.core.util.DirectoryUtil;
import com.sismics.docs.rest.constant.BaseFunction;
import com.sismics.rest.exception.ClientException;
import com.sismics.rest.exception.ForbiddenClientException;
import com.sismics.rest.exception.ServerException;
import com.sismics.rest.util.JsonUtil;
import com.sismics.rest.util.ValidationUtil;
import com.sismics.util.css.Selector;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataParam;
import javax.json.*;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Map;
/**
@@ -26,6 +35,10 @@ import java.util.Map;
*/
@Path("/theme")
public class ThemeResource extends BaseResource {
// Filenames for images in theme directory
private static final String LOGO_IMAGE = "logo";
private static final String BACKGROUND_IMAGE = "background";
/**
* Returns custom CSS stylesheet.
*
@@ -116,10 +129,63 @@ public class ThemeResource extends BaseResource {
throw new ForbiddenClientException();
}
checkBaseFunction(BaseFunction.ADMIN);
if (logoBodyPart == null && backgrounBodyPart == null) {
throw new ClientException("NoImageProvided", "logo or background is required");
}
// Only a background or a logo is handled
FormDataBodyPart bodyPart = logoBodyPart == null ? backgrounBodyPart : logoBodyPart;
String type = logoBodyPart == null ? BACKGROUND_IMAGE : LOGO_IMAGE;
java.nio.file.Path filePath = DirectoryUtil.getThemeDirectory().resolve(type);
// Copy the image to the theme directory
try (InputStream inputStream = bodyPart.getValueAs(InputStream.class)) {
Files.copy(inputStream, filePath, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new ServerException("CopyError", "Error copying the image to the theme directory", e);
}
return Response.ok().build();
}
@GET
@Produces("image/*")
@Path("image/{type: logo|background}")
public Response getImage(@PathParam("type") final String type) {
if (!LOGO_IMAGE.equals(type) && !BACKGROUND_IMAGE.equals(type)) {
throw new ClientException("InvalidType", "Type must be logo or background");
}
final java.nio.file.Path filePath = DirectoryUtil.getThemeDirectory().resolve(type);
// Copy the image to the response output
return Response.ok(new StreamingOutput() {
@Override
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
InputStream inputStream = null;
try {
if (Files.exists(filePath)) {
inputStream = Files.newInputStream(filePath);
} else {
inputStream = getClass().getResource("/image/" + (type.equals(LOGO_IMAGE) ? "logo.png" : "background.jpg")).openStream();
}
ByteStreams.copy(inputStream, outputStream);
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
outputStream.close();
} catch (IOException e) {
// Ignore
}
}
}
})
.header("Content-Type", "image/*")
.build();
}
/**
* Returns the theme configuration object.
*

View File

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -93,7 +93,7 @@ module.exports = function(grunt) {
},
replace: {
dist: {
src: ['dist/docs.min.js', 'dist/share.min.js', 'dist/**/*.html'],
src: ['dist/docs.min.js', 'dist/share.min.js', 'dist/**/*.html', 'dist/style/style.min.css'],
overwrite: true,
replacements: [{
from: '../api',

View File

@@ -4,7 +4,7 @@
<title ng-bind-template="{{ appName }}">Sismics Docs</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="favicon.png" />
<link rel="shortcut icon" href="../api/theme/image/logo" />
<!-- ref:css style/style.min.css -->
<link rel="stylesheet" href="style/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="style/colorpicker.css" type="text/css" />
@@ -100,7 +100,7 @@
</button>
<div class="hidden-xs navbar-text navbar-logo">
<img src="favicon.png" />
<img src="../api/theme/image/logo" />
</div>
<a class="navbar-brand" href="#"> {{ appName }}</a>

View File

@@ -46,7 +46,7 @@
<div class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<div class="hidden-xs navbar-text navbar-logo">
<img src="favicon.png" />
<img src="../api/theme/image/logo" />
</div>
<a class="navbar-brand" href="#"> {{ appName }}</a>

View File

@@ -156,10 +156,6 @@ input[readonly].share-link {
// Pagination box
.pagination-box {
pagination {
vertical-align: top;
}
select {
vertical-align: top;
width: auto;
@@ -234,7 +230,7 @@ input[readonly].share-link {
// Login
.login-box-container {
background: url('../img/background.jpg') no-repeat center;
background: url('../../api/theme/image/background') no-repeat center;
}
.login-box {