Initial #1

Merged
ruslan merged 4 commits from master into main 2023-08-19 19:08:07 +00:00
8 changed files with 326 additions and 273 deletions
Showing only changes of commit ef619715e4 - Show all commits

47
pom.xml
View File

@@ -15,6 +15,7 @@
<description>Bad-practice editor</description> <description>Bad-practice editor</description>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<jte.version>3.0.3</jte.version>
<repackage.classifier/> <repackage.classifier/>
<spring-native.version>0.12.1</spring-native.version> <spring-native.version>0.12.1</spring-native.version>
</properties> </properties>
@@ -23,10 +24,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId> <artifactId>spring-boot-starter-webflux</artifactId>
@@ -47,6 +44,17 @@
<version>2.11.0</version> <version>2.11.0</version>
</dependency> </dependency>
<dependency>
<groupId>gg.jte</groupId>
<artifactId>jte</artifactId>
<version>${jte.version}</version>
</dependency>
<dependency>
<groupId>gg.jte</groupId>
<artifactId>jte-spring-boot-starter-2</artifactId>
<version>${jte.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
@@ -110,6 +118,37 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>gg.jte</groupId>
<artifactId>jte-maven-plugin</artifactId>
<version>${jte.version}</version>
<configuration>
<sourceDirectory>${basedir}/src/main/jte</sourceDirectory>
<contentType>Html</contentType>
<targetResourceDirectory>${project.build.directory}/classes</targetResourceDirectory>
<extensions>
<extension>
<className>gg.jte.nativeimage.NativeResourcesExtension</className>
</extension>
</extensions>
</configuration>
<executions>
<execution>
<id>jte-gen</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>gg.jte</groupId>
<artifactId>jte-native-resources</artifactId>
<version>${jte.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins> </plugins>
</build> </build>
<repositories> <repositories>

View File

@@ -0,0 +1,29 @@
package com.github.russp.bpe.config;
import gg.jte.springframework.boot.autoconfigure.ReactiveJteAutoConfiguration;
import gg.jte.springframework.boot.autoconfigure.ReactiveJteViewResolver;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.util.Locale;
@Slf4j
@Configuration
@ImportAutoConfiguration(ReactiveJteAutoConfiguration.class)
@RequiredArgsConstructor
public class JteConfiguration {
private final ReactiveJteViewResolver jteViewResolver;
@PostConstruct
public void vr() {
log.info("ReactiveJteViewResolver created: {}", jteViewResolver);
jteViewResolver.resolveViewName("login", Locale.ENGLISH)
.log()
.block();
}
}

View File

@@ -72,7 +72,7 @@ public class BrowserController {
model.addAttribute("breadcrumbs", breadcrumbs); model.addAttribute("breadcrumbs", breadcrumbs);
model.addAttribute("selectedFile", path); model.addAttribute("selectedFile", path);
model.addAttribute("selectedFileName", Paths.get(path).getFileName()); model.addAttribute("selectedFileName", Paths.get(path).getFileName().toString());
return "edit"; return "edit";
} }

View File

@@ -1,3 +1,9 @@
@import java.util.List
@import com.github.russp.bpe.http.FileDto
@param List<FileDto> files
@param List<FileDto> breadcrumbs
<!DOCTYPE html> <!DOCTYPE html>
<html lang="ru"> <html lang="ru">
<head> <head>
@@ -26,9 +32,9 @@
<nav> <nav>
<ul class="breadcrumbs"> <ul class="breadcrumbs">
<li><a href="/"><i class="fa fa-home"></i></a></li> <li><a href="/"><i class="fa fa-home"></i></a></li>
{{#breadcrumbs}} @for(FileDto breadcrumb : breadcrumbs)
<li><a href="/?path={{fullName}}">{{name}}</a></li> <li><a href="/?path=${breadcrumb.getFullName()}">${breadcrumb.getName()}</a></li>
{{/breadcrumbs}} @endfor
</ul> </ul>
</nav> </nav>
</header> </header>
@@ -47,26 +53,25 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{#files}} @for(FileDto file : files)
<tr> <tr>
<th scope="row"> <th scope="row">
{{#dir}} @if(file.isDir())
<a href="/?path={{fullName}}"> <a href="/?path=${file.getFullName()}">
<i class="fa fa-folder"></i> <i class="fa fa-folder"></i>
{{name}} ${file.getName()}
</a> </a>
{{/dir}} @else
{{^dir}} <a href="/edit?path=${file.getFullName()}">
<a href="/edit?path={{fullName}}">
<i class="fa fa-file"></i> <i class="fa fa-file"></i>
{{name}} ${file.getName()}
</a> </a>
{{/dir}} @endif
</th> </th>
<td>{{modifiedAt}}</td> <td>${file.getModifiedAt()}</td>
<td>{{size}}</td> <td>${file.getSize()}</td>
</tr> </tr>
{{/files}} @endfor
</tbody> </tbody>
</table> </table>
</figure> </figure>

View File

@@ -1,3 +1,14 @@
@import java.util.List
@import org.springframework.security.web.server.csrf.CsrfToken
@import com.github.russp.bpe.http.FileDto
@param String selectedFile
@param String selectedFileName
@param List<FileDto> breadcrumbs
@param CsrfToken _csrf
<!DOCTYPE html> <!DOCTYPE html>
<html lang="ru"> <html lang="ru">
<head> <head>
@@ -5,10 +16,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Browser"> <meta name="description" content="Browser">
<meta name="_csrf" content="{{_csrf.token}}"/> <meta name="_csrf" content="${_csrf.getToken()}"/>
<meta name="_csrf_header" content="{{_csrf.headerName}}"/> <meta name="_csrf_header" content="${_csrf.getHeaderName()}"/>
<title>Edit {{selectedFileName}}</title> <title>Edit ${selectedFileName}</title>
<link rel="shortcut icon" href="https://picocss.com/favicon.ico"> <link rel="shortcut icon" href="https://picocss.com/favicon.ico">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"
@@ -23,14 +34,14 @@
<body> <body>
<header class="container"> <header class="container">
<h5>Edit {{selectedFileName}}</h5> <h5>Edit ${selectedFileName}</h5>
<nav> <nav>
<ul class="breadcrumbs"> <ul class="breadcrumbs">
<li><a href="/"><i class="fa fa-home"></i></a></li> <li><a href="/"><i class="fa fa-home"></i></a></li>
{{#breadcrumbs}} @for(FileDto breadcrumb : breadcrumbs)
<li><a href="/?path={{fullName}}">{{name}}</a></li> <li><a href="/?path=${breadcrumb.getFullName()}">${breadcrumb.getName()}</a></li>
{{/breadcrumbs}} @endfor
<li>{{selectedFileName}}</li> <li>${selectedFileName}</li>
</ul> </ul>
<ul> <ul>
<li><a href="javascript:save()" role="button">Save</a></li> <li><a href="javascript:save()" role="button">Save</a></li>
@@ -71,7 +82,7 @@
<script> <script>
var modelist = require("ace/ext/modelist"); var modelist = require("ace/ext/modelist");
var mode = modelist.getModeForPath("{{selectedFileName}}"); var mode = modelist.getModeForPath("${selectedFileName}");
var editor = ace.edit("editor", var editor = ace.edit("editor",
{ {
mode: mode.mode, mode: mode.mode,
@@ -80,7 +91,7 @@
}); });
document.getElementById('editor').style.fontSize = '1.2em'; document.getElementById('editor').style.fontSize = '1.2em';
fetch('/content?path={{selectedFile}}') fetch('/content?path=${selectedFile}')
.then(function (response) { .then(function (response) {
return response.text() return response.text()
}) })
@@ -94,11 +105,11 @@
var blob = new Blob([editor.getValue()]); var blob = new Blob([editor.getValue()]);
var formData = new FormData(); var formData = new FormData();
formData.set("file", blob); formData.set("file", blob);
fetch('/content?path={{selectedFile}}', { fetch('/content?path=${selectedFile}', {
method: 'POST', method: 'POST',
credentials: 'include', credentials: 'include',
headers: { headers: {
"{{_csrf.headerName}}": "{{_csrf.token}}" "${_csrf.getHeaderName()}": "${_csrf.getToken()}"
}, },
body: formData, body: formData,
}) })

View File

@@ -1,3 +1,7 @@
@import org.springframework.security.web.server.csrf.CsrfToken
@param CsrfToken _csrf
<!DOCTYPE html> <!DOCTYPE html>
<html lang="ru"> <html lang="ru">
<head> <head>
@@ -14,7 +18,7 @@
<!-- Pico.css --> <!-- Pico.css -->
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css"> <link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
<!-- Custom template--> <!-- Custom template-->
<!-- <link rel="stylesheet" href="/stylesheet.css">--> <!-- <link rel="stylesheet" href="/stylesheet.css">-->
<style> <style>
/* Grid */ /* Grid */
@@ -107,7 +111,7 @@
<form method="post"> <form method="post">
<input type="text" name="username" placeholder="Username" aria-label="Login" autocomplete="nickname" required> <input type="text" name="username" placeholder="Username" aria-label="Login" autocomplete="nickname" required>
<input type="password" name="password" placeholder="Password" aria-label="Password" autocomplete="current-password" required> <input type="password" name="password" placeholder="Password" aria-label="Password" autocomplete="current-password" required>
<input type="hidden" name="{{_csrf.parameterName}}" value="{{_csrf.token}}"/> <input type="hidden" name="${_csrf.getParameterName()}" value="${_csrf.getToken()}"/>
<button type="submit" class="contrast">Login</button> <button type="submit" class="contrast">Login</button>
</form> </form>
</div> </div>

View File

@@ -1,35 +0,0 @@
<header class="container">
<hgroup>
<h1>Basic template</h1>
<h2>A basic custom template for Pico using only CSS custom properties (variables).</h2>
</hgroup>
<nav>
<ul>
<li>
<details role="list">
<summary aria-haspopup="listbox" role="button" class="secondary">Theme</summary>
<ul role="listbox">
<li><a href="#" data-theme-switcher="auto">Auto</a></li>
<li><a href="#" data-theme-switcher="light">Light</a></li>
<li><a href="#" data-theme-switcher="dark">Dark</a></li>
</ul>
</details>
</li>
<li>
<details role="list">
<summary aria-haspopup="listbox">Examples</summary>
<ul role="listbox">
<li><a href="../preview/">Preview</a></li>
<li><a href="../preview-rtl/">Right-to-left</a></li>
<li><a href="../classless/">Class-less</a></li>
<li><a href="../basic-template/">Basic template</a></li>
<li><a href="../company/">Company</a></li>
<li><a href="../google-amp/">Google Amp</a></li>
<li><a href="../sign-in/">Sign in</a></li>
<li><a href="../bootstrap-grid/">Bootstrap grid</a></li>
</ul>
</details>
</li>
</ul>
</nav>
</header>